Bug 898744 - Make browser_394759_basic.js wait for tab invalidation before closing the window; r=yoric

This commit is contained in:
Tim Taubert 2013-08-15 08:19:13 +02:00
parent 7eab9e8813
commit 12e5a03e65

View File

@ -2,74 +2,85 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const TEST_URL = "data:text/html;charset=utf-8,<input%20id=txt>" +
"<input%20type=checkbox%20id=chk>";
/**
* This test ensures that closing a window is a reversible action. We will
* close the the window, restore it and check that all data has been restored.
* This includes window-specific data as well as form data for tabs.
*/
function test() {
waitForExplicitFinish();
let testURL = "about:config";
let uniqueKey = "bug 394759";
let uniqueValue = "unik" + Date.now();
let uniqueText = "pi != " + Math.random();
// Be consistent: let the page actually display, as we are "interacting" with it.
Services.prefs.setBoolPref("general.warnOnAboutConfig", false);
// make sure that the next closed window will increase getClosedWindowCount
let max_windows_undo = Services.prefs.getIntPref("browser.sessionstore.max_windows_undo");
Services.prefs.setIntPref("browser.sessionstore.max_windows_undo", max_windows_undo + 1);
let closedWindowCount = ss.getClosedWindowCount();
// Clear the list of closed windows.
while (SessionStore.getClosedWindowCount()) {
SessionStore.forgetClosedWindow(0);
}
provideWindow(function onTestURLLoaded(newWin) {
newWin.gBrowser.addTab().linkedBrowser.stop();
// mark the window with some unique data to be restored later on
ss.setWindowValue(newWin, uniqueKey, uniqueValue);
let textbox = newWin.content.document.getElementById("textbox");
textbox.value = uniqueText;
let [txt, chk] = newWin.content.document.querySelectorAll("#txt, #chk");
txt.value = uniqueText;
newWin.close();
// Toggle the checkbox to cause a SessionStore:input message to be sent.
EventUtils.sendMouseEvent({type: "click"}, chk);
is(ss.getClosedWindowCount(), closedWindowCount + 1,
"The closed window was added to Recently Closed Windows");
let data = JSON.parse(ss.getClosedWindowData())[0];
ok(data.title == testURL && JSON.stringify(data).indexOf(uniqueText) > -1,
"The closed window data was stored correctly");
let browser = newWin.gBrowser.selectedBrowser;
waitForContentMessage(browser, "SessionStore:input", 1000, result => {
ok(result, "received message for input changes");
// reopen the closed window and ensure its integrity
let newWin2 = ss.undoCloseWindow(0);
newWin.close();
ok(newWin2 instanceof ChromeWindow,
"undoCloseWindow actually returned a window");
is(ss.getClosedWindowCount(), closedWindowCount,
"The reopened window was removed from Recently Closed Windows");
is(ss.getClosedWindowCount(), 1,
"The closed window was added to Recently Closed Windows");
let data = JSON.parse(ss.getClosedWindowData())[0];
ok(data.title == TEST_URL && JSON.stringify(data).indexOf(uniqueText) > -1,
"The closed window data was stored correctly");
// SSTabRestored will fire more than once, so we need to make sure we count them
let restoredTabs = 0;
let expectedTabs = data.tabs.length;
newWin2.addEventListener("SSTabRestored", function sstabrestoredListener(aEvent) {
++restoredTabs;
info("Restored tab " + restoredTabs + "/" + expectedTabs);
if (restoredTabs < expectedTabs) {
return;
}
// reopen the closed window and ensure its integrity
let newWin2 = ss.undoCloseWindow(0);
newWin2.removeEventListener("SSTabRestored", sstabrestoredListener, true);
ok(newWin2 instanceof ChromeWindow,
"undoCloseWindow actually returned a window");
is(ss.getClosedWindowCount(), 0,
"The reopened window was removed from Recently Closed Windows");
is(newWin2.gBrowser.tabs.length, 2,
"The window correctly restored 2 tabs");
is(newWin2.gBrowser.currentURI.spec, testURL,
"The window correctly restored the URL");
// SSTabRestored will fire more than once, so we need to make sure we count them
let restoredTabs = 0;
let expectedTabs = data.tabs.length;
newWin2.addEventListener("SSTabRestored", function sstabrestoredListener(aEvent) {
++restoredTabs;
info("Restored tab " + restoredTabs + "/" + expectedTabs);
if (restoredTabs < expectedTabs) {
return;
}
let textbox = newWin2.content.document.getElementById("textbox");
is(textbox.value, uniqueText,
"The window correctly restored the form");
is(ss.getWindowValue(newWin2, uniqueKey), uniqueValue,
"The window correctly restored the data associated with it");
is(restoredTabs, expectedTabs, "correct number of tabs restored");
newWin2.removeEventListener("SSTabRestored", sstabrestoredListener, true);
// clean up
newWin2.close();
Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo");
Services.prefs.clearUserPref("general.warnOnAboutConfig");
finish();
}, true);
}, testURL);
is(newWin2.gBrowser.tabs.length, 2,
"The window correctly restored 2 tabs");
is(newWin2.gBrowser.currentURI.spec, TEST_URL,
"The window correctly restored the URL");
let [txt, chk] = newWin2.content.document.querySelectorAll("#txt, #chk");
ok(txt.value == uniqueText && chk.checked,
"The window correctly restored the form");
is(ss.getWindowValue(newWin2, uniqueKey), uniqueValue,
"The window correctly restored the data associated with it");
// clean up
newWin2.close();
finish();
}, true);
});
}, TEST_URL);
}