OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 import os | 4 import os |
5 | 5 |
6 from telemetry.core import util | 6 from telemetry.core import util |
7 from telemetry.page import page as page_module | 7 from telemetry.page import page as page_module |
8 from telemetry.page.actions import scroll | 8 from telemetry.page.actions import scroll |
9 from telemetry.unittest import tab_test_case | 9 from telemetry.unittest import tab_test_case |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 page = self.CreateAndNavigateToPageFromUnittestDataDir( | 30 page = self.CreateAndNavigateToPageFromUnittestDataDir( |
31 "blank.html", | 31 "blank.html", |
32 page_attributes={"smoothness": { | 32 page_attributes={"smoothness": { |
33 "action": "scroll" | 33 "action": "scroll" |
34 }}) | 34 }}) |
35 # Make page bigger than window so it's scrollable. | 35 # Make page bigger than window so it's scrollable. |
36 self._tab.ExecuteJavaScript("""document.body.style.height = | 36 self._tab.ExecuteJavaScript("""document.body.style.height = |
37 (2 * window.innerHeight + 1) + 'px';""") | 37 (2 * window.innerHeight + 1) + 'px';""") |
38 | 38 |
39 self.assertEquals( | 39 self.assertEquals( |
40 self._tab.EvaluateJavaScript('document.body.scrollTop'), 0) | 40 self._tab.EvaluateJavaScript("""document.documentElement.scrollTop |
| 41 || document.body.scrollTop"""), 0) |
41 | 42 |
42 i = scroll.ScrollAction() | 43 i = scroll.ScrollAction() |
43 i.WillRunAction(page, self._tab) | 44 i.WillRunAction(page, self._tab) |
44 | 45 |
45 self._tab.ExecuteJavaScript(""" | 46 self._tab.ExecuteJavaScript(""" |
46 window.__scrollAction.beginMeasuringHook = function() { | 47 window.__scrollAction.beginMeasuringHook = function() { |
47 window.__didBeginMeasuring = true; | 48 window.__didBeginMeasuring = true; |
48 }; | 49 }; |
49 window.__scrollAction.endMeasuringHook = function() { | 50 window.__scrollAction.endMeasuringHook = function() { |
50 window.__didEndMeasuring = true; | 51 window.__didEndMeasuring = true; |
51 };""") | 52 };""") |
52 i.RunAction(page, self._tab, None) | 53 i.RunAction(page, self._tab, None) |
53 | 54 |
54 self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) | 55 self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) |
55 self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) | 56 self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) |
56 | 57 |
57 # Allow for roundoff error in scaled viewport. | 58 # Allow for roundoff error in scaled viewport. |
58 scroll_position = self._tab.EvaluateJavaScript( | 59 scroll_position = self._tab.EvaluateJavaScript( |
59 'document.body.scrollTop + window.innerHeight') | 60 """(document.documentElement.scrollTop || document.body.scrollTop) |
| 61 + window.innerHeight""") |
60 scroll_height = self._tab.EvaluateJavaScript('document.body.scrollHeight') | 62 scroll_height = self._tab.EvaluateJavaScript('document.body.scrollHeight') |
61 difference = scroll_position - scroll_height | 63 difference = scroll_position - scroll_height |
62 self.assertTrue(abs(difference) <= 1) | 64 self.assertTrue(abs(difference) <= 1) |
63 | 65 |
64 def testBoundingClientRect(self): | 66 def testBoundingClientRect(self): |
65 self.CreateAndNavigateToPageFromUnittestDataDir('blank.html', {}) | 67 self.CreateAndNavigateToPageFromUnittestDataDir('blank.html', {}) |
66 with open(os.path.join(os.path.dirname(__file__), 'scroll.js')) as f: | 68 with open(os.path.join(os.path.dirname(__file__), 'scroll.js')) as f: |
67 js = f.read() | 69 js = f.read() |
68 self._tab.ExecuteJavaScript(js) | 70 self._tab.ExecuteJavaScript(js) |
69 | 71 |
(...skipping 20 matching lines...) Expand all Loading... |
90 '__ScrollAction_GetBoundingVisibleRect(document.body).width')) | 92 '__ScrollAction_GetBoundingVisibleRect(document.body).width')) |
91 rect_right = rect_left + rect_width | 93 rect_right = rect_left + rect_width |
92 | 94 |
93 viewport_height = int(self._tab.EvaluateJavaScript('window.innerHeight')) | 95 viewport_height = int(self._tab.EvaluateJavaScript('window.innerHeight')) |
94 viewport_width = int(self._tab.EvaluateJavaScript('window.innerWidth')) | 96 viewport_width = int(self._tab.EvaluateJavaScript('window.innerWidth')) |
95 | 97 |
96 self.assertTrue(rect_bottom <= viewport_height, | 98 self.assertTrue(rect_bottom <= viewport_height, |
97 msg='%s + %s <= %s' % (rect_top, rect_height, viewport_height)) | 99 msg='%s + %s <= %s' % (rect_top, rect_height, viewport_height)) |
98 self.assertTrue(rect_right <= viewport_width, | 100 self.assertTrue(rect_right <= viewport_width, |
99 msg='%s + %s <= %s' % (rect_left, rect_width, viewport_width)) | 101 msg='%s + %s <= %s' % (rect_left, rect_width, viewport_width)) |
OLD | NEW |