def testDiagonalScrollAction(self): # Diagonal scrolling was not supported in the ScrollAction until Chrome # branch number 2332 branch_num = self._tab.browser._browser_backend.devtools_client \ .GetChromeBranchNumber() if branch_num < 2332: return self.Navigate('blank.html') # Make page bigger than window so it's scrollable. self._tab.ExecuteJavaScript("""document.body.style.height = (2 * window.innerHeight + 1) + 'px';""") self._tab.ExecuteJavaScript("""document.body.style.width = (2 * window.innerWidth + 1) + 'px';""") self.assertEquals( self._tab.EvaluateJavaScript("""document.documentElement.scrollTop || document.body.scrollTop"""), 0) self.assertEquals( self._tab.EvaluateJavaScript("""document.documentElement.scrollLeft || document.body.scrollLeft"""), 0) i = scroll.ScrollAction(direction='downright') i.WillRunAction(self._tab) i.RunAction(self._tab) viewport_top = self._tab.EvaluateJavaScript( '(document.documentElement.scrollTop || document.body.scrollTop)') self.assertTrue(viewport_top != 0, msg='viewport_top=%d;' % viewport_top) viewport_left = self._tab.EvaluateJavaScript( '(document.documentElement.scrollLeft || document.body.scrollLeft)') self.assertTrue(viewport_left != 0, msg='viewport_left=%d;' % viewport_left)
def testDiagonalScrollAction(self): # Diagonal scrolling was not supported in the ScrollAction until Chrome # branch number 2332 branch_num = self._tab.browser._browser_backend.devtools_client \ .GetChromeBranchNumber() if branch_num < 2332: return self._MakePageVerticallyScrollable() self.assertEquals( self._tab.EvaluateJavaScript('document.scrollingElement.scrollTop'), 0) self._MakePageHorizontallyScrollable() self.assertEquals( self._tab.EvaluateJavaScript('document.scrollingElement.scrollLeft'), 0) i = scroll.ScrollAction(direction='downright') i.WillRunAction(self._tab) i.RunAction(self._tab) viewport_top = self._tab.EvaluateJavaScript( 'document.scrollingElement.scrollTop') self.assertTrue(viewport_top != 0, msg='viewport_top=%d;' % viewport_top) viewport_left = self._tab.EvaluateJavaScript( 'document.scrollingElement.scrollLeft') self.assertTrue(viewport_left != 0, msg='viewport_left=%d;' % viewport_left)
def testScrollAction(self): self.Navigate('blank.html') # Make page bigger than window so it's scrollable. self._tab.ExecuteJavaScript("""document.body.style.height = (2 * window.innerHeight + 1) + 'px';""") self.assertEquals( self._tab.EvaluateJavaScript("""document.documentElement.scrollTop || document.body.scrollTop"""), 0) i = scroll.ScrollAction() i.WillRunAction(self._tab) self._tab.ExecuteJavaScript(""" window.__scrollAction.beginMeasuringHook = function() { window.__didBeginMeasuring = true; }; window.__scrollAction.endMeasuringHook = function() { window.__didEndMeasuring = true; };""") i.RunAction(self._tab) self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) scroll_position = self._tab.EvaluateJavaScript( '(document.documentElement.scrollTop || document.body.scrollTop)') self.assertTrue(scroll_position != 0, msg='scroll_position=%d;' % (scroll_position))
def testScrollAction(self): self._MakePageVerticallyScrollable() self.assertEquals( self._tab.EvaluateJavaScript('document.scrollingElement.scrollTop'), 0) i = scroll.ScrollAction() i.WillRunAction(self._tab) self._tab.ExecuteJavaScript(""" window.__scrollAction.beginMeasuringHook = function() { window.__didBeginMeasuring = true; }; window.__scrollAction.endMeasuringHook = function() { window.__didEndMeasuring = true; };""") i.RunAction(self._tab) self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) scroll_position = self._tab.EvaluateJavaScript( 'document.scrollingElement.scrollTop') self.assertTrue( scroll_position != 0, msg='scroll_position=%d;' % (scroll_position))
def testWheelScrollDistanceWhileZoomed(self): # TODO(bokan): This API was added recently so only run the test once it's # available. Remove this check once it rolls into stable builds. chromeSupportsSetPageScaleFactor = self._tab.EvaluateJavaScript( "'setPageScaleFactor' in chrome.gpuBenchmarking") if not chromeSupportsSetPageScaleFactor: return self._tab.EvaluateJavaScript( 'chrome.gpuBenchmarking.setPageScaleFactor(2)') # Wheel scrolling can cause animated scrolls. This is a problem here since # Chrome currently doesn't hand off the animation between the visual and # layout viewports. To account for this, scroll the visual viewport to it's # maximum extent so that the entire scroll goes to the layout viewport. screenHeight = self._tab.EvaluateJavaScript( 'window.visualViewport.height') i = scroll.ScrollAction( distance=screenHeight * 2, direction="down", speed_in_pixels_per_second=5000, synthetic_gesture_source=page_action.GESTURE_SOURCE_MOUSE) i.WillRunAction(self._tab) i.RunAction(self._tab) # Ensure the layout viewport isn't scrolled but the visual is. self.assertGreater( self._tab.EvaluateJavaScript('window.visualViewport.offsetTop'), screenHeight / 2 - 1) self.assertEqual(self._tab.EvaluateJavaScript('window.scrollY'), 0) self._RunScrollDistanceTest(2000, 2000, page_action.GESTURE_SOURCE_MOUSE, 60)
def testDiagonalScrollAction(self): self._MakePageVerticallyScrollable() self.assertEquals( self._tab.EvaluateJavaScript( 'document.scrollingElement.scrollTop'), 0) self._MakePageHorizontallyScrollable() self.assertEquals( self._tab.EvaluateJavaScript( 'document.scrollingElement.scrollLeft'), 0) i = scroll.ScrollAction(direction='downright') i.WillRunAction(self._tab) i.RunAction(self._tab) viewport_top = self._tab.EvaluateJavaScript( 'document.scrollingElement.scrollTop') self.assertTrue(viewport_top != 0, msg='viewport_top=%d;' % viewport_top) viewport_left = self._tab.EvaluateJavaScript( 'document.scrollingElement.scrollLeft') self.assertTrue(viewport_left != 0, msg='viewport_left=%d;' % viewport_left)
def run_once(self): """Runs the test once.""" perf_results = {} def record_fps_info(fps_data, fps_info): ''' record the fps info from |fps_meter| ''' frame_info, frame_times = fps_info frame_info_str = ''.join(frame_info) fps_count = sum(map(int, frame_info_str.replace(_SEPARATOR, ""))) fps_data.append(fps_count) fps_data = [] fps = fps_meter.FPSMeter(functools.partial(record_fps_info, fps_data)) with chrome.Chrome(init_network_controller=True) as cr: for url in _LIST_OF_URLS: tab = cr.browser.tabs.New() tab.Navigate(url) try: tab.WaitForDocumentReadyStateToBeComplete(timeout=15) except py_utils.TimeoutException: logging.warning('Time out during loading url ' + url) for x in range(0, 3): page_scroll = scroll.ScrollAction( speed_in_pixels_per_second=_SCROLL_SPEED, distance=_SCROLL_DISTANCE) cr.browser.platform.SetHTTPServerDirectories(self.bindir) page_scroll.WillRunAction(tab) fps.start() page_scroll.RunAction(tab) fps.stop() page_scroll = scroll.ScrollAction( direction="up", speed_in_pixels_per_second=_SCROLL_SPEED, distance=_SCROLL_DISTANCE) page_scroll.WillRunAction(tab) fps.start() page_scroll.RunAction(tab) fps.stop() time.sleep(1) value = getattr(numpy, "mean")(fps_data) self.output_perf_value(description="fps average", value=value, units='frame per second', higher_is_better=True)
def _RunScrollDistanceTest(self, distance, speed, source, maxError): # TODO(bokan): Distance tests will fail on versions of Chrome that haven't # been fixed. The fixes landed at the same time as the # setBrowserControlsShown method was added so only run the test if that's # available. Once that rolls into ref builds we can remove this check. distanceFixedInChrome = self._tab.EvaluateJavaScript( "'setBrowserControlsShown' in chrome.gpuBenchmarking") if not distanceFixedInChrome: return # Hide the URL bar so we can measure scrolled distance without worrying # about the URL bar consuming delta. self._tab.ExecuteJavaScript( 'chrome.gpuBenchmarking.setBrowserControlsShown(false);') # Make the document tall enough to accomodate the requested distance but # also leave enough space so we can tell if the scroll overshoots the # target. screenHeight = self._tab.EvaluateJavaScript( 'window.visualViewport.height') documentHeight = (screenHeight + distance) * 2 self._tab.ExecuteJavaScript('document.body.style.height = "' + str(documentHeight) + 'px";') self.assertEquals( self._tab.EvaluateJavaScript( 'document.scrollingElement.scrollTop'), 0) # Allow for some visual viewport offset. For example, if the test doesn't # want any visual viewport offset due to animation handoff error between # the two viewports. start_offset = self._tab.EvaluateJavaScript( 'window.visualViewport.pageTop') i = scroll.ScrollAction(distance=distance, direction="down", speed_in_pixels_per_second=speed, synthetic_gesture_source=source) i.WillRunAction(self._tab) i.RunAction(self._tab) actual = self._tab.EvaluateJavaScript( 'window.visualViewport.pageTop') - start_offset # TODO(bokan): setBrowserControlsShown isn't quite enough. Chrome will hide # the browser controls but then they animate in after a timeout. We'll need # to add a way to lock them to hidden. Until then, just increase the # allowed error. urlBarError = 150 self.assertAlmostEqual(distance, actual, delta=maxError + urlBarError)