diff --git a/browser/base/content/test/general/browser_bug580956.js b/browser/base/content/test/general/browser_bug580956.js index e7573b0f1320..6d203bf34062 100644 --- a/browser/base/content/test/general/browser_bug580956.js +++ b/browser/base/content/test/general/browser_bug580956.js @@ -19,9 +19,9 @@ function test() { browser.addEventListener("load", function() { browser.removeEventListener("load", arguments.callee, true); - gBrowser.removeTab(tab); - ok(isUndoCloseEnabled(), "Undo Close Tab should be enabled."); - - finish(); + BrowserTestUtils.removeTab(tab).then(() => { + ok(isUndoCloseEnabled(), "Undo Close Tab should be enabled."); + finish(); + }); }, true); } diff --git a/browser/base/content/test/general/browser_bug817947.js b/browser/base/content/test/general/browser_bug817947.js index 142b016b4391..3a76e36d3b90 100644 --- a/browser/base/content/test/general/browser_bug817947.js +++ b/browser/base/content/test/general/browser_bug817947.js @@ -34,14 +34,15 @@ function preparePendingTab(aCallback) { let tab = gBrowser.addTab(URL); whenLoaded(tab.linkedBrowser, function () { - gBrowser.removeTab(tab); - let [{state}] = JSON.parse(SessionStore.getClosedTabData(window)); + BrowserTestUtils.removeTab(tab).then(() => { + let [{state}] = JSON.parse(SessionStore.getClosedTabData(window)); - tab = gBrowser.addTab("about:blank"); - whenLoaded(tab.linkedBrowser, function () { - SessionStore.setTabState(tab, JSON.stringify(state)); - ok(tab.hasAttribute("pending"), "tab should be pending"); - aCallback(tab); + tab = gBrowser.addTab("about:blank"); + whenLoaded(tab.linkedBrowser, function () { + SessionStore.setTabState(tab, JSON.stringify(state)); + ok(tab.hasAttribute("pending"), "tab should be pending"); + aCallback(tab); + }); }); }); } diff --git a/browser/base/content/test/general/browser_tab_detach_restore.js b/browser/base/content/test/general/browser_tab_detach_restore.js index 804be0869d7b..ef3522046da4 100644 --- a/browser/base/content/test/general/browser_tab_detach_restore.js +++ b/browser/base/content/test/general/browser_tab_detach_restore.js @@ -10,6 +10,7 @@ add_task(function*() { let tab = gBrowser.addTab(); tab.linkedBrowser.loadURI(uri); yield BrowserTestUtils.browserLoaded(tab.linkedBrowser); + TabState.flush(tab.linkedBrowser); let key = tab.linkedBrowser.permanentKey; let win = gBrowser.replaceTabWithWindow(tab); diff --git a/browser/components/sessionstore/test/head.js b/browser/components/sessionstore/test/head.js index 5dffc25cdc34..1c00f0714621 100644 --- a/browser/components/sessionstore/test/head.js +++ b/browser/components/sessionstore/test/head.js @@ -529,15 +529,5 @@ for (let name of FORM_HELPERS) { } function promiseRemoveTab(tab) { - return new Promise(resolve => { - let {messageManager: mm, frameLoader} = tab.linkedBrowser; - mm.addMessageListener("SessionStore:update", function onMessage(msg) { - if (msg.targetFrameLoader == frameLoader && msg.data.isFinal) { - mm.removeMessageListener("SessionStore:update", onMessage); - resolve(); - } - }, true); - - tab.ownerDocument.defaultView.gBrowser.removeTab(tab); - }); + return BrowserTestUtils.removeTab(tab); } diff --git a/browser/components/tabview/content.js b/browser/components/tabview/content.js index 049cfe757dc9..309ce6fbbd9a 100644 --- a/browser/components/tabview/content.js +++ b/browser/components/tabview/content.js @@ -61,7 +61,8 @@ let WindowMessageHandler = { // Function: isDocumentLoaded // Checks if the currently active document is loaded. isDocumentLoaded: function WMH_isDocumentLoaded(cx) { - let isLoaded = (content.document.readyState != "uninitialized" && + let isLoaded = (content && + content.document.readyState != "uninitialized" && !webProgress.isLoadingDocument); sendAsyncMessage(cx.name, {isLoaded: isLoaded}); @@ -71,7 +72,8 @@ let WindowMessageHandler = { // Function: isImageDocument // Checks if the currently active document is an image document or not. isImageDocument: function WMH_isImageDocument(cx) { - let isImageDocument = (content.document instanceof Ci.nsIImageDocument); + let isImageDocument = (content && + content.document instanceof Ci.nsIImageDocument); sendAsyncMessage(cx.name, {isImageDocument: isImageDocument}); }, diff --git a/browser/components/tabview/favicons.js b/browser/components/tabview/favicons.js index 7ec26d4e84fa..e744b3a7554f 100644 --- a/browser/components/tabview/favicons.js +++ b/browser/components/tabview/favicons.js @@ -89,7 +89,9 @@ let FavIcons = { tabImage = this._favIconService.getFaviconLinkForIcon(tabImageURI).spec; } - tabImage = PlacesUtils.getImageURLForResolution(window, tabImage); + if (tabImage) { + tabImage = PlacesUtils.getImageURLForResolution(window, tabImage); + } callback(tabImage); }, diff --git a/browser/components/tabview/test/browser_tabview_bug608037.js b/browser/components/tabview/test/browser_tabview_bug608037.js index 8e02d611feda..664dfe2bf8df 100644 --- a/browser/components/tabview/test/browser_tabview_bug608037.js +++ b/browser/components/tabview/test/browser_tabview_bug608037.js @@ -24,19 +24,20 @@ function onTabViewWindowLoaded() { is(groupItems.length, 1, "There is only one group"); is(groupItems[0].getChildren().length, 3, "The group has three tab items"); - gBrowser.removeTab(tabTwo); - ok(TabView.isVisible(), "Tab View is still visible after removing a tab"); - is(groupItems[0].getChildren().length, 2, "The group has two tab items"); + BrowserTestUtils.removeTab(tabTwo).then(() => { + ok(TabView.isVisible(), "Tab View is still visible after removing a tab"); + is(groupItems[0].getChildren().length, 2, "The group has two tab items"); - restoreTab(function (tabTwo) { - ok(TabView.isVisible(), "Tab View is still visible after restoring a tab"); - is(groupItems[0].getChildren().length, 3, "The group still has three tab items"); + restoreTab(function (tabTwo) { + ok(TabView.isVisible(), "Tab View is still visible after restoring a tab"); + is(groupItems[0].getChildren().length, 3, "The group still has three tab items"); - // clean up and finish - hideTabView(function () { - gBrowser.removeTab(tabOne); - gBrowser.removeTab(tabTwo); - finish(); + // clean up and finish + hideTabView(function () { + gBrowser.removeTab(tabOne); + gBrowser.removeTab(tabTwo); + finish(); + }); }); }); } diff --git a/browser/components/tabview/test/browser_tabview_bug624847.js b/browser/components/tabview/test/browser_tabview_bug624847.js index 685a132d6062..b614668ca1ee 100644 --- a/browser/components/tabview/test/browser_tabview_bug624847.js +++ b/browser/components/tabview/test/browser_tabview_bug624847.js @@ -56,18 +56,19 @@ function test() { assertNumberOfTabs(2); afterAllTabsLoaded(function () { - win.gBrowser.removeTab(tab); - assertNumberOfTabs(1); - assertNumberOfPinnedTabs(0); + BrowserTestUtils.removeTab(tab).then(() => { + assertNumberOfTabs(1); + assertNumberOfPinnedTabs(0); - restoreTab(function () { - prefix = 'unpinned-restored'; - assertValidPrerequisites(); - assertGroupItemPreserved(); + restoreTab(function () { + prefix = 'unpinned-restored'; + assertValidPrerequisites(); + assertGroupItemPreserved(); - createBlankTab(); - afterAllTabsLoaded(testUndoCloseWithSelectedBlankPinnedTab, win); - }, 0, win); + createBlankTab(); + afterAllTabsLoaded(testUndoCloseWithSelectedBlankPinnedTab, win); + }, 0, win); + }); }, win); } diff --git a/browser/components/tabview/test/browser_tabview_bug628270.js b/browser/components/tabview/test/browser_tabview_bug628270.js index 4887c88a5939..2119c3c2c6b1 100644 --- a/browser/components/tabview/test/browser_tabview_bug628270.js +++ b/browser/components/tabview/test/browser_tabview_bug628270.js @@ -70,17 +70,24 @@ function test() { let groupItem = getGroupItem(1); let tabItem = groupItem.getChild(0); + // Wait until the tab has been removed but close it ourselves. + let promise = BrowserTestUtils.removeTab(tabItem.tab, {dontRemove: true}); + + // Close the tab. EventUtils.synthesizeMouseAtCenter( tabItem.$close[0], {}, TabView.getContentWindow()); - assertNumberOfTabsInGroup(groupItem, 1); - restoreTab(function () { - assertNumberOfTabsInGroup(groupItem, 2); + promise.then(() => { + assertNumberOfTabsInGroup(groupItem, 1); - activateFirstGroupItem(); - gBrowser.removeTab(gBrowser.tabs[1]); - gBrowser.removeTab(gBrowser.tabs[1]); - hideTabView(finishTest); + restoreTab(function () { + assertNumberOfTabsInGroup(groupItem, 2); + + activateFirstGroupItem(); + gBrowser.removeTab(gBrowser.tabs[1]); + gBrowser.removeTab(gBrowser.tabs[1]); + hideTabView(finishTest); + }); }); } diff --git a/testing/mochitest/BrowserTestUtils/BrowserTestUtil.jsm b/testing/mochitest/BrowserTestUtils/BrowserTestUtil.jsm new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm index 569b1cbf13c2..4dfd93ebf776 100644 --- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm +++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm @@ -339,5 +339,27 @@ this.BrowserTestUtils = { synthesizeMouseAtPoint(offsetX, offsetY, event, browser) { return BrowserTestUtils.synthesizeMouse(null, offsetX, offsetY, event, browser); + }, + + /** + * Removes the given tab from its parent tabbrowser and + * waits until its final message has reached the parent. + */ + removeTab(tab, options = {}) { + let dontRemove = options && options.dontRemove; + + return new Promise(resolve => { + let {messageManager: mm, frameLoader} = tab.linkedBrowser; + mm.addMessageListener("SessionStore:update", function onMessage(msg) { + if (msg.targetFrameLoader == frameLoader && msg.data.isFinal) { + mm.removeMessageListener("SessionStore:update", onMessage); + resolve(); + } + }, true); + + if (!dontRemove && !tab.closing) { + tab.ownerDocument.defaultView.gBrowser.removeTab(tab); + } + }); } };