Exemple #1
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)
Exemple #2
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)
Exemple #3
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))
Exemple #4
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))
Exemple #5
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))
    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))
Exemple #8
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;
        });""")
Exemple #9
0
  def __init__(self, selector=None, text=None, element_function=None,
               left_start_ratio=0.5, top_start_ratio=0.5,
               direction='down', distance=100,
               overscroll=10, repeat_count=10,
               speed_in_pixels_per_second=400,
               synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT):
    super(ScrollBounceAction, 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
    # Should be big enough to do more than just hide the URL bar.
    self._distance = distance
    self._direction = direction
    # 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.
    self._overscroll = overscroll
    # It's the transitions we really want to stress, make this big.
    self._repeat_count = repeat_count
    # 7 pixels per frame should be plenty of frames.
    self._speed = speed_in_pixels_per_second
    self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' %
                                      synthetic_gesture_source)

    if (self._selector is None and self._text is None and
        self._element_function is None):
      self._element_function = '(document.scrollingElement || document.body)'
    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)
Exemple #11
0
    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,
                 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT):
        super(ScrollAction, self).__init__()
        if direction not in ('down', 'up', 'left', 'right', 'downleft',
                             'downright', 'upleft', 'upright'):
            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._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' %
                                          synthetic_gesture_source)

        self._distance_func = js_template.RenderValue(None)
        if distance:
            assert not distance_expr
            distance_expr = str(distance)
        if distance_expr:
            self._distance_func = js_template.Render(
                'function() { return 0 + {{ @expr }}; }', expr=distance_expr)
Exemple #12
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)
Exemple #13
0
  def WillRunAction(self, tab):
    utils.InjectJavaScript(tab, 'gesture_common.js')
    utils.InjectJavaScript(tab, 'tap.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')

    tab.ExecuteJavaScript("""
        window.__tapActionDone = false;
        window.__tapAction = new __TapAction(function() {
          window.__tapActionDone = true;
        });""")
Exemple #14
0
  def WillRunAction(self, tab):
    utils.InjectJavaScript(tab, 'gesture_common.js')
    utils.InjectJavaScript(tab, 'pinch.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')

    done_callback = 'function() { window.__pinchActionDone = true; }'
    tab.ExecuteJavaScript("""
        window.__pinchActionDone = false;
        window.__pinchAction = new __PinchAction(%s);"""
        % done_callback)
Exemple #15
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;
        });""")
Exemple #16
0
    def WillRunAction(self, tab):
        utils.InjectJavaScript(tab, 'gesture_common.js')
        utils.InjectJavaScript(tab, 'tap.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; }'
        # TODO(catapult:#3028): Fix interpolation of JavaScript values.
        tab.ExecuteJavaScript("""
        window.__tapActionDone = false;
        window.__tapAction = new __TapAction(%s);""" % (done_callback))
Exemple #17
0
  def testRunStoryAndProcessErrorIfNeeded_tryUnsupportedAction_finallyException(
      self):
    root_mock = self._CreateErrorProcessingMock(method_exceptions={
      'test.WillRunStory': page_action.PageActionNotSupported('foo'),
      'state.DidRunStory': Exception('bar')
    })

    story_runner._RunStoryAndProcessErrorIfNeeded(
        root_mock.story, root_mock.results, root_mock.state, root_mock.test)

    self.assertEquals(root_mock.method_calls, [
      mock.call.test.WillRunStory(root_mock.state.platform),
      mock.call.results.AddValue(SkipValueMatcher()),
      mock.call.state.DidRunStory(root_mock.results)
    ])
Exemple #18
0
    def WillRunAction(self, 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 testRunStoryAndProcessErrorIfNeeded_tryUnsupportedAction(self):
    root_mock = self._CreateErrorProcessingMock(method_exceptions={
        'state.RunStory': page_action.PageActionNotSupported('foo')
    })

    story_runner._RunStoryAndProcessErrorIfNeeded(
        root_mock.story, root_mock.results, root_mock.state, root_mock.test)
    self.assertEquals(root_mock.method_calls, [
        mock.call.results.CreateArtifact('logs.txt'),
        mock.call.test.WillRunStory(root_mock.state.platform, root_mock.story),
        mock.call.state.WillRunStory(root_mock.story),
        mock.call.state.CanRunStory(root_mock.story),
        mock.call.state.RunStory(root_mock.results),
        mock.call.results.Skip('Unsupported page action: foo'),
        mock.call.test.DidRunStory(root_mock.state.platform, root_mock.results),
        mock.call.state.DidRunStory(root_mock.results),
    ])
Exemple #20
0
 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_in_pixels_per_second=800,
              synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT):
   super(SwipeAction, self).__init__()
   if direction not in ['down', 'up', 'left', 'right']:
     raise page_action.PageActionNotSupported(
         'Invalid swipe 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._distance = distance
   self._speed = speed_in_pixels_per_second
   self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' %
                                     synthetic_gesture_source)
 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_in_pixels_per_second=800):
     super(SwipeAction, self).__init__()
     if direction not in ['down', 'up', 'left', 'right']:
         raise page_action.PageActionNotSupported(
             'Invalid swipe 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._distance = distance
     self._speed = speed_in_pixels_per_second