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

This commit is contained in:
Tim Taubert 2015-04-28 16:30:47 +02:00
Родитель a362ac3e71
Коммит 13d48c8601
21 изменённых файлов: 137 добавлений и 188 удалений

Просмотреть файл

@ -1,4 +1,6 @@
function test() {
"use strict";
add_task(function* () {
/** Test for Bug 350525 **/
function test(aLambda) {
@ -9,8 +11,6 @@ function test() {
return false;
}
waitForExplicitFinish();
////////////////////////////
// setWindowValue, et al. //
////////////////////////////
@ -56,7 +56,7 @@ function test() {
ok(test(function() ss.deleteTabValue(tab, key)), "delete non-existent tab value");
// clean up
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
/////////////////////////////////////
// getClosedTabCount, undoCloseTab //
@ -71,29 +71,26 @@ function test() {
// create a new tab
let testURL = "about:";
tab = gBrowser.addTab(testURL);
promiseBrowserLoaded(tab.linkedBrowser).then(() => {
// make sure that the next closed tab will increase getClosedTabCount
gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
yield promiseBrowserLoaded(tab.linkedBrowser);
// remove tab
gBrowser.removeTab(tab);
// make sure that the next closed tab will increase getClosedTabCount
gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
registerCleanupFunction(() => gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"));
// getClosedTabCount
var newcount = ss.getClosedTabCount(window);
ok(newcount > count, "after closing a tab, getClosedTabCount has been incremented");
// remove tab
yield promiseRemoveTab(tab);
// undoCloseTab
tab = test(function() ss.undoCloseTab(window, 0));
ok(tab, "undoCloseTab doesn't throw")
// getClosedTabCount
let newcount = ss.getClosedTabCount(window);
ok(newcount > count, "after closing a tab, getClosedTabCount has been incremented");
promiseTabRestored(tab).then(() => {
is(tab.linkedBrowser.currentURI.spec, testURL, "correct tab was reopened");
// undoCloseTab
tab = test(function() ss.undoCloseTab(window, 0));
ok(tab, "undoCloseTab doesn't throw")
// clean up
if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo"))
gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
gBrowser.removeTab(tab);
finish();
});
});
}
yield promiseTabRestored(tab);
is(tab.linkedBrowser.currentURI.spec, testURL, "correct tab was reopened");
// clean up
gBrowser.removeTab(tab);
});

Просмотреть файл

@ -2,36 +2,40 @@
* 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/. */
function test() {
/** Test for Bug 367052 **/
waitForExplicitFinish();
"use strict";
add_task(function* () {
// make sure that the next closed tab will increase getClosedTabCount
let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo");
gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
let closedTabCount = ss.getClosedTabCount(window);
registerCleanupFunction(() => gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"));
// Empty the list of closed tabs.
while (ss.getClosedTabCount(window)) {
ss.forgetClosedTab(window, 0);
}
// restore a blank tab
let tab = gBrowser.addTab("about:");
promiseBrowserLoaded(tab.linkedBrowser).then(() => {
let history = tab.linkedBrowser.webNavigation.sessionHistory;
ok(history.count >= 1, "the new tab does have at least one history entry");
yield promiseBrowserLoaded(tab.linkedBrowser);
promiseTabState(tab, {entries: []}).then(() => {
// We may have a different sessionHistory object if the tab
// switched from non-remote to remote.
history = tab.linkedBrowser.webNavigation.sessionHistory;
ok(history.count == 0, "the tab was restored without any history whatsoever");
let count = yield promiseSHistoryCount(tab.linkedBrowser);
ok(count >= 1, "the new tab does have at least one history entry");
gBrowser.removeTab(tab);
ok(ss.getClosedTabCount(window) == closedTabCount,
"The closed blank tab wasn't added to Recently Closed Tabs");
yield promiseTabState(tab, {entries: []});
// clean up
if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo"))
gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
finish();
});
// We may have a different sessionHistory object if the tab
// switched from non-remote to remote.
count = yield promiseSHistoryCount(tab.linkedBrowser);
is(count, 0, "the tab was restored without any history whatsoever");
yield promiseRemoveTab(tab);
is(ss.getClosedTabCount(window), 0,
"The closed blank tab wasn't added to Recently Closed Tabs");
});
function promiseSHistoryCount(browser) {
return ContentTask.spawn(browser, null, function* () {
return docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory.count;
});
}

Просмотреть файл

@ -2,19 +2,15 @@
* 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/. */
/** Private Browsing Test for Bug 394759 **/
let closedWindowCount = 0;
// Prevent VM timers issues, cache now and increment it manually.
let now = Date.now();
"use strict";
const TESTS = [
{ url: "about:config",
key: "bug 394759 Non-PB",
value: "uniq" + (++now) },
value: "uniq" + r() },
{ url: "about:mozilla",
key: "bug 394759 PB",
value: "uniq" + (++now) },
value: "uniq" + r() },
];
function promiseTestOpenCloseWindow(aIsPrivate, aTest) {
@ -33,53 +29,11 @@ function promiseTestOpenCloseWindow(aIsPrivate, aTest) {
function promiseTestOnWindow(aIsPrivate, aValue) {
return Task.spawn(function*() {
let win = yield promiseNewWindowLoaded({ "private": aIsPrivate });
yield promiseCheckClosedWindows(aIsPrivate, aValue);
registerCleanupFunction(() => promiseWindowClosed(win));
});
}
function promiseCheckClosedWindows(aIsPrivate, aValue) {
return Task.spawn(function*() {
let data = JSON.parse(ss.getClosedWindowData())[0];
is(ss.getClosedWindowCount(), 1, "Check that the closed window count hasn't changed");
ok(JSON.stringify(data).indexOf(aValue) > -1,
"Check the closed window data was stored correctly");
});
}
function promiseBlankState() {
return Task.spawn(function*() {
// Set interval to a large time so state won't be written while we setup
// environment.
Services.prefs.setIntPref("browser.sessionstore.interval", 100000);
registerCleanupFunction(() => Services.prefs.clearUserPref("browser.sessionstore.interval"));
// Set up the browser in a blank state. Popup windows in previous tests
// result in different states on different platforms.
let blankState = JSON.stringify({
windows: [{
tabs: [{ entries: [{ url: "about:blank" }] }],
_closedTabs: []
}],
_closedWindows: []
});
ss.setBrowserState(blankState);
// Wait for the sessionstore.js file to be written before going on.
// Note: we don't wait for the complete event, since if asyncCopy fails we
// would timeout.
yield forceSaveState();
closedWindowCount = ss.getClosedWindowCount();
is(closedWindowCount, 0, "Correctly set window count");
// Remove the sessionstore.js file before setting the interval to 0
yield SessionFile.wipe();
// Make sure that sessionstore.js can be forced to be created by setting
// the interval pref to 0.
yield forceSaveState();
registerCleanupFunction(() => promiseWindowClosed(win));
});
}

Просмотреть файл

@ -28,7 +28,7 @@ add_task(function* test_dont_save_passwords() {
yield setInputValue(browser, {id: "passwd", value: PASS});
// Close and restore the tab.
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
tab = ss.undoCloseTab(window, 0);
browser = tab.linkedBrowser;
yield promiseTabRestored(tab);
@ -46,7 +46,6 @@ add_task(function* test_dont_save_passwords() {
ok(!state.includes(PASS), "password has not been written to file " + key)
);
// Cleanup.
gBrowser.removeTab(tab);
});

Просмотреть файл

@ -19,7 +19,7 @@ add_task(function test_restore_nonstandard_input_values() {
yield setFormElementValues(browser, {value: expectedValue});
// Remove tab and check collected form data.
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
let undoItems = JSON.parse(ss.getClosedTabData(window));
let savedFormData = undoItems[0].state.formdata;

Просмотреть файл

@ -1,21 +1,20 @@
function test() {
waitForExplicitFinish();
"use strict";
var tab1 = gBrowser.addTab("data:text/plain;charset=utf-8,foo");
add_task(function* () {
let tab1 = gBrowser.addTab("data:text/plain;charset=utf-8,foo");
gBrowser.pinTab(tab1);
promiseBrowserLoaded(tab1.linkedBrowser).then(() => {
var tab2 = gBrowser.addTab();
gBrowser.pinTab(tab2);
yield promiseBrowserLoaded(tab1.linkedBrowser);
let tab2 = gBrowser.addTab();
gBrowser.pinTab(tab2);
is(Array.indexOf(gBrowser.tabs, tab1), 0, "pinned tab 1 is at the first position");
gBrowser.removeTab(tab1);
tab1 = undoCloseTab();
ok(tab1.pinned, "pinned tab 1 has been restored as a pinned tab");
is(Array.indexOf(gBrowser.tabs, tab1), 0, "pinned tab 1 has been restored to the first position");
is(Array.indexOf(gBrowser.tabs, tab1), 0, "pinned tab 1 is at the first position");
yield promiseRemoveTab(tab1);
gBrowser.removeTab(tab1);
gBrowser.removeTab(tab2);
finish();
});
}
tab1 = undoCloseTab();
ok(tab1.pinned, "pinned tab 1 has been restored as a pinned tab");
is(Array.indexOf(gBrowser.tabs, tab1), 0, "pinned tab 1 has been restored to the first position");
gBrowser.removeTab(tab1);
gBrowser.removeTab(tab2);
});

Просмотреть файл

@ -1,36 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
// Tests that an about:blank tab with no history will not be saved into
// session store and thus, it will not show up in Recently Closed Tabs.
let tab;
function test() {
waitForExplicitFinish();
"use strict";
gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", 0);
gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
add_task(function* () {
let tab = gBrowser.addTab("about:blank");
yield promiseBrowserLoaded(tab.linkedBrowser);
is(ss.getClosedTabCount(window), 0, "should be no closed tabs");
is(tab.linkedBrowser.currentURI.spec, "about:blank",
"we will be removing an about:blank tab");
gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true);
let r = `rand-${Math.random()}`;
ss.setTabValue(tab, "foobar", r);
tab = gBrowser.addTab();
}
function onTabOpen(aEvent) {
gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true);
// Let other listeners react to the TabOpen event before removing the tab.
executeSoon(function() {
is(gBrowser.browsers[1].currentURI.spec, "about:blank",
"we will be removing an about:blank tab");
gBrowser.removeTab(tab);
is(ss.getClosedTabCount(window), 0, "should still be no closed tabs");
executeSoon(finish);
});
}
yield promiseRemoveTab(tab);
let closedTabData = ss.getClosedTabData(window);
ok(!closedTabData.contains(r), "tab not stored in _closedTabs");
});

Просмотреть файл

@ -30,15 +30,16 @@ function test() {
ok(tab.hidden, "newly created tab is now hidden");
// close and restore hidden tab
gBrowser.removeTab(tab);
tab = ss.undoCloseTab(window, 0);
promiseRemoveTab(tab).then(() => {
tab = ss.undoCloseTab(window, 0);
// check that everything was restored correctly, clean up and finish
whenTabIsLoaded(tab, function () {
is(tab.linkedBrowser.currentURI.spec, "about:mozilla", "restored tab has correct url");
// check that everything was restored correctly, clean up and finish
whenTabIsLoaded(tab, function () {
is(tab.linkedBrowser.currentURI.spec, "about:mozilla", "restored tab has correct url");
gBrowser.removeTab(tab);
finish();
gBrowser.removeTab(tab);
finish();
});
});
});
}

Просмотреть файл

@ -29,7 +29,7 @@ add_task(function* test() {
"CSP should block the script loaded by the clicked data URI");
// close the tab
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
// open new tab and recover the state
tab = ss.undoCloseTab(window, 0);

Просмотреть файл

@ -1,18 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
"use strict";
// Tests that an about:privatebrowsing tab with no history will not
// be saved into session store and thus, it will not show up in
// Recently Closed Tabs.
add_task(function* () {
while (ss.getClosedTabCount(window)) {
ss.forgetClosedTab(window, 0);
}
is(ss.getClosedTabCount(window), 0, "should be no closed tabs");
let tab = gBrowser.addTab("about:privatebrowsing");
let browser = tab.linkedBrowser;
yield promiseBrowserLoaded(browser);
@ -20,6 +12,10 @@ add_task(function* () {
is(gBrowser.browsers[1].currentURI.spec, "about:privatebrowsing",
"we will be removing an about:privatebrowsing tab");
gBrowser.removeTab(tab);
is(ss.getClosedTabCount(window), 0, "should still be no closed tabs");
let r = `rand-${Math.random()}`;
ss.setTabValue(tab, "foobar", r);
yield promiseRemoveTab(tab);
let closedTabData = ss.getClosedTabData(window);
ok(!closedTabData.contains(r), "tab not stored in _closedTabs");
});

Просмотреть файл

@ -14,7 +14,7 @@ add_task(function flush_on_tabclose() {
let browser = tab.linkedBrowser;
yield modifySessionStorage(browser, {test: "on-tab-close"});
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
let [{state: {storage}}] = JSON.parse(ss.getClosedTabData(window));
is(storage["http://example.com"].test, "on-tab-close",
@ -59,7 +59,7 @@ add_task(function flush_on_duplicate() {
"sessionStorage data has been flushed when duplicating tabs");
yield promiseTabRestored(tab2);
gBrowser.removeTab(tab2);
yield promiseRemoveTab(tab2);
[{state: {storage}}] = JSON.parse(ss.getClosedTabData(window));
is(storage["http://example.com"].test, "on-duplicate",
"sessionStorage data has been flushed when duplicating tabs");
@ -128,7 +128,7 @@ add_task(function flush_on_tabclose_racy() {
// Flush all data contained in the content script but send it using
// asynchronous messages.
TabState.flushAsync(browser);
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
let [{state: {storage}}] = JSON.parse(ss.getClosedTabData(window));
is(storage["http://example.com"].test, "on-tab-close-racy",

Просмотреть файл

@ -71,8 +71,8 @@ add_task(function* test_open_and_close() {
// Now close stuff, this should add closeAt
yield promiseWindowClosed(newWin);
gBrowser.removeTab(newTab1);
gBrowser.removeTab(newTab2);
yield promiseRemoveTab(newTab1);
yield promiseRemoveTab(newTab2);
state = CLOSED_STATE = JSON.parse(ss.getBrowserState());

Просмотреть файл

@ -20,7 +20,7 @@ add_task(function* test() {
let tab = win.gBrowser.addTab("about:mozilla");
yield promiseBrowserLoaded(tab.linkedBrowser);
TabState.flush(tab.linkedBrowser);
win.gBrowser.removeTab(win.gBrowser.tabs[0]);
yield promiseRemoveTab(win.gBrowser.tabs[0]);
// Make sure our window is still tracked by sessionstore
// and the window state is as expected.

Просмотреть файл

@ -30,7 +30,7 @@ add_task(function test_formdata() {
yield setInputValue(browser, {id: "txt", value: INNER_VALUE, frame: 0});
// Remove the tab.
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
});
}
@ -119,7 +119,7 @@ add_task(function test_nested() {
yield sendMessage(browser, "ss-test:sendKeyEvent", {key: "m", frame: 0});
// Remove the tab and check that we stored form data correctly.
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
let [{state: {formdata}}] = JSON.parse(ss.getClosedTabData(window));
is(JSON.stringify(formdata), JSON.stringify(FORM_DATA),
"formdata for iframe stored correctly");
@ -156,7 +156,7 @@ add_task(function test_design_mode() {
yield sendMessage(browser, "ss-test:sendKeyEvent", {key: "m"});
// Close and restore the tab.
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
tab = ss.undoCloseTab(window, 0);
browser = tab.linkedBrowser;
yield promiseTabRestored(tab);
@ -167,7 +167,7 @@ add_task(function test_design_mode() {
is(html, expected, "editable document has been restored correctly");
// Close and restore the tab.
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
tab = ss.undoCloseTab(window, 0);
browser = tab.linkedBrowser;
yield promiseTabRestored(tab);
@ -232,7 +232,7 @@ add_task(function test_ccNumbers() {
yield setInputValue(browser, {id: "txt", value: formValue});
// Remove the tab.
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
}
// Test that valid CC numbers are not collected.

Просмотреть файл

@ -32,7 +32,7 @@ add_task(function() {
yield promise;
info("Close then un-close page, 4 loads should take place");
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
let newTab = ss.undoCloseTab(window, 0);
yield waitForLoadsInBrowser(newTab.linkedBrowser, 4);
@ -77,7 +77,7 @@ add_task(function() {
yield promise;
info("iframe: Close then un-close page, 5 loads should take place");
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
let newTab = ss.undoCloseTab(window, 0);
yield waitForLoadsInBrowser(newTab.linkedBrowser, 5);

Просмотреть файл

@ -59,7 +59,7 @@ add_task(function nested_page_style() {
yield promiseBrowserLoaded(browser);
yield enableSubDocumentStyleSheetsForSet(browser, "alternate");
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
let [{state: {pageStyle}}] = JSON.parse(ss.getClosedTabData(window));
let expected = JSON.stringify({children: [{pageStyle: "alternate"}]});

Просмотреть файл

@ -15,7 +15,7 @@ add_task(function test_load_start() {
// Load a new URI but remove the tab before it has finished loading.
browser.loadURI("about:mozilla");
yield promiseContentMessage(browser, "ss-test:OnHistoryReplaceEntry");
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
// Undo close the tab.
tab = ss.undoCloseTab(window, 0);

Просмотреть файл

@ -129,7 +129,7 @@ add_task(function purge_domain() {
add_task(function respect_privacy_level() {
let tab = gBrowser.addTab(URL + "&secure");
yield promiseBrowserLoaded(tab.linkedBrowser);
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
let [{state: {storage}}] = JSON.parse(ss.getClosedTabData(window));
is(storage["http://mochi.test:8888"].test, OUTER_VALUE,
@ -142,7 +142,7 @@ add_task(function respect_privacy_level() {
tab = gBrowser.addTab(URL + "&secure");
yield promiseBrowserLoaded(tab.linkedBrowser);
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
[{state: {storage}}] = JSON.parse(ss.getClosedTabData(window));
is(storage["http://mochi.test:8888"].test, OUTER_VALUE,
@ -158,7 +158,7 @@ add_task(function respect_privacy_level() {
yield promiseBrowserLoaded(tab.linkedBrowser);
let tab2 = gBrowser.duplicateTab(tab);
yield promiseTabRestored(tab2);
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
// With privacy_level=2 the |tab| shouldn't have any sessionStorage data.
[{state: {storage}}] = JSON.parse(ss.getClosedTabData(window));
@ -166,7 +166,7 @@ add_task(function respect_privacy_level() {
// Restore the default privacy level and close the duplicated tab.
Services.prefs.clearUserPref("browser.sessionstore.privacy_level");
gBrowser.removeTab(tab2);
yield promiseRemoveTab(tab2);
// With privacy_level=0 the duplicated |tab2| should persist all data.
[{state: {storage}}] = JSON.parse(ss.getClosedTabData(window));

Просмотреть файл

@ -76,7 +76,7 @@ add_task(function history() {
}
} finally {
if (tab) {
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
}
}
});
@ -93,7 +93,7 @@ add_task(function close_tab() {
let statistics = yield promiseStats();
info("Now closing a tab");
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
tab = null;
let statistics2 = yield promiseStats();
@ -108,7 +108,7 @@ add_task(function close_tab() {
} finally {
if (tab) {
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
}
}
});
@ -202,7 +202,7 @@ add_task(function dom_storage() {
} finally {
if (tab) {
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
}
}
});
@ -235,7 +235,7 @@ add_task(function formdata() {
}
} finally {
if (tab) {
gBrowser.removeTab(tab);
yield promiseRemoveTab(tab);
}
}
});

Просмотреть файл

@ -65,8 +65,10 @@ let historyListener = {
])
};
docShell.QueryInterface(Ci.nsIWebNavigation).
let {sessionHistory} = docShell.QueryInterface(Ci.nsIWebNavigation);
if (sessionHistory) {
sessionHistory.addSHistoryListener(historyListener);
}
/**
* This frame script is only loaded for sessionstore mochitests. It enables us

Просмотреть файл

@ -527,3 +527,17 @@ for (let name of FORM_HELPERS) {
let msg = "ss-test:" + name;
this[name] = (browser, data) => sendMessage(browser, msg, data);
}
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);
});
}