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 |
(...skipping 23 matching lines...) Expand all Loading... | |
34 i.RunAction(self._tab) | 34 i.RunAction(self._tab) |
35 | 35 |
36 self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) | 36 self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) |
37 self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) | 37 self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) |
38 | 38 |
39 scroll_position = self._tab.EvaluateJavaScript( | 39 scroll_position = self._tab.EvaluateJavaScript( |
40 '(document.documentElement.scrollTop || document.body.scrollTop)') | 40 '(document.documentElement.scrollTop || document.body.scrollTop)') |
41 self.assertTrue(scroll_position != 0, | 41 self.assertTrue(scroll_position != 0, |
42 msg='scroll_position=%d;' % (scroll_position)) | 42 msg='scroll_position=%d;' % (scroll_position)) |
43 | 43 |
44 def testDiagonalScrollAction(self): | |
45 self.Navigate('blank.html') | |
46 | |
47 # Make page bigger than window so it's scrollable. | |
48 self._tab.ExecuteJavaScript("""document.body.style.height = | |
49 (2 * window.innerHeight + 1) + 'px';""") | |
50 self._tab.ExecuteJavaScript("""document.body.style.width = | |
51 (2 * window.innerWidth + 1) + 'px';""") | |
52 | |
53 self.assertEquals( | |
54 self._tab.EvaluateJavaScript("""document.documentElement.scrollTop | |
55 || document.body.scrollTop"""), 0) | |
56 self.assertEquals( | |
57 self._tab.EvaluateJavaScript("""document.documentElement.scrollLeft | |
58 || document.body.scrollLeft"""), 0) | |
59 | |
60 i = scroll.ScrollAction(direction='downright') | |
61 i.WillRunAction(self._tab) | |
62 | |
63 self._tab.ExecuteJavaScript(""" | |
64 window.__scrollAction.beginMeasuringHook = function() { | |
65 window.__didBeginMeasuring = true; | |
66 }; | |
67 window.__scrollAction.endMeasuringHook = function() { | |
68 window.__didEndMeasuring = true; | |
69 };""") | |
70 i.RunAction(self._tab) | |
71 | |
72 self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) | |
73 self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) | |
nednguyen
2015/03/06 19:07:51
Why do we need this?
| |
74 | |
75 viewport_top = self._tab.EvaluateJavaScript( | |
76 '(document.documentElement.scrollTop || document.body.scrollTop)') | |
77 self.assertTrue(viewport_top != 0, msg='viewport_top=%d;' % viewport_top) | |
78 | |
79 viewport_left = self._tab.EvaluateJavaScript( | |
80 '(document.documentElement.scrollLeft || document.body.scrollLeft)') | |
81 self.assertTrue(viewport_left != 0, msg='viewport_left=%d;' % viewport_left) | |
82 | |
44 def testBoundingClientRect(self): | 83 def testBoundingClientRect(self): |
45 self.Navigate('blank.html') | 84 self.Navigate('blank.html') |
46 | 85 |
47 with open(os.path.join(os.path.dirname(__file__), | 86 with open(os.path.join(os.path.dirname(__file__), |
48 'gesture_common.js')) as f: | 87 'gesture_common.js')) as f: |
49 js = f.read() | 88 js = f.read() |
50 self._tab.ExecuteJavaScript(js) | 89 self._tab.ExecuteJavaScript(js) |
51 | 90 |
52 # Verify that the rect returned by getBoundingVisibleRect() in scroll.js is | 91 # Verify that the rect returned by getBoundingVisibleRect() in scroll.js is |
53 # completely contained within the viewport. Scroll events dispatched by the | 92 # completely contained within the viewport. Scroll events dispatched by the |
(...skipping 26 matching lines...) Expand all Loading... | |
80 viewport_width = int(self._tab.EvaluateJavaScript('window.innerWidth')) | 119 viewport_width = int(self._tab.EvaluateJavaScript('window.innerWidth')) |
81 | 120 |
82 self.assertTrue(rect_top >= 0, | 121 self.assertTrue(rect_top >= 0, |
83 msg='%s >= %s' % (rect_top, 0)) | 122 msg='%s >= %s' % (rect_top, 0)) |
84 self.assertTrue(rect_left >= 0, | 123 self.assertTrue(rect_left >= 0, |
85 msg='%s >= %s' % (rect_left, 0)) | 124 msg='%s >= %s' % (rect_left, 0)) |
86 self.assertTrue(rect_bottom <= viewport_height, | 125 self.assertTrue(rect_bottom <= viewport_height, |
87 msg='%s + %s <= %s' % (rect_top, rect_height, viewport_height)) | 126 msg='%s + %s <= %s' % (rect_top, rect_height, viewport_height)) |
88 self.assertTrue(rect_right <= viewport_width, | 127 self.assertTrue(rect_right <= viewport_width, |
89 msg='%s + %s <= %s' % (rect_left, rect_width, viewport_width)) | 128 msg='%s + %s <= %s' % (rect_left, rect_width, viewport_width)) |
OLD | NEW |