summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/test/data/scroll/scroll.js82
-rw-r--r--chrome/test/functional/perf.py48
2 files changed, 130 insertions, 0 deletions
diff --git a/chrome/test/data/scroll/scroll.js b/chrome/test/data/scroll/scroll.js
new file mode 100644
index 0000000..c3e840f
--- /dev/null
+++ b/chrome/test/data/scroll/scroll.js
@@ -0,0 +1,82 @@
+// Copyright (c) 2011 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.
+
+// Function that sets a callback called when the next frame is rendered.
+var __set_frame_callback;
+
+// Amount of scrolling at each frame.
+var __scroll_delta = 500;
+
+// Current scroll position.
+var __ypos;
+
+// Time of previous scroll callback execution.
+var __start_time = 0;
+
+// Deltas are in milliseconds.
+var __delta_max = 0;
+var __delta_min = 1000000;
+var __delta_sum = 0;
+var __delta_square_sum = 0;
+var __n_samples = 0;
+
+// Whether all scroll tests have completed.
+var __tests_complete = false;
+
+// Initializes the platform-independent frame callback scheduler function.
+function __init_set_frame_callback() {
+ if (!__set_frame_callback) {
+ if ("webkitRequestAnimationFrame" in window)
+ __set_frame_callback = webkitRequestAnimationFrame;
+ else if ("mozRequestAnimationFrame" in window)
+ __set_frame_callback = mozRequestAnimationFrame;
+ }
+}
+
+
+function record_delta_time() {
+ var time = new Date().getTime();
+ if (__start_time != 0) {
+ var delta = time - __start_time;
+ document.title = delta + " (" + Math.round(1000.0 / delta) + ")";
+ __n_samples++;
+ __delta_sum += delta;
+ __delta_square_sum += delta * delta;
+ if (delta < __delta_min) {
+ __delta_min = delta;
+ }
+ if (delta > __delta_max) {
+ __delta_max = delta;
+ }
+ }
+ __start_time = time;
+}
+
+
+// Scrolls page down and reschedules itself until it hits the bottom. Collects
+// stats.
+function __frame_callback() {
+ record_delta_time();
+ window.scrollBy(0, __scroll_delta);
+ __ypos += __scroll_delta;
+ scrollable_distance = document.body.scrollHeight - window.innerHeight;
+ if (__ypos < scrollable_distance) {
+ __set_frame_callback(__frame_callback, document.body);
+ } else {
+ __tests_complete = true;
+ }
+}
+
+// Sets things here after the document has been rendered.
+function __first_frame_callback() {
+ document.body.scrollTop = 0;
+ __set_frame_callback(__frame_callback, document.body);
+}
+
+
+function __start_scroll_test() {
+ __init_set_frame_callback();
+ __ypos = 0;
+ __set_frame_callback(__first_frame_callback, document.body);
+}
diff --git a/chrome/test/functional/perf.py b/chrome/test/functional/perf.py
index 29e8e69..b393050 100644
--- a/chrome/test/functional/perf.py
+++ b/chrome/test/functional/perf.py
@@ -455,6 +455,54 @@ class FileUploadDownloadTest(BasePerfTest):
self._PrintSummaryResults('Upload50MBFile', timings, 'milliseconds')
+class ScrollTest(BasePerfTest):
+ """Tests to measure scrolling performance."""
+
+ def RunTestScroll(self):
+ # Navigate to a webpage, inject the scroll test code, and initiate the test.
+ self.assertTrue(self.AppendTab(pyauto.GURL(self.GetFileURLForDataPath(
+ 'find_in_page', 'largepage.html'))),
+ msg='Failed to append tab for webpage.')
+
+ scroll_file = os.path.join(self.DataDir(), 'scroll', 'scroll.js')
+ with open(scroll_file, 'r') as f:
+ scroll_text = f.read()
+ js = """
+ %s
+ __start_scroll_test();
+ window.domAutomationController.send('done');
+ """ % scroll_text
+ self.ExecuteJavascript(js, 0, 1)
+
+ # Poll the webpage until the test is complete.
+ def IsTestDone():
+ done_js = """
+ if (__tests_complete)
+ window.domAutomationController.send('true');
+ else
+ window.domAutomationController.send('false');
+ """
+ return self.ExecuteJavascript(done_js, 0, 1) == 'true'
+
+ self.assertTrue(
+ self.WaitUntil(IsTestDone, timeout=300, expect_retval=True,
+ retry_sleep=0.10),
+ msg='Timed out when waiting for scrolling tests to complete.')
+
+ # Get the scroll tests results from the webpage.
+ results_js = """
+ window.domAutomationController.send(
+ "{'delta_max': " + __delta_max + ", 'delta_min': " + __delta_min +
+ ", 'delta_sum': " + __delta_sum + ", 'delta_square_sum': " +
+ __delta_square_sum + ", 'n_samples': " + __n_samples + "}"
+ );
+ """
+ results = eval(self.ExecuteJavascript(results_js, 0, 1))
+ print '===== SCROLL TEST RESULTS ====='
+ self.pprint(results)
+ print '==============================='
+
+
class PerfTestServerRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
"""Request handler for the local performance test server."""