Bug 1254145 - Use BrowserTestUtils.removeTab instead of gBrowser.removeTab in BrowserTestUtils.withNewTab since BrowserTestUtils.removeTab is more deterministic since it waits for SessionStore to update. r=gijs
authorJared Wein <jwein@mozilla.com>
Mon, 07 Mar 2016 07:31:00 +0100
changeset 330762 12e42798a15089a17911ab222ad48aa715dc21a5
parent 330761 bd9ece9514679a997549446c0f4a2b9cbf49ab6a
child 330763 f6241b9dc0e90b1a7b418142c3a12202ebfc0df4
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs
bugs1254145
milestone48.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 1254145 - Use BrowserTestUtils.removeTab instead of gBrowser.removeTab in BrowserTestUtils.withNewTab since BrowserTestUtils.removeTab is more deterministic since it waits for SessionStore to update. r=gijs MozReview-Commit-ID: 8DoAiwCuGKl MozReview-Commit-ID: 5quEUBvfSOR
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -70,18 +70,26 @@ this.BrowserTestUtils = {
   withNewTab: Task.async(function* (options, taskFn) {
     if (typeof(options) == "string") {
       options = {
         gBrowser: Services.wm.getMostRecentWindow("navigator:browser").gBrowser,
         url: options
       }
     }
     let tab = yield BrowserTestUtils.openNewForegroundTab(options.gBrowser, options.url);
+    let originalWindow = tab.ownerDocument.defaultView;
     let result = yield taskFn(tab.linkedBrowser);
-    options.gBrowser.removeTab(tab);
+    let finalWindow = tab.ownerDocument.defaultView;
+    if (originalWindow == finalWindow && !tab.closing && tab.linkedBrowser) {
+      yield BrowserTestUtils.removeTab(tab);
+    } else {
+      Services.console.logStringMessage(
+        "BrowserTestUtils.withNewTab: Tab was already closed before " +
+        "removeTab would have been called");
+    }
     return Promise.resolve(result);
   }),
 
   /**
    * Opens a new tab in the foreground.
    *
    * @param {tabbrowser} tabbrowser
    *        The tabbrowser to open the tab new in.