зеркало из https://github.com/mozilla/gecko-dev.git
Bug 822093 - Make browser_819510_perwindowpb.js wait for the sessionstore data to update before performing tests on it. r=jdm
This commit is contained in:
Родитель
d165c2299d
Коммит
5ef9c3160a
|
@ -8,7 +8,6 @@ function test() {
|
|||
waitForExplicitFinish();
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
Services.prefs.clearUserPref("browser.sessionstore.interval");
|
||||
ss.setBrowserState(originalState);
|
||||
});
|
||||
|
||||
|
@ -34,8 +33,6 @@ function runNextTest() {
|
|||
let currentTest = tests.shift();
|
||||
waitForBrowserState(testState, currentTest);
|
||||
} else {
|
||||
Services.prefs.clearUserPref("browser.sessionstore.interval");
|
||||
ss.setBrowserState(originalState);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
@ -105,12 +102,11 @@ function test_2() {
|
|||
// Test opening default-normal-private-normal windows and closing a normal window
|
||||
function test_3() {
|
||||
testOnWindow(false, function(normalWindow) {
|
||||
let tab = normalWindow.gBrowser.addTab("http://www.example.com/1");
|
||||
whenBrowserLoaded(tab.linkedBrowser, function() {
|
||||
waitForTabLoad(normalWindow, "http://www.example.com/", function() {
|
||||
testOnWindow(true, function(aWindow) {
|
||||
aWindow.gBrowser.addTab("http://www.example.com/2");
|
||||
waitForTabLoad(aWindow, "http://www.example.com/", function() {
|
||||
testOnWindow(false, function(aWindow) {
|
||||
aWindow.gBrowser.addTab("http://www.example.com/3");
|
||||
waitForTabLoad(aWindow, "http://www.example.com/", function() {
|
||||
|
||||
let curState = JSON.parse(ss.getBrowserState());
|
||||
is(curState.windows.length, 4, "Browser has opened 4 windows");
|
||||
|
@ -138,33 +134,32 @@ function test_3() {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function waitForWindowClose(aWin, aCallback) {
|
||||
Services.obs.addObserver(function observe(aSubject, aTopic, aData) {
|
||||
if (aTopic == "domwindowclosed" && aWin == aSubject) {
|
||||
Services.obs.removeObserver(observe, aTopic);
|
||||
checkWindowIsClosed(aWin, aCallback);
|
||||
}
|
||||
}, "domwindowclosed", false);
|
||||
aWin.close();
|
||||
}
|
||||
|
||||
function checkWindowIsClosed(aWin, aCallback) {
|
||||
if (aWin.closed) {
|
||||
info("Window is closed");
|
||||
executeSoon(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(function() {
|
||||
checkWindowIsClosed(aWin, aCallback);
|
||||
});
|
||||
executeSoon(checkCount);
|
||||
}
|
||||
}
|
||||
executeSoon(checkCount);
|
||||
}, false);
|
||||
aWin.close();
|
||||
}
|
||||
|
||||
function forceWriteState(aCallback) {
|
||||
Services.obs.addObserver(function observe(aSubject, aTopic, aData) {
|
||||
if (aTopic == "sessionstore-state-write") {
|
||||
Services.obs.removeObserver(observe, aTopic);
|
||||
Services.prefs.clearUserPref("browser.sessionstore.interval");
|
||||
aSubject.QueryInterface(Ci.nsISupportsString);
|
||||
aCallback(JSON.parse(aSubject.data));
|
||||
}
|
||||
|
@ -179,3 +174,11 @@ function testOnWindow(aIsPrivate, aCallback) {
|
|||
executeSoon(function() { aCallback(win); });
|
||||
}, false);
|
||||
}
|
||||
|
||||
function waitForTabLoad(aWin, aURL, aCallback) {
|
||||
aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
|
||||
aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
|
||||
aCallback();
|
||||
}, true);
|
||||
aWin.gBrowser.selectedBrowser.loadURI(aURL);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче