Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / play.py
index 62a2c55..76fc913 100644 (file)
@@ -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,15 +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 = self.wait_timeout if hasattr(self, 'wait_timeout') 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)
+      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)
+      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)