Esempio n. 1
0
 def RunGesture(self, tab):
   if (self._selector is None and self._text is None and
       self._element_function is None):
     self._element_function = 'document.body'
   code = '''
       function(element, info) {
         if (!element) {
           throw Error('Cannot find element: ' + info);
         }
         window.__swipeAction.start({
           element: element,
           left_start_ratio: %s,
           top_start_ratio: %s,
           direction: '%s',
           distance: %s,
           speed: %s
         });
       }''' % (self._left_start_ratio,
               self._top_start_ratio,
               self._direction,
               self._distance,
               self._speed)
   page_action.EvaluateCallbackWithElement(
       tab, code, selector=self._selector, text=self._text,
       element_function=self._element_function)
   tab.WaitForJavaScriptExpression('window.__swipeActionDone', 60)
Esempio n. 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 = page_action.GetGestureSourceTypeFromOptions(tab)
        if self._use_touch:
            gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'

        code = '''
        function(element, info) {
          if (!element) {
            throw Error('Cannot find element: ' + info);
          }
          window.__scrollAction.start({
            element: element,
            left_start_ratio: %s,
            top_start_ratio: %s,
            direction: '%s',
            speed: %s,
            gesture_source_type: %s
          });
        }''' % (self._left_start_ratio, self._top_start_ratio, self._direction,
                self._speed, gesture_source_type)
        page_action.EvaluateCallbackWithElement(
            tab,
            code,
            selector=self._selector,
            text=self._text,
            element_function=self._element_function)
        tab.WaitForJavaScriptExpression('window.__scrollActionDone', 60)
Esempio n. 3
0
    def RunAction(self, tab):
        if not self.HasElementSelector():
            self.element_function = 'document.body'
        gesture_source_type = page_action.GetGestureSourceTypeFromOptions(tab)

        tap_cmd = ('''
        window.__tapAction.start({
          element: element,
          left_position_percentage: %s,
          top_position_percentage: %s,
          duration_ms: %s,
          gesture_source_type: %s
        });''' % (self.left_position_percentage, self.top_position_percentage,
                  self.duration_ms, gesture_source_type))
        code = '''
        function(element, errorMsg) {
          if (!element) {
            throw Error('Cannot find element: ' + errorMsg);
          }
          %s;
        }''' % tap_cmd

        page_action.EvaluateCallbackWithElement(
            tab,
            code,
            selector=self.selector,
            text=self.text,
            element_function=self.element_function)
        tab.WaitForJavaScriptExpression('window.__tapActionDone', 60)
Esempio n. 4
0
 def RunAction(self, tab):
     code = 'function(element) { return element != null; }'
     page_action.EvaluateCallbackWithElement(
         tab,
         code,
         selector=self.selector,
         text=self.text,
         element_function=self.element_function,
         wait=True,
         timeout_in_seconds=self.timeout_in_seconds)
 def RunAction(self, tab):
   code = '''
       function(element, errorMsg) {
         if (!element) {
           throw Error('Cannot find element: ' + errorMsg);
         }
         element.click();
       }'''
   page_action.EvaluateCallbackWithElement(
       tab, code, selector=self.selector, text=self.text,
       element_function=self.element_function)
Esempio n. 6
0
    def testEvaluateCallbackWithElement(self):
        self.Navigate('blank.html')
        runner = action_runner.ActionRunner(self._tab)
        runner.ExecuteJavaScript('''
        (function() {
           function createElement(id, textContent) {
             var el = document.createElement("div");
             el.id = id;
             el.textContent = textContent;
             document.body.appendChild(el);
           }

           createElement('test-1', 'foo');
           createElement('test-2', 'bar');
           createElement('test-3', 'baz');
        })();''')
        self.assertEqual(
            'foo',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el.textContent; }',
                selector='#test-1'))
        self.assertEqual(
            'bar',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el.textContent; }',
                text='bar'))
        self.assertEqual(
            'baz',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el.textContent; }',
                element_function='document.getElementById("test-3")'))
        self.assertEqual(
            'baz',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el.textContent; }',
                element_function='''
                (function() {
                  return document.getElementById("test-3");
                })()'''))

        # Test for when the element is not found.
        self.assertEqual(
            None,
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el; }',
                element_function='document.getElementById("test-4")'))

        # Test the info message.
        self.assertEqual(
            'using selector "#test-1"',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el, info) { return info; }',
                selector='#test-1'))
Esempio n. 7
0
 def RunAction(self, tab):
     code = '''
     function(element, info) {
       if (!element) {
         throw Error('Cannot find element: ' + info);
       }
       window.__mouseClickAction.start({
         element: element
       });
     }'''
     page_action.EvaluateCallbackWithElement(tab,
                                             code,
                                             selector=self._selector)
     tab.WaitForJavaScriptExpression('window.__mouseClickActionDone', 60)
Esempio n. 8
0
 def RunAction(self, tab):
     scale_factor = (self._scale_factor if self._scale_factor else
                     PinchAction._GetDefaultScaleFactorForPage(tab))
     code = '''
     function(element, info) {
       if (!element) {
         throw Error('Cannot find element: ' + info);
       }
       window.__pinchAction.start({
         element: element,
         left_anchor_ratio: %s,
         top_anchor_ratio: %s,
         scale_factor: %s,
         speed: %s
       });
     }''' % (self._left_anchor_ratio, self._top_anchor_ratio, scale_factor,
             self._speed)
     page_action.EvaluateCallbackWithElement(
         tab,
         code,
         selector=self._selector,
         text=self._text,
         element_function=self._element_function)
     tab.WaitForJavaScriptExpression('window.__pinchActionDone', 60)
Esempio n. 9
0
 def Evaluate3():
     page_action.EvaluateCallbackWithElement(self._tab,
                                             'function() {}',
                                             text='foo',
                                             element_function='')
Esempio n. 10
0
 def Evaluate2():
     page_action.EvaluateCallbackWithElement(self._tab,
                                             'function() {}',
                                             selector='div',
                                             element_function='foo')