Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / media_action.py
index 5baf023..8f80e76 100644 (file)
@@ -4,6 +4,7 @@
 
 """Common media action functions."""
 
+import logging
 import os
 
 from telemetry.core import util
@@ -11,12 +12,12 @@ from telemetry.page.actions import page_action
 
 
 class MediaAction(page_action.PageAction):
-  def WillRunAction(self, page, tab):
+  def WillRunAction(self, tab):
     """Loads the common media action JS code prior to running the action."""
     self.LoadJS(tab, 'media_action.js')
 
-  def RunAction(self, page, tab, previous_action):
-    super(MediaAction, self).RunAction(page, tab, previous_action)
+  def RunAction(self, tab):
+    super(MediaAction, self).RunAction(tab)
 
   def LoadJS(self, tab, js_file_name):
     """Loads and executes a JS file in the tab."""
@@ -24,18 +25,27 @@ class MediaAction(page_action.PageAction):
       js = f.read()
       tab.ExecuteJavaScript(js)
 
-  def WaitForEvent(self, tab, selector, event_name, timeout):
+  def WaitForEvent(self, tab, selector, event_name, timeout_in_seconds):
     """Halts media action until the selector's event is fired.
 
     Args:
       tab: The tab to check for event on.
       selector: Media element selector.
       event_name: Name of the event to check if fired or not.
-      timeout: Timeout to check for event, throws an exception if not fired.
+      timeout_in_seconds: Timeout to check for event, throws an exception if
+          not fired.
     """
-    util.WaitFor(lambda: self.HasEventCompleted(tab, selector, event_name),
-                 timeout=timeout)
-
-  def HasEventCompleted(self, tab, selector, event_name):
-    return tab.EvaluateJavaScript(
-        'window.__hasEventCompleted("%s", "%s");' % (selector, event_name))
+    util.WaitFor(lambda:
+                     self.HasEventCompletedOrError(tab, selector, event_name),
+                 timeout=timeout_in_seconds)
+
+  def HasEventCompletedOrError(self, tab, selector, event_name):
+    if tab.EvaluateJavaScript(
+        'window.__hasEventCompleted("%s", "%s");' % (selector, event_name)):
+      return True
+    error = tab.EvaluateJavaScript('window.__error')
+    if error:
+      logging.error('Detected media error while waiting for %s: %s', event_name,
+                    error)
+      return True
+    return False