Bug 1259029 - Ensure that getChromeWindowHandles() returns the same window list for chrome and content scope. r=ato
authorHenrik Skupin <mail@hskupin.info>
Wed, 23 Mar 2016 15:48:11 +0100
changeset 290352 26e9ebbb6441bc7054a342389f76f1a081d61f6d
parent 290351 74a77e202f330dffac2cf722a5d9d7480cb1c201
child 290353 e5f4aa4f69c2e12dbf9f4dd1512447e7cdb71067
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1259029
milestone48.0a1
Bug 1259029 - Ensure that getChromeWindowHandles() returns the same window list for chrome and content scope. r=ato MozReview-Commit-ID: EcmUfEH4lKd
testing/marionette/driver.js
testing/marionette/harness/marionette/tests/unit/test_window_handles.py
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -260,29 +260,16 @@ GeckoDriver.prototype.getCurrentWindow =
     } else {
       return this.curBrowser.window;
     }
   } else {
     return this.curFrame;
   }
 };
 
-/**
- * Gets the the window enumerator.
- *
- * @return {nsISimpleEnumerator}
- */
-GeckoDriver.prototype.getWinEnumerator = function() {
-  let typ = null;
-  if (this.appName != "B2G" && this.context == Context.CONTENT) {
-    typ = "navigator:browser";
-  }
-  return Services.wm.getEnumerator(typ);
-};
-
 GeckoDriver.prototype.addFrameCloseListener = function(action) {
   let win = this.getCurrentWindow();
   this.mozBrowserClose = e => {
     if (e.target.id == this.oopFrameId) {
       win.removeEventListener("mozbrowserclose", this.mozBrowserClose, true);
       this.switchToGlobalMessageManager();
       throw new NoSuchWindowError("The window closed during action: " + action);
     }
@@ -1375,17 +1362,17 @@ GeckoDriver.prototype.getIdForBrowser = 
  * Each window handle is assigned by the server and is guaranteed unique,
  * however the return array does not have a specified ordering.
  *
  * @return {Array.<string>}
  *     Unique window handles.
  */
 GeckoDriver.prototype.getWindowHandles = function(cmd, resp) {
   let hs = [];
-  let winEn = this.getWinEnumerator();
+  let winEn = Services.wm.getEnumerator(null);
   while (winEn.hasMoreElements()) {
     let win = winEn.getNext();
     if (win.gBrowser && this.appName != "B2G") {
       let tabbrowser = win.gBrowser;
       for (let i = 0; i < tabbrowser.browsers.length; ++i) {
         let winId = this.getIdForBrowser(tabbrowser.getBrowserAtIndex(i));
         if (winId !== null) {
           hs.push(winId);
@@ -1427,17 +1414,17 @@ GeckoDriver.prototype.getChromeWindowHan
  * Returns identifiers for each open chrome window for tests interested in
  * managing a set of chrome windows and tabs separately.
  *
  * @return {Array.<string>}
  *     Unique window handles.
  */
 GeckoDriver.prototype.getChromeWindowHandles = function(cmd, resp) {
   let hs = [];
-  let winEn = this.getWinEnumerator();
+  let winEn = Services.wm.getEnumerator(null);
   while (winEn.hasMoreElements()) {
     let foundWin = winEn.getNext();
     let winId = foundWin.QueryInterface(Ci.nsIInterfaceRequestor)
         .getInterface(Ci.nsIDOMWindowUtils)
         .outerWindowID;
     winId = winId + ((this.appName == "B2G") ? "-b2g" : "");
     hs.push(winId);
   }
@@ -1502,17 +1489,17 @@ GeckoDriver.prototype.switchToWindow = f
   };
 
   let byNameOrId = function(name, outerId, contentWindowId) {
     return switchTo == name ||
         switchTo == contentWindowId ||
         switchTo == outerId;
   };
 
-  let winEn = this.getWinEnumerator();
+  let winEn = Services.wm.getEnumerator(null);
   while (winEn.hasMoreElements()) {
     let win = winEn.getNext();
     let outerId = getOuterWindowId(win);
 
     if (win.gBrowser && !isB2G) {
       let tabbrowser = win.gBrowser;
       for (let i = 0; i < tabbrowser.browsers.length; ++i) {
         let browser = tabbrowser.getBrowserAtIndex(i);
@@ -2332,17 +2319,17 @@ GeckoDriver.prototype.deleteCookie = fun
  */
 GeckoDriver.prototype.close = function(cmd, resp) {
   // can't close windows on B2G
   if (this.appName == "B2G") {
     return;
   }
 
   let nwins = 0;
-  let winEn = this.getWinEnumerator();
+  let winEn = Services.wm.getEnumerator(null);
   while (winEn.hasMoreElements()) {
     let win = winEn.getNext();
 
     // count both windows and tabs
     if (win.gBrowser) {
       nwins += win.gBrowser.browsers.length;
     } else {
       nwins++;
@@ -2379,17 +2366,17 @@ GeckoDriver.prototype.close = function(c
 GeckoDriver.prototype.closeChromeWindow = function(cmd, resp) {
   // can't close windows on B2G
   if (this.appName == "B2G") {
     return;
   }
 
   // Get the total number of windows
   let nwins = 0;
-  let winEn = this.getWinEnumerator();
+  let winEn = Services.wm.getEnumerator(null);
   while (winEn.hasMoreElements()) {
     nwins++;
     winEn.getNext();
   }
 
   // if there is only 1 window left, delete the session
   if (nwins == 1) {
     this.sessionTearDown();
@@ -2430,17 +2417,17 @@ GeckoDriver.prototype.sessionTearDown = 
     for (let win in this.browsers) {
       let browser = this.browsers[win];
       for (let i in browser.knownFrames) {
         globalMessageManager.broadcastAsyncMessage(
             "Marionette:deleteSession" + browser.knownFrames[i], {});
       }
     }
 
-    let winEn = this.getWinEnumerator();
+    let winEn = Services.wm.getEnumerator(null);
     while (winEn.hasMoreElements()) {
       winEn.getNext().messageManager.removeDelayedFrameScript(FRAME_SCRIPT);
     }
 
     this.curBrowser.frameManager.removeMessageManagerListeners(
         globalMessageManager);
   }
 
--- a/testing/marionette/harness/marionette/tests/unit/test_window_handles.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_window_handles.py
@@ -86,16 +86,46 @@ class TestWindowHandles(MarionetteTestCa
             self.wait_for_condition(lambda mn: len(mn.window_handles) == i + 3)
             self.assertEqual(len(self.marionette.chrome_window_handles), 2)
 
         self.marionette.close_chrome_window()
         self.assertEqual(len(self.marionette.chrome_window_handles), 1)
         self.assertEqual(len(self.marionette.window_handles), 1)
         self.marionette.switch_to_window(start_tab)
 
+    def test_chrome_window_handles_with_scopes(self):
+        start_tab = self.marionette.current_window_handle
+        start_chrome_window = self.marionette.current_chrome_window_handle
+        start_chrome_windows = self.marionette.chrome_window_handles
+
+        # Ensure that we work in chrome scope so we don't have any limitations
+        with self.marionette.using_context("chrome"):
+            # Open a browser and a non-browser (about window) chrome window
+            self.marionette.execute_script("window.open()")
+            self.marionette.find_element(By.ID, "aboutName").click()
+
+            self.wait_for_condition(lambda mn: len(mn.chrome_window_handles) ==
+                                    len(start_chrome_windows) + 2)
+
+            handles_in_chrome_scope = self.marionette.chrome_window_handles
+            with self.marionette.using_context("content"):
+                self.assertEqual(self.marionette.chrome_window_handles,
+                                 handles_in_chrome_scope)
+
+        for handle in handles_in_chrome_scope:
+            if handle != start_chrome_window:
+                self.marionette.switch_to_window(handle)
+                self.marionette.close_chrome_window()
+
+        self.marionette.switch_to_window(start_tab)
+
+        self.assertEqual(len(self.marionette.chrome_window_handles), 1)
+        self.assertEqual(len(self.marionette.window_handles), 1)
+        self.assertEqual(self.marionette.current_window_handle, start_tab)
+
     def test_tab_and_window_handles(self):
         start_tab = self.marionette.current_window_handle
         start_chrome_window = self.marionette.current_chrome_window_handle
         tab_open_page = self.marionette.absolute_url("windowHandles.html")
         window_open_page = self.marionette.absolute_url("test_windows.html")
 
         # Open a new tab and switch to it.
         self.marionette.navigate(tab_open_page)