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

Unified Diff: tools/telemetry/telemetry/scrolling_interaction.py

Issue 11316017: Refactoring scrolling_benchmark code into scrolling_interaction.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Trying out marja's suggestion Created 8 years, 1 month 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/scrolling_interaction.py
diff --git a/tools/telemetry/telemetry/scrolling_interaction.py b/tools/telemetry/telemetry/scrolling_interaction.py
new file mode 100644
index 0000000000000000000000000000000000000000..ffe56aad239ec8a50ac2828d18506f8525c21cd2
--- /dev/null
+++ b/tools/telemetry/telemetry/scrolling_interaction.py
@@ -0,0 +1,61 @@
+# Copyright (c) 2012 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.
+import os
+
+from telemetry import multi_page_benchmark
+from telemetry import page_interaction
+from telemetry import util
+
+class DidNotScrollException(multi_page_benchmark.MeasurementFailure):
marja 2012/11/15 22:16:03 Should this subclass the "interaction failed" exce
hartmanng 2012/11/16 16:19:24 Yep, you're right. However, if we're going to move
marja 2012/11/19 09:47:09 Yes, the right super class of this exception depen
+ def __init__(self):
+ super(DidNotScrollException, self).__init__('Page did not scroll')
+
+class ScrollingInteraction(page_interaction.PageInteraction):
+ def __init__(self, attributes=None):
+ super(ScrollingInteraction, self).__init__(attributes)
+
+ def PerformInteraction(self, page, tab):
+ scroll_js_path = os.path.join(os.path.dirname(__file__),
+ '..',
+ '..',
+ 'perf',
+ 'perf_tools',
+ 'scroll.js')
+ scroll_js = open(scroll_js_path, 'r').read()
+
+ # Run scroll test.
+ tab.runtime.Execute(scroll_js)
+
+ with tab.browser.platform.GetSurfaceCollector(''):
+
+ start_scroll_js = """
+ window.__renderingStatsDeltas = null;
+ new __ScrollTest(function(rendering_stats_deltas) {
+ window.__renderingStatsDeltas = rendering_stats_deltas;
+ }).start(element);
+ """
+ # scrollable_element_function is a function that passes the scrollable
+ # element on the page to a callback. For example:
+ # function (callback) {
+ # callback(document.getElementById('foo'));
+ # }
+ if hasattr(self, 'scrollable_element_function'):
+ tab.runtime.Execute('(%s)(function(element) { %s });' %
+ (self.scrollable_element_function, start_scroll_js))
+ else:
+ tab.runtime.Execute(
+ '(function() { var element = document.body; %s})();' %
+ start_scroll_js)
+
+ # Poll for scroll benchmark completion.
+ util.WaitFor(lambda: tab.runtime.Evaluate(
+ 'window.__renderingStatsDeltas'), 60)
+
+ rendering_stats_deltas = tab.runtime.Evaluate(
+ 'window.__renderingStatsDeltas')
+
+ if not (rendering_stats_deltas['numFramesSentToScreen'] > 0):
+ raise DidNotScrollException()
+
+ page.scroll_results = rendering_stats_deltas
marja 2012/11/16 12:40:33 So, this is for transmitting the information to Me
hartmanng 2012/11/16 16:19:24 Thanks for the suggestion, I like this better, thi

Powered by Google App Engine
This is Rietveld 408576698