Bug 1127264 - Clean up sessionstore tests r=smacleod

This commit is contained in:
Tim Taubert 2015-01-29 09:41:57 +01:00
Родитель 0c7b831923
Коммит 1bdcff6e82
56 изменённых файлов: 482 добавлений и 733 удалений

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

@ -100,7 +100,7 @@ function test() {
// public session, add new tab: (A)
let tab_A = aWin.gBrowser.addTab(testURL);
ss.setTabState(tab_A, JSON.stringify(state));
whenBrowserLoaded(tab_A.linkedBrowser, function() {
promiseBrowserLoaded(tab_A.linkedBrowser).then(() => {
// make sure that the next closed tab will increase getClosedTabCount
Services.prefs.setIntPref(
"browser.sessionstore.max_tabs_undo", max_tabs_undo + 1)
@ -119,7 +119,7 @@ function test() {
// verify tab: (A), in undo list
let tab_A_restored = test(function() ss.undoCloseTab(aWin, 0));
ok(tab_A_restored, "a tab is in undo list");
whenTabRestored(tab_A_restored, function() {
promiseTabRestored(tab_A_restored).then(() => {
is(testURL, tab_A_restored.linkedBrowser.currentURI.spec,
"it's the same tab that we expect");
aWin.gBrowser.removeTab(tab_A_restored);
@ -136,15 +136,14 @@ function test() {
};
let tab_B = aWin.gBrowser.addTab(testURL2);
ss.setTabState(tab_B, JSON.stringify(state1));
whenTabRestored(tab_B, function() {
promiseTabState(tab_B, state1).then(() => {
// populate tab: (B) with different form data
for (let item in fieldList)
setFormValue(tab_B, item, fieldList[item]);
// duplicate tab: (B)
let tab_C = aWin.gBrowser.duplicateTab(tab_B);
whenTabRestored(tab_C, function() {
promiseTabRestored(tab_C).then(() => {
// verify the correctness of the duplicated tab
is(ss.getTabValue(tab_C, key1), value1,
"tab successfully duplicated - correct state");

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

@ -11,13 +11,13 @@ function test() {
"browser/components/sessionstore/test/browser_339445_sample.html";
let tab = gBrowser.addTab(testURL);
whenBrowserLoaded(tab.linkedBrowser, function() {
promiseBrowserLoaded(tab.linkedBrowser).then(() => {
let doc = tab.linkedBrowser.contentDocument;
is(doc.getElementById("storageTestItem").textContent, "PENDING",
"sessionStorage value has been set");
let tab2 = gBrowser.duplicateTab(tab);
whenTabRestored(tab2, function() {
promiseTabRestored(tab2).then(() => {
let doc2 = tab2.linkedBrowser.contentDocument;
is(doc2.getElementById("storageTestItem").textContent, "SUCCESS",
"sessionStorage value has been duplicated");

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

@ -71,7 +71,7 @@ function test() {
// create a new tab
let testURL = "about:";
tab = gBrowser.addTab(testURL);
whenBrowserLoaded(tab.linkedBrowser, function() {
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);
@ -86,7 +86,7 @@ function test() {
tab = test(function() ss.undoCloseTab(window, 0));
ok(tab, "undoCloseTab doesn't throw")
whenTabRestored(tab, function() {
promiseTabRestored(tab).then(() => {
is(tab.linkedBrowser.currentURI.spec, testURL, "correct tab was reopened");
// clean up

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

@ -14,12 +14,11 @@ function test() {
// restore a blank tab
let tab = gBrowser.addTab("about:");
whenBrowserLoaded(tab.linkedBrowser, function() {
promiseBrowserLoaded(tab.linkedBrowser).then(() => {
let history = tab.linkedBrowser.webNavigation.sessionHistory;
ok(history.count >= 1, "the new tab does have at least one history entry");
ss.setTabState(tab, JSON.stringify({ entries: [] }));
whenTabRestored(tab, function() {
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;

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

@ -20,9 +20,7 @@ function test() {
let uniqueText = "pi != " + Math.random();
// Clear the list of closed windows.
while (SessionStore.getClosedWindowCount()) {
SessionStore.forgetClosedWindow(0);
}
forgetClosedWindows();
provideWindow(function onTestURLLoaded(newWin) {
newWin.gBrowser.addTab().linkedBrowser.stop();

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

@ -84,9 +84,7 @@ function promiseBlankState() {
}
add_task(function* init() {
while (ss.getClosedWindowCount() > 0) {
ss.forgetClosedWindow(0);
}
forgetClosedWindows();
while (ss.getClosedTabCount(window) > 0) {
ss.forgetClosedTab(window, 0);
}

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

@ -29,7 +29,7 @@ function test() {
executeSoon(function() {
newWin.gBrowser.loadURI(testURL, null, null);
whenBrowserLoaded(newWin.gBrowser.selectedBrowser, function() {
promiseBrowserLoaded(newWin.gBrowser.selectedBrowser).then(() => {
// get the sessionstore state for the window
TabState.flush(newWin.gBrowser.selectedBrowser);
let state = ss.getWindowState(newWin);

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

@ -18,14 +18,13 @@ function test() {
});
let tab = gBrowser.addTab();
whenBrowserLoaded(tab.linkedBrowser, function() {
promiseBrowserLoaded(tab.linkedBrowser).then(() => {
let tabState = { entries: [] };
let max_entries = gPrefService.getIntPref("browser.sessionhistory.max_entries");
for (let i = 0; i < max_entries; i++)
tabState.entries.push({ url: baseURL + i });
ss.setTabState(tab, JSON.stringify(tabState));
whenTabRestored(tab, function() {
promiseTabState(tab, tabState).then(() => {
TabState.flush(tab.linkedBrowser);
tabState = JSON.parse(ss.getTabState(tab));
is(tabState.entries.length, max_entries, "session history filled to the limit");

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

@ -17,15 +17,13 @@ add_task(function test_check_urls_before_restoring() {
yield promiseBrowserLoaded(browser);
// Restore form data with a valid URL.
ss.setTabState(tab, getState(URL));
yield promiseTabRestored(tab);
yield promiseTabState(tab, getState(URL));
let value = yield getInputValue(browser, {id: "text"});
is(value, "foobar", "value was restored");
// Restore form data with an invalid URL.
ss.setTabState(tab, getState("http://example.com/"));
yield promiseTabRestored(tab);
yield promiseTabState(tab, getState("http://example.com/"));
value = yield getInputValue(browser, {id: "text"});
is(value, "", "value was not restored");

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

@ -32,7 +32,7 @@ function test() {
typeText(doc.defaultView.frames[0].frames[1].document.getElementById("in1"), new Date());
let tab2 = gBrowser.duplicateTab(tab);
whenTabRestored(tab2, function() {
promiseTabRestored(tab2).then(() => {
let doc = tab2.linkedBrowser.contentDocument;
let win = tab2.linkedBrowser.contentWindow;
isnot(doc.getElementById("out1").value,

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

@ -13,7 +13,7 @@ function test() {
// set a unique value on a new, blank tab
let tab1 = gBrowser.addTab();
whenBrowserLoaded(tab1.linkedBrowser, function() {
promiseBrowserLoaded(tab1.linkedBrowser).then(() => {
ss.setTabValue(tab1, uniqueName, uniqueValue1);
// duplicate the tab with that value
@ -24,8 +24,7 @@ function test() {
isnot(ss.getTabValue(tab1, uniqueName), uniqueValue2, "tab values aren't sync'd");
// overwrite the tab with the value which should remove it
ss.setTabState(tab1, JSON.stringify({ entries: [] }));
whenTabRestored(tab1, function() {
promiseTabState(tab1, {entries: []}).then(() => {
is(ss.getTabValue(tab1, uniqueName), "", "tab value was cleared");
// clean up

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

@ -37,18 +37,15 @@ add_task(function test_nested_about_sessionrestore() {
yield promiseBrowserLoaded(browser);
// test 1
ss.setTabState(tab, JSON.stringify(STATE));
yield promiseTabRestored(tab);
yield promiseTabState(tab, STATE);
checkState("test1", tab);
// test 2
ss.setTabState(tab, JSON.stringify(STATE2));
yield promiseTabRestored(tab);
yield promiseTabState(tab, STATE2);
checkState("test2", tab);
// test 3
ss.setTabState(tab, JSON.stringify(STATE3));
yield promiseTabRestored(tab);
yield promiseTabState(tab, STATE3);
checkState("test3", tab);
// Cleanup.

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

@ -13,12 +13,12 @@ function test() {
let tab = gBrowser.addTab("about:sessionrestore");
gBrowser.selectedTab = tab;
let browser = tab.linkedBrowser;
whenBrowserLoaded(browser, function() {
promiseBrowserLoaded(browser).then(() => {
let doc = browser.contentDocument;
// click on the "Start New Session" button after about:sessionrestore is loaded
doc.getElementById("errorCancel").click();
whenBrowserLoaded(browser, function() {
promiseBrowserLoaded(browser).then(() => {
let doc = browser.contentDocument;
is(doc.URL, "about:blank", "loaded page is about:blank");
@ -29,12 +29,12 @@ function test() {
gPrefService.setCharPref("browser.startup.homepage", homepage);
gPrefService.setIntPref("browser.startup.page", 1);
gBrowser.loadURI("about:sessionrestore");
whenBrowserLoaded(browser, function() {
promiseBrowserLoaded(browser).then(() => {
let doc = browser.contentDocument;
// click on the "Start New Session" button after about:sessionrestore is loaded
doc.getElementById("errorCancel").click();
whenBrowserLoaded(browser, function() {
promiseBrowserLoaded(browser).then(() => {
let doc = browser.contentDocument;
is(doc.URL, homepage, "loaded page is the homepage");

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

@ -10,7 +10,7 @@ function test() {
let uniqueValue = Math.random() + "\u2028Second line\u2029Second paragraph\u2027";
let tab = gBrowser.addTab();
whenBrowserLoaded(tab.linkedBrowser, function() {
promiseBrowserLoaded(tab.linkedBrowser).then(() => {
ss.setTabValue(tab, "bug485563", uniqueValue);
let tabState = JSON.parse(ss.getTabState(tab));
is(tabState.extData["bug485563"], uniqueValue,

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

@ -14,21 +14,20 @@ function test() {
gBrowser.selectedTab = tab;
let browser = tab.linkedBrowser;
whenBrowserLoaded(browser, function() {
promiseBrowserLoaded(browser).then(() => {
let tabState = JSON.parse(ss.getTabState(tab));
is(tabState.entries[0].referrer, REFERRER1,
"Referrer retrieved via getTabState matches referrer set via loadURI.");
tabState.entries[0].referrer = REFERRER2;
ss.setTabState(tab, JSON.stringify(tabState));
whenTabRestored(tab, function(e) {
promiseTabState(tab, tabState).then(() => {
is(window.content.document.referrer, REFERRER2, "document.referrer matches referrer set via setTabState.");
gBrowser.removeTab(tab);
let newTab = ss.undoCloseTab(window, 0);
whenTabRestored(newTab, function() {
promiseTabRestored(newTab).then(() => {
is(window.content.document.referrer, REFERRER2, "document.referrer is still correct after closing and reopening the tab.");
gBrowser.removeTab(newTab);

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

@ -83,10 +83,10 @@ function test() {
let tab = gBrowser.addTab("about:blank");
let browser = tab.linkedBrowser;
whenBrowserLoaded(browser, function() {
promiseBrowserLoaded(browser).then(() => {
browser.loadURI("http://example.com", null, null);
whenBrowserLoaded(browser, function() {
promiseBrowserLoaded(browser).then(() => {
// After these push/replaceState calls, the window should have three
// history entries:
// testURL (state object: null) <-- oldest
@ -109,9 +109,7 @@ function test() {
ss.setTabState(tab2, state, true);
// Run checkState() once the tab finishes loading its restored state.
whenTabRestored(tab2, function() {
checkState(tab2);
});
promiseTabRestored(tab2).then(() => checkState(tab2));
});
});
});

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

@ -47,7 +47,7 @@ function test() {
// create and select a first tab
let tab = gBrowser.addTab(TEST_URL);
whenBrowserLoaded(tab.linkedBrowser, function() {
promiseBrowserLoaded(tab.linkedBrowser).then(() => {
// step1: the above has triggered some saveStateDelayed(), sleep until
// it's done, and get the initial sessionstore.js mtime
setTimeout(function step1(e) {

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

@ -3,12 +3,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function test() {
let tab1 = gBrowser.addTab("about:rights");
let tab2 = gBrowser.addTab("about:mozilla");
whenBrowserLoaded(tab1.linkedBrowser, mainPart);
waitForExplicitFinish();
function mainPart() {
let tab1 = gBrowser.addTab("about:rights");
let tab2 = gBrowser.addTab("about:mozilla");
promiseBrowserLoaded(tab1.linkedBrowser).then(() => {
// Tell the session storer that the tab is pinned
let newTabState = '{"entries":[{"url":"about:rights"}],"pinned":true,"userTypedValue":"Hello World!"}';
ss.setTabState(tab1, newTabState);
@ -26,5 +26,5 @@ function test() {
gBrowser.removeTab(tab1);
gBrowser.removeTab(tab2);
finish();
}
});
}

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

@ -4,7 +4,7 @@ function test() {
var tab1 = gBrowser.addTab("data:text/plain;charset=utf-8,foo");
gBrowser.pinTab(tab1);
whenBrowserLoaded(tab1.linkedBrowser, function() {
promiseBrowserLoaded(tab1.linkedBrowser).then(() => {
var tab2 = gBrowser.addTab();
gBrowser.pinTab(tab2);

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

@ -4,11 +4,7 @@
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true);
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
@ -25,29 +21,36 @@ function runTests() {
], selected: 5 }] };
let loadCount = 0;
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
loadCount++;
let promiseRestoringTabs = new Promise(resolve => {
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
loadCount++;
// We'll make sure that the loads we get come from pinned tabs or the
// the selected tab.
// We'll make sure that the loads we get come from pinned tabs or the
// the selected tab.
// get the tab
let tab;
for (let i = 0; i < window.gBrowser.tabs.length; i++) {
if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
tab = window.gBrowser.tabs[i];
}
// get the tab
let tab;
for (let i = 0; i < window.gBrowser.tabs.length; i++) {
if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
tab = window.gBrowser.tabs[i];
}
ok(tab.pinned || tab.selected,
"load came from pinned or selected tab");
ok(tab.pinned || tab.selected,
"load came from pinned or selected tab");
// We should get 4 loads: 3 app tabs + 1 normal selected tab
if (loadCount < 4)
return;
// We should get 4 loads: 3 app tabs + 1 normal selected tab
if (loadCount < 4)
return;
gProgressListener.unsetCallback();
executeSoon(next);
gProgressListener.unsetCallback();
resolve();
});
});
yield ss.setBrowserState(JSON.stringify(state));
}
let backupState = ss.getBrowserState();
ss.setBrowserState(JSON.stringify(state));
yield promiseRestoringTabs;
// Cleanup.
yield promiseBrowserState(backupState);
});

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

@ -5,11 +5,7 @@
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
const PREF_RESTORE_PINNED_TABS_ON_DEMAND = "browser.sessionstore.restore_pinned_tabs_on_demand";
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true);
Services.prefs.setBoolPref(PREF_RESTORE_PINNED_TABS_ON_DEMAND, true);
@ -28,23 +24,30 @@ function runTests() {
{ entries: [{ url: "http://example.org/#7" }], extData: { "uniq": r() } },
], selected: 5 }] };
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
// get the tab
let tab;
for (let i = 0; i < window.gBrowser.tabs.length; i++) {
if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
tab = window.gBrowser.tabs[i];
}
let promiseRestoringTabs = new Promise(resolve => {
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
// get the tab
let tab;
for (let i = 0; i < window.gBrowser.tabs.length; i++) {
if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
tab = window.gBrowser.tabs[i];
}
// Check that the load only comes from the selected tab.
ok(tab.selected, "load came from selected tab");
is(aNeedRestore, 6, "six tabs left to restore");
is(aRestoring, 1, "one tab is restoring");
is(aRestored, 0, "no tabs have been restored, yet");
// Check that the load only comes from the selected tab.
ok(tab.selected, "load came from selected tab");
is(aNeedRestore, 6, "six tabs left to restore");
is(aRestoring, 1, "one tab is restoring");
is(aRestored, 0, "no tabs have been restored, yet");
gProgressListener.unsetCallback();
executeSoon(next);
gProgressListener.unsetCallback();
resolve();
});
});
yield ss.setBrowserState(JSON.stringify(state));
}
let backupState = ss.getBrowserState();
ss.setBrowserState(JSON.stringify(state));
yield promiseRestoringTabs;
// Cleanup.
yield promiseBrowserState(backupState);
});

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

@ -4,11 +4,7 @@
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false);
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
@ -64,32 +60,33 @@ function runTests() {
let numTabs = state2.windows[0].tabs.length + state2.windows[1].tabs.length;
let loadCount = 0;
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
loadCount++;
let promiseRestoringTabs = new Promise(resolve => {
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
loadCount++;
if (aBrowser.currentURI.spec == state1.windows[0].tabs[2].entries[0].url)
loadedWindow1 = true;
if (aBrowser.currentURI.spec == state1.windows[1].tabs[0].entries[0].url)
loadedWindow2 = true;
if (aBrowser.currentURI.spec == state1.windows[0].tabs[2].entries[0].url)
loadedWindow1 = true;
if (aBrowser.currentURI.spec == state1.windows[1].tabs[0].entries[0].url)
loadedWindow2 = true;
if (!interruptedAfter && loadedWindow1 && loadedWindow2) {
interruptedAfter = loadCount;
ss.setBrowserState(JSON.stringify(state2));
return;
}
if (!interruptedAfter && loadedWindow1 && loadedWindow2) {
interruptedAfter = loadCount;
ss.setBrowserState(JSON.stringify(state2));
return;
}
if (loadCount < numTabs + interruptedAfter)
return;
if (loadCount < numTabs + interruptedAfter)
return;
// We don't actually care about load order in this test, just that they all
// do load.
is(loadCount, numTabs + interruptedAfter, "all tabs were restored");
is(aNeedRestore, 0, "there are no tabs left needing restore");
// We don't actually care about load order in this test, just that they all
// do load.
is(loadCount, numTabs + interruptedAfter, "all tabs were restored");
is(aNeedRestore, 0, "there are no tabs left needing restore");
// Remove the progress listener from this window, it will be removed from
// theWin when that window is closed (in setBrowserState).
gProgressListener.unsetCallback();
executeSoon(next);
// Remove the progress listener.
gProgressListener.unsetCallback();
resolve();
});
});
// We also want to catch the extra windows (there should be 2), so we need to observe domwindowopened
@ -104,5 +101,11 @@ function runTests() {
}
});
yield ss.setBrowserState(JSON.stringify(state1));
}
let backupState = ss.getBrowserState();
ss.setBrowserState(JSON.stringify(state1));
yield promiseRestoringTabs;
// Cleanup.
yield promiseAllButPrimaryWindowClosed();
yield promiseBrowserState(backupState);
});

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

@ -4,11 +4,7 @@
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false);
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
@ -33,19 +29,26 @@ function runTests() {
];
let loadCount = 0;
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
loadCount++;
let expected = expectedCounts[loadCount - 1];
let promiseRestoringTabs = new Promise(resolve => {
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
loadCount++;
let expected = expectedCounts[loadCount - 1];
is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored");
is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring");
is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored");
is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored");
is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring");
is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored");
if (loadCount == state.windows[0].tabs.length) {
gProgressListener.unsetCallback();
executeSoon(next);
}
if (loadCount == state.windows[0].tabs.length) {
gProgressListener.unsetCallback();
resolve();
}
});
});
yield ss.setBrowserState(JSON.stringify(state));
}
let backupState = ss.getBrowserState();
ss.setBrowserState(JSON.stringify(state));
yield promiseRestoringTabs;
// Cleanup.
yield promiseBrowserState(backupState);
});

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

@ -4,11 +4,7 @@
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false);
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
@ -38,16 +34,18 @@ function runTests() {
let numTabs = state.windows[0].tabs.length + state.windows[1].tabs.length;
let loadCount = 0;
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
if (++loadCount == numTabs) {
// We don't actually care about load order in this test, just that they all
// do load.
is(loadCount, numTabs, "all tabs were restored");
is(aNeedRestore, 0, "there are no tabs left needing restore");
let promiseRestoringTabs = new Promise(resolve => {
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
if (++loadCount == numTabs) {
// We don't actually care about load order in this test, just that they all
// do load.
is(loadCount, numTabs, "all tabs were restored");
is(aNeedRestore, 0, "there are no tabs left needing restore");
gProgressListener.unsetCallback();
executeSoon(next);
}
gProgressListener.unsetCallback();
resolve();
}
});
});
// We also want to catch the 2nd window, so we need to observe domwindowopened
@ -62,5 +60,11 @@ function runTests() {
}
});
yield ss.setBrowserState(JSON.stringify(state));
}
let backupState = ss.getBrowserState();
ss.setBrowserState(JSON.stringify(state));
yield promiseRestoringTabs;
// Cleanup.
yield promiseAllButPrimaryWindowClosed();
yield promiseBrowserState(backupState);
});

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

@ -4,11 +4,7 @@
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true);
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
@ -27,28 +23,32 @@ function runTests() {
], selected: 1 }] };
let loadCount = 0;
gBrowser.tabContainer.addEventListener("SSTabRestored", function onRestored(event) {
let tab = event.target;
let browser = tab.linkedBrowser;
let tabData = state.windows[0].tabs[loadCount++];
let promiseRestoringTabs = new Promise(resolve => {
gBrowser.tabContainer.addEventListener("SSTabRestored", function onRestored(event) {
let tab = event.target;
let browser = tab.linkedBrowser;
let tabData = state.windows[0].tabs[loadCount++];
// double check that this tab was the right one
is(browser.currentURI.spec, tabData.entries[0].url,
"load " + loadCount + " - browser loaded correct url");
is(ss.getTabValue(tab, "uniq"), tabData.extData.uniq,
"load " + loadCount + " - correct tab was restored");
// double check that this tab was the right one
is(browser.currentURI.spec, tabData.entries[0].url,
"load " + loadCount + " - browser loaded correct url");
is(ss.getTabValue(tab, "uniq"), tabData.extData.uniq,
"load " + loadCount + " - correct tab was restored");
if (loadCount == state.windows[0].tabs.length) {
gBrowser.tabContainer.removeEventListener("SSTabRestored", onRestored);
executeSoon(function () {
waitForBrowserState(TestRunner.backupState, finish);
});
} else {
// reload the next tab
gBrowser.browsers[loadCount].reload();
}
if (loadCount == state.windows[0].tabs.length) {
gBrowser.tabContainer.removeEventListener("SSTabRestored", onRestored);
resolve();
} else {
// reload the next tab
gBrowser.browsers[loadCount].reload();
}
});
});
yield ss.setBrowserState(JSON.stringify(state));
}
let backupState = ss.getBrowserState();
ss.setBrowserState(JSON.stringify(state));
yield promiseRestoringTabs;
// Cleanup.
yield promiseBrowserState(backupState);
});

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

@ -4,11 +4,7 @@
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true);
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
@ -34,33 +30,40 @@ function runTests() {
let tabOrder = [0, 5, 1, 4, 3, 2];
let loadCount = 0;
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
loadCount++;
let expected = expectedCounts[loadCount - 1];
let promiseRestoringTabs = new Promise(resolve => {
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
loadCount++;
let expected = expectedCounts[loadCount - 1];
is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored");
is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring");
is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored");
is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored");
is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring");
is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored");
if (loadCount < state.windows[0].tabs.length) {
// double check that this tab was the right one
let expectedData = state.windows[0].tabs[tabOrder[loadCount - 1]].extData.uniq;
let tab;
for (let i = 0; i < window.gBrowser.tabs.length; i++) {
if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
tab = window.gBrowser.tabs[i];
if (loadCount < state.windows[0].tabs.length) {
// double check that this tab was the right one
let expectedData = state.windows[0].tabs[tabOrder[loadCount - 1]].extData.uniq;
let tab;
for (let i = 0; i < window.gBrowser.tabs.length; i++) {
if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
tab = window.gBrowser.tabs[i];
}
is(ss.getTabValue(tab, "uniq"), expectedData,
"load " + loadCount + " - correct tab was restored");
// select the next tab
window.gBrowser.selectTabAtIndex(tabOrder[loadCount]);
} else {
gProgressListener.unsetCallback();
resolve();
}
is(ss.getTabValue(tab, "uniq"), expectedData,
"load " + loadCount + " - correct tab was restored");
// select the next tab
window.gBrowser.selectTabAtIndex(tabOrder[loadCount]);
} else {
gProgressListener.unsetCallback();
executeSoon(next);
}
});
});
yield ss.setBrowserState(JSON.stringify(state));
}
let backupState = ss.getBrowserState();
ss.setBrowserState(JSON.stringify(state));
yield promiseRestoringTabs;
// Cleanup.
yield promiseBrowserState(backupState);
});

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

@ -4,11 +4,7 @@
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false);
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
@ -33,24 +29,31 @@ function runTests() {
let numTabs = state1.windows[0].tabs.length + state2.windows[0].tabs.length;
let loadCount = 0;
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
// When loadCount == 2, we'll also restore state2 into the window
if (++loadCount == 2) {
ss.setWindowState(window, JSON.stringify(state2), false);
}
let promiseRestoringTabs = new Promise(resolve => {
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
// When loadCount == 2, we'll also restore state2 into the window
if (++loadCount == 2) {
ss.setWindowState(window, JSON.stringify(state2), false);
}
if (loadCount < numTabs) {
return;
}
if (loadCount < numTabs) {
return;
}
// We don't actually care about load order in this test, just that they all
// do load.
is(loadCount, numTabs, "test_setWindowStateNoOverwrite: all tabs were restored");
is(aNeedRestore, 0, "there are no tabs left needing restore");
// We don't actually care about load order in this test, just that they all
// do load.
is(loadCount, numTabs, "test_setWindowStateNoOverwrite: all tabs were restored");
is(aNeedRestore, 0, "there are no tabs left needing restore");
gProgressListener.unsetCallback();
executeSoon(next);
gProgressListener.unsetCallback();
resolve();
});
});
yield ss.setWindowState(window, JSON.stringify(state1), true);
}
let backupState = ss.getBrowserState();
ss.setWindowState(window, JSON.stringify(state1), true);
yield promiseRestoringTabs;
// Cleanup.
yield promiseBrowserState(backupState);
});

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

@ -4,11 +4,7 @@
const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false);
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
@ -33,24 +29,31 @@ function runTests() {
let numTabs = 2 + state2.windows[0].tabs.length;
let loadCount = 0;
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
// When loadCount == 2, we'll also restore state2 into the window
if (++loadCount == 2) {
executeSoon(() => ss.setWindowState(window, JSON.stringify(state2), true));
}
let promiseRestoringTabs = new Promise(resolve => {
gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
// When loadCount == 2, we'll also restore state2 into the window
if (++loadCount == 2) {
executeSoon(() => ss.setWindowState(window, JSON.stringify(state2), true));
}
if (loadCount < numTabs) {
return;
}
if (loadCount < numTabs) {
return;
}
// We don't actually care about load order in this test, just that they all
// do load.
is(loadCount, numTabs, "all tabs were restored");
is(aNeedRestore, 0, "there are no tabs left needing restore");
// We don't actually care about load order in this test, just that they all
// do load.
is(loadCount, numTabs, "all tabs were restored");
is(aNeedRestore, 0, "there are no tabs left needing restore");
gProgressListener.unsetCallback();
executeSoon(next);
gProgressListener.unsetCallback();
resolve();
});
});
yield ss.setWindowState(window, JSON.stringify(state1), true);
}
let backupState = ss.getBrowserState();
ss.setWindowState(window, JSON.stringify(state1), true);
yield promiseRestoringTabs;
// Cleanup.
yield promiseBrowserState(backupState);
});

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

@ -32,7 +32,7 @@ function newWindowWithState(state, callback) {
executeSoon(function () {
win.addEventListener("SSWindowStateReady", function onReady() {
win.removeEventListener("SSWindowStateReady", onReady, false);
whenTabRestored(win.gBrowser.tabs[0], () => callback(win));
promiseTabRestored(win.gBrowser.tabs[0]).then(() => callback(win));
}, false);
ss.setWindowState(win, JSON.stringify(state), true);

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

@ -163,7 +163,7 @@ function onStateRestored(aSubject, aTopic, aData) {
newWin.addEventListener("load", function(aEvent) {
newWin.removeEventListener("load", arguments.callee, false);
whenBrowserLoaded(newWin.gBrowser.selectedBrowser, function() {
promiseBrowserLoaded(newWin.gBrowser.selectedBrowser).then(() => {
// pin this tab
if (shouldPinTab)
newWin.gBrowser.pinTab(newWin.gBrowser.selectedTab);

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

@ -7,9 +7,7 @@
*/
add_task(function test_close_last_nonpopup_window() {
// Purge the list of closed windows.
while (ss.getClosedWindowCount()) {
ss.forgetClosedWindow(0);
}
forgetClosedWindows();
let oldState = ss.getWindowState(window);

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

@ -1,11 +1,9 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function test() {
TestRunner.run();
}
let TEST_STATE = { windows: [{ tabs: [{ url: "about:blank" }] }] };
function runTests() {
add_task(function* () {
function assertNumberOfTabs(num, msg) {
is(gBrowser.tabs.length, num, msg);
}
@ -29,13 +27,9 @@ function runTests() {
assertNumberOfPinnedTabs(2, "both tabs are now pinned");
// run the test
yield waitForBrowserState(
{ windows: [{ tabs: [{ url: "about:blank" }] }] },
function () {
assertNumberOfTabs(1, "one tab left after setBrowserState()");
assertNumberOfPinnedTabs(0, "there are no pinned tabs");
is(gBrowser.tabs[0].linkedBrowser, linkedBrowser, "first tab's browser got re-used");
next();
}
);
}
yield promiseBrowserState(TEST_STATE);
assertNumberOfTabs(1, "one tab left after setBrowserState()");
assertNumberOfPinnedTabs(0, "there are no pinned tabs");
is(gBrowser.tabs[0].linkedBrowser, linkedBrowser, "first tab's browser got re-used");
});

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

@ -17,9 +17,7 @@ add_task(function* setup() {
// We'll clear all closed windows to make sure our state is clean
// forgetClosedWindow doesn't trigger a delayed save
while (ss.getClosedWindowCount()) {
ss.forgetClosedWindow(0);
}
forgetClosedWindows();
is(ss.getClosedWindowCount(), 0, "starting with no closed windows");
});
@ -79,8 +77,6 @@ add_task(function* done() {
// The API still represents the closed window as closed, so we can clear it
// with the API, but just to make sure...
// is(ss.getClosedWindowCount(), 1, "1 closed window according to API");
while (ss.getClosedWindowCount()) {
ss.forgetClosedWindow(0);
}
forgetClosedWindows();
Services.prefs.clearUserPref("browser.sessionstore.interval");
});

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

@ -18,10 +18,6 @@ const TEST_STATE = {
}]
};
function test() {
TestRunner.run();
}
/**
* This test ensures that windows that have just been restored will be marked
* as dirty, otherwise _getCurrentState() might ignore them when collecting
@ -32,19 +28,20 @@ function test() {
* their state at least once.
*/
function runTests() {
let win;
add_task(function* test() {
// Wait until the new window has been opened.
Services.obs.addObserver(function onOpened(subject) {
Services.obs.removeObserver(onOpened, "domwindowopened");
win = subject;
executeSoon(next);
}, "domwindowopened", false);
let promiseWindow = new Promise(resolve => {
Services.obs.addObserver(function onOpened(subject) {
Services.obs.removeObserver(onOpened, "domwindowopened");
resolve(subject);
}, "domwindowopened", false);
});
// Set the new browser state that will
// restore a window with two slowly loading tabs.
yield SessionStore.setBrowserState(JSON.stringify(TEST_STATE));
let backupState = SessionStore.getBrowserState();
SessionStore.setBrowserState(JSON.stringify(TEST_STATE));
let win = yield promiseWindow;
// The window has now been opened. Check the state that is returned,
// this should come from the cache while the window isn't restored, yet.
@ -53,10 +50,14 @@ function runTests() {
// The history has now been restored and the tabs are loading. The data must
// now come from the window, if it's correctly been marked as dirty before.
yield whenDelayedStartupFinished(win, next);
yield new Promise(resolve => whenDelayedStartupFinished(win, resolve));
info("the delayed startup has finished");
checkWindows();
}
// Cleanup.
yield promiseWindowClosed(win);
yield promiseBrowserState(backupState);
});
function checkWindows() {
let state = JSON.parse(SessionStore.getBrowserState());

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

@ -63,10 +63,8 @@ function testTabRestoreData(aFormData, aExpectedValue, aCallback) {
let tab = gBrowser.addTab(testURL);
let tabState = { entries: [{ url: testURL, formdata: aFormData}] };
whenBrowserLoaded(tab.linkedBrowser, function() {
ss.setTabState(tab, JSON.stringify(tabState));
whenTabRestored(tab, function() {
promiseBrowserLoaded(tab.linkedBrowser).then(() => {
promiseTabState(tab, tabState).then(() => {
let doc = tab.linkedBrowser.contentDocument;
let select = doc.getElementById("select_id");
let value = select.options[select.selectedIndex].value;

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

@ -30,7 +30,7 @@ function test()
});
let tab = gBrowser.addTab("about:blank");
waitForTabState(tab, state, function () {
promiseTabState(tab, state).then(() => {
let history = tab.linkedBrowser.webNavigation.sessionHistory;
is(history.count, 2, "history.count");

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

@ -18,15 +18,14 @@ function test() {
let browser = tab.linkedBrowser;
waitForTabState(tab, tabState, function () {
promiseTabState(tab, tabState).then(() => {
let sessionHistory = browser.sessionHistory;
let entry = sessionHistory.getEntryAtIndex(0, false);
entry.QueryInterface(Ci.nsISHContainer);
whenChildCount(entry, 1, function () {
whenChildCount(entry, 2, function () {
whenBrowserLoaded(browser, function () {
promiseBrowserLoaded(browser).then(() => {
TabState.flush(browser);
let {entries} = JSON.parse(ss.getTabState(tab));
is(entries.length, 1, "tab has one history entry");

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

@ -18,15 +18,14 @@ function test() {
let browser = tab.linkedBrowser;
waitForTabState(tab, tabState, function() {
promiseTabState(tab, tabState).then(() => {
let sessionHistory = browser.sessionHistory;
let entry = sessionHistory.getEntryAtIndex(0, false);
entry.QueryInterface(Ci.nsISHContainer);
whenChildCount(entry, 1, function () {
whenChildCount(entry, 2, function () {
whenBrowserLoaded(browser, function () {
promiseBrowserLoaded(browser).then(() => {
let sessionHistory = browser.sessionHistory;
let entry = sessionHistory.getEntryAtIndex(0, false);

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

@ -18,7 +18,7 @@ function test() {
let tab = gBrowser.addTab("about:blank");
let browser = tab.linkedBrowser;
whenBrowserLoaded(browser, function () {
promiseBrowserLoaded(browser).then(() => {
isnot(gBrowser.selectedTab, tab, "newly created tab is not selected");
ss.setTabState(tab, JSON.stringify(tabState));
@ -28,7 +28,7 @@ function test() {
let formdata = state.entries[0].formdata;
is(formdata && formdata.id["foo"], "bar", "tab state's formdata is valid");
whenTabRestored(tab, function () {
promiseTabRestored(tab).then(() => {
let input = browser.contentDocument.getElementById("foo");
is(input.value, "bar", "formdata has been restored correctly");
finish();
@ -38,17 +38,3 @@ function test() {
gBrowser.selectedTab = tab;
});
}
function whenBrowserLoaded(aBrowser, aCallback) {
aBrowser.addEventListener("load", function onLoad() {
aBrowser.removeEventListener("load", onLoad, true);
executeSoon(aCallback);
}, true);
}
function whenTabRestored(aTab, aCallback) {
aTab.addEventListener("SSTabRestored", function onRestored() {
aTab.removeEventListener("SSTabRestored", onRestored);
executeSoon(aCallback);
});
}

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

@ -1,183 +1,116 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const originalState = ss.getBrowserState();
/** Private Browsing Test for Bug 819510 **/
function test() {
waitForExplicitFinish();
runNextTest();
}
let tests = [test_1, test_2, test_3 ];
const testState = {
windows: [{
tabs: [
{ entries: [{ url: "about:blank" }] },
]
}]
};
function runNextTest() {
// Set an empty state
closeAllButPrimaryWindow();
// Run the next test, or finish
if (tests.length) {
let currentTest = tests.shift();
waitForBrowserState(testState, currentTest);
} else {
Services.obs.addObserver(
function observe(aSubject, aTopic, aData) {
Services.obs.removeObserver(observe, aTopic);
finish();
},
"sessionstore-browser-state-restored", false);
ss.setBrowserState(originalState);
}
}
// Test opening default mochitest-normal-private-normal-private windows
// (saving the state with last window being private)
function test_1() {
testOnWindow(false, function(aWindow) {
aWindow.gBrowser.addTab("http://www.example.com/1");
testOnWindow(true, function(aWindow) {
aWindow.gBrowser.addTab("http://www.example.com/2");
testOnWindow(false, function(aWindow) {
aWindow.gBrowser.addTab("http://www.example.com/3");
testOnWindow(true, function(aWindow) {
aWindow.gBrowser.addTab("http://www.example.com/4");
add_task(function* test_1() {
let win = yield promiseNewWindowLoaded();
win.gBrowser.addTab("http://www.example.com/1");
let curState = JSON.parse(ss.getBrowserState());
is (curState.windows.length, 5, "Browser has opened 5 windows");
is (curState.windows[2].isPrivate, true, "Window is private");
is (curState.windows[4].isPrivate, true, "Last window is private");
is (curState.selectedWindow, 5, "Last window opened is the one selected");
win = yield promiseNewWindowLoaded({private: true});
win.gBrowser.addTab("http://www.example.com/2");
forceWriteState(function(state) {
is(state.windows.length, 3,
"sessionstore state: 3 windows in data being written to disk");
is (state.selectedWindow, 3,
"Selected window is updated to match one of the saved windows");
state.windows.forEach(function(win) {
is(!win.isPrivate, true, "Saved window is not private");
});
is(state._closedWindows.length, 0,
"sessionstore state: no closed windows in data being written to disk");
runNextTest();
});
});
});
});
});
}
win = yield promiseNewWindowLoaded();
win.gBrowser.addTab("http://www.example.com/3");
win = yield promiseNewWindowLoaded({private: true});
win.gBrowser.addTab("http://www.example.com/4");
let curState = JSON.parse(ss.getBrowserState());
is(curState.windows.length, 5, "Browser has opened 5 windows");
is(curState.windows[2].isPrivate, true, "Window is private");
is(curState.windows[4].isPrivate, true, "Last window is private");
is(curState.selectedWindow, 5, "Last window opened is the one selected");
let state = JSON.parse(yield promiseRecoveryFileContents());
is(state.windows.length, 3,
"sessionstore state: 3 windows in data being written to disk");
is(state.selectedWindow, 3,
"Selected window is updated to match one of the saved windows");
ok(state.windows.every(win => !win.isPrivate),
"Saved windows are not private");
is(state._closedWindows.length, 0,
"sessionstore state: no closed windows in data being written to disk");
// Cleanup.
yield promiseAllButPrimaryWindowClosed();
forgetClosedWindows();
});
// Test opening default mochitest window + 2 private windows
function test_2() {
testOnWindow(true, function(aWindow) {
aWindow.gBrowser.addTab("http://www.example.com/1");
testOnWindow(true, function(aWindow) {
aWindow.gBrowser.addTab("http://www.example.com/2");
add_task(function* test_2() {
let win = yield promiseNewWindowLoaded({private: true});
win.gBrowser.addTab("http://www.example.com/1");
let curState = JSON.parse(ss.getBrowserState());
is (curState.windows.length, 3, "Browser has opened 3 windows");
is (curState.windows[1].isPrivate, true, "Window 1 is private");
is (curState.windows[2].isPrivate, true, "Window 2 is private");
is (curState.selectedWindow, 3, "Last window opened is the one selected");
win = yield promiseNewWindowLoaded({private: true});
win.gBrowser.addTab("http://www.example.com/2");
forceWriteState(function(state) {
is(state.windows.length, 1,
"sessionstore state: 1 windows in data being written to disk");
is (state.selectedWindow, 1,
"Selected window is updated to match one of the saved windows");
is(state._closedWindows.length, 0,
"sessionstore state: no closed windows in data being written to disk");
runNextTest();
});
});
});
}
let curState = JSON.parse(ss.getBrowserState());
is(curState.windows.length, 3, "Browser has opened 3 windows");
is(curState.windows[1].isPrivate, true, "Window 1 is private");
is(curState.windows[2].isPrivate, true, "Window 2 is private");
is(curState.selectedWindow, 3, "Last window opened is the one selected");
let state = JSON.parse(yield promiseRecoveryFileContents());
is(state.windows.length, 1,
"sessionstore state: 1 windows in data being written to disk");
is(state.selectedWindow, 1,
"Selected window is updated to match one of the saved windows");
is(state._closedWindows.length, 0,
"sessionstore state: no closed windows in data being written to disk");
// Cleanup.
yield promiseAllButPrimaryWindowClosed();
forgetClosedWindows();
});
// Test opening default-normal-private-normal windows and closing a normal window
function test_3() {
testOnWindow(false, function(normalWindow) {
waitForTabLoad(normalWindow, "http://www.example.com/", function() {
testOnWindow(true, function(aWindow) {
waitForTabLoad(aWindow, "http://www.example.com/", function() {
testOnWindow(false, function(aWindow) {
waitForTabLoad(aWindow, "http://www.example.com/", function() {
add_task(function* test_3() {
let normalWindow = yield promiseNewWindowLoaded();
yield promiseTabLoad(normalWindow, "http://www.example.com/");
let curState = JSON.parse(ss.getBrowserState());
is(curState.windows.length, 4, "Browser has opened 4 windows");
is(curState.windows[2].isPrivate, true, "Window 2 is private");
is(curState.selectedWindow, 4, "Last window opened is the one selected");
let win = yield promiseNewWindowLoaded({private: true});
yield promiseTabLoad(win, "http://www.example.com/");
waitForWindowClose(normalWindow, function() {
// Pin and unpin a tab before checking the written state so that
// the list of restoring windows gets cleared. Otherwise the
// window we just closed would be marked as not closed.
let tab = aWindow.gBrowser.tabs[0];
aWindow.gBrowser.pinTab(tab);
aWindow.gBrowser.unpinTab(tab);
win = yield promiseNewWindowLoaded();
yield promiseTabLoad(win, "http://www.example.com/");
forceWriteState(function(state) {
is(state.windows.length, 2,
"sessionstore state: 2 windows in data being written to disk");
is(state.selectedWindow, 2,
"Selected window is updated to match one of the saved windows");
state.windows.forEach(function(win) {
is(!win.isPrivate, true, "Saved window is not private");
});
is(state._closedWindows.length, 1,
"sessionstore state: 1 closed window in data being written to disk");
state._closedWindows.forEach(function(win) {
is(!win.isPrivate, true, "Closed window is not private");
});
runNextTest();
});
});
});
});
});
});
});
});
}
function waitForWindowClose(aWin, aCallback) {
let winCount = JSON.parse(ss.getBrowserState()).windows.length;
aWin.addEventListener("SSWindowClosing", function onWindowClosing() {
aWin.removeEventListener("SSWindowClosing", onWindowClosing, false);
function checkCount() {
let state = JSON.parse(ss.getBrowserState());
if (state.windows.length == (winCount - 1)) {
aCallback();
} else {
executeSoon(checkCount);
}
}
executeSoon(checkCount);
}, false);
aWin.close();
}
function forceWriteState(aCallback) {
return promiseRecoveryFileContents().then(function(data) {
aCallback(JSON.parse(data));
});
}
function testOnWindow(aIsPrivate, aCallback) {
whenNewWindowLoaded({private: aIsPrivate}, aCallback);
}
function waitForTabLoad(aWin, aURL, aCallback) {
let browser = aWin.gBrowser.selectedBrowser;
browser.loadURI(aURL);
whenBrowserLoaded(browser, function () {
TabState.flush(browser);
executeSoon(aCallback);
});
let curState = JSON.parse(ss.getBrowserState());
is(curState.windows.length, 4, "Browser has opened 4 windows");
is(curState.windows[2].isPrivate, true, "Window 2 is private");
is(curState.selectedWindow, 4, "Last window opened is the one selected");
yield promiseWindowClosed(normalWindow);
// Pin and unpin a tab before checking the written state so that
// the list of restoring windows gets cleared. Otherwise the
// window we just closed would be marked as not closed.
let tab = win.gBrowser.tabs[0];
win.gBrowser.pinTab(tab);
win.gBrowser.unpinTab(tab);
let state = JSON.parse(yield promiseRecoveryFileContents());
is(state.windows.length, 2,
"sessionstore state: 2 windows in data being written to disk");
is(state.selectedWindow, 2,
"Selected window is updated to match one of the saved windows");
ok(state.windows.every(win => !win.isPrivate),
"Saved windows are not private");
is(state._closedWindows.length, 1,
"sessionstore state: 1 closed window in data being written to disk");
ok(state._closedWindows.every(win => !win.isPrivate),
"Closed windows are not private");
// Cleanup.
yield promiseAllButPrimaryWindowClosed();
forgetClosedWindows();
});
function promiseTabLoad(win, url) {
let browser = win.gBrowser.selectedBrowser;
browser.loadURI(url);
return promiseBrowserLoaded(browser).then(() => TabState.flush(browser));
}

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

@ -5,18 +5,14 @@
// security policy with the document.
// The policy being tested disallows inline scripts
function test() {
TestRunner.run();
}
function runTests() {
add_task(function* test() {
// create a tab that has a CSP
let testURL = "http://mochi.test:8888/browser/browser/components/sessionstore/test/browser_911547_sample.html";
let tab = gBrowser.selectedTab = gBrowser.addTab(testURL);
gBrowser.selectedTab = tab;
let browser = tab.linkedBrowser;
yield waitForLoad(browser);
yield promiseBrowserLoaded(browser);
// this is a baseline to ensure CSP is active
// attempt to inject and run a script via inline (pre-restore, allowed)
@ -27,7 +23,7 @@ function runTests() {
// attempt to click a link to a data: URI (will inherit the CSP of the
// origin document) and navigate to the data URI in the link.
browser.contentDocument.getElementById("test_data_link").click();
yield waitForLoad(browser);
yield promiseBrowserLoaded(browser);
is(browser.contentDocument.getElementById("test_id2").value, "ok",
"CSP should block the script loaded by the clicked data URI");
@ -37,7 +33,7 @@ function runTests() {
// open new tab and recover the state
tab = ss.undoCloseTab(window, 0);
yield waitForTabRestored(tab);
yield promiseTabRestored(tab);
browser = tab.linkedBrowser;
is(browser.contentDocument.getElementById("test_id2").value, "ok",
@ -45,21 +41,7 @@ function runTests() {
// clean up
gBrowser.removeTab(tab);
}
function waitForLoad(aElement) {
aElement.addEventListener("load", function onLoad() {
aElement.removeEventListener("load", onLoad, true);
executeSoon(next);
}, true);
}
function waitForTabRestored(aElement) {
aElement.addEventListener("SSTabRestored", function tabRestored(e) {
aElement.removeEventListener("SSTabRestored", tabRestored, true);
executeSoon(next);
}, true);
}
});
// injects an inline script element (with a text body)
function injectInlineScript(browser, scriptText) {

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

@ -1,10 +1,6 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function test() {
TestRunner.run();
}
/**
* This test makes sure that we correctly preserve tab attributes when storing
* and restoring tabs. It also ensures that we skip special attributes like
@ -13,13 +9,13 @@ function test() {
const PREF = "browser.sessionstore.restore_on_demand";
function runTests() {
add_task(function* test() {
Services.prefs.setBoolPref(PREF, true)
registerCleanupFunction(() => Services.prefs.clearUserPref(PREF));
// Add a new tab with a nice icon.
let tab = gBrowser.addTab("about:robots");
yield whenBrowserLoaded(tab.linkedBrowser);
yield promiseBrowserLoaded(tab.linkedBrowser);
// Check that the tab has an 'image' attribute.
ok(tab.hasAttribute("image"), "tab.image exists");
@ -44,15 +40,16 @@ function runTests() {
};
// Prepare a pending tab waiting to be restored.
whenTabRestoring(tab);
yield ss.setTabState(tab, JSON.stringify(state));
let promise = promiseTabRestoring(tab);
ss.setTabState(tab, JSON.stringify(state));
yield promise;
ok(tab.hasAttribute("pending"), "tab is pending");
is(gBrowser.getIcon(tab), state.attributes.image, "tab has correct icon");
// Let the pending tab load.
gBrowser.selectedTab = tab;
yield whenTabRestored(tab);
yield promiseTabRestored(tab);
// Ensure no 'image' or 'pending' attributes are stored.
({attributes} = JSON.parse(ss.getTabState(tab)));
@ -62,11 +59,13 @@ function runTests() {
// Clean up.
gBrowser.removeTab(tab);
}
});
function whenTabRestoring(tab) {
tab.addEventListener("SSTabRestoring", function onRestoring() {
tab.removeEventListener("SSTabRestoring", onRestoring);
executeSoon(next);
function promiseTabRestoring(tab) {
return new Promise(resolve => {
tab.addEventListener("SSTabRestoring", function onRestoring() {
tab.removeEventListener("SSTabRestoring", onRestoring);
resolve();
});
});
}

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

@ -102,8 +102,7 @@ add_task(function flush_on_settabstate() {
// asynchronous messages.
TabState.flushAsync(browser);
ss.setTabState(tab, state);
yield promiseTabRestored(tab);
yield promiseTabState(tab, state);
let {storage} = JSON.parse(ss.getTabState(tab));
is(storage["http://example.com"].test, INITIAL_VALUE,

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

@ -41,8 +41,7 @@ add_task(function docshell_capabilities() {
is(disallow.size, 2, "two capabilities disallowed");
// Reuse the tab to restore a new, clean state into it.
ss.setTabState(tab, JSON.stringify({ entries: [{url: "about:robots"}] }));
yield promiseTabRestored(tab);
yield promiseTabState(tab, {entries: [{url: "about:robots"}]});
// Flush to make sure chrome received all data.
TabState.flush(browser);
@ -53,8 +52,7 @@ add_task(function docshell_capabilities() {
ok(flags.every(f => docShell[f]), "all flags set to true");
// Restore the state with disallowed features.
ss.setTabState(tab, JSON.stringify(disallowedState));
yield promiseTabRestored(tab);
yield promiseTabState(tab, disallowedState);
// Check that docShell flags are set.
ok(!docShell.allowImages, "images not allowed");

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

@ -37,9 +37,7 @@ function getClosedState() {
let CLOSED_STATE;
add_task(function* init() {
while (ss.getClosedWindowCount() > 0) {
ss.forgetClosedWindow(0);
}
forgetClosedWindows();
while (ss.getClosedTabCount(window) > 0) {
ss.forgetClosedTab(window, 0);
}

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

@ -1,29 +1,24 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function test() {
TestRunner.run();
}
/**
* This test ensures that after closing a window we keep its state data around
* as long as something keeps a reference to it. It should only be possible to
* read data after closing - writing should fail.
*/
function runTests() {
add_task(function* test() {
// Open a new window.
let win = OpenBrowserWindow();
yield whenDelayedStartupFinished(win, next);
let win = yield promiseNewWindowLoaded();
// Load some URL in the current tab.
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY;
win.gBrowser.selectedBrowser.loadURIWithFlags("about:robots", flags);
yield whenBrowserLoaded(win.gBrowser.selectedBrowser);
yield promiseBrowserLoaded(win.gBrowser.selectedBrowser);
// Open a second tab and close the first one.
let tab = win.gBrowser.addTab("about:mozilla");
yield whenBrowserLoaded(tab.linkedBrowser);
yield promiseBrowserLoaded(tab.linkedBrowser);
TabState.flush(tab.linkedBrowser);
win.gBrowser.removeTab(win.gBrowser.tabs[0]);
@ -36,9 +31,8 @@ function runTests() {
let state = ss.getWindowState(win);
let closedTabData = ss.getClosedTabData(win);
// Close our window and wait a tick.
whenWindowClosed(win);
yield win.close();
// Close our window.
yield promiseWindowClosed(win);
// SessionStore should no longer track our window
// but it should still report the same state.
@ -46,11 +40,11 @@ function runTests() {
checkWindowState(win);
// Make sure we're not allowed to modify state data.
ok(shouldThrow(() => ss.setWindowState(win, {})),
"we're not allowed to modify state data anymore");
ok(shouldThrow(() => ss.setWindowValue(win, "foo", "baz")),
"we're not allowed to modify state data anymore");
}
Assert.throws(() => ss.setWindowState(win, {}),
"we're not allowed to modify state data anymore");
Assert.throws(() => ss.setWindowValue(win, "foo", "baz"),
"we're not allowed to modify state data anymore");
});
function checkWindowState(window) {
let {windows: [{tabs}]} = JSON.parse(ss.getWindowState(window));
@ -71,10 +65,3 @@ function shouldThrow(f) {
return true;
}
}
function whenWindowClosed(window) {
window.addEventListener("SSWindowClosing", function onClosing() {
window.removeEventListener("SSWindowClosing", onClosing);
executeSoon(next);
});
}

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

@ -73,8 +73,7 @@ add_task(function test_old_format() {
// Check that the form value is restored.
let state = {entries: [{url: URL, formdata: {id: {input: VALUE}}}]};
ss.setTabState(tab, JSON.stringify(state));
yield promiseTabRestored(tab);
yield promiseTabState(tab, state);
is((yield getInputValue(browser, "input")), VALUE, "form data restored");
// Cleanup.
@ -97,8 +96,7 @@ add_task(function test_old_format_inner_html() {
// Restore the tab state.
let state = {entries: [{url: URL, innerHTML: VALUE}]};
ss.setTabState(tab, JSON.stringify(state));
yield promiseTabRestored(tab);
yield promiseTabState(tab, state);
// Check that the innerHTML value was restored.
let html = yield getInnerHTML(browser);
@ -130,8 +128,7 @@ add_task(function test_url_check() {
state.formdata.url = url;
}
ss.setTabState(tab, JSON.stringify(state));
return promiseTabRestored(tab).then(() => getInputValue(browser, "input"));
return promiseTabState(tab, state).then(() => getInputValue(browser, "input"));
}
// Check that the form value is restored with the correct URL.

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

@ -75,9 +75,7 @@ function testTabRestoreData(aFormData, aExpectedValue, aCallback) {
Task.spawn(function () {
yield promiseBrowserLoaded(tab.linkedBrowser);
ss.setTabState(tab, JSON.stringify(tabState));
yield promiseTabRestored(tab);
yield promiseTabState(tab, tabState);
TabState.flush(tab.linkedBrowser);
let restoredTabState = JSON.parse(ss.getTabState(tab));

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

@ -2,7 +2,7 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests the API for saving global session data.
function runTests() {
add_task(function* () {
const key1 = "Unique name 1: " + Date.now();
const key2 = "Unique name 2: " + Date.now();
const value1 = "Unique value 1: " + Math.random();
@ -39,11 +39,7 @@ function runTests() {
is(ss.getGlobalValue(key2), "", "global value was deleted");
}
yield waitForBrowserState(testState, next);
yield promiseBrowserState(testState);
testRestoredState();
testGlobalStore();
}
function test() {
TestRunner.run();
}
});

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

@ -47,8 +47,7 @@ add_task(function *test_history_cap() {
info("Testing situation where only a subset of session history entries should be restored.");
ss.setTabState(tab, JSON.stringify(tabState));
yield promiseTabRestored(tab);
yield promiseTabState(tab, tabState);
TabState.flush(tab.linkedBrowser);
let restoredTabState = JSON.parse(ss.getTabState(tab));
@ -68,8 +67,7 @@ add_task(function *test_history_cap() {
info("Testing situation where all of the entries in the session history should be restored.");
ss.setTabState(tab, JSON.stringify(tabState));
yield promiseTabRestored(tab);
yield promiseTabState(tab, tabState);
TabState.flush(tab.linkedBrowser);
restoredTabState = JSON.parse(ss.getTabState(tab));
@ -87,8 +85,7 @@ add_task(function *test_history_cap() {
// Set the one-based tab-state index to the oldest session history entry.
tabState.index = 1;
ss.setTabState(tab, JSON.stringify(tabState));
yield promiseTabRestored(tab);
yield promiseTabState(tab, tabState);
TabState.flush(tab.linkedBrowser);
restoredTabState = JSON.parse(ss.getTabState(tab));
@ -106,8 +103,7 @@ add_task(function *test_history_cap() {
// Set the one-based tab-state index to the newest session history entry.
tabState.index = maxEntries;
ss.setTabState(tab, JSON.stringify(tabState));
yield promiseTabRestored(tab);
yield promiseTabState(tab, tabState);
TabState.flush(tab.linkedBrowser);
restoredTabState = JSON.parse(ss.getTabState(tab));

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

@ -68,9 +68,7 @@ add_task(function () {
"docShell.QueryInterface%28Components.interfaces.nsILoadContext%29.usePrivateBrowsing%3Dtrue";
// Clear the list of closed windows.
while (ss.getClosedWindowCount()) {
ss.forgetClosedWindow(0);
}
forgetClosedWindows();
// Create a new window to attach our frame script to.
let win = yield promiseNewWindowLoaded();
@ -109,9 +107,7 @@ add_task(function () {
add_task(function () {
// Clear the list of closed windows.
while (ss.getClosedWindowCount()) {
ss.forgetClosedWindow(0);
}
forgetClosedWindows();
// Create a new window to attach our frame script to.
let win = yield promiseNewWindowLoaded({private: true});

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

@ -115,8 +115,7 @@ add_task(function test_scroll_old_format() {
yield promiseBrowserLoaded(browser);
// Apply the tab state with the old format.
ss.setTabState(tab, JSON.stringify(TAB_STATE));
yield promiseTabRestored(tab);
yield promiseTabState(tab, TAB_STATE);
// Check that the scroll positions has been applied.
let scroll = yield sendMessage(browser, "ss-test:getScrollPosition");

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

@ -20,7 +20,7 @@ add_task(function test_load_start() {
// Undo close the tab.
tab = ss.undoCloseTab(window, 0);
browser = tab.linkedBrowser;
yield promiseBrowserLoaded(browser);
yield promiseTabRestored(tab);
// Check that the correct URL was restored.
is(browser.currentURI.spec, "about:mozilla", "url is correct");

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

@ -24,9 +24,7 @@ function gt(a, b, message) {
}
add_task(function init() {
for (let i = ss.getClosedWindowCount() - 1; i >= 0; --i) {
ss.forgetClosedWindow(i);
}
forgetClosedWindows();
for (let i = ss.getClosedTabCount(window) - 1; i >= 0; --i) {
ss.forgetClosedTab(window, i);
}

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

@ -8,8 +8,7 @@ function test() {
waitForExplicitFinish();
// Purging the list of closed windows
while(ss.getClosedWindowCount() > 0)
ss.forgetClosedWindow(0);
forgetClosedWindows();
// Load a private window, then close it
// and verify it doesn't get remembered for restoring

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

@ -172,29 +172,14 @@ function promiseBrowserState(aState) {
return new Promise(resolve => waitForBrowserState(aState, resolve));
}
// Doesn't assume that the tab needs to be closed in a cleanup function.
// If that's the case, the test author should handle that in the test.
function waitForTabState(aTab, aState, aCallback) {
let listening = true;
function onSSTabRestored() {
aTab.removeEventListener("SSTabRestored", onSSTabRestored, false);
listening = false;
aCallback();
function promiseTabState(tab, state) {
if (typeof(state) != "string") {
state = JSON.stringify(state);
}
aTab.addEventListener("SSTabRestored", onSSTabRestored, false);
registerCleanupFunction(function() {
if (listening) {
aTab.removeEventListener("SSTabRestored", onSSTabRestored, false);
}
});
ss.setTabState(aTab, JSON.stringify(aState));
}
function promiseTabState(tab, state) {
return new Promise(resolve => waitForTabState(tab, state, resolve));
let promise = promiseTabRestored(tab);
ss.setTabState(tab, state);
return promise;
}
/**
@ -297,55 +282,14 @@ let promiseForEachSessionRestoreFile = Task.async(function*(cb) {
}
});
function whenBrowserLoaded(aBrowser, aCallback = next, ignoreSubFrames = true, expectedURL = null) {
aBrowser.messageManager.addMessageListener("ss-test:loadEvent", function onLoad(msg) {
if (expectedURL && aBrowser.currentURI.spec != expectedURL) {
return;
}
if (!ignoreSubFrames || !msg.data.subframe) {
aBrowser.messageManager.removeMessageListener("ss-test:loadEvent", onLoad);
executeSoon(aCallback);
}
});
}
function promiseBrowserLoaded(aBrowser, ignoreSubFrames = true) {
return new Promise(resolve => {
whenBrowserLoaded(aBrowser, resolve, ignoreSubFrames);
});
}
function whenBrowserUnloaded(aBrowser, aContainer, aCallback = next) {
aBrowser.addEventListener("unload", function onUnload() {
aBrowser.removeEventListener("unload", onUnload, true);
executeSoon(aCallback);
}, true);
}
/**
* Loads a page in a browser, and returns a Promise that
* resolves once a "load" event has been fired within that
* browser.
*
* @param browser
* The browser to load the page in.
* @param uri
* The URI to load.
*
* @return Promise
*/
function loadPage(browser, uri) {
return new Promise((resolve, reject) => {
browser.addEventListener("load", function onLoad(event) {
browser.removeEventListener("load", onLoad, true);
resolve();
}, true);
browser.loadURI(uri);
});
}
function promiseBrowserUnloaded(aBrowser, aContainer) {
return new Promise(resolve => {
whenBrowserUnloaded(aBrowser, aContainer, resolve);
aBrowser.messageManager.addMessageListener("ss-test:loadEvent", function onLoad(msg) {
if (!ignoreSubFrames || !msg.data.subframe) {
aBrowser.messageManager.removeMessageListener("ss-test:loadEvent", onLoad);
resolve();
}
});
});
}
@ -361,15 +305,6 @@ function promiseWindowLoaded(aWindow) {
return new Promise(resolve => whenWindowLoaded(aWindow, resolve));
}
function whenTabRestored(aTab, aCallback = next) {
aTab.addEventListener("SSTabRestored", function onRestored(aEvent) {
aTab.removeEventListener("SSTabRestored", onRestored, true);
executeSoon(function executeWhenTabRestored() {
aCallback();
});
}, true);
}
var gUniqueCounter = 0;
function r() {
return Date.now() + "-" + (++gUniqueCounter);
@ -464,14 +399,23 @@ registerCleanupFunction(function () {
gProgressListener.unsetCallback();
});
// Close everything but our primary window. We can't use waitForFocus()
// because apparently it's buggy. See bug 599253.
function closeAllButPrimaryWindow() {
// Close all but our primary window.
function promiseAllButPrimaryWindowClosed() {
let windows = [];
for (let win in BrowserWindowIterator()) {
if (win != window) {
win.close();
windows.push(win);
}
}
return Promise.all(windows.map(promiseWindowClosed));
}
// Forget all closed windows.
function forgetClosedWindows() {
while (ss.getClosedWindowCount() > 0) {
ss.forgetClosedWindow(0);
}
}
/**
@ -544,56 +488,6 @@ function promiseDelayedStartupFinished(aWindow) {
return new Promise(resolve => whenDelayedStartupFinished(aWindow, resolve));
}
/**
* The test runner that controls the execution flow of our tests.
*/
let TestRunner = {
_iter: null,
/**
* Holds the browser state from before we started so
* that we can restore it after all tests ran.
*/
backupState: {},
/**
* Starts the test runner.
*/
run: function () {
waitForExplicitFinish();
SessionStore.promiseInitialized.then(() => {
this.backupState = JSON.parse(ss.getBrowserState());
this._iter = runTests();
this.next();
});
},
/**
* Runs the next available test or finishes if there's no test left.
*/
next: function () {
try {
TestRunner._iter.next();
} catch (e if e instanceof StopIteration) {
TestRunner.finish();
}
},
/**
* Finishes all tests and cleans up.
*/
finish: function () {
closeAllButPrimaryWindow();
gBrowser.selectedTab = gBrowser.tabs[0];
waitForBrowserState(this.backupState, finish);
}
};
function next() {
TestRunner.next();
}
function promiseTabRestored(tab) {
return new Promise(resolve => {
tab.addEventListener("SSTabRestored", function onRestored() {