OLD | NEW |
---|---|
1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 | 6 |
7 from telemetry import decorators | 7 from telemetry import decorators |
8 from telemetry.page.actions import scroll | 8 from telemetry.page.actions import scroll |
9 from telemetry.unittest_util import tab_test_case | 9 from telemetry.unittest_util import tab_test_case |
10 | 10 |
11 | 11 |
12 class ScrollActionTest(tab_test_case.TabTestCase): | 12 class ScrollActionTest(tab_test_case.TabTestCase): |
13 @decorators.Disabled # Disabled due to flakiness: crbug.com/330544 | |
nednguyen
2015/03/04 05:40:49
Can you make a separate patch for enabling this? T
| |
14 def testScrollAction(self): | 13 def testScrollAction(self): |
15 self.Navigate('blank.html') | 14 self.Navigate('blank.html') |
16 | 15 |
17 # Make page bigger than window so it's scrollable. | 16 # Make page bigger than window so it's scrollable. |
18 self._tab.ExecuteJavaScript("""document.body.style.height = | 17 self._tab.ExecuteJavaScript("""document.body.style.height = |
19 (2 * window.innerHeight + 1) + 'px';""") | 18 (2 * window.innerHeight + 1) + 'px';""") |
20 | 19 |
21 self.assertEquals( | 20 self.assertEquals( |
22 self._tab.EvaluateJavaScript("""document.documentElement.scrollTop | 21 self._tab.EvaluateJavaScript("""document.documentElement.scrollTop |
23 || document.body.scrollTop"""), 0) | 22 || document.body.scrollTop"""), 0) |
(...skipping 16 matching lines...) Expand all Loading... | |
40 # Allow for roundoff error in scaled viewport. | 39 # Allow for roundoff error in scaled viewport. |
41 scroll_position = self._tab.EvaluateJavaScript( | 40 scroll_position = self._tab.EvaluateJavaScript( |
42 """(document.documentElement.scrollTop || document.body.scrollTop) | 41 """(document.documentElement.scrollTop || document.body.scrollTop) |
43 + window.innerHeight""") | 42 + window.innerHeight""") |
44 scroll_height = self._tab.EvaluateJavaScript('document.body.scrollHeight') | 43 scroll_height = self._tab.EvaluateJavaScript('document.body.scrollHeight') |
45 difference = scroll_position - scroll_height | 44 difference = scroll_position - scroll_height |
46 self.assertTrue(abs(difference) <= 1, | 45 self.assertTrue(abs(difference) <= 1, |
47 msg='scroll_position=%d; scroll_height=%d' % | 46 msg='scroll_position=%d; scroll_height=%d' % |
48 (scroll_position, scroll_height)) | 47 (scroll_position, scroll_height)) |
49 | 48 |
49 def testDiagonalScrollAction(self): | |
50 self.Navigate('blank.html') | |
51 | |
52 # Make page bigger than window so it's scrollable. | |
53 self._tab.ExecuteJavaScript("""document.body.style.height = | |
54 (2 * window.innerHeight + 1) + 'px';""") | |
55 self._tab.ExecuteJavaScript("""document.body.style.width = | |
56 (2 * window.innerWidth + 1) + 'px';""") | |
57 | |
58 self.assertEquals( | |
59 self._tab.EvaluateJavaScript("""document.documentElement.scrollTop | |
60 || document.body.scrollTop"""), 0) | |
61 self.assertEquals( | |
62 self._tab.EvaluateJavaScript("""document.documentElement.scrollLeft | |
63 || document.body.scrollLeft"""), 0) | |
64 | |
65 i = scroll.ScrollAction(direction='downright') | |
66 i.WillRunAction(self._tab) | |
67 | |
68 self._tab.ExecuteJavaScript(""" | |
69 window.__scrollAction.beginMeasuringHook = function() { | |
70 window.__didBeginMeasuring = true; | |
71 }; | |
72 window.__scrollAction.endMeasuringHook = function() { | |
73 window.__didEndMeasuring = true; | |
74 };""") | |
75 i.RunAction(self._tab) | |
76 | |
77 self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) | |
78 self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) | |
79 | |
80 # Allow for roundoff error in scaled viewport. | |
81 viewport_bottom = self._tab.EvaluateJavaScript( | |
82 """(document.documentElement.scrollTop || document.body.scrollTop) | |
83 + window.innerHeight""") | |
84 page_height = self._tab.EvaluateJavaScript('document.body.scrollHeight') | |
85 viewport_right = self._tab.EvaluateJavaScript( | |
86 """(document.documentElement.scrollLeft || document.body.scrollLeft) | |
87 + window.innerWidth""") | |
88 page_width = self._tab.EvaluateJavaScript('document.body.scrollWidth') | |
89 | |
90 # The diagonal scrolling behaves like a square. | |
91 # It will not continue scrolling down if it cannot also scroll right. | |
92 # So determine which axis scrolled all the way to its end. | |
93 vertical_difference = abs(viewport_bottom - page_height) | |
94 horizontal_difference = abs(viewport_right - page_width) | |
95 scroll_distance = min(vertical_difference, horizontal_difference) | |
96 self.assertTrue(scroll_distance <= 1, | |
97 msg=('vertical_difference=%d; ' | |
98 'horizontal_difference=%d; ' | |
99 'scroll_distance=%d ' | |
100 'page_height=%d ' | |
101 'page_width=%d') % | |
102 (vertical_difference, | |
103 horizontal_difference, | |
104 scroll_distance, | |
105 page_height, | |
106 page_width)) | |
107 | |
50 def testBoundingClientRect(self): | 108 def testBoundingClientRect(self): |
51 self.Navigate('blank.html') | 109 self.Navigate('blank.html') |
52 | 110 |
53 with open(os.path.join(os.path.dirname(__file__), | 111 with open(os.path.join(os.path.dirname(__file__), |
54 'gesture_common.js')) as f: | 112 'gesture_common.js')) as f: |
55 js = f.read() | 113 js = f.read() |
56 self._tab.ExecuteJavaScript(js) | 114 self._tab.ExecuteJavaScript(js) |
57 | 115 |
58 # Verify that the rect returned by getBoundingVisibleRect() in scroll.js is | 116 # Verify that the rect returned by getBoundingVisibleRect() in scroll.js is |
59 # completely contained within the viewport. Scroll events dispatched by the | 117 # completely contained within the viewport. Scroll events dispatched by the |
(...skipping 26 matching lines...) Expand all Loading... | |
86 viewport_width = int(self._tab.EvaluateJavaScript('window.innerWidth')) | 144 viewport_width = int(self._tab.EvaluateJavaScript('window.innerWidth')) |
87 | 145 |
88 self.assertTrue(rect_top >= 0, | 146 self.assertTrue(rect_top >= 0, |
89 msg='%s >= %s' % (rect_top, 0)) | 147 msg='%s >= %s' % (rect_top, 0)) |
90 self.assertTrue(rect_left >= 0, | 148 self.assertTrue(rect_left >= 0, |
91 msg='%s >= %s' % (rect_left, 0)) | 149 msg='%s >= %s' % (rect_left, 0)) |
92 self.assertTrue(rect_bottom <= viewport_height, | 150 self.assertTrue(rect_bottom <= viewport_height, |
93 msg='%s + %s <= %s' % (rect_top, rect_height, viewport_height)) | 151 msg='%s + %s <= %s' % (rect_top, rect_height, viewport_height)) |
94 self.assertTrue(rect_right <= viewport_width, | 152 self.assertTrue(rect_right <= viewport_width, |
95 msg='%s + %s <= %s' % (rect_left, rect_width, viewport_width)) | 153 msg='%s + %s <= %s' % (rect_left, rect_width, viewport_width)) |
OLD | NEW |