| Index: tools/telemetry/telemetry/page/actions/play.py
|
| diff --git a/tools/telemetry/telemetry/page/actions/play.py b/tools/telemetry/telemetry/page/actions/play.py
|
| index 7fd33a76b572cddfc0f1134a2c709482541ddbce..76fc91326e9c84a8e05b81c91a3e15a98ff97e30 100644
|
| --- a/tools/telemetry/telemetry/page/actions/play.py
|
| +++ b/tools/telemetry/telemetry/page/actions/play.py
|
| @@ -4,12 +4,13 @@
|
|
|
| """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
|
| 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
|
| -the action to wait until playing and ended events get fired respectively.
|
| +Other arguments to use are: playing_event_timeout_in_seconds and
|
| +ended_event_timeout_in_seconds, which forces the action to wait until
|
| +playing and ended events get fired respectively.
|
| """
|
|
|
| from telemetry.core import exceptions
|
| @@ -18,8 +19,13 @@ from telemetry.page.actions import page_action
|
|
|
|
|
| class PlayAction(media_action.MediaAction):
|
| - def __init__(self, attributes=None):
|
| - super(PlayAction, self).__init__(attributes)
|
| + def __init__(self, selector=None,
|
| + 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):
|
| """Load the media metrics JS code prior to running the action."""
|
| @@ -28,16 +34,15 @@ class PlayAction(media_action.MediaAction):
|
|
|
| def RunAction(self, tab):
|
| try:
|
| - selector = self.selector if hasattr(self, 'selector') else ''
|
| - tab.ExecuteJavaScript('window.__playMedia("%s");' % selector)
|
| - timeout_in_seconds = (self.wait_timeout_in_seconds
|
| - if hasattr(self, 'wait_timeout_in_seconds') else 60)
|
| + tab.ExecuteJavaScript('window.__playMedia("%s");' % self._selector)
|
| # Check if we need to wait for 'playing' event to fire.
|
| - if hasattr(self, 'wait_for_playing') and self.wait_for_playing:
|
| - self.WaitForEvent(tab, selector, 'playing', timeout_in_seconds)
|
| + if self._playing_event_timeout_in_seconds > 0:
|
| + self.WaitForEvent(tab, self._selector, 'playing',
|
| + self._playing_event_timeout_in_seconds)
|
| # Check if we need to wait for 'ended' event to fire.
|
| - if hasattr(self, 'wait_for_ended') and self.wait_for_ended:
|
| - self.WaitForEvent(tab, selector, 'ended', timeout_in_seconds)
|
| + if self._ended_event_timeout_in_seconds > 0:
|
| + self.WaitForEvent(tab, self._selector, 'ended',
|
| + self._ended_event_timeout_in_seconds)
|
| except exceptions.EvaluateException:
|
| raise page_action.PageActionFailed('Cannot play media element(s) with '
|
| - 'selector = %s.' % selector)
|
| + 'selector = %s.' % self._selector)
|
|
|