Bug 836952 - accept coordinates for single_tap/double_tap, r=mdas
authorYiming Yang <yiyang@mozilla.com>
Fri, 01 Feb 2013 13:29:10 -0800
changeset 130923 53c091a119ed634a0c44f6dc964d6e4bec0f1630
parent 130922 34927afb65e24ebd4c3e71e6eeccb289199034bf
child 130924 03232247aef81e733219b76815518a77802b77c4
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs836952
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 836952 - accept coordinates for single_tap/double_tap, r=mdas
testing/marionette/client/marionette/marionette.py
testing/marionette/client/marionette/tests/unit/test_touch.py
testing/marionette/client/marionette/www/testTouch.html
testing/marionette/marionette-actors.js
testing/marionette/marionette-listener.js
--- a/testing/marionette/client/marionette/marionette.py
+++ b/testing/marionette/client/marionette/marionette.py
@@ -45,21 +45,21 @@ class HTMLElement(object):
         return self.marionette.find_elements(method, target, self.id)
 
     def get_attribute(self, attribute):
         return self.marionette._send_message('getElementAttribute', 'value', element=self.id, name=attribute)
 
     def click(self):
         return self.marionette._send_message('clickElement', 'ok', element=self.id)
 
-    def single_tap(self):
-        return self.marionette._send_message('singleTap', 'ok', element=self.id)
+    def single_tap(self, x=None, y=None):
+        return self.marionette._send_message('singleTap', 'ok', element=self.id, x=x, y=y)
 
-    def double_tap(self):
-        return self.marionette._send_message('doubleTap', 'ok', element=self.id)
+    def double_tap(self, x=None, y=None):
+        return self.marionette._send_message('doubleTap', 'ok', element=self.id, x=x, y=y)
 
     @property
     def text(self):
         return self.marionette._send_message('getElementText', 'value', element=self.id)
 
     def send_keys(self, *string):
         typing = []
         for val in string:
--- a/testing/marionette/client/marionette/tests/unit/test_touch.py
+++ b/testing/marionette/client/marionette/tests/unit/test_touch.py
@@ -8,16 +8,19 @@ from marionette_test import MarionetteTe
 from marionette import HTMLElement
 from errors import MarionetteException
 
 class testTouch(MarionetteTestCase):
     def test_touch(self):
       testTouch = self.marionette.absolute_url("testTouch.html")
       self.marionette.navigate(testTouch)
       button = self.marionette.find_element("id", "mozLink")
+      button.single_tap(0, 300)
+      time.sleep(10)
+      self.assertEqual("Clicked", self.marionette.execute_script("return document.getElementById('mozLinkPos').innerHTML;"))
       button.single_tap()
       time.sleep(10)
       self.assertEqual("Clicked", self.marionette.execute_script("return document.getElementById('mozLink').innerHTML;"))
 
     def test_invisible(self):
       testTouch = self.marionette.absolute_url("testTouch.html")
       self.marionette.navigate(testTouch)
       ele = self.marionette.find_element("id", "testh2")
--- a/testing/marionette/client/marionette/www/testTouch.html
+++ b/testing/marionette/client/marionette/www/testTouch.html
@@ -25,18 +25,23 @@
     function clicked() {
       var link = document.getElementById("mozLink");
       link.innerHTML = "Clicked";
     }
     function clicked2() {
       var link2 = document.getElementById("scroll");
       link2.innerHTML = "Clicked";
     }
+    function clicked3() {
+      var link3 = document.getElementById("mozLinkPos");
+      link3.innerHTML = "Clicked";
+    }
   </script>
-  <button id="mozLink" type="button" onclick="clicked()" allowevents=true>Click Me!</button>
+  <button id="mozLink" style="position:absolute;left:0px;top:55px;" type="button" onclick="clicked()" allowevents=true>Click Me!</button>
+  <button id="mozLinkPos" style="position:absolute;left:0px;top:355px;" type="button" onclick="clicked3()" allowevents=true>Position!</button>
   <div id="testDiv">
     <a href="#" id="divLink" class="linkClass" onclick="clicked()">Div click me!</a>
     <a href="#" id="divLink2" class="linkClass" onclick="clicked()">Div click me!</a>
   </div>
   <input name="myInput" type="text" value="asdf"/>
   <input name="myCheckBox" type="checkbox" />
   <h2 id="testh2" style="visibility: hidden" class="linkClass">Hidden</h2>
   <h3 id="testh3">Voluntary Termination</h3>
--- a/testing/marionette/marionette-actors.js
+++ b/testing/marionette/marionette-actors.js
@@ -1263,39 +1263,47 @@ MarionetteDriverActor.prototype = {
    * Single Tap
    *
    * @param object aRequest
             'element' represents the ID of the element to single tap on
    */
   singleTap: function MDA_singleTap(aRequest) {
     this.command_id = this.getCommandId();
     let serId = aRequest.element;
+    let x = aRequest.x;
+    let y = aRequest.y;
     if (this.context == "chrome") {
       this.sendError("Not in Chrome", 500, null, this.command_id);
     }
     else {
       this.sendAsync("singleTap", {value: serId,
+                                   corx: x,
+                                   cory: y,
                                    command_id: this.command_id});
     }
   },
 
   /**
    * Double Tap
    *
    * @param object aRequest
    *        'element' represents the ID of the element to double tap on
    */
   doubleTap: function MDA_doubleTap(aRequest) {
     this.command_id = this.getCommandId();
     let serId = aRequest.element;
+    let x = aRequest.x;
+    let y = aRequest.y;
     if (this.context == "chrome") {
       this.sendError("Not in Chrome", 500, null, this.command_id);
     }
     else {
       this.sendAsync("doubleTap", {value: serId,
+                                   corx: x,
+                                   cory: y,
                                    command_id: this.command_id});
     }
   },
 
   /**
    * Find an element using the indicated search strategy.
    *
    * @param object aRequest
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -740,22 +740,28 @@ function checkVisible(el, command_id) {
 /**
  * Function that perform a single tap
  */
 function singleTap(msg) {
   let command_id = msg.json.command_id;
   let el;
   try {
     el = elementManager.getKnownElement(msg.json.value, curWindow);
+    let x = msg.json.corx;
+    let y = msg.json.cory;
     if (!checkVisible(el, command_id)) {
       sendError("Element is not currently visible and may not be manipulated", 11, null, command_id);
       return;
     }
-    let x = '50%';
-    let y = '50%';
+    if (x == null) {
+      x = '50%';
+    }
+    if (y == null) {
+      y = '50%';
+    }
     let c = coordinates(el, x, y);
     touch(el, 3000, [c.x0, c.x0], [c.y0, c.y0], null);
     sendOk(msg.json.command_id);
   }
   catch (e) {
     sendError(e.message, e.code, e.stack, msg.json.command_id);
   }
 }
@@ -763,22 +769,28 @@ function singleTap(msg) {
 /**
  * Function that performs a double tap
  */
 function doubleTap(msg) {
   let command_id = msg.json.command_id;
   let el;
   try {
     el = elementManager.getKnownElement(msg.json.value, curWindow);
+    let x = msg.json.corx;
+    let y = msg.json.cory;
     if (!checkVisible(el, command_id)) {
       sendError("Element is not currently visible and may not be manipulated", 11, null, command_id);
       return;
     }
-    let x = '50%';
-    let y = '50%';
+    if (x == null){
+      x = '50%';
+    }
+    if (y == null){
+      y = '50%';
+    }
     let c = coordinates(el, x, y);
     touch(el, 25, [c.x0, c.x0], [c.y0, c.y0], function() {
       // When the first tap is done, start a timer for interval ms
       checkTimer.initWithCallback(function() {
           //After interval ms, send the second tap
           touch(el, 25, [c.x0, c.x0], [c.y0, c.y0], null);
       }, 50, Ci.nsITimer.TYPE_ONE_SHOT);
     });