Commit d7943e32 authored by chrishenry@google.com's avatar chrishenry@google.com

Add ActionRunner wrapper for the remaining less used actions (try 2):

RepaintContinouosly
ReloadAction
PinchAction
ScrollBounceAction
Play/Seek/LoopAction (media actions)

Changes in try 2: fixed missing change to pinch.js, also
revamped documentation for scroll bounce gesture.

BUG=361809

Review URL: https://codereview.chromium.org/346923003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282218 0039d316-1c4b-4281-b951-d872f2087c98
parent 093318e5
...@@ -18,7 +18,7 @@ class TestRepaintPage(page_module.Page): ...@@ -18,7 +18,7 @@ class TestRepaintPage(page_module.Page):
page_set, base_dir) page_set, base_dir)
def RunRepaint(self, action_runner): def RunRepaint(self, action_runner):
action_runner.RunAction(RepaintContinuouslyAction({'seconds': 2})) action_runner.RepaintContinuously(seconds=2)
class RepaintUnitTest( class RepaintUnitTest(
......
...@@ -22,7 +22,7 @@ class GmailRefreshPage(page_module.Page): ...@@ -22,7 +22,7 @@ class GmailRefreshPage(page_module.Page):
self.archive_data_file = 'data/gmail_refresh.json' self.archive_data_file = 'data/gmail_refresh.json'
def RunEndure(self, action_runner): def RunEndure(self, action_runner):
action_runner.RunAction(ReloadAction({'seconds': 2})) action_runner.ReloadPage()
class GmailRefreshPageSet(page_set_module.PageSet): class GmailRefreshPageSet(page_set_module.PageSet):
......
...@@ -23,7 +23,7 @@ class KeyMobileSitesPage(page_module.Page): ...@@ -23,7 +23,7 @@ class KeyMobileSitesPage(page_module.Page):
interaction.End() interaction.End()
def RunRepaint(self, action_runner): def RunRepaint(self, action_runner):
action_runner.RunAction(RepaintContinuouslyAction({'seconds': 5})) action_runner.RepaintContinuously(seconds=5)
class Page1(KeyMobileSitesPage): class Page1(KeyMobileSitesPage):
......
...@@ -14,37 +14,22 @@ class BasicPlayPage(page_module.Page): ...@@ -14,37 +14,22 @@ class BasicPlayPage(page_module.Page):
self.add_browser_metrics = True self.add_browser_metrics = True
def PlayAction(self, action_runner): def PlayAction(self, action_runner):
action_runner.RunAction(PlayAction( action_runner.PlayMedia(playing_event_timeout_in_seconds=60,
{ ended_event_timeout_in_seconds=60)
'wait_for_playing': True,
'wait_for_ended': True
}))
def RunMediaMetrics(self, action_runner): def RunMediaMetrics(self, action_runner):
self.PlayAction(action_runner) self.PlayAction(action_runner)
def SeekBeforeAndAfterPlayhead(self, action_runner): def SeekBeforeAndAfterPlayhead(self, action_runner):
action_runner.RunAction(PlayAction( action_runner.PlayMedia(playing_event_timeout_in_seconds=60)
{
'wait_for_playing': True,
'wait_for_ended': False
}))
# Wait for 1 second so that we know the play-head is at ~1s. # Wait for 1 second so that we know the play-head is at ~1s.
action_runner.Wait(1) action_runner.Wait(1)
# Seek to before the play-head location. # Seek to before the play-head location.
action_runner.RunAction(SeekAction( action_runner.SeekMedia(seconds=0.5, timeout_in_seconds=60,
{ label='seek_warm')
'seek_time': '0.5',
'wait_for_seeked': True,
'seek_label': 'seek_warm'
}))
# Seek to after the play-head location. # Seek to after the play-head location.
action_runner.RunAction(SeekAction( action_runner.SeekMedia(seconds=15, timeout_in_seconds=60,
{ label='seek_cold')
'seek_time': 15,
'wait_for_seeked': True,
'seek_label': 'seek_cold'
}))
class SeekBeforeAndAfterPlayheadPage(BasicPlayPage): class SeekBeforeAndAfterPlayheadPage(BasicPlayPage):
......
...@@ -30,7 +30,7 @@ class GmailPage(MobileMemoryPage): ...@@ -30,7 +30,7 @@ class GmailPage(MobileMemoryPage):
self.credentials = 'google' self.credentials = 'google'
def ReloadAndGc(self, action_runner): def ReloadAndGc(self, action_runner):
action_runner.RunAction(ReloadAction()) action_runner.ReloadPage()
action_runner.Wait(15) action_runner.Wait(15)
action_runner.ForceGarbageCollection() action_runner.ForceGarbageCollection()
......
...@@ -31,10 +31,7 @@ class Top25Page(page_module.Page): ...@@ -31,10 +31,7 @@ class Top25Page(page_module.Page):
interaction.End() interaction.End()
def RunRepaint(self, action_runner): def RunRepaint(self, action_runner):
action_runner.RunAction(RepaintContinuouslyAction( action_runner.RepaintContinuously(seconds=5)
{
'seconds': 5
}))
class GoogleWebSearchPage(Top25Page): class GoogleWebSearchPage(Top25Page):
......
...@@ -16,7 +16,7 @@ class Top2012Q3Page(page.Page): ...@@ -16,7 +16,7 @@ class Top2012Q3Page(page.Page):
self.archive_data_file = 'data/2012Q3.json' self.archive_data_file = 'data/2012Q3.json'
def ReloadAndGc(self, action_runner): def ReloadAndGc(self, action_runner):
action_runner.RunAction(ReloadAction()) action_runner.ReloadPage()
action_runner.Wait(1) action_runner.Wait(1)
action_runner.ForceGarbageCollection() action_runner.ForceGarbageCollection()
......
...@@ -17,7 +17,10 @@ class ToughPinchZoomCasesPage(page_module.Page): ...@@ -17,7 +17,10 @@ class ToughPinchZoomCasesPage(page_module.Page):
self.archive_data_file = 'data/tough_pinch_zoom_cases.json' self.archive_data_file = 'data/tough_pinch_zoom_cases.json'
def RunSmoothness(self, action_runner): def RunSmoothness(self, action_runner):
action_runner.RunAction(PinchAction()) interaction = action_runner.BeginGestureInteraction(
'PinchAction', is_smooth=True)
action_runner.PinchPage()
interaction.End()
class GoogleSearchPage(ToughPinchZoomCasesPage): class GoogleSearchPage(ToughPinchZoomCasesPage):
...@@ -68,11 +71,10 @@ class GoogleCalendarPage(ToughPinchZoomCasesPage): ...@@ -68,11 +71,10 @@ class GoogleCalendarPage(ToughPinchZoomCasesPage):
action_runner.Wait(2) action_runner.Wait(2)
def RunSmoothness(self, action_runner): def RunSmoothness(self, action_runner):
action_runner.RunAction(PinchAction( interaction = action_runner.BeginGestureInteraction(
{ 'PinchAction', is_smooth=True)
'left_anchor_percentage': 0.1, action_runner.PinchPage(left_anchor_ratio=0.1, top_anchor_ratio=0.3)
'top_anchor_percentage': 0.3 interaction.End()
}))
class GoogleImageSearchPage(ToughPinchZoomCasesPage): class GoogleImageSearchPage(ToughPinchZoomCasesPage):
...@@ -103,13 +105,10 @@ class GooglePlusPage(ToughPinchZoomCasesPage): ...@@ -103,13 +105,10 @@ class GooglePlusPage(ToughPinchZoomCasesPage):
action_runner.WaitForElement(text='Home') action_runner.WaitForElement(text='Home')
def RunSmoothness(self, action_runner): def RunSmoothness(self, action_runner):
action_runner.RunAction(PinchAction( interaction = action_runner.BeginGestureInteraction(
{ 'PinchAction', is_smooth=True)
'element_function': ''' action_runner.PinchElement(selector='110031535020051778989-tab-bar')
function(callback) { interaction.End()
callback(document.getElementById("110031535020051778989-tab-bar"))
}'''
}))
class YoutubePage(ToughPinchZoomCasesPage): class YoutubePage(ToughPinchZoomCasesPage):
...@@ -237,13 +236,10 @@ class YahooAnswersPage(ToughPinchZoomCasesPage): ...@@ -237,13 +236,10 @@ class YahooAnswersPage(ToughPinchZoomCasesPage):
page_set=page_set) page_set=page_set)
def RunSmoothness(self, action_runner): def RunSmoothness(self, action_runner):
action_runner.RunAction(PinchAction( interaction = action_runner.BeginGestureInteraction(
{ 'PinchAction', is_smooth=True)
'element_function': ''' action_runner.PinchElement(selector='ya-content-apps')
function(callback) { interaction.End()
callback(document.getElementById("ya-content-apps"))
}'''
}))
class ToughPinchZoomCasesPageSet(page_set_module.PageSet): class ToughPinchZoomCasesPageSet(page_set_module.PageSet):
......
...@@ -338,7 +338,10 @@ class EmptyTouchHandlerPage(ToughSchedulingCasesPage): ...@@ -338,7 +338,10 @@ class EmptyTouchHandlerPage(ToughSchedulingCasesPage):
def RunSmoothness(self, action_runner): def RunSmoothness(self, action_runner):
if self.bounce: if self.bounce:
action_runner.RunAction(ScrollBounceAction()) interaction = action_runner.BeginGestureInteraction(
'ScrollBounceAction', is_smooth=True)
action_runner.ScrollBouncePage()
interaction.End()
else: else:
interaction = action_runner.BeginGestureInteraction( interaction = action_runner.BeginGestureInteraction(
'ScrollAction', is_smooth=True) 'ScrollAction', is_smooth=True)
...@@ -359,7 +362,10 @@ class SynchronizedScrollOffsetPage(ToughSchedulingCasesPage): ...@@ -359,7 +362,10 @@ class SynchronizedScrollOffsetPage(ToughSchedulingCasesPage):
page_set=page_set) page_set=page_set)
def RunSmoothness(self, action_runner): def RunSmoothness(self, action_runner):
action_runner.RunAction(ScrollBounceAction()) interaction = action_runner.BeginGestureInteraction(
'ScrollBounceAction', is_smooth=True)
action_runner.ScrollBouncePage()
interaction.End()
class ToughSchedulingCasesPageSet(page_set_module.PageSet): class ToughSchedulingCasesPageSet(page_set_module.PageSet):
......
...@@ -13,54 +13,28 @@ class ToughVideoCasesPage(page_module.Page): ...@@ -13,54 +13,28 @@ class ToughVideoCasesPage(page_module.Page):
super(ToughVideoCasesPage, self).__init__(url=url, page_set=page_set) super(ToughVideoCasesPage, self).__init__(url=url, page_set=page_set)
def LoopMixedAudio(self, action_runner): def LoopMixedAudio(self, action_runner):
action_runner.RunAction(PlayAction( action_runner.PlayMedia(selector='#background_audio',
{ playing_event_timeout_in_seconds=60)
'wait_for_playing': True, action_runner.LoopMedia(loop_count=50, selector='#mixed_audio')
'wait_for_ended': False,
'selector': '#background_audio'
}))
action_runner.RunAction(LoopAction(
{
'loop_count': 50,
'selector': '#mixed_audio'
}))
def LoopSingleAudio(self, action_runner): def LoopSingleAudio(self, action_runner):
action_runner.RunAction(LoopAction( action_runner.LoopMedia(loop_count=50, selector='#single_audio')
{
'loop_count': 50,
'selector': '#single_audio'
}))
def PlayAction(self, action_runner): def PlayAction(self, action_runner):
action_runner.RunAction(PlayAction( action_runner.PlayMedia(playing_event_timeout_in_seconds=60,
{ ended_event_timeout_in_seconds=60)
'wait_for_playing': True,
'wait_for_ended': True
}))
def SeekBeforeAndAfterPlayhead(self, action_runner): def SeekBeforeAndAfterPlayhead(self, action_runner):
action_runner.RunAction(PlayAction( action_runner.PlayMedia(playing_event_timeout_in_seconds=60,
{ ended_event_timeout_in_seconds=60)
'wait_for_playing': True,
'wait_for_ended': False
}))
# Wait for 1 second so that we know the play-head is at ~1s. # Wait for 1 second so that we know the play-head is at ~1s.
action_runner.Wait(1) action_runner.Wait(1)
# Seek to before the play-head location. # Seek to before the play-head location.
action_runner.RunAction(SeekAction( action_runner.SeekMedia(seconds=0.5, timeout_in_seconds=60,
{ label='seek_warm')
'seek_time': '0.5',
'wait_for_seeked': True,
'seek_label': 'seek_warm'
}))
# Seek to after the play-head location. # Seek to after the play-head location.
action_runner.RunAction(SeekAction( action_runner.SeekMedia(seconds=9, timeout_in_seconds=60,
{ label='seek_cold')
'seek_time': '9',
'wait_for_seeked': True,
'seek_label': 'seek_cold'
}))
class Page1(ToughVideoCasesPage): class Page1(ToughVideoCasesPage):
......
...@@ -3,17 +3,6 @@ ...@@ -3,17 +3,6 @@
# found in the LICENSE file. # found in the LICENSE file.
# pylint: disable=W0611 # pylint: disable=W0611
# TODO(nednguyen): Remove all of these imports when we done porting all actions # TODO(chrishenry): File no longer does anything. Delete once all import is
# to action_runner # deleted.
from telemetry.page.actions.loop import LoopAction
from telemetry.page.actions.media_action import MediaAction
from telemetry.page.actions.pinch import PinchAction
from telemetry.page.actions.play import PlayAction
from telemetry.page.actions.reload import ReloadAction
# pylint: disable=C0301 # pylint: disable=C0301
from telemetry.page.actions.repaint_continuously import (
RepaintContinuouslyAction)
from telemetry.page.actions.scroll import ScrollAction
from telemetry.page.actions.scroll_bounce import ScrollBounceAction
from telemetry.page.actions.seek import SeekAction
from telemetry.page.actions.swipe import SwipeAction
...@@ -4,14 +4,12 @@ ...@@ -4,14 +4,12 @@
"""A Telemetry page_action that loops media playback. """A Telemetry page_action that loops media playback.
Action attributes are: Action parameters are:
- loop_count: The number of times to loop media. - loop_count: The number of times to loop media.
- selector: If no selector is defined then the action attempts to loop the first - selector: If no selector is defined then the action attempts to loop the first
media element on the page. If 'all' then loop all media elements. media element on the page. If 'all' then loop all media elements.
- wait_timeout_in_seconds: Timeout to wait for media to loop. Default is - timeout_in_seconds: Timeout to wait for media to loop. Default is
60 sec x loop_count. 60 sec x loop_count. 0 means do not wait.
- wait_for_loop: If true, forces the action to wait for last loop to end,
otherwise it starts the loops and exit. Default true.
""" """
from telemetry.core import exceptions from telemetry.core import exceptions
...@@ -20,6 +18,13 @@ from telemetry.page.actions import page_action ...@@ -20,6 +18,13 @@ from telemetry.page.actions import page_action
class LoopAction(media_action.MediaAction): class LoopAction(media_action.MediaAction):
def __init__(self, loop_count, selector=None, timeout_in_seconds=None):
super(LoopAction, self).__init__()
self._loop_count = loop_count
self._selector = selector if selector else ''
self._timeout_in_seconds = (
timeout_in_seconds if timeout_in_seconds else 60 * loop_count)
def WillRunAction(self, tab): def WillRunAction(self, tab):
"""Load the media metrics JS code prior to running the action.""" """Load the media metrics JS code prior to running the action."""
super(LoopAction, self).WillRunAction(tab) super(LoopAction, self).WillRunAction(tab)
...@@ -27,18 +32,10 @@ class LoopAction(media_action.MediaAction): ...@@ -27,18 +32,10 @@ class LoopAction(media_action.MediaAction):
def RunAction(self, tab): def RunAction(self, tab):
try: try:
assert hasattr(self, 'loop_count') and self.loop_count > 0
selector = self.selector if hasattr(self, 'selector') else ''
tab.ExecuteJavaScript('window.__loopMedia("%s", %i);' % tab.ExecuteJavaScript('window.__loopMedia("%s", %i);' %
(selector, self.loop_count)) (self._selector, self._loop_count))
timeout_in_seconds = ( if self._timeout_in_seconds > 0:
self.wait_timeout_in_seconds if hasattr(self, self.WaitForEvent(tab, self._selector, 'loop', self._timeout_in_seconds)
'wait_timeout_in_seconds')
else 60 * self.loop_count)
# Check if there is no need to wait for all loops to end
if hasattr(self, 'wait_for_loop') and not self.wait_for_loop:
return
self.WaitForEvent(tab, selector, 'loop', timeout_in_seconds)
except exceptions.EvaluateException: except exceptions.EvaluateException:
raise page_action.PageActionFailed('Cannot loop media element(s) with ' raise page_action.PageActionFailed('Cannot loop media element(s) with '
'selector = %s.' % selector) 'selector = %s.' % self._selector)
...@@ -21,8 +21,7 @@ class LoopActionTest(tab_test_case.TabTestCase): ...@@ -21,8 +21,7 @@ class LoopActionTest(tab_test_case.TabTestCase):
@decorators.Disabled('android') @decorators.Disabled('android')
def testLoopWithNoSelector(self): def testLoopWithNoSelector(self):
"""Tests that with no selector Loop action loops first media element.""" """Tests that with no selector Loop action loops first media element."""
data = {'selector': '#video_1', 'loop_count': 2} action = loop.LoopAction(loop_count=2, selector='#video_1')
action = loop.LoopAction(data)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
action.RunAction(self._tab) action.RunAction(self._tab)
# Assert only first video has played. # Assert only first video has played.
...@@ -32,8 +31,7 @@ class LoopActionTest(tab_test_case.TabTestCase): ...@@ -32,8 +31,7 @@ class LoopActionTest(tab_test_case.TabTestCase):
@decorators.Disabled('android') @decorators.Disabled('android')
def testLoopWithAllSelector(self): def testLoopWithAllSelector(self):
"""Tests that Loop action loops all video elements with selector='all'.""" """Tests that Loop action loops all video elements with selector='all'."""
data = {'selector': 'all', 'loop_count': 2} action = loop.LoopAction(loop_count=2, selector='all')
action = loop.LoopAction(data)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
# Both videos not playing before running action. # Both videos not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
...@@ -46,18 +44,8 @@ class LoopActionTest(tab_test_case.TabTestCase): ...@@ -46,18 +44,8 @@ class LoopActionTest(tab_test_case.TabTestCase):
@decorators.Disabled('android') @decorators.Disabled('android')
def testLoopWaitForLoopTimeout(self): def testLoopWaitForLoopTimeout(self):
"""Tests that wait_for_loop timeout_in_secondss if video does not loop.""" """Tests that wait_for_loop timeout_in_secondss if video does not loop."""
data = {'selector': '#video_1', action = loop.LoopAction(loop_count=2, selector='#video_1',
'wait_timeout_in_seconds': 1, timeout_in_seconds=1)
'loop_count': 2}
action = loop.LoopAction(data)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_LOOP_CHECK))
self.assertRaises(util.TimeoutException, action.RunAction, self._tab) self.assertRaises(util.TimeoutException, action.RunAction, self._tab)
@decorators.Disabled('android')
def testLoopWithoutLoopCount(self):
"""Tests that loop action fails with no loop count."""
data = {}
action = loop.LoopAction(data)
action.WillRunAction(self._tab)
self.assertRaises(AssertionError, action.RunAction, self._tab)
...@@ -13,14 +13,14 @@ ...@@ -13,14 +13,14 @@
function PinchGestureOptions(opt_options) { function PinchGestureOptions(opt_options) {
if (opt_options) { if (opt_options) {
this.element_ = opt_options.element; this.element_ = opt_options.element;
this.left_anchor_percentage_ = opt_options.left_anchor_percentage; this.left_anchor_ratio_ = opt_options.left_anchor_ratio;
this.top_anchor_percentage_ = opt_options.top_anchor_percentage; this.top_anchor_ratio_ = opt_options.top_anchor_ratio;
this.scale_factor_ = opt_options.scale_factor; this.scale_factor_ = opt_options.scale_factor;
this.speed_ = opt_options.speed; this.speed_ = opt_options.speed;
} else { } else {
this.element_ = document.body; this.element_ = document.body;
this.left_anchor_percentage_ = 0.5; this.left_anchor_ratio_ = 0.5;
this.top_anchor_percentage_ = 0.5; this.top_anchor_ratio_ = 0.5;
this.scale_factor_ = 2.0; this.scale_factor_ = 2.0;
this.speed_ = 800; this.speed_ = 800;
} }
...@@ -54,9 +54,9 @@ ...@@ -54,9 +54,9 @@
var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_); var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_);
var anchor_left = var anchor_left =
rect.left + rect.width * this.options_.left_anchor_percentage_; rect.left + rect.width * this.options_.left_anchor_ratio_;
var anchor_top = var anchor_top =
rect.top + rect.height * this.options_.top_anchor_percentage_; rect.top + rect.height * this.options_.top_anchor_ratio_;
chrome.gpuBenchmarking.pinchBy(this.options_.scale_factor_, chrome.gpuBenchmarking.pinchBy(this.options_.scale_factor_,
anchor_left, anchor_top, anchor_left, anchor_top,
this.onGestureComplete_.bind(this), this.onGestureComplete_.bind(this),
......
...@@ -7,8 +7,22 @@ from telemetry.page.actions.gesture_action import GestureAction ...@@ -7,8 +7,22 @@ from telemetry.page.actions.gesture_action import GestureAction
from telemetry.page.actions import page_action from telemetry.page.actions import page_action
class PinchAction(GestureAction): class PinchAction(GestureAction):
def __init__(self, attributes=None): def __init__(self, selector=None, text=None, element_function=None,
super(PinchAction, self).__init__(attributes) left_anchor_ratio=0.5, top_anchor_ratio=0.5,
scale_factor=None, speed_in_pixels_per_second=800):
super(PinchAction, self).__init__()
self.automatically_record_interaction = False
self._selector = selector
self._text = text
self._element_function = element_function
self._left_anchor_ratio = left_anchor_ratio
self._top_anchor_ratio = top_anchor_ratio
self._scale_factor = scale_factor
self._speed = speed_in_pixels_per_second
if (self._selector is None and self._text is None and
self._element_function is None):
self._element_function = 'document.body'
def WillRunAction(self, tab): def WillRunAction(self, tab):
for js_file in ['gesture_common.js', 'pinch.js']: for js_file in ['gesture_common.js', 'pinch.js']:
...@@ -49,36 +63,25 @@ class PinchAction(GestureAction): ...@@ -49,36 +63,25 @@ class PinchAction(GestureAction):
return 3.0 / current_scale_factor return 3.0 / current_scale_factor
def RunGesture(self, tab): def RunGesture(self, tab):
left_anchor_percentage = getattr(self, 'left_anchor_percentage', 0.5) scale_factor = (self._scale_factor if self._scale_factor else
top_anchor_percentage = getattr(self, 'top_anchor_percentage', 0.5) PinchAction._GetDefaultScaleFactorForPage(tab))
scale_factor = getattr(self, 'scale_factor', code = '''
PinchAction._GetDefaultScaleFactorForPage(tab)) function(element, info) {
speed = getattr(self, 'speed_in_pixels_per_second', 800) if (!element) {
throw Error('Cannot find element: ' + info);
if hasattr(self, 'element_function'): }
tab.ExecuteJavaScript(""" window.__pinchAction.start({
(%s)(function(element) { window.__pinchAction.start( element: element,
{ element: element, left_anchor_ratio: %s,
left_anchor_percentage: %s, top_anchor_ratio: %s,
top_anchor_percentage: %s,
scale_factor: %s,
speed: %s })
});""" % (self.element_function,
left_anchor_percentage,
top_anchor_percentage,
scale_factor,
speed))
else:
tab.ExecuteJavaScript("""
window.__pinchAction.start(
{ element: document.body,
left_anchor_percentage: %s,
top_anchor_percentage: %s,
scale_factor: %s, scale_factor: %s,
speed: %s });""" speed: %s
% (left_anchor_percentage, });
top_anchor_percentage, }''' % (self._left_anchor_ratio,
scale_factor, self._top_anchor_ratio,
speed)) scale_factor,
self._speed)
page_action.EvaluateCallbackWithElement(
tab, code, selector=self._selector, text=self._text,
element_function=self._element_function)
tab.WaitForJavaScriptExpression('window.__pinchActionDone', 60) tab.WaitForJavaScriptExpression('window.__pinchActionDone', 60)
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from telemetry.page.actions import action_runner as action_runner_module
from telemetry.page.actions.gesture_action import GestureAction
from telemetry.unittest import tab_test_case
class PinchActionTest(tab_test_case.TabTestCase):
def setUp(self):
super(PinchActionTest, self).setUp()
def testPinchByApiCalledWithCorrectArguments(self):
self.Navigate('blank.html')
if not GestureAction.IsGestureSourceTypeSupported(self._tab, 'touch'):
return
action_runner = action_runner_module.ActionRunner(self._tab)
action_runner.ExecuteJavaScript('''
chrome.gpuBenchmarking.pinchBy = function(
scaleFactor, anchorLeft, anchorTop, callback, speed) {
window.__test_scaleFactor = scaleFactor;
window.__test_anchorLeft = anchorLeft;
window.__test_anchorTop = anchorTop;
window.__test_callback = callback;
window.__test_speed = speed;
window.__pinchActionDone = true;
};''')
action_runner.PinchPage(scale_factor=2)
self.assertEqual(
2, action_runner.EvaluateJavaScript('window.__test_scaleFactor'))
self.assertTrue(
action_runner.EvaluateJavaScript('!isNaN(window.__test_anchorLeft)'))
self.assertTrue(
action_runner.EvaluateJavaScript('!isNaN(window.__test_anchorTop)'))
self.assertTrue(
action_runner.EvaluateJavaScript('!!window.__test_callback'))
self.assertEqual(
800, action_runner.EvaluateJavaScript('window.__test_speed'))
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
"""A Telemetry page_action that performs the "play" action on media elements. """A Telemetry page_action that performs the "play" action on media elements.
Media elements can be specified by a selector attribute. If no selector is Media elements can be specified by a selector argument. If no selector is
defined then then the action attempts to play the first video element or audio defined then then the action attempts to play the first video element or audio
element on the page. A selector can also be 'all' to play all media elements. element on the page. A selector can also be 'all' to play all media elements.
Other attributes to use are: wait_for_playing and wait_for_ended, which forces Other arguments to use are: playing_event_timeout_in_seconds and
the action to wait until playing and ended events get fired respectively. ended_event_timeout_in_seconds, which forces the action to wait until
playing and ended events get fired respectively.
""" """
from telemetry.core import exceptions from telemetry.core import exceptions
...@@ -18,8 +19,13 @@ from telemetry.page.actions import page_action ...@@ -18,8 +19,13 @@ from telemetry.page.actions import page_action
class PlayAction(media_action.MediaAction): class PlayAction(media_action.MediaAction):
def __init__(self, attributes=None): def __init__(self, selector=None,
super(PlayAction, self).__init__(attributes) playing_event_timeout_in_seconds=0,
ended_event_timeout_in_seconds=0):
super(PlayAction, self).__init__()
self._selector = selector if selector else ''
self._playing_event_timeout_in_seconds = playing_event_timeout_in_seconds
self._ended_event_timeout_in_seconds = ended_event_timeout_in_seconds
def WillRunAction(self, tab): def WillRunAction(self, tab):
"""Load the media metrics JS code prior to running the action.""" """Load the media metrics JS code prior to running the action."""
...@@ -28,16 +34,15 @@ class PlayAction(media_action.MediaAction): ...@@ -28,16 +34,15 @@ class PlayAction(media_action.MediaAction):
def RunAction(self, tab): def RunAction(self, tab):
try: try:
selector = self.selector if hasattr(self, 'selector') else '' tab.ExecuteJavaScript('window.__playMedia("%s");' % self._selector)
tab.ExecuteJavaScript('window.__playMedia("%s");' % selector)
timeout_in_seconds = (self.wait_timeout_in_seconds
if hasattr(self, 'wait_timeout_in_seconds') else 60)
# Check if we need to wait for 'playing' event to fire. # Check if we need to wait for 'playing' event to fire.
if hasattr(self, 'wait_for_playing') and self.wait_for_playing: if self._playing_event_timeout_in_seconds > 0:
self.WaitForEvent(tab, selector, 'playing', timeout_in_seconds) self.WaitForEvent(tab, self._selector, 'playing',
self._playing_event_timeout_in_seconds)
# Check if we need to wait for 'ended' event to fire. # Check if we need to wait for 'ended' event to fire.
if hasattr(self, 'wait_for_ended') and self.wait_for_ended: if self._ended_event_timeout_in_seconds > 0:
self.WaitForEvent(tab, selector, 'ended', timeout_in_seconds) self.WaitForEvent(tab, self._selector, 'ended',
self._ended_event_timeout_in_seconds)
except exceptions.EvaluateException: except exceptions.EvaluateException:
raise page_action.PageActionFailed('Cannot play media element(s) with ' raise page_action.PageActionFailed('Cannot play media element(s) with '
'selector = %s.' % selector) 'selector = %s.' % self._selector)
...@@ -22,8 +22,7 @@ class PlayActionTest(tab_test_case.TabTestCase): ...@@ -22,8 +22,7 @@ class PlayActionTest(tab_test_case.TabTestCase):
@decorators.Disabled('android') @decorators.Disabled('android')
def testPlayWithNoSelector(self): def testPlayWithNoSelector(self):
"""Tests that with no selector Play action plays first video element.""" """Tests that with no selector Play action plays first video element."""
data = {'wait_for_playing': True} action = play.PlayAction(playing_event_timeout_in_seconds=60)
action = play.PlayAction(data)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
# Both videos not playing before running action. # Both videos not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK))
...@@ -36,8 +35,8 @@ class PlayActionTest(tab_test_case.TabTestCase): ...@@ -36,8 +35,8 @@ class PlayActionTest(tab_test_case.TabTestCase):
@decorators.Disabled('android') @decorators.Disabled('android')
def testPlayWithVideoSelector(self): def testPlayWithVideoSelector(self):
"""Tests that Play action plays video element matching selector.""" """Tests that Play action plays video element matching selector."""
data = {'selector': '#video_1', 'wait_for_playing': True} action = play.PlayAction(selector='#video_1',
action = play.PlayAction(data) playing_event_timeout_in_seconds=60)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
# Both videos not playing before running action. # Both videos not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK))
...@@ -50,8 +49,8 @@ class PlayActionTest(tab_test_case.TabTestCase): ...@@ -50,8 +49,8 @@ class PlayActionTest(tab_test_case.TabTestCase):
@decorators.Disabled('android') @decorators.Disabled('android')
def testPlayWithAllSelector(self): def testPlayWithAllSelector(self):
"""Tests that Play action plays all video elements with selector='all'.""" """Tests that Play action plays all video elements with selector='all'."""
data = {'selector': 'all', 'wait_for_playing': True} action = play.PlayAction(selector='all',
action = play.PlayAction(data) playing_event_timeout_in_seconds=60)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
# Both videos not playing before running action. # Both videos not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK))
...@@ -64,10 +63,8 @@ class PlayActionTest(tab_test_case.TabTestCase): ...@@ -64,10 +63,8 @@ class PlayActionTest(tab_test_case.TabTestCase):
# http://crbug.com/273887 # http://crbug.com/273887
def testPlayWaitForPlayTimeout(self): def testPlayWaitForPlayTimeout(self):
"""Tests that wait_for_playing timeouts if video does not play.""" """Tests that wait_for_playing timeouts if video does not play."""
data = {'selector': '#video_1', action = play.PlayAction(selector='#video_1',
'wait_for_playing': True, playing_event_timeout_in_seconds=1)
'wait_timeout_in_seconds': 1}
action = play.PlayAction(data)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
self._tab.EvaluateJavaScript('document.getElementById("video_1").src = ""') self._tab.EvaluateJavaScript('document.getElementById("video_1").src = ""')
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK))
...@@ -76,8 +73,8 @@ class PlayActionTest(tab_test_case.TabTestCase): ...@@ -76,8 +73,8 @@ class PlayActionTest(tab_test_case.TabTestCase):
@decorators.Disabled('android') @decorators.Disabled('android')
def testPlayWaitForEnded(self): def testPlayWaitForEnded(self):
"""Tests that wait_for_ended waits for video to end.""" """Tests that wait_for_ended waits for video to end."""
data = {'selector': '#video_1', 'wait_for_ended': True} action = play.PlayAction(selector='#video_1',
action = play.PlayAction(data) ended_event_timeout_in_seconds=60)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
# Assert video not playing before running action. # Assert video not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK))
...@@ -88,8 +85,8 @@ class PlayActionTest(tab_test_case.TabTestCase): ...@@ -88,8 +85,8 @@ class PlayActionTest(tab_test_case.TabTestCase):
def testPlayWithoutWaitForEnded(self): def testPlayWithoutWaitForEnded(self):
"""Tests that wait_for_ended waits for video to end.""" """Tests that wait_for_ended waits for video to end."""
data = {'selector': '#video_1', 'wait_for_ended': False} action = play.PlayAction(selector='#video_1',
action = play.PlayAction(data) ended_event_timeout_in_seconds=0)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
# Assert video not playing before running action. # Assert video not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK))
...@@ -100,9 +97,8 @@ class PlayActionTest(tab_test_case.TabTestCase): ...@@ -100,9 +97,8 @@ class PlayActionTest(tab_test_case.TabTestCase):
def testPlayWaitForEndedTimeout(self): def testPlayWaitForEndedTimeout(self):
"""Tests that action raises exception if timeout is reached.""" """Tests that action raises exception if timeout is reached."""
data = {'selector': '#video_1', 'wait_for_ended': True, action = play.PlayAction(selector='#video_1',
'wait_timeout_in_seconds': 1} ended_event_timeout_in_seconds=1)
action = play.PlayAction(data)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
# Assert video not playing before running action. # Assert video not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_PLAYING_CHECK))
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from telemetry.page.actions import page_action
class ReloadAction(page_action.PageAction):
def __init__(self, attributes=None):
super(ReloadAction, self).__init__(attributes)
def RunAction(self, tab):
tab.ExecuteJavaScript('window.location.reload()')
tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
...@@ -11,11 +11,11 @@ class RepaintContinuouslyAction(page_action.PageAction): ...@@ -11,11 +11,11 @@ class RepaintContinuouslyAction(page_action.PageAction):
until self.seconds have elapsed AND at least three RAFs have been fired. Times until self.seconds have elapsed AND at least three RAFs have been fired. Times
out after max(60, self.seconds), if less than three RAFs were fired. out after max(60, self.seconds), if less than three RAFs were fired.
""" """
def __init__(self, attributes=None): def __init__(self, seconds):
super(RepaintContinuouslyAction, self).__init__(attributes) super(RepaintContinuouslyAction, self).__init__()
self._seconds = seconds
def RunAction(self, tab): def RunAction(self, tab):
assert(hasattr(self, 'seconds'))
start_time = time.time() start_time = time.time()
tab.ExecuteJavaScript( tab.ExecuteJavaScript(
'window.__rafCount = 0;' 'window.__rafCount = 0;'
...@@ -25,16 +25,17 @@ class RepaintContinuouslyAction(page_action.PageAction): ...@@ -25,16 +25,17 @@ class RepaintContinuouslyAction(page_action.PageAction):
'};' '};'
'window.webkitRequestAnimationFrame(window.__rafFunction);') 'window.webkitRequestAnimationFrame(window.__rafFunction);')
time_out = max(60, self.seconds) time_out = max(60, self._seconds)
min_rafs = 3 min_rafs = 3
# Wait until al leat self.seconds have elapsed AND min_rafs have been fired. # Wait until at least self.seconds have elapsed AND min_rafs have
# Use a hard time-out after 60 seconds (or self.seconds). # been fired. Use a hard time-out after 60 seconds (or
# self.seconds).
while True: while True:
raf_count = tab.EvaluateJavaScript('window.__rafCount;') raf_count = tab.EvaluateJavaScript('window.__rafCount;')
elapsed_time = time.time() - start_time elapsed_time = time.time() - start_time
if elapsed_time > time_out: if elapsed_time > time_out:
break break
elif elapsed_time > self.seconds and raf_count > min_rafs: elif elapsed_time > self._seconds and raf_count > min_rafs:
break break
time.sleep(1) time.sleep(1)
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element); var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element);
var start_left = var start_left =
rect.left + rect.width * this.options_.left_start_percentage; rect.left + rect.width * this.options_.left_start_ratio;
var start_top = var start_top =
rect.top + rect.height * this.options_.top_start_percentage; rect.top + rect.height * this.options_.top_start_ratio;
chrome.gpuBenchmarking.scrollBounce(this.options_.direction, chrome.gpuBenchmarking.scrollBounce(this.options_.direction,
this.options_.distance, this.options_.distance,
this.options_.overscroll, this.options_.overscroll,
......
...@@ -7,8 +7,36 @@ from telemetry.page.actions.gesture_action import GestureAction ...@@ -7,8 +7,36 @@ from telemetry.page.actions.gesture_action import GestureAction
from telemetry.page.actions import page_action from telemetry.page.actions import page_action
class ScrollBounceAction(GestureAction): class ScrollBounceAction(GestureAction):
def __init__(self, attributes=None): def __init__(self, selector=None, text=None, element_function=None,
super(ScrollBounceAction, self).__init__(attributes) left_start_ratio=0.5, top_start_ratio=0.5,
direction='down', distance=100,
overscroll=10, repeat_count=10,
speed_in_pixels_per_second=400):
super(ScrollBounceAction, self).__init__()
if direction not in ['down', 'up', 'left', 'right']:
raise page_action.PageActionNotSupported(
'Invalid scroll direction: %s' % self.direction)
self.automatically_record_interaction = False
self._selector = selector
self._text = text
self._element_function = element_function
self._left_start_ratio = left_start_ratio
self._top_start_ratio = top_start_ratio
# Should be big enough to do more than just hide the URL bar.
self._distance = distance
self._direction = direction
# This needs to be < height / repeat_count so we don't walk off the screen.
# We also probably don't want to spend more than a couple frames in
# overscroll since it may mask any synthetic delays.
self._overscroll = overscroll
# It's the transitions we really want to stress, make this big.
self._repeat_count = repeat_count
# 7 pixels per frame should be plenty of frames.
self._speed = speed_in_pixels_per_second
if (self._selector is None and self._text is None and
self._element_function is None):
self._element_function = 'document.body'
def WillRunAction(self, tab): def WillRunAction(self, tab):
for js_file in ['gesture_common.js', 'scroll_bounce.js']: for js_file in ['gesture_common.js', 'scroll_bounce.js']:
...@@ -40,72 +68,29 @@ class ScrollBounceAction(GestureAction): ...@@ -40,72 +68,29 @@ class ScrollBounceAction(GestureAction):
% (done_callback)) % (done_callback))
def RunGesture(self, tab): def RunGesture(self, tab):
left_start_percentage = 0.5 code = '''
top_start_percentage = 0.5 function(element, info) {
direction = 'down' if (!element) {
# Should be big enough to do more than just hide the URL bar. throw Error('Cannot find element: ' + info);
distance = 100 }
# This needs to be < height / repeat_count so we don't walk off the screen. window.__scrollBounceAction.start({
# We also probably don't want to spend more than a couple frames in element: element,
# overscroll since it may mask any synthetic delays. left_start_ratio: %s,
overscroll = 10 top_start_ratio: %s,
# It's the transitions we really want to stress, make this big.
repeat_count = 10
# 7 pixels per frame should be plenty of frames.
speed = 400
if hasattr(self, 'left_start_percentage'):
left_start_percentage = self.left_start_percentage
if hasattr(self, 'top_start_percentage'):
top_start_percentage = self.top_start_percentage
if hasattr(self, 'direction'):
direction = self.direction
if direction not in ['down', 'up', 'left', 'right']:
raise page_action.PageActionNotSupported(
'Invalid scroll bounce direction: %s' % direction)
if hasattr(self, 'distance'):
distance = self.distance
if hasattr(self, 'overscroll'):
overscroll = self.overscroll
if hasattr(self, 'repeat_count'):
repeat_count = self.repeat_count
if hasattr(self, 'speed_in_pixels_per_second'):
speed = self.speed
if hasattr(self, 'element_function'):
tab.ExecuteJavaScript("""
(%s)(function(element) { window.__scrollBounceAction.start(
{ element: element,
left_start_percentage: %s,
top_start_percentage: %s,
direction: '%s',
distance: %s,
overscroll: %s,
repeat_count: %s,
speed: %s })
});""" % (self.element_function,
left_start_percentage,
top_start_percentage,
direction,
distance,
overscroll,
repeat_count,
speed))
else:
tab.ExecuteJavaScript("""
window.__scrollBounceAction.start(
{ element: document.body,
left_start_percentage: %s,
top_start_percentage: %s,
direction: '%s', direction: '%s',
distance: %s, distance: %s,
overscroll: %s, overscroll: %s,
repeat_count: %s, repeat_count: %s,
speed: %s });""" speed: %s
% (left_start_percentage, });
top_start_percentage, }''' % (self._left_start_ratio,
direction, self._top_start_ratio,
distance, self._direction,
overscroll, self._distance,
repeat_count, self._overscroll,
speed)) self._repeat_count,
self._speed)
page_action.EvaluateCallbackWithElement(
tab, code, selector=self._selector, text=self._text,
element_function=self._element_function)
tab.WaitForJavaScriptExpression('window.__scrollBounceActionDone', 60) tab.WaitForJavaScriptExpression('window.__scrollBounceActionDone', 60)
...@@ -4,18 +4,17 @@ ...@@ -4,18 +4,17 @@
"""A Telemetry page_action that performs the "seek" action on media elements. """A Telemetry page_action that performs the "seek" action on media elements.
Action attributes are: Action parameters are:
- seek_time: The media time to seek to. Test fails if not provided. - seconds: The media time to seek to. Test fails if not provided.
- selector: If no selector is defined then the action attempts to seek the first - selector: If no selector is defined then the action attempts to seek the first
media element on the page. If 'all' then seek all media elements. media element on the page. If 'all' then seek all media elements.
- log_seek_time: If true the seek time is recorded, otherwise media measurement - timeout_in_seconds: Maximum waiting time for the "seeked" event
will not be aware of the seek action. Used to perform multiple (dispatched when the seeked operation completes)
seeks. Default true. to be fired. 0 means do not wait.
- wait_for_seeked: If true forces the action to wait for seeked event to fire. - log_time: If true the seek time is recorded, otherwise media
Default false. measurement will not be aware of the seek action. Used to
- wait_timeout_in_seconds: Timeout to wait for seeked event. Only valid with perform multiple seeks. Default true.
wait_for_seeked=true - label: A suffix string to name the seek perf measurement.
- seek_label: A suffix string to name the seek perf measurement.
""" """
from telemetry.core import exceptions from telemetry.core import exceptions
...@@ -24,6 +23,15 @@ from telemetry.page.actions import page_action ...@@ -24,6 +23,15 @@ from telemetry.page.actions import page_action
class SeekAction(media_action.MediaAction): class SeekAction(media_action.MediaAction):
def __init__(self, seconds, selector=None, timeout_in_seconds=0,
log_time=True, label=''):
super(SeekAction, self).__init__()
self._seconds = seconds
self._selector = selector if selector else ''
self._timeout_in_seconds = timeout_in_seconds
self._log_time = log_time
self._label = label
def WillRunAction(self, tab): def WillRunAction(self, tab):
"""Load the media metrics JS code prior to running the action.""" """Load the media metrics JS code prior to running the action."""
super(SeekAction, self).WillRunAction(tab) super(SeekAction, self).WillRunAction(tab)
...@@ -31,17 +39,12 @@ class SeekAction(media_action.MediaAction): ...@@ -31,17 +39,12 @@ class SeekAction(media_action.MediaAction):
def RunAction(self, tab): def RunAction(self, tab):
try: try:
assert hasattr(self, 'seek_time') tab.ExecuteJavaScript(
selector = self.selector if hasattr(self, 'selector') else '' 'window.__seekMedia("%s", "%s", %i, "%s");' %
log_seek = self.log_seek == True if hasattr(self, 'log_seek') else True (self._selector, self._seconds, self._log_time, self._label))
seek_label = self.seek_label if hasattr(self, 'seek_label') else '' if self._timeout_in_seconds > 0:
tab.ExecuteJavaScript('window.__seekMedia("%s", "%s", %i, "%s");' % self.WaitForEvent(tab, self._selector, 'seeked',
(selector, self.seek_time, log_seek, seek_label)) self._timeout_in_seconds)
timeout_in_seconds = (self.wait_timeout_in_seconds
if hasattr(self, 'wait_timeout_in_seconds') else 60)
# Check if we need to wait for 'seeked' event to fire.
if hasattr(self, 'wait_for_seeked') and self.wait_for_seeked:
self.WaitForEvent(tab, selector, 'seeked', timeout_in_seconds)
except exceptions.EvaluateException: except exceptions.EvaluateException:
raise page_action.PageActionFailed('Cannot seek media element(s) with ' raise page_action.PageActionFailed('Cannot seek media element(s) with '
'selector = %s.' % selector) 'selector = %s.' % self._selector)
...@@ -19,8 +19,7 @@ class SeekActionTest(tab_test_case.TabTestCase): ...@@ -19,8 +19,7 @@ class SeekActionTest(tab_test_case.TabTestCase):
def testSeekWithNoSelector(self): def testSeekWithNoSelector(self):
"""Tests that with no selector Seek action seeks first media element.""" """Tests that with no selector Seek action seeks first media element."""
data = {'wait_for_seeked': True, 'seek_time': 1} action = seek.SeekAction(seconds=1, timeout_in_seconds=10)
action = seek.SeekAction(data)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
action.RunAction(self._tab) action.RunAction(self._tab)
# Assert only first video has played. # Assert only first video has played.
...@@ -29,8 +28,8 @@ class SeekActionTest(tab_test_case.TabTestCase): ...@@ -29,8 +28,8 @@ class SeekActionTest(tab_test_case.TabTestCase):
def testSeekWithVideoSelector(self): def testSeekWithVideoSelector(self):
"""Tests that Seek action seeks video element matching selector.""" """Tests that Seek action seeks video element matching selector."""
data = {'selector': '#video_1', 'wait_for_seeked': True, 'seek_time': 1} action = seek.SeekAction(seconds=1, selector='#video_1',
action = seek.SeekAction(data) timeout_in_seconds=10)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
# Both videos not playing before running action. # Both videos not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
...@@ -42,8 +41,8 @@ class SeekActionTest(tab_test_case.TabTestCase): ...@@ -42,8 +41,8 @@ class SeekActionTest(tab_test_case.TabTestCase):
def testSeekWithAllSelector(self): def testSeekWithAllSelector(self):
"""Tests that Seek action seeks all video elements with selector='all'.""" """Tests that Seek action seeks all video elements with selector='all'."""
data = {'selector': 'all', 'wait_for_seeked': True, 'seek_time': 1} action = seek.SeekAction(seconds=1, selector='all',
action = seek.SeekAction(data) timeout_in_seconds=10)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
# Both videos not playing before running action. # Both videos not playing before running action.
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
...@@ -55,19 +54,9 @@ class SeekActionTest(tab_test_case.TabTestCase): ...@@ -55,19 +54,9 @@ class SeekActionTest(tab_test_case.TabTestCase):
def testSeekWaitForSeekTimeout(self): def testSeekWaitForSeekTimeout(self):
"""Tests that wait_for_seeked timeouts if video does not seek.""" """Tests that wait_for_seeked timeouts if video does not seek."""
data = {'selector': '#video_1', action = seek.SeekAction(seconds=1, selector='#video_1',
'wait_for_seeked': True, timeout_in_seconds=1)
'wait_timeout_in_seconds': 1,
'seek_time': 1}
action = seek.SeekAction(data)
action.WillRunAction(self._tab) action.WillRunAction(self._tab)
self._tab.EvaluateJavaScript('document.getElementById("video_1").src = ""') self._tab.EvaluateJavaScript('document.getElementById("video_1").src = ""')
self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK)) self.assertFalse(self._tab.EvaluateJavaScript(VIDEO_1_SEEKED_CHECK))
self.assertRaises(util.TimeoutException, action.RunAction, self._tab) self.assertRaises(util.TimeoutException, action.RunAction, self._tab)
def testSeekWithoutSeekTime(self):
"""Tests that seek action fails with no seek time."""
data = {'wait_for_seeked': True}
action = seek.SeekAction(data)
action.WillRunAction(self._tab)
self.assertRaises(AssertionError, action.RunAction, self._tab)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment