Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: tools/telemetry/telemetry/page/actions/media_action.py

Issue 19482009: Telemetry media Seek action and metrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add base media action class and JS code. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/page/actions/media_action.py
diff --git a/tools/telemetry/telemetry/page/actions/media_action.py b/tools/telemetry/telemetry/page/actions/media_action.py
new file mode 100644
index 0000000000000000000000000000000000000000..a55a3d729702163b25179dc8940732c18f2d0006
--- /dev/null
+++ b/tools/telemetry/telemetry/page/actions/media_action.py
@@ -0,0 +1,46 @@
+# Copyright (c) 2013 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.
+
+"""Common media action functions."""
+
+import os
+
+from telemetry.core import util
+from telemetry.page.actions import page_action
+
+
+class MediaAction(page_action.PageAction):
+ def __init__(self, attributes=None):
+ super(MediaAction, self).__init__(attributes)
+
+ def WillRunAction(self, page, 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 LoadJS(self, tab, js_file_name):
+ """Loads and executes a JS file in the tab."""
+ with open(os.path.join(os.path.dirname(__file__), js_file_name)) as f:
+ js = f.read()
+ tab.ExecuteJavaScript(js)
+
+ def WaitForEvent(self, tab, selector, event_name, timeout,
+ poll_interval=0.5):
+ """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.
+ poll_interval: Interval to poll for event firing status.
+ """
+ util.WaitFor(lambda: self.HasEventCompleted(tab, selector, event_name),
+ timeout=timeout, poll_interval=poll_interval)
+
+ def HasEventCompleted(self, tab, selector, event_name):
+ return tab.EvaluateJavaScript(
+ 'window.__hasEventCompleted("%s", "%s");' % (selector, event_name))
« no previous file with comments | « tools/telemetry/telemetry/page/actions/media_action.js ('k') | tools/telemetry/telemetry/page/actions/play.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698