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

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

Issue 21134002: Add Telemetry media loop action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 4 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/loop.py
diff --git a/tools/telemetry/telemetry/page/actions/loop.py b/tools/telemetry/telemetry/page/actions/loop.py
new file mode 100644
index 0000000000000000000000000000000000000000..c5c258ab3485214192295b9c32dfcba8222f9347
--- /dev/null
+++ b/tools/telemetry/telemetry/page/actions/loop.py
@@ -0,0 +1,42 @@
+# 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.
+
+"""A Telemetry page_action that loops media playback.
+
+Action attributes are:
+- loop_count: The number of times to loop media.
+- selector: If no selector is defined then the action attempts to loop the first
+ media element on the page. If 'all' then loop all media elements.
+- wait_timeout: Timeout to wait for media to loop. Default is
+ 60 sec x loop_count.
+- wait_for_loop: If true, forces the action to wait for last loop to end,
+ otherwise it starts the loops and exit. Default true.
+"""
+
+from telemetry.core import exceptions
+from telemetry.page.actions import page_action
+import telemetry.page.actions.media_action as media_action
+
+
+class LoopAction(media_action.MediaAction):
+ def WillRunAction(self, page, tab):
+ """Load the media metrics JS code prior to running the action."""
+ super(LoopAction, self).WillRunAction(page, tab)
+ self.LoadJS(tab, 'loop.js')
+
+ def RunAction(self, page, tab, previous_action):
+ try:
+ assert hasattr(self, 'loop_count') and self.loop_count > 0
+ selector = self.selector if hasattr(self, 'selector') else ''
+ tab.ExecuteJavaScript('window.__loopMedia("%s", %i);' %
+ (selector, self.loop_count))
+ timeout = (self.wait_timeout if hasattr(self, 'wait_timeout')
+ else 60 * self.loop_count)
+ # Check if there is no need to wait for all loops to end
+ if hasattr(self, 'wait_for_loop') and not self.wait_for_loop:
+ return
+ self.WaitForEvent(tab, selector, 'loop', timeout)
+ except exceptions.EvaluateException:
+ raise page_action.PageActionFailed('Cannot loop media element(s) with '
+ 'selector = %s.' % selector)
« no previous file with comments | « tools/telemetry/telemetry/page/actions/loop.js ('k') | tools/telemetry/telemetry/page/actions/loop_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698