def testScroll(self): if not page_action.IsGestureSourceTypeSupported(self._tab, 'touch'): return self.Navigate('page_with_swipeables.html') action_runner = action_runner_module.ActionRunner(self._tab, skip_waits=True) action_runner.ScrollElement(selector='#left-right', direction='right', left_start_ratio=0.9) self.assertTrue( action_runner.EvaluateJavaScript( 'document.querySelector("#left-right").scrollLeft') > 75) action_runner.ScrollElement(selector='#top-bottom', direction='down', top_start_ratio=0.9) self.assertTrue( action_runner.EvaluateJavaScript( 'document.querySelector("#top-bottom").scrollTop') > 75) action_runner.ScrollPage(direction='right', left_start_ratio=0.9, distance=100) self.assertTrue( action_runner.EvaluateJavaScript('document.body.scrollLeft') > 75)
def testPinchByApiCalledWithCorrectArguments(self): self.Navigate('blank.html') if not page_action.IsGestureSourceTypeSupported(self._tab, 'touch'): return action_runner = action_runner_module.ActionRunner(self._tab) action_runner.ExecuteJavaScript(''' chrome.gpuBenchmarking.pinchBy = function( scaleFactor, anchorLeft, anchorTop, callback, speed) { window.__test_scaleFactor = scaleFactor; window.__test_anchorLeft = anchorLeft; window.__test_anchorTop = anchorTop; window.__test_callback = callback; window.__test_speed = speed; window.__pinchActionDone = true; };''') action_runner.PinchPage(scale_factor=2) self.assertEqual( 2, action_runner.EvaluateJavaScript('window.__test_scaleFactor')) self.assertTrue( action_runner.EvaluateJavaScript('!isNaN(window.__test_anchorLeft)')) self.assertTrue( action_runner.EvaluateJavaScript('!isNaN(window.__test_anchorTop)')) self.assertTrue( action_runner.EvaluateJavaScript('!!window.__test_callback')) self.assertEqual( 800, action_runner.EvaluateJavaScript('window.__test_speed'))
def WillRunAction(self, tab): for js_file in ['gesture_common.js', 'swipe.js']: with open(os.path.join(os.path.dirname(__file__), js_file)) as f: js = f.read() tab.ExecuteJavaScript(js) # Fail if browser doesn't support synthetic swipe gestures. if not tab.EvaluateJavaScript( 'window.__SwipeAction_SupportedByBrowser()'): raise page_action.PageActionNotSupported( 'Synthetic swipe not supported for this browser') if (page_action.GetGestureSourceTypeFromOptions(tab) == 'chrome.gpuBenchmarking.MOUSE_INPUT'): raise page_action.PageActionNotSupported( 'Swipe page action does not support mouse input') if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): raise page_action.PageActionNotSupported( 'Touch input not supported for this browser') done_callback = 'function() { window.__swipeActionDone = true; }' tab.ExecuteJavaScript(""" window.__swipeActionDone = false; window.__swipeAction = new __SwipeAction(%s);""" % (done_callback))
def WillRunAction(self, tab): for js_file in ['gesture_common.js', 'scroll.js']: with open(os.path.join(os.path.dirname(__file__), js_file)) as f: js = f.read() tab.ExecuteJavaScript(js) # Fail if browser doesn't support synthetic scroll gestures. if not tab.EvaluateJavaScript( 'window.__ScrollAction_SupportedByBrowser()'): raise page_action.PageActionNotSupported( 'Synthetic scroll not supported for this browser') # Fail if this action requires touch and we can't send touch events. if self._use_touch: if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): raise page_action.PageActionNotSupported( 'Touch scroll not supported for this browser') if (page_action.GetGestureSourceTypeFromOptions(tab) == 'chrome.gpuBenchmarking.MOUSE_INPUT'): raise page_action.PageActionNotSupported( 'Scroll requires touch on this page but mouse input was requested' ) done_callback = 'function() { window.__scrollActionDone = true; }' tab.ExecuteJavaScript(""" window.__scrollActionDone = false; window.__scrollAction = new __ScrollAction(%s, %s);""" % (done_callback, self._distance_func))
def WillRunAction(self, tab): for js_file in ['gesture_common.js', 'pinch.js']: with open(os.path.join(os.path.dirname(__file__), js_file)) as f: js = f.read() tab.ExecuteJavaScript(js) # Fail if browser doesn't support synthetic pinch gestures. if not tab.EvaluateJavaScript( 'window.__PinchAction_SupportedByBrowser()'): raise page_action.PageActionNotSupported( 'Synthetic pinch not supported for this browser') # TODO(dominikg): Remove once JS interface changes have rolled into stable. if not tab.EvaluateJavaScript( 'chrome.gpuBenchmarking.newPinchInterface'): raise page_action.PageActionNotSupported( 'This version of the browser doesn\'t support the new JS interface ' 'for pinch gestures.') if (page_action.GetGestureSourceTypeFromOptions(tab) == 'chrome.gpuBenchmarking.MOUSE_INPUT'): raise page_action.PageActionNotSupported( 'Pinch page action does not support mouse input') if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): raise page_action.PageActionNotSupported( 'Touch input not supported for this browser') done_callback = 'function() { window.__pinchActionDone = true; }' tab.ExecuteJavaScript(""" window.__pinchActionDone = false; window.__pinchAction = new __PinchAction(%s);""" % done_callback)