Bug 1363428 - Make it possible to close tabless content windows, r=ato draft
authorJames Graham <james@hoppipolla.co.uk>
Fri, 09 Jun 2017 18:28:10 +0100
changeset 600211 637b01884025ad9a7fb409082eabff52f4434af5
parent 600210 875d7c1bc9eef5b6454794ba7a2ce2018a559554
child 600212 c96ffa60c0c47fd67926dfc1176e5a42a10f02a5
push id65688
push userbmo:james@hoppipolla.co.uk
push dateSat, 24 Jun 2017 11:04:46 +0000
reviewersato
bugs1363428
milestone56.0a1
Bug 1363428 - Make it possible to close tabless content windows, r=ato MozReview-Commit-ID: 8xltsYCN3QA
testing/marionette/browser.js
testing/marionette/driver.js
--- a/testing/marionette/browser.js
+++ b/testing/marionette/browser.js
@@ -225,17 +225,17 @@ browser.Context = class {
    *     A promise which is resolved when the current tab has been closed.
    *
    * @throws UnsupportedOperationError
    *     If tab handling for the current application isn't supported.
    */
   closeTab() {
     // If the current window is not a browser then close it directly. Do the
     // same if only one remaining tab is open, or no tab selected at all.
-    if (!this.tabBrowser || this.tabBrowser.tabs.length === 1 || !this.tab) {
+    if (!this.tabBrowser || !this.tabBrowser.tabs || this.tabBrowser.tabs.length === 1 || !this.tab) {
       return this.closeWindow();
     }
 
     return new Promise((resolve, reject) => {
       if (this.tabBrowser.closeTab) {
         // Fennec
         this.tabBrowser.deck.addEventListener("TabClose", ev => {
           resolve();
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -206,17 +206,17 @@ Object.defineProperty(GeckoDriver.protot
 Object.defineProperty(GeckoDriver.prototype, "windowHandles", {
   get: function () {
     let hs = [];
 
     for (let win of this.windows) {
       let tabBrowser = browser.getTabBrowser(win);
 
       // Only return handles for browser windows
-      if (tabBrowser) {
+      if (tabBrowser && tabBrowser.tabs) {
         tabBrowser.tabs.forEach(tab => {
           let winId = this.getIdForBrowser(browser.getBrowserForTab(tab));
           if (winId !== null) {
             hs.push(winId);
           }
         });
       }
     }
@@ -1431,17 +1431,17 @@ GeckoDriver.prototype.switchToWindow = f
  */
 GeckoDriver.prototype.findWindow = function (winIterable, filter) {
   for (let win of winIterable) {
     let outerId = getOuterWindowId(win);
     let tabBrowser = browser.getTabBrowser(win);
     if (filter(win, outerId)) {
       // In case the wanted window is a chrome window, we are done.
       return {win: win, outerId: outerId, hasTabBrowser: !!tabBrowser};
-    } else if (tabBrowser) {
+    } else if (tabBrowser && tabBrowser.tabs) {
       // Otherwise check if the chrome window has a tab browser, and that it
       // contains a tab with the wanted window handle.
       for (let i = 0; i < tabBrowser.tabs.length; ++i) {
         let contentBrowser = browser.getBrowserForTab(tabBrowser.tabs[i]);
         let contentWindowId = this.getIdForBrowser(contentBrowser);
 
         if (filter(win, contentWindowId)) {
           return {
@@ -2536,19 +2536,20 @@ GeckoDriver.prototype.close = function (
   assert.contentBrowser(this.curBrowser);
   assert.noUserPrompt(this.dialog);
 
   let nwins = 0;
 
   for (let win of this.windows) {
     // For browser windows count the tabs. Otherwise take the window itself.
     let tabbrowser = browser.getTabBrowser(win);
-
-    if (tabbrowser) {
+    if (tabbrowser && tabbrowser.tabs) {
       nwins += tabbrowser.tabs.length;
+    } else {
+      nwins += 1;
     }
   }
 
   // If there is only 1 window left, do not close it. Instead return a faked
   // empty array of window handles. This will instruct geckodriver to terminate
   // the application.
   if (nwins === 1) {
     return [];