Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(795)

Side by Side Diff: tools/telemetry/telemetry/page/actions/scroll_unittest.py

Issue 976063003: Reenabling an old unit test for scrolling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Accidentally left the test checking the bottom of the viewport instead of comparing the top of the … Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
24 23
25 i = scroll.ScrollAction() 24 i = scroll.ScrollAction()
26 i.WillRunAction(self._tab) 25 i.WillRunAction(self._tab)
27 26
28 self._tab.ExecuteJavaScript(""" 27 self._tab.ExecuteJavaScript("""
29 window.__scrollAction.beginMeasuringHook = function() { 28 window.__scrollAction.beginMeasuringHook = function() {
30 window.__didBeginMeasuring = true; 29 window.__didBeginMeasuring = true;
31 }; 30 };
32 window.__scrollAction.endMeasuringHook = function() { 31 window.__scrollAction.endMeasuringHook = function() {
33 window.__didEndMeasuring = true; 32 window.__didEndMeasuring = true;
34 };""") 33 };""")
35 i.RunAction(self._tab) 34 i.RunAction(self._tab)
36 35
37 self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) 36 self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring'))
38 self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) 37 self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring'))
39 38
40 # Allow for roundoff error in scaled viewport.
41 scroll_position = self._tab.EvaluateJavaScript( 39 scroll_position = self._tab.EvaluateJavaScript(
42 """(document.documentElement.scrollTop || document.body.scrollTop) 40 """(document.documentElement.scrollTop || document.body.scrollTop)""")
sullivan 2015/03/05 03:03:58 Nit: Don't need the triple quotes since this fits
43 + window.innerHeight""") 41 self.assertTrue(scroll_position != 0,
44 scroll_height = self._tab.EvaluateJavaScript('document.body.scrollHeight') 42 msg='scroll_position=%d;' % (scroll_position))
45 difference = scroll_position - scroll_height
46 self.assertTrue(abs(difference) <= 1,
47 msg='scroll_position=%d; scroll_height=%d' %
48 (scroll_position, scroll_height))
49 43
50 def testBoundingClientRect(self): 44 def testBoundingClientRect(self):
51 self.Navigate('blank.html') 45 self.Navigate('blank.html')
52 46
53 with open(os.path.join(os.path.dirname(__file__), 47 with open(os.path.join(os.path.dirname(__file__),
54 'gesture_common.js')) as f: 48 'gesture_common.js')) as f:
55 js = f.read() 49 js = f.read()
56 self._tab.ExecuteJavaScript(js) 50 self._tab.ExecuteJavaScript(js)
57 51
58 # Verify that the rect returned by getBoundingVisibleRect() in scroll.js is 52 # Verify that the rect returned by getBoundingVisibleRect() in scroll.js is
(...skipping 27 matching lines...) Expand all
86 viewport_width = int(self._tab.EvaluateJavaScript('window.innerWidth')) 80 viewport_width = int(self._tab.EvaluateJavaScript('window.innerWidth'))
87 81
88 self.assertTrue(rect_top >= 0, 82 self.assertTrue(rect_top >= 0,
89 msg='%s >= %s' % (rect_top, 0)) 83 msg='%s >= %s' % (rect_top, 0))
90 self.assertTrue(rect_left >= 0, 84 self.assertTrue(rect_left >= 0,
91 msg='%s >= %s' % (rect_left, 0)) 85 msg='%s >= %s' % (rect_left, 0))
92 self.assertTrue(rect_bottom <= viewport_height, 86 self.assertTrue(rect_bottom <= viewport_height,
93 msg='%s + %s <= %s' % (rect_top, rect_height, viewport_height)) 87 msg='%s + %s <= %s' % (rect_top, rect_height, viewport_height))
94 self.assertTrue(rect_right <= viewport_width, 88 self.assertTrue(rect_right <= viewport_width,
95 msg='%s + %s <= %s' % (rect_left, rect_width, viewport_width)) 89 msg='%s + %s <= %s' % (rect_left, rect_width, viewport_width))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698