Bug 773159 - Add support for returning the title and type of the active chrome window, r=mdas
authorMathieu Bultel <mat.bultel@gmail.com>
Fri, 24 May 2013 22:14:29 +0200
changeset 133046 291792974254b70a3029c476aaeb6d39921b71c0
parent 133045 fd25fb9e951e5b07a0966f554b3b6ba83dcbf287
child 133047 f1992b1f5c42a74b101f3a9285b3345f23c8ddbd
push id24738
push userphilringnalda@gmail.com
push dateTue, 28 May 2013 01:51:52 +0000
treeherdermozilla-central@1d6a04be8c0f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs773159
milestone24.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 773159 - Add support for returning the title and type of the active chrome window, r=mdas
testing/marionette/client/marionette/chrome/test.xul
testing/marionette/client/marionette/marionette.py
testing/marionette/client/marionette/tests/unit/test_window_title.py
testing/marionette/client/marionette/tests/unit/test_window_type.py
testing/marionette/client/marionette/tests/unit/unit-tests.ini
testing/marionette/marionette-actors.js
--- a/testing/marionette/client/marionette/chrome/test.xul
+++ b/testing/marionette/client/marionette/chrome/test.xul
@@ -1,21 +1,23 @@
 <?xml version="1.0"?>
 <!-- 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/. -->
 
 <!DOCTYPE window [
 ]>
-
-<dialog id="dia"
-            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<window id="winTest" title="Title Test" windowtype="Test Type"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+    <dialog id="dia"
+                xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
-  <vbox id="things">
-    <checkbox id="testBox"  label="box" />
-    <textbox id="textInput"  size="6" value="test" label="input" />
-    <textbox id="textInput2"  size="6" value="test" label="input" />
-    <textbox id="textInput3" class="asdf" size="6" value="test" label="input" />
-  </vbox>
-     
-  <iframe id="iframe" name="iframename" src="chrome://marionette/content/test2.xul"/>
-  <iframe id="iframe" name="iframename" src="chrome://marionette/content/test_nested_iframe.xul"/>
-</dialog>
+      <vbox id="things">
+        <checkbox id="testBox"  label="box" />
+        <textbox id="textInput"  size="6" value="test" label="input" />
+        <textbox id="textInput2"  size="6" value="test" label="input" />
+        <textbox id="textInput3" class="asdf" size="6" value="test" label="input" />
+      </vbox>
+         
+      <iframe id="iframe" name="iframename" src="chrome://marionette/content/test2.xul"/>
+      <iframe id="iframe" name="iframename" src="chrome://marionette/content/test_nested_iframe.xul"/>
+    </dialog>
+</window>
--- a/testing/marionette/client/marionette/marionette.py
+++ b/testing/marionette/client/marionette/marionette.py
@@ -524,16 +524,20 @@ class Marionette(object):
         else:
             response = self._send_message('switchToFrame', 'ok', value=frame, focus=focus)
         return response
 
     def get_url(self):
         response = self._send_message('getUrl', 'value')
         return response
 
+    def get_window_type(self):
+        response = self._send_message('getWindowType', 'value')
+        return response
+
     def navigate(self, url):
         response = self._send_message('goUrl', 'ok', value=url)
         return response
 
     def timeouts(self, timeout_type, ms):
         assert(timeout_type == self.TIMEOUT_SEARCH or timeout_type == self.TIMEOUT_SCRIPT or timeout_type == self.TIMEOUT_PAGE)
         response = self._send_message('timeouts', 'ok', timeoutType=timeout_type, ms=ms)
         return response
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/tests/unit/test_window_title.py
@@ -0,0 +1,33 @@
+# 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
+
+#TODO use @skip_if_b2g when Bug 875921 is fixed
+class TestTitleChrome(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/test.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 test_get_chrome_title(self):
+        title = self.marionette.execute_script("return window.document.documentElement.getAttribute('title');")
+        self.assertEqual(title, self.marionette.title)
+        self.assertEqual('Title Test', self.marionette.title)
+
+class TestTitle(MarionetteTestCase):
+    def test_get_html_title(self):
+        test_html = self.marionette.absolute_url("test.html")
+        self.marionette.navigate(test_html)
+        self.assertEqual('Marionette Test', self.marionette.title)
+
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/tests/unit/test_window_type.py
@@ -0,0 +1,26 @@
+# 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 TestWindowTypeChrome(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/test.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 test_get_window_type(self):
+        window_type = self.marionette.execute_script("return window.document.documentElement.getAttribute('windowtype');")
+        self.assertEqual(window_type, self.marionette.get_window_type())
+        self.assertEqual('Test Type', self.marionette.get_window_type())
+
--- a/testing/marionette/client/marionette/tests/unit/unit-tests.ini
+++ b/testing/marionette/client/marionette/tests/unit/unit-tests.ini
@@ -81,8 +81,12 @@ b2g = false
 
 [test_window_management.py]
 b2g = false
 
 [test_appcache.py]
 [test_screenshot.py]
 [test_cookies.py]
 b2g = false
+[test_window_title.py]
+b2g = false
+[test_window_type.py]
+b2g = false
--- a/testing/marionette/marionette-actors.js
+++ b/testing/marionette/marionette-actors.js
@@ -1070,17 +1070,34 @@ MarionetteDriverActor.prototype = {
     }
   },
 
   /**
    * Gets the current title of the window
    */
   getTitle: function MDA_getTitle() {
     this.command_id = this.getCommandId();
-    this.sendAsync("getTitle", {}, this.command_id);
+    if (this.context == "chrome"){
+      var curWindow = this.getCurrentWindow();
+      var title = curWindow.document.documentElement.getAttribute('title');
+      this.sendResponse(title, this.command_id);
+    }
+    else {
+      this.sendAsync("getTitle", {}, this.command_id);
+    }
+  },
+
+  /**
+   * Gets the current type of the window
+   */
+  getWindowType: function MDA_getWindowType() {
+    this.command_id = this.getCommandId();
+      var curWindow = this.getCurrentWindow();
+      var type = curWindow.document.documentElement.getAttribute('windowtype');
+      this.sendResponse(type, this.command_id);
   },
 
   /**
    * Gets the page source of the content document
    */
   getPageSource: function MDA_getPageSource(){
     this.command_id = this.getCommandId();
     if (this.context == "chrome"){
@@ -2214,16 +2231,17 @@ MarionetteDriverActor.prototype.requestT
   "getElementValueOfCssProperty": MarionetteDriverActor.prototype.getElementValueOfCssProperty,
   "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,
+  "getWindowType": MarionetteDriverActor.prototype.getWindowType,
   "getPageSource": MarionetteDriverActor.prototype.getPageSource,
   "goUrl": MarionetteDriverActor.prototype.goUrl,
   "getUrl": MarionetteDriverActor.prototype.getUrl,
   "goBack": MarionetteDriverActor.prototype.goBack,
   "goForward": MarionetteDriverActor.prototype.goForward,
   "refresh":  MarionetteDriverActor.prototype.refresh,
   "getWindow":  MarionetteDriverActor.prototype.getWindow,
   "getWindows":  MarionetteDriverActor.prototype.getWindows,