Bug 800956: adding the ability to get the size of elements to marionette; r=mdas
authorDavid Burns <dburns@mozilla.com>
Fri, 19 Oct 2012 21:59:15 +0100
changeset 110820 e0ddf5c89441a592d1ed9e846bad8216a478ae08
parent 110819 81c2eb10eb8271b510ca99ddefb969f26edfed94
child 110821 ad953d3aaebee624723e886b68c5d211dfb1bf97
push id23716
push userryanvm@gmail.com
push dateSat, 20 Oct 2012 01:43:16 +0000
treeherdermozilla-central@ff4af83233dc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs800956
milestone19.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 800956: adding the ability to get the size of elements to marionette; r=mdas
testing/marionette/client/marionette/marionette.py
testing/marionette/client/marionette/tests/unit/test_elementsize.py
testing/marionette/client/marionette/www/testSize.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
@@ -69,16 +69,20 @@ class HTMLElement(object):
     def is_selected(self):
         return self.marionette._send_message('isElementSelected', 'value', element=self.id)
 
     def is_enabled(self):
         return self.marionette._send_message('isElementEnabled', 'value', element=self.id)
 
     def is_displayed(self):
         return self.marionette._send_message('isElementDisplayed', 'value', element=self.id)
+     
+    @property
+    def size(self):
+        return self.marionette._send_message('getElementSize', 'value', element=self.id)
 
     @property
     def tag_name(self):
         return self.marionette._send_message('getElementTagName', 'value', element=self.id)
 
     @property
     def location(self):
         return self.marionette._send_message('getElementPosition', 'value', element=self.id)
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/tests/unit/test_elementsize.py
@@ -0,0 +1,40 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from marionette_test import MarionetteTestCase
+
+class TestElementSize(MarionetteTestCase):
+    def testShouldReturnTheSizeOfALink(self):
+        test_html = self.marionette.absolute_url("testSize.html")
+        self.marionette.navigate(test_html)
+        shrinko = self.marionette.find_element('id', 'linkId')
+        size = shrinko.size
+        self.assertTrue(size['width'] > 0)
+        self.assertTrue(size['height'] > 0)
+
+class TestElementSizeChrome(MarionetteTestCase):
+    def setUp(self):
+        MarionetteTestCase.setUp(self)
+        self.marionette.set_context("chrome")
+        self.win = self.marionette.current_window_handle
+        self.marionette.execute_script("window.open('chrome://marionette/content/test2.xul', 'foo', 'chrome,centerscreen');")
+        self.marionette.switch_to_window('foo')
+        self.assertNotEqual(self.win, self.marionette.current_window_handle)
+
+    def tearDown(self):
+        self.assertNotEqual(self.win, self.marionette.current_window_handle)
+        self.marionette.execute_script("window.close();")
+        self.marionette.switch_to_window(self.win)
+        MarionetteTestCase.tearDown(self)
+
+    def testShouldReturnTheSizeOfAnInput(self):
+        wins = self.marionette.window_handles
+        wins.remove(self.win)
+        newWin = wins.pop()
+        self.marionette.switch_to_window(newWin)
+        shrinko = self.marionette.find_element('id', 'textInput')
+        size = shrinko.size
+        self.assertTrue(size['width'] > 0)
+        self.assertTrue(size['height'] > 0)
+
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/testSize.html
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <title>Test page for element size</title>
+  </head>
+  <body>
+    <p>Let's get the size of <a href='#' id='linkId'>some really cool link</a></p>
+  </body>
+</html>
--- a/testing/marionette/marionette-actors.js
+++ b/testing/marionette/marionette-actors.js
@@ -1332,16 +1332,32 @@ MarionetteDriverActor.prototype = {
         this.sendError(e.message, e.code, e.stack);
       }
     }
     else {
       this.sendAsync("isElementSelected", {element:aRequest.element});
     }
   },
 
+  getElementSize: function MDA_getElementSize(aRequest) {
+    if (this.context == "chrome") {
+      try {
+        let el = this.curBrowser.elementManager.getKnownElement(aRequest.element, this.getCurrentWindow());
+        let clientRect = el.getBoundingClientRect();  
+        this.sendResponse({width: clientRect.width, height: clientRect.height});
+      }
+      catch (e) {
+        this.sendError(e.message, e.code, e.stack);
+      }
+    }
+    else {
+      this.sendAsync("getElementSize", {element:aRequest.element});
+    }
+  },
+
   /**
    * Send key presses to element after focusing on it
    *
    * @param object aRequest
    *        'element' member holds the reference id to
    *        the element that will be checked
    *        'value' member holds the value to send to the element
    */
@@ -1683,16 +1699,17 @@ MarionetteDriverActor.prototype.requestT
   "setSearchTimeout": MarionetteDriverActor.prototype.setSearchTimeout,
   "findElement": MarionetteDriverActor.prototype.findElement,
   "findElements": MarionetteDriverActor.prototype.findElements,
   "clickElement": MarionetteDriverActor.prototype.clickElement,
   "getElementAttribute": MarionetteDriverActor.prototype.getElementAttribute,
   "getElementText": MarionetteDriverActor.prototype.getElementText,
   "getElementTagName": MarionetteDriverActor.prototype.getElementTagName,
   "isElementDisplayed": MarionetteDriverActor.prototype.isElementDisplayed,
+  "getElementSize": MarionetteDriverActor.prototype.getElementSize,
   "isElementEnabled": MarionetteDriverActor.prototype.isElementEnabled,
   "isElementSelected": MarionetteDriverActor.prototype.isElementSelected,
   "sendKeysToElement": MarionetteDriverActor.prototype.sendKeysToElement,
   "getElementPosition": MarionetteDriverActor.prototype.getElementPosition,
   "clearElement": MarionetteDriverActor.prototype.clearElement,
   "getTitle": MarionetteDriverActor.prototype.getTitle,
   "getPageSource": MarionetteDriverActor.prototype.getPageSource,
   "goUrl": MarionetteDriverActor.prototype.goUrl,
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -100,16 +100,17 @@ function startListeners() {
   addMessageListenerId("Marionette:refresh", refresh);
   addMessageListenerId("Marionette:findElementContent", findElementContent);
   addMessageListenerId("Marionette:findElementsContent", findElementsContent);
   addMessageListenerId("Marionette:clickElement", clickElement);
   addMessageListenerId("Marionette:getElementAttribute", getElementAttribute);
   addMessageListenerId("Marionette:getElementText", getElementText);
   addMessageListenerId("Marionette:getElementTagName", getElementTagName);
   addMessageListenerId("Marionette:isElementDisplayed", isElementDisplayed);
+  addMessageListenerId("Marionette:getElementSize", getElementSize);
   addMessageListenerId("Marionette:isElementEnabled", isElementEnabled);
   addMessageListenerId("Marionette:isElementSelected", isElementSelected);
   addMessageListenerId("Marionette:sendKeysToElement", sendKeysToElement);
   addMessageListenerId("Marionette:getElementPosition", getElementPosition);
   addMessageListenerId("Marionette:clearElement", clearElement);
   addMessageListenerId("Marionette:switchToFrame", switchToFrame);
   addMessageListenerId("Marionette:deleteSession", deleteSession);
   addMessageListenerId("Marionette:sleepSession", sleepSession);
@@ -163,16 +164,17 @@ function deleteSession(msg) {
   removeMessageListenerId("Marionette:goForward", goForward);
   removeMessageListenerId("Marionette:refresh", refresh);
   removeMessageListenerId("Marionette:findElementContent", findElementContent);
   removeMessageListenerId("Marionette:findElementsContent", findElementsContent);
   removeMessageListenerId("Marionette:clickElement", clickElement);
   removeMessageListenerId("Marionette:getElementAttribute", getElementAttribute);
   removeMessageListenerId("Marionette:getElementTagName", getElementTagName);
   removeMessageListenerId("Marionette:isElementDisplayed", isElementDisplayed);
+  removeMessageListenerId("Marionette:getElementSize", getElementSize);
   removeMessageListenerId("Marionette:isElementEnabled", isElementEnabled);
   removeMessageListenerId("Marionette:isElementSelected", isElementSelected);
   removeMessageListenerId("Marionette:sendKeysToElement", sendKeysToElement);
   removeMessageListenerId("Marionette:getElementPosition", getElementPosition);
   removeMessageListenerId("Marionette:clearElement", clearElement);
   removeMessageListenerId("Marionette:switchToFrame", switchToFrame);
   removeMessageListenerId("Marionette:deleteSession", deleteSession);
   removeMessageListenerId("Marionette:sleepSession", sleepSession);
@@ -667,16 +669,30 @@ function isElementDisplayed(msg) {
     sendResponse({value: utils.isElementDisplayed(el)});
   }
   catch (e) {
     sendError(e.message, e.code, e.stack);
   }
 }
 
 /**
+ * Get the size of the element and return it
+ */
+function getElementSize(msg){
+  try {
+    let el = elementManager.getKnownElement(msg.json.element, curWindow);
+    let clientRect = el.getBoundingClientRect();  
+    sendResponse({value: {width: clientRect.width, height: clientRect.height}});
+  }
+  catch (e) {
+    sendError(e.message, e.code, e.stack);
+  }
+}
+
+/**
  * Check if element is enabled
  */
 function isElementEnabled(msg) {
   try {
     let el = elementManager.getKnownElement(msg.json.element, curWindow);
     sendResponse({value: utils.isElementEnabled(el)});
   }
   catch (e) {