Bug 1109875 - Fix various other tests to properly wait for data from closed tabs r=billm

This commit is contained in:
Tim Taubert 2015-05-04 19:08:06 +02:00
parent ad5e1fe842
commit 03a70398ec
11 changed files with 80 additions and 53 deletions

View File

@ -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);
}

View File

@ -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);
});
});
});
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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});
},

View File

@ -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);
},

View File

@ -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();
});
});
});
}

View File

@ -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);
}

View File

@ -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);
});
});
}

View File

@ -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);
}
});
}
};