예제 #1
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;
        });""")
예제 #2
0
파일: scroll.py 프로젝트: subhanshuja/ofa
    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'
                )

        done_callback = 'function() { window.__scrollActionDone = true; }'
        tab.ExecuteJavaScript("""
        window.__scrollActionDone = false;
        window.__scrollAction = new __ScrollAction(%s, %s);""" %
                              (done_callback, self._distance_func))
예제 #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))
예제 #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):
    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;
        });""")
예제 #6
0
파일: pinch.py 프로젝트: subhanshuja/ofa
  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)
예제 #7
0
파일: tap.py 프로젝트: kiara07/catapult
    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))
예제 #8
0
 def WillRunAction(self, tab):
   utils.InjectJavaScript(tab, 'gesture_common.js')
   # Get the dimensions of the screen.
   self._windowsize = tab.EvaluateJavaScript(
       '[__GestureCommon_GetWindowWidth(),'
       ' __GestureCommon_GetWindowHeight()]')
   assert len(self._windowsize) == 2
   assert all(isinstance(d, numbers.Number) for d in self._windowsize)
예제 #9
0
 def WillRunAction(self, tab):
     """Load the mouse click JS code prior to running the action."""
     super(MouseClickAction, self).WillRunAction(tab)
     utils.InjectJavaScript(tab, 'mouse_click.js')
     tab.ExecuteJavaScript("""
     window.__mouseClickActionDone = false;
     window.__mouseClickAction = new __MouseClickAction(function() {
       window.__mouseClickActionDone = true;
     });""")
예제 #10
0
 def WillRunAction(self, tab):
     """Load the mouse click JS code prior to running the action."""
     super(MouseClickAction, self).WillRunAction(tab)
     utils.InjectJavaScript(tab, 'mouse_click.js')
     done_callback = 'function() { window.__mouseClickActionDone = true; }'
     # TODO(catapult:#3028): Fix interpolation of JavaScript values.
     tab.ExecuteJavaScript("""
     window.__mouseClickActionDone = false;
     window.__mouseClickAction = new __MouseClickAction(%s);""" %
                           (done_callback))
예제 #11
0
    def testDragAction(self):
        self.Navigate('draggable.html')

        utils.InjectJavaScript(self._tab, 'gesture_common.js')

        div_width = self._tab.EvaluateJavaScript(
            '__GestureCommon_GetBoundingVisibleRect(document.body).width')
        div_height = self._tab.EvaluateJavaScript(
            '__GestureCommon_GetBoundingVisibleRect(document.body).height')

        i = drag.DragAction(left_start_ratio=0.5,
                            top_start_ratio=0.5,
                            left_end_ratio=0.25,
                            top_end_ratio=0.25)
        try:
            i.WillRunAction(self._tab)
        except page_action.PageActionNotSupported:
            logging.warning(
                'This browser does not support drag gesture. Please try'
                ' updating chrome.')
            return

        self._tab.ExecuteJavaScript('''
        window.__dragAction.beginMeasuringHook = function() {
            window.__didBeginMeasuring = true;
        };
        window.__dragAction.endMeasuringHook = function() {
            window.__didEndMeasuring = true;
        };''')
        i.RunAction(self._tab)

        self.assertTrue(
            self._tab.EvaluateJavaScript('window.__didBeginMeasuring'))
        self.assertTrue(
            self._tab.EvaluateJavaScript('window.__didEndMeasuring'))

        div_position_x = self._tab.EvaluateJavaScript(
            'document.getElementById("drag_div").offsetLeft')
        div_position_y = self._tab.EvaluateJavaScript(
            'document.getElementById("drag_div").offsetTop')

        # 0.25 is the ratio of displacement to the initial size.
        expected_x = math.floor(div_width * -0.25)
        expected_y = math.floor(div_height * -0.25)
        error_ratio = 0.1

        self.assertTrue(
            self.CheckWithinRange(div_position_x, expected_x, error_ratio),
            msg="Moved element's left coordinate: %d, expected: %d" %
            (div_position_x, expected_x))
        self.assertTrue(
            self.CheckWithinRange(div_position_y, expected_y, error_ratio),
            msg="Moved element's top coordinate: %d, expected: %d" %
            (div_position_y, expected_y))
예제 #12
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;
        });""")
  def setUp(self):
    tab_test_case.TabTestCase.setUp(self)
    self.Navigate('blank.html')
    utils.InjectJavaScript(self._tab, 'gesture_common.js')

    # Make page taller than window so it's scrollable.
    self._tab.ExecuteJavaScript(
        'document.body.style.height ='
        '(3 * __GestureCommon_GetWindowHeight() + 1) + "px";')

    self.assertEquals(
        self._tab.EvaluateJavaScript('document.scrollingElement.scrollTop'), 0)

    self._browser_info = browser_info_module.BrowserInfo(self._tab.browser)
    self._window_height = int(
        self._tab.EvaluateJavaScript('__GestureCommon_GetWindowHeight()'))
예제 #14
0
 def WillRunAction(self, tab):
     """Load the JS code prior to running the action."""
     super(LoadMediaAction, self).WillRunAction(tab)
     utils.InjectJavaScript(tab, 'load_media.js')
예제 #15
0
 def setUp(self):
   tab_test_case.TabTestCase.setUp(self)
   self.Navigate('blank.html')
   utils.InjectJavaScript(self._tab, 'gesture_common.js')
예제 #16
0
 def setUp(self):
   super(PinchActionTest, self).setUp()
   self.Navigate('zoom.html')
   utils.InjectJavaScript(self._tab, 'gesture_common.js')
예제 #17
0
파일: loop.py 프로젝트: gam0za/AlbaAlza
 def WillRunAction(self, tab):
     """Load the media metrics JS code prior to running the action."""
     super(LoopAction, self).WillRunAction(tab)
     utils.InjectJavaScript(tab, 'loop.js')
예제 #18
0
 def WillRunAction(self, tab):
     """Loads the common media action JS code prior to running the action."""
     utils.InjectJavaScript(tab, 'media_action.js')