Index: tools/telemetry/telemetry/page/actions/seek.py |
diff --git a/tools/telemetry/telemetry/page/actions/seek.py b/tools/telemetry/telemetry/page/actions/seek.py |
index 02ce3ff600d295e94cfb42c72e0803e3a48578f6..1d12693a4d3c9668c7a6a7956f6b8ae77b2e68c2 100644 |
--- a/tools/telemetry/telemetry/page/actions/seek.py |
+++ b/tools/telemetry/telemetry/page/actions/seek.py |
@@ -4,18 +4,17 @@ |
"""A Telemetry page_action that performs the "seek" action on media elements. |
-Action attributes are: |
-- seek_time: The media time to seek to. Test fails if not provided. |
+Action parameters are: |
+- 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 |
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 |
- will not be aware of the seek action. Used to perform multiple |
- seeks. Default true. |
-- wait_for_seeked: If true forces the action to wait for seeked event to fire. |
- Default false. |
-- wait_timeout_in_seconds: Timeout to wait for seeked event. Only valid with |
- wait_for_seeked=true |
-- seek_label: A suffix string to name the seek perf measurement. |
+- timeout_in_seconds: Maximum waiting time for the "seeked" event |
+ (dispatched when the seeked operation completes) |
+ to be fired. 0 means do not wait. |
+- log_time: If true the seek time is recorded, otherwise media |
+ measurement will not be aware of the seek action. Used to |
+ perform multiple seeks. Default true. |
+- label: A suffix string to name the seek perf measurement. |
""" |
from telemetry.core import exceptions |
@@ -24,6 +23,15 @@ from telemetry.page.actions import page_action |
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): |
"""Load the media metrics JS code prior to running the action.""" |
super(SeekAction, self).WillRunAction(tab) |
@@ -31,17 +39,12 @@ class SeekAction(media_action.MediaAction): |
def RunAction(self, tab): |
try: |
- assert hasattr(self, 'seek_time') |
- selector = self.selector if hasattr(self, 'selector') else '' |
- log_seek = self.log_seek == True if hasattr(self, 'log_seek') else True |
- seek_label = self.seek_label if hasattr(self, 'seek_label') else '' |
- tab.ExecuteJavaScript('window.__seekMedia("%s", "%s", %i, "%s");' % |
- (selector, self.seek_time, log_seek, seek_label)) |
- 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) |
+ tab.ExecuteJavaScript( |
+ 'window.__seekMedia("%s", "%s", %i, "%s");' % |
+ (self._selector, self._seconds, self._log_time, self._label)) |
+ if self._timeout_in_seconds > 0: |
+ self.WaitForEvent(tab, self._selector, 'seeked', |
+ self._timeout_in_seconds) |
except exceptions.EvaluateException: |
raise page_action.PageActionFailed('Cannot seek media element(s) with ' |
- 'selector = %s.' % selector) |
+ 'selector = %s.' % self._selector) |