Пример #1
0
  def WillRunAction(self, tab):
    if self._direction in ('downleft', 'downright', 'upleft', 'upright'):
      # Diagonal scrolling support was added in Chrome branch number 2332.
      branch_num = (
          tab.browser._browser_backend.devtools_client.GetChromeBranchNumber())
      if branch_num < 2332:
        raise ValueError('Diagonal scrolling requires Chrome branch number'
                         ' 2332 or later. Found branch number %d' %
                         branch_num)
    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 (self._synthetic_gesture_source ==
          '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))
Пример #2
0
    def RunAction(self, tab):
        if (self._selector is None and self._text is None
                and self._element_function is None):
            self._element_function = 'document.body'

        gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'
        if (page_action.IsGestureSourceTypeSupported(tab, 'mouse')
                and not self._use_touch):
            gesture_source_type = 'chrome.gpuBenchmarking.MOUSE_INPUT'

        code = '''
        function(element, info) {
          if (!element) {
            throw Error('Cannot find element: ' + info);
          }
          window.__dragAction.start({
            element: element,
            left_start_ratio: %s,
            top_start_ratio: %s,
            left_end_ratio: %s,
            top_end_ratio: %s,
            speed: %s,
            gesture_source_type: %s
          });
        }''' % (self._left_start_ratio, self._top_start_ratio,
                self._left_end_ratio, self._top_end_ratio, self._speed,
                gesture_source_type)
        page_action.EvaluateCallbackWithElement(
            tab,
            code,
            selector=self._selector,
            text=self._text,
            element_function=self._element_function)
        tab.WaitForJavaScriptExpression('window.__dragActionDone', 60)
Пример #3
0
    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 (self._synthetic_gesture_source ==
                '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)
Пример #4
0
    def WillRunAction(self, tab):
        utils.InjectJavaScript(tab, 'gesture_common.js')
        utils.InjectJavaScript(tab, 'scroll.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 (self._synthetic_gesture_source ==
                    'chrome.gpuBenchmarking.MOUSE_INPUT'):
                raise page_action.PageActionNotSupported(
                    'Scroll requires touch on this page but mouse input was requested'
                )

        tab.ExecuteJavaScript(
            """
        window.__scrollActionDone = false;
        window.__scrollAction = new __ScrollAction(
            {{ @callback }}, {{ @distance }});""",
            callback='function() { window.__scrollActionDone = true; }',
            distance=self._distance_func)
Пример #5
0
  def WillRunAction(self, 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 page_action.IsGestureSourceTypeSupported(tab, 'touch'):
      raise page_action.PageActionNotSupported(
          'Touch scroll not supported for this browser')

    if (self._synthetic_gesture_source ==
        '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))
Пример #6
0
  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 testSwipe(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.SwipeElement(selector='#left-right',
                                   direction='left',
                                   left_start_ratio=0.9)
        self.assertTrue(
            action_runner.EvaluateJavaScript(
                'document.querySelector("#left-right").scrollLeft') > 75)
        action_runner.SwipeElement(selector='#top-bottom',
                                   direction='up',
                                   top_start_ratio=0.9)
        self.assertTrue(
            action_runner.EvaluateJavaScript(
                'document.querySelector("#top-bottom").scrollTop') > 75)

        action_runner.SwipePage(direction='left', left_start_ratio=0.9)
        self.assertTrue(
            action_runner.EvaluateJavaScript(
                '(document.scrollingElement || document.body).scrollLeft') > 75
        )
Пример #8
0
    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))
Пример #9
0
    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))
Пример #10
0
  def WillRunAction(self, tab):
    utils.InjectJavaScript(tab, 'gesture_common.js')
    utils.InjectJavaScript(tab, 'drag.js')

    # Fail if browser doesn't support synthetic drag gestures.
    if not tab.EvaluateJavaScript('window.__DragAction_SupportedByBrowser()'):
      raise page_action.PageActionNotSupported(
          'Synthetic drag 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 drag not supported for this browser')

      if (self._synthetic_gesture_source ==
          'chrome.gpuBenchmarking.MOUSE_INPUT'):
        raise page_action.PageActionNotSupported(
            'Drag requires touch on this page but mouse input was requested')

    tab.ExecuteJavaScript("""
        window.__dragActionDone = false;
        window.__dragAction = new __DragAction(function() {
          window.__dragActionDone = true;
        });""")
Пример #11
0
  def RunAction(self, tab):
    if not self.HasElementSelector():
      self._element_function = 'document.body'

    gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'
    if (page_action.IsGestureSourceTypeSupported(tab, 'mouse') and
        not self._use_touch):
      gesture_source_type = 'chrome.gpuBenchmarking.MOUSE_INPUT'

    code = js_template.Render(
        """
        function(element, info) {
          if (!element) {
            throw Error('Cannot find element: ' + info);
          }
          window.__dragAction.start({
            element: element,
            left_start_ratio: {{ left_start_ratio }},
            top_start_ratio: {{ top_start_ratio }},
            left_end_ratio: {{ left_end_ratio }},
            top_end_ratio: {{ top_end_ratio }},
            speed: {{ speed }},
            gesture_source_type: {{ @gesture_source_type }}
          });
        }""",
        left_start_ratio=self._left_start_ratio,
        top_start_ratio=self._top_start_ratio,
        left_end_ratio=self._left_end_ratio,
        top_end_ratio=self._top_end_ratio,
        speed=self._speed,
        gesture_source_type=gesture_source_type)
    self.EvaluateCallback(tab, code)
    tab.WaitForJavaScriptCondition('window.__dragActionDone', timeout=60)
Пример #12
0
    def WillRunAction(self, tab):
        utils.InjectJavaScript(tab, 'gesture_common.js')
        utils.InjectJavaScript(tab, 'scroll_bounce.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 page_action.IsGestureSourceTypeSupported(tab, 'touch'):
            raise page_action.PageActionNotSupported(
                'Touch scroll not supported for this browser')

        if (self._synthetic_gesture_source ==
                'chrome.gpuBenchmarking.MOUSE_INPUT'):
            raise page_action.PageActionNotSupported(
                'ScrollBounce page action does not support mouse input')

        done_callback = 'function() { window.__scrollBounceActionDone = true; }'
        # TODO(catapult:#3028): Fix interpolation of JavaScript values.
        tab.ExecuteJavaScript("""
        window.__scrollBounceActionDone = false;
        window.__scrollBounceAction = new __ScrollBounceAction(%s);""" %
                              (done_callback))
Пример #13
0
    def testScrollDistanceFastTouch(self):
        # Just pass the test on platforms that don't support touch (i.e. Mac)
        if not page_action.IsGestureSourceTypeSupported(self._tab, 'touch'):
            return

        # Scrolling distance for touch will have some error from the excess delta
        # of the event that crosses the slop threshold but isn't applied.
        self._RunScrollDistanceTest(500000, 200000,
                                    page_action.GESTURE_SOURCE_TOUCH, 50)
Пример #14
0
    def testScrollDistanceSlowTouch(self):
        # Just pass the test on platforms that don't support touch (i.e. Mac)
        if not page_action.IsGestureSourceTypeSupported(self._tab, 'touch'):
            return

        # Scrolling slowly produces larger error since each event will have a
        # smaller delta. Thus error from snapping in each event will be a larger
        # share of the total delta.
        self._RunScrollDistanceTest(1000, 300,
                                    page_action.GESTURE_SOURCE_TOUCH, 10)
Пример #15
0
    def testRepeatableScrollActionNoRepeatsZoomed(self):
        if not page_action.IsGestureSourceTypeSupported(self._tab, 'touch'):
            self.skipText('touch gestures not supported')

        self._tab.action_runner.PinchPage(scale_factor=0.1)

        inner_height = self._tab.EvaluateJavaScript('window.innerHeight')
        outer_height = self._tab.EvaluateJavaScript('window.outerHeight')

        self.assertGreater(inner_height, outer_height)

        i = repeatable_scroll.RepeatableScrollAction(
            y_scroll_distance_ratio=0.5)
        i.WillRunAction(self._tab)
        i.RunAction(self._tab)
  def testRepeatableScrollActionNoRepeatsZoomed(self):
    if (not self._browser_info.HasRepeatableSynthesizeScrollGesture() or
        not page_action.IsGestureSourceTypeSupported(self._tab, 'touch')):
      return

    self._tab.action_runner.PinchPage(scale_factor=0.1)

    inner_height = self._tab.EvaluateJavaScript('window.innerHeight')
    outer_height = self._tab.EvaluateJavaScript('window.outerHeight')

    self.assertGreater(inner_height, outer_height)

    i = repeatable_scroll.RepeatableScrollAction(y_scroll_distance_ratio=0.5)
    i.WillRunAction(self._tab)
    i.RunAction(self._tab)
Пример #17
0
  def testTouchScrollDistanceWhileZoomed(self):
    # Just pass the test on platforms that don't support touch (i.e. Mac)
    if not page_action.IsGestureSourceTypeSupported(self._tab, 'touch'):
      return

    # 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)')
    self._RunScrollDistanceTest(
        2000, 2000, page_action.GESTURE_SOURCE_TOUCH, 20)
Пример #18
0
    def WillRunAction(self, tab):
        if self._direction in ('downleft', 'downright', 'upleft', 'upright'):
            # Diagonal scrolling support was added in Chrome branch number 2332.
            branch_num = (tab.browser._browser_backend.devtools_client.
                          GetChromeBranchNumber())
            if branch_num < 2332:
                raise ValueError(
                    'Diagonal scrolling requires Chrome branch number'
                    ' 2332 or later. Found branch number %d' % branch_num)
        utils.InjectJavaScript(tab, 'gesture_common.js')
        utils.InjectJavaScript(tab, 'scroll.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 (self._synthetic_gesture_source ==
                    'chrome.gpuBenchmarking.MOUSE_INPUT'):
                raise page_action.PageActionNotSupported(
                    'Scroll requires touch on this page but mouse input was requested'
                )

        # TODO(catapult:#3028): Render in JavaScript method when supported by API.
        code = js_template.Render(
            """
        window.__scrollActionDone = false;
        window.__scrollAction = new __ScrollAction(
            {{ @callback }}, {{ @distance }});""",
            callback='function() { window.__scrollActionDone = true; }',
            distance=self._distance_func)
        tab.ExecuteJavaScript(code)
Пример #19
0
    def WillRunAction(self, tab):
        utils.InjectJavaScript(tab, 'gesture_common.js')
        utils.InjectJavaScript(tab, 'swipe.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 self._synthetic_gesture_source == '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')

        tab.ExecuteJavaScript("""
        window.__swipeActionDone = false;
        window.__swipeAction = new __SwipeAction(function() {
          window.__swipeActionDone = true;
        });""")