Index: tools/chrome_remote_control/chrome_remote_control/scroll_interaction.py |
diff --git a/tools/chrome_remote_control/chrome_remote_control/scroll_interaction.py b/tools/chrome_remote_control/chrome_remote_control/scroll_interaction.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..67a1af85d8976d4be14b11bd7100b4454626696d |
--- /dev/null |
+++ b/tools/chrome_remote_control/chrome_remote_control/scroll_interaction.py |
@@ -0,0 +1,67 @@ |
+# 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 chrome_remote_control import interaction |
+from chrome_remote_control import page_test |
+from chrome_remote_control import util |
+ |
+class ScrollInteraction(interaction.Interaction): |
+ def __init__(self, use_gpu_benchmarking_extension=True): |
+ super(ScrollInteraction, self).__init__() |
+ self._use_gpu_benchmarking_extension = use_gpu_benchmarking_extension |
+ |
+ def CustomizeBrowserOptions(self, options): |
+ if self._use_gpu_benchmarking_extension: |
+ options.extra_browser_args.append('--enable-gpu-benchmarking') |
+ |
+ def SupportedForPage(self, page, tab): |
+ # TODO(nduca): Detect if the page isn't scrollable up front and raise an |
+ # interaction.InteractionNotSupported. |
+ return True |
+ |
+ def PerformInteraction(self, page, tab, test): |
+ scroll_js_path = os.path.join(os.path.dirname(__file__), |
+ 'scroll.js') |
+ scroll_js = open(scroll_js_path, 'r').read() |
+ |
+ # Run scroll test. |
+ tab.runtime.Execute(scroll_js) |
+ |
+ start_scroll_js = """ |
+ window.__renderingStatsDeltas = null; |
+ window.__scrollElement = element; |
+ 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')); |
+ # } |
+ test.WillPerformInteraction(self, page, tab) |
+ |
+ if hasattr(page, 'scrollable_element_function'): |
+ tab.runtime.Execute('(%s)(function(element) { %s });' % |
+ (page.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 page_test.Failure('Interaction failed: Page did not scroll!') |
+ test.DidPerformInteraction(self, page, tab, rendering_stats_deltas) |
+ |
+ def CleanUp(self, page, tab): |
+ tab.runtime.Execute('window.__scrollElement.scrollTop = 0;') |
+ |
+interaction.RegisterClass('scroll', ScrollInteraction) |