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 (GestureAction.GetGestureSourceTypeFromOptions(tab) == 'chrome.gpuBenchmarking.MOUSE_INPUT'): raise page_action.PageActionNotSupported( 'Pinch page action does not support mouse input') if not GestureAction.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)
def WillRunAction(self, page, tab): for js_file in ['gesture_common.js', 'scroll_bounce.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 bounce gestures. if not tab.EvaluateJavaScript( 'window.__ScrollBounceAction_SupportedByBrowser()'): raise page_action.PageActionNotSupported( 'Synthetic scroll bounce not supported for this browser') # Fail if we can't send touch events (bouncing is really only # interesting for touch) if not GestureAction.IsGestureSourceTypeSupported(tab, 'touch'): raise page_action.PageActionNotSupported( 'Touch scroll not supported for this browser') if (GestureAction.GetGestureSourceTypeFromOptions(tab) == 'chrome.gpuBenchmarking.MOUSE_INPUT'): raise page_action.PageActionNotSupported( 'ScrollBounce page action does not support mouse input') done_callback = 'function() { window.__scrollBounceActionDone = true; }' tab.ExecuteJavaScript(""" window.__scrollBounceActionDone = false; window.__scrollBounceAction = new __ScrollBounceAction(%s);""" % (done_callback))
def WillRunAction(self, page, 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 (hasattr(self, 'scroll_requires_touch') and self.scroll_requires_touch and not tab.EvaluateJavaScript( 'chrome.gpuBenchmarking.smoothScrollBySendsTouch()')): raise page_action.PageActionNotSupported( 'Touch scroll not supported for this browser') distance_func = 'null' if hasattr(self, 'remaining_scroll_distance_function'): distance_func = self.remaining_scroll_distance_function done_callback = 'function() { window.__scrollActionDone = true; }' tab.ExecuteJavaScript(""" window.__scrollActionDone = false; window.__scrollAction = new __ScrollAction(%s, %s);""" % (done_callback, distance_func))
def WillRunAction(self, page, 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 hasattr(self, 'scroll_requires_touch'): if (self.scroll_requires_touch and not GestureAction.IsGestureSourceTypeSupported( tab, 'touch')): raise page_action.PageActionNotSupported( 'Touch scroll not supported for this browser') if (GestureAction.GetGestureSourceTypeFromOptions(tab) == 'chrome.gpuBenchmarking.MOUSE_INPUT'): raise page_action.PageActionNotSupported( 'Scroll requires touch on this page but mouse input was requested' ) distance_func = 'null' if hasattr(self, 'scroll_distance_function'): distance_func = self.scroll_distance_function done_callback = 'function() { window.__scrollActionDone = true; }' tab.ExecuteJavaScript(""" window.__scrollActionDone = false; window.__scrollAction = new __ScrollAction(%s, %s);""" % (done_callback, distance_func))
def __init__(self, selector=None, text=None, element_function=None, left_start_ratio=0.5, top_start_ratio=0.5, direction='down', distance=None, distance_expr=None, speed_in_pixels_per_second=800, use_touch=False): super(ScrollAction, self).__init__() if direction not in ['down', 'up', 'left', 'right']: raise page_action.PageActionNotSupported( 'Invalid scroll direction: %s' % self.direction) self._selector = selector self._text = text self._element_function = element_function self._left_start_ratio = left_start_ratio self._top_start_ratio = top_start_ratio self._direction = direction self._speed = speed_in_pixels_per_second self._use_touch = use_touch self._distance_func = 'null' if distance: assert not distance_expr distance_expr = str(distance) if distance_expr: self._distance_func = ('function() { return 0 + %s; }' % distance_expr)
def RunGesture(self, page, tab, previous_action): # scrollable_element_function is a function that passes the scrollable # element on the page to a callback. For example: # function (callback) { # callback(document.getElementById('foo')); # } left_start_percentage = 0.5 top_start_percentage = 0.5 direction = 'down' speed = 800 gesture_source_type = GestureAction.GetGestureSourceTypeFromOptions(tab) if hasattr(self, 'left_start_percentage'): left_start_percentage = self.left_start_percentage if hasattr(self, 'top_start_percentage'): top_start_percentage = self.top_start_percentage if hasattr(self, 'direction'): direction = self.direction if direction not in ['down', 'up', 'left', 'right']: raise page_action.PageActionNotSupported( 'Invalid scroll direction: %s' % direction) if hasattr(self, 'speed'): speed = self.speed if hasattr(self, 'scroll_requires_touch') and self.scroll_requires_touch: gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT' if hasattr(self, 'scrollable_element_function'): tab.ExecuteJavaScript(""" (%s)(function(element) { window.__scrollAction.start( { element: element, left_start_percentage: %s, top_start_percentage: %s, direction: '%s', speed: %s, gesture_source_type: %s }) });""" % (self.scrollable_element_function, left_start_percentage, top_start_percentage, direction, speed, gesture_source_type)) else: tab.ExecuteJavaScript(""" window.__scrollAction.start( { element: document.body, left_start_percentage: %s, top_start_percentage: %s, direction: '%s', speed: %s, gesture_source_type: %s });""" % (left_start_percentage, top_start_percentage, direction, speed, gesture_source_type)) tab.WaitForJavaScriptExpression('window.__scrollActionDone', 60)
def WillRunAction(self, page, 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') if (GestureAction.GetGestureSourceTypeFromOptions(tab) == 'chrome.gpuBenchmarking.MOUSE_INPUT'): raise page_action.PageActionNotSupported( 'Pinch page action does not support mouse input') done_callback = 'function() { window.__pinchActionDone = true; }' tab.ExecuteJavaScript(""" window.__pinchActionDone = false; window.__pinchAction = new __PinchAction(%s);""" % done_callback)
def WillRunAction(self, page, tab): for js_file in ['gesture_common.js', 'tap.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 tap gestures. if not tab.EvaluateJavaScript('window.__TapAction_SupportedByBrowser()'): raise page_action.PageActionNotSupported( 'Synthetic tap not supported for this browser') done_callback = 'function() { window.__tapActionDone = true; }' tab.ExecuteJavaScript(""" window.__tapActionDone = false; window.__tapAction = new __TapAction(%s);""" % (done_callback))
def __init__(self, selector=None, text=None, element_function=None, left_start_ratio=0.5, top_start_ratio=0.5, direction='left', distance=100, speed=800): super(SwipeAction, self).__init__(None) if direction not in ['down', 'up', 'left', 'right']: raise page_action.PageActionNotSupported( 'Invalid swipe direction: %s' % self.direction) self.automatically_record_interaction = False self._selector = selector self._text = text self._element_function = element_function self._left_start_ratio = left_start_ratio self._top_start_ratio = top_start_ratio self._direction = direction self._distance = distance self._speed = speed
def RunGesture(self, page, tab, previous_action): left_start_percentage = 0.5 top_start_percentage = 0.5 direction = 'left' distance = 100 if hasattr(self, 'left_start_percentage'): left_start_percentage = self.left_start_percentage if hasattr(self, 'top_start_percentage'): top_start_percentage = self.top_start_percentage if hasattr(self, 'direction'): direction = self.direction if direction not in ['down', 'up', 'left', 'right']: raise page_action.PageActionNotSupported( 'Invalid swipe direction: %s' % direction) if hasattr(self, 'distance'): distance = self.distance if hasattr(self, 'element_function'): tab.ExecuteJavaScript(""" (%s)(function(element) { window.__swipeAction.start( { element: element, left_start_percentage: %s, top_start_percentage: %s, direction: '%s', distance: %s }) });""" % (self.element_function, left_start_percentage, top_start_percentage, direction, distance)) else: tab.ExecuteJavaScript(""" window.__swipeAction.start( { element: document.body, left_start_percentage: %s, top_start_percentage: %s, direction: '%s', distance: %s });""" % (left_start_percentage, top_start_percentage, direction, distance)) tab.WaitForJavaScriptExpression('window.__swipeActionDone', 60)
def WillRunAction(self, page, 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') # TODO(dominikg): Query synthetic gesture target to check if touch is # supported. done_callback = 'function() { window.__swipeActionDone = true; }' tab.ExecuteJavaScript(""" window.__swipeActionDone = false; window.__swipeAction = new __SwipeAction(%s);""" % (done_callback))
def RunGesture(self, page, tab): left_start_percentage = 0.5 top_start_percentage = 0.5 direction = 'down' # Should be big enough to do more than just hide the URL bar. distance = 100 # This needs to be < height / repeat_count so we don't walk off the screen. # We also probably don't want to spend more than a couple frames in # overscroll since it may mask any synthetic delays. overscroll = 10 # It's the transitions we really want to stress, make this big. repeat_count = 10 # 7 pixels per frame should be plenty of frames. speed = 400 if hasattr(self, 'left_start_percentage'): left_start_percentage = self.left_start_percentage if hasattr(self, 'top_start_percentage'): top_start_percentage = self.top_start_percentage if hasattr(self, 'direction'): direction = self.direction if direction not in ['down', 'up', 'left', 'right']: raise page_action.PageActionNotSupported( 'Invalid scroll bounce direction: %s' % direction) if hasattr(self, 'distance'): distance = self.distance if hasattr(self, 'overscroll'): overscroll = self.overscroll if hasattr(self, 'repeat_count'): repeat_count = self.repeat_count if hasattr(self, 'speed'): speed = self.speed if hasattr(self, 'element_function'): tab.ExecuteJavaScript(""" (%s)(function(element) { window.__scrollBounceAction.start( { element: element, left_start_percentage: %s, top_start_percentage: %s, direction: '%s', distance: %s, overscroll: %s, repeat_count: %s, speed: %s }) });""" % (self.element_function, left_start_percentage, top_start_percentage, direction, distance, overscroll, repeat_count, speed)) else: tab.ExecuteJavaScript( """ window.__scrollBounceAction.start( { element: document.body, left_start_percentage: %s, top_start_percentage: %s, direction: '%s', distance: %s, overscroll: %s, repeat_count: %s, speed: %s });""" % (left_start_percentage, top_start_percentage, direction, distance, overscroll, repeat_count, speed)) tab.WaitForJavaScriptExpression('window.__scrollBounceActionDone', 60)