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

Side by Side Diff: tools/telemetry/telemetry/scrolling_action.py

Issue 12278015: [Telemetry] Reorganize everything. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-add shebangs. Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import os
5
6 from telemetry import page_action
7 from telemetry import util
8
9 class ScrollingAction(page_action.PageAction):
10 def __init__(self, attributes=None):
11 super(ScrollingAction, self).__init__(attributes)
12
13 def WillRunAction(self, page, tab):
14 with open(
15 os.path.join(os.path.dirname(__file__),
16 'scrolling_action.js')) as f:
17 js = f.read()
18 tab.ExecuteJavaScript(js)
19
20 tab.ExecuteJavaScript("""
21 window.__scrollingActionDone = false;
22 window.__scrollingAction = new __ScrollingAction(function() {
23 window.__scrollingActionDone = true;
24 });
25 """)
26
27 def RunAction(self, page, tab, previous_action):
28 with tab.browser.platform.GetSurfaceCollector(''):
29 # scrollable_element_function is a function that passes the scrollable
30 # element on the page to a callback. For example:
31 # function (callback) {
32 # callback(document.getElementById('foo'));
33 # }
34 if hasattr(self, 'scrollable_element_function'):
35 tab.ExecuteJavaScript("""
36 (%s)(function(element) {
37 window.__scrollingAction.start(element);
38 });""" % (self.scrollable_element_function))
39 else:
40 tab.ExecuteJavaScript(
41 'window.__scrollingAction.start(document.body);')
42
43 # Poll for scroll benchmark completion.
44 util.WaitFor(lambda: tab.EvaluateJavaScript(
45 'window.__scrollingActionDone'), 60)
46
47 def CanBeBound(self):
48 return True
49
50 def BindMeasurementJavaScript(self, tab, start_js, stop_js):
51 # Make the scrolling action start and stop measurement automatically.
52 tab.ExecuteJavaScript("""
53 window.__scrollingAction.beginMeasuringHook = function() { %s };
54 window.__scrollingAction.endMeasuringHook = function() { %s };
55 """ % (start_js, stop_js))
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/scrolling_action.js ('k') | tools/telemetry/telemetry/scrolling_action_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698