[Bug 669077] Cleanup sessionstore tests suite. Ports bug 667202 and syncs head.js with FF. r+=Neil

This commit is contained in:
Misak Khachatryan 2011-07-05 14:56:25 +05:00
Родитель 260c4bfcc3
Коммит b7548924db
40 изменённых файлов: 159 добавлений и 268 удалений

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

@ -37,11 +37,6 @@
function test() {
/** Test for Bug 339445 **/
try {
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
}
catch (ex) { }
waitForExplicitFinish();
let testURL = "http://mochi.test:8888/browser/" +
@ -62,8 +57,8 @@ function test() {
"sessionStorage value has been duplicated");
// clean up
gBrowser.removeTab(tab2);
gBrowser.removeTab(tab);
getBrowser().removeTab(tab2);
getBrowser().removeTab(tab);
finish();
}, true);

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

@ -47,8 +47,6 @@ function test() {
}
}
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
// all of the following calls with illegal arguments should throw NS_ERROR_ILLEGAL_VALUE
ok(test(function() ss.getWindowState({})),
"Invalid window for getWindowState throws");

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

@ -37,12 +37,6 @@
function test() {
/** Test for Bug 346337 **/
try {
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
}
catch (ex) { }
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsILocalFile);

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

@ -9,18 +9,8 @@ function test() {
return false;
}
// test setup
let tabbrowser = getBrowser();
waitForExplicitFinish();
// component
let ssComponent = test(function() Components.classes["@mozilla.org/suite/sessionstore;1"]);
ok(ssComponent, "reference the sessionstore component");
// service
let ss = test(function() ssComponent.getService(Components.interfaces.nsISessionStore));
ok(ss, "reference the sessionstore service");
////////////////////////////
// setWindowValue, et al. //
////////////////////////////
@ -44,7 +34,7 @@ function test() {
/////////////////////////
key = "Unique name: " + Math.random();
value = "Unique value: " + Date.now();
let tab = tabbrowser.addTab();
let tab = getBrowser().addTab();
tab.linkedBrowser.stop();
// test adding
@ -59,7 +49,7 @@ function test() {
is(ss.getTabValue(tab, key), "", "tab value was deleted");
// clean up
tabbrowser.removeTab(tab);
getBrowser().removeTab(tab);
/////////////////////////////////////
// getClosedTabCount, undoCloseTab //
@ -76,14 +66,14 @@ function test() {
// create a new tab
let testURL = "about:";
tab = tabbrowser.addTab(testURL);
tab = getBrowser().addTab(testURL);
tab.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
// make sure that the next closed tab will increase getClosedTabCount
gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
// remove tab
tabbrowser.removeTab(tab);
getBrowser().removeTab(tab);
// getClosedTabCount
var newcount = ss.getClosedTabCount(window);
@ -100,7 +90,7 @@ function test() {
// clean up
if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo"))
gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
tabbrowser.removeTab(tab);
getBrowser().removeTab(tab);
finish();
}, true);
}, true);

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

@ -37,25 +37,19 @@
function test() {
/** Test for Bug 367052 **/
// test setup
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
let tabbrowser = gBrowser;
waitForExplicitFinish();
// make sure that the next closed tab will increase getClosedTabCount
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo");
gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
let max_tabs_undo = Services.prefs.getIntPref("browser.sessionstore.max_tabs_undo");
Services.prefs.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
let closedTabCount = ss.getClosedTabCount(window);
// restore a blank tab
let tab = tabbrowser.addTab("about:");
let tab = getBrowser().addTab("about:");
tab.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
let browser = tabbrowser.getBrowserForTab(tab);
let browser = getBrowser().getBrowserForTab(tab);
let history = browser.webNavigation.sessionHistory;
ok(history.count >= 1, "the new tab does have at least one history entry");
@ -64,13 +58,13 @@ function test() {
this.removeEventListener("load", arguments.callee, true);
ok(history.count == 0, "the tab was restored without any history whatsoever");
tabbrowser.removeTab(tab);
getBrowser().removeTab(tab);
ok(ss.getClosedTabCount(window) == closedTabCount,
"The closed blank tab wasn't added to Recently Closed Tabs");
// clean up
if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo"))
gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
if (Services.prefs.prefHasUserValue("browser.sessionstore.max_tabs_undo"))
Services.prefs.clearUserPref("browser.sessionstore.max_tabs_undo");
finish();
}, true);
}, true);

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

@ -1,13 +1,6 @@
function test() {
/** Test for Bug 393716 **/
// set up the basics (SessionStore service, tabbrowser)
try {
var ss = Cc["@mozilla.org/suite/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
}
catch (ex) { }
ok(ss, "SessionStore service is available");
let tabbrowser = getBrowser();
waitForExplicitFinish();
/////////////////
@ -18,7 +11,7 @@ function test() {
let testURL = "about:config";
// create a new tab
let tab = tabbrowser.addTab(testURL);
let tab = getBrowser().addTab(testURL);
ss.setTabValue(tab, key, value);
tab.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
@ -36,7 +29,7 @@ function test() {
"Got the expected state object (test manually set tab value)");
// clean up
tabbrowser.removeTab(tab);
getBrowser().removeTab(tab);
}, true);
//////////////////////////////////
@ -48,7 +41,7 @@ function test() {
let state = { entries: [{ url: testURL }], extData: { key2: value2 } };
// create a new tab
let tab2 = tabbrowser.addTab();
let tab2 = getBrowser().addTab();
// set the tab's state
ss.setTabState(tab2, JSON.stringify(state));
tab2.linkedBrowser.addEventListener("load", function(aEvent) {
@ -63,7 +56,7 @@ function test() {
// duplicate the tab
let duplicateTab = ss.duplicateTab(window, tab2);
tabbrowser.removeTab(tab2);
getBrowser().removeTab(tab2);
duplicateTab.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
@ -74,7 +67,7 @@ function test() {
is(textbox.value, value3, "also duplicated text data");
// clean up
tabbrowser.removeTab(duplicateTab);
getBrowser().removeTab(duplicateTab);
finish();
}, true);
}, true);

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

@ -37,16 +37,12 @@
function test() {
/** Test for Bug 408470 **/
try {
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
}
catch (ex) { }
waitForExplicitFinish();
let pendingCount = 1;
let rootDir = getRootDirectory(gTestPath);
let testURL = rootDir + "browser_408470_sample.html";
let tab = gBrowser.addTab(testURL);
let tab = getBrowser().addTab(testURL);
let window = tab.ownerDocument.defaultView;
tab.linkedBrowser.addEventListener("load", function(aEvent) {
@ -69,7 +65,7 @@ function test() {
else
ok(correct, "restored stylesheet " + ssTitle);
gBrowser.removeTab(newTab);
getBrowser().removeTab(newTab);
if (--pendingCount == 0)
finish();
}, true);
@ -83,11 +79,11 @@ function test() {
is(newTab.linkedBrowser.markupDocumentViewer.authorStyleDisabled, true,
"disabled all stylesheets");
gBrowser.removeTab(newTab);
getBrowser().removeTab(newTab);
if (--pendingCount == 0)
finish();
}, true);
gBrowser.removeTab(tab);
getBrowser().removeTab(tab);
}, true);
}

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

@ -51,20 +51,14 @@ function test() {
// bug 423132, ported by bug 524371.
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
// test setup
waitForExplicitFinish();
let cs = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager2);
cs.removeAll();
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
// make sure that sessionstore.js can be forced to be created by setting
// the interval pref to 0
gPrefService.setIntPref("browser.sessionstore.interval", 0);
Services.prefs.setIntPref("browser.sessionstore.interval", 0);
const testURL = "http://mochi.test:8888/browser/" +
"suite/common/tests/browser/browser_423132_sample.html";
@ -113,8 +107,8 @@ function test() {
is(cookie.path, cookie2.path, "cookie path successfully restored");
// clean up
if (gPrefService.prefHasUserValue("browser.sessionstore.interval"))
gPrefService.clearUserPref("browser.sessionstore.interval");
if (Services.prefs.prefHasUserValue("browser.sessionstore.interval"))
Services.prefs.clearUserPref("browser.sessionstore.interval");
cs.removeAll();
newWin.close();
is(browserWindowsCount(), 1, "Only one browser window should be open eventually");

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

@ -37,22 +37,16 @@
function test() {
/** Test for Bug 447951 **/
// test setup
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
waitForExplicitFinish();
const baseURL = "http://mochi.test:8888/browser/" +
"suite/common/tests/browser/browser_447951_sample.html#";
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
let tab = getBrowser().addTab();
tab.linkedBrowser.addEventListener("load", function(aEvent) {
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
let tabState = { entries: [] };
let max_entries = gPrefService.getIntPref("browser.sessionhistory.max_entries");
let max_entries = Services.prefs.getIntPref("browser.sessionhistory.max_entries");
for (let i = 0; i < max_entries; i++)
tabState.entries.push({ url: baseURL + i });

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

@ -37,14 +37,6 @@
function test() {
/** Test for Bug 448741 **/
// test setup
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
waitForExplicitFinish();
let uniqueName = "bug 448741";
@ -76,7 +68,7 @@ function test() {
ok(valueWasCleaned, "found and removed the specific tab value");
aSubject.data = JSON.stringify(state);
os.removeObserver(cleaningObserver, aTopic, false);
Services.obs.removeObserver(cleaningObserver, aTopic, false);
}
// make sure that all later observers don't see that value any longer
@ -87,16 +79,16 @@ function test() {
// clean up
getBrowser().removeTab(tab);
os.removeObserver(checkingObserver, aTopic, false);
if (gPrefService.prefHasUserValue("browser.sessionstore.interval"))
gPrefService.clearUserPref("browser.sessionstore.interval");
Services.obs.removeObserver(checkingObserver, aTopic, false);
if (Services.prefs.prefHasUserValue("browser.sessionstore.interval"))
Services.prefs.clearUserPref("browser.sessionstore.interval");
finish();
}
// last added observers are invoked first
os.addObserver(checkingObserver, "sessionstore-state-write", false);
os.addObserver(cleaningObserver, "sessionstore-state-write", false);
Services.obs.addObserver(checkingObserver, "sessionstore-state-write", false);
Services.obs.addObserver(cleaningObserver, "sessionstore-state-write", false);
// trigger an immediate save operation
gPrefService.setIntPref("browser.sessionstore.interval", 0);
Services.prefs.setIntPref("browser.sessionstore.interval", 0);
}

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

@ -45,10 +45,7 @@ function test() {
};
// make sure we do save form data
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
gPrefService.setIntPref("browser.sessionstore.privacy_level", 0);
Services.prefs.setIntPref("browser.sessionstore.privacy_level", 0);
let rootDir = getRootDirectory(gTestPath);
let testURL = rootDir + "browser_454908_sample.html";
@ -74,8 +71,8 @@ function test() {
}
// clean up
if (gPrefService.prefHasUserValue("browser.sessionstore.privacy_level"))
gPrefService.clearUserPref("browser.sessionstore.privacy_level");
if (Services.prefs.prefHasUserValue("browser.sessionstore.privacy_level"))
Services.prefs.clearUserPref("browser.sessionstore.privacy_level");
// undoCloseTab can reuse a single blank tab, so we have to
// make sure not to close the window when closing our last tab
if (gBrowser.tabContainer.childNodes.length == 1)

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

@ -40,13 +40,7 @@ function test() {
waitForExplicitFinish();
// make sure we do save form data
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
gPrefService.setIntPref("browser.sessionstore.privacy_level", 0);
Services.prefs.setIntPref("browser.sessionstore.privacy_level", 0);
let rootDir = getRootDirectory(gTestPath);
let testURL = rootDir + "browser_456342_sample.xhtml";
@ -78,8 +72,8 @@ function test() {
is(countBad, 0, "Didn't save text for ignored field types");
// clean up
if (gPrefService.prefHasUserValue("browser.sessionstore.privacy_level"))
gPrefService.clearUserPref("browser.sessionstore.privacy_level");
if (Services.prefs.prefHasUserValue("browser.sessionstore.privacy_level"))
Services.prefs.clearUserPref("browser.sessionstore.privacy_level");
finish();
}, true);
}

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

@ -49,10 +49,6 @@ function test() {
/** Test for Bug 461634, ported by Bug 524345 **/
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
// test setup
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
waitForExplicitFinish();
const REMEMBER = Date.now(), FORGET = Math.random();
@ -80,8 +76,8 @@ function test() {
// open a window and add the above closed tab list
let newWin = openDialog(location, "", "chrome,all,dialog=no");
newWin.addEventListener("load", function(aEvent) {
gPrefService.setIntPref("browser.sessionstore.max_tabs_undo",
test_state.windows[0]._closedTabs.length);
Services.prefs.setIntPref("browser.sessionstore.max_tabs_undo",
test_state.windows[0]._closedTabs.length);
ss.setWindowState(newWin, JSON.stringify(test_state), true);
let closedTabs = JSON.parse(ss.getClosedTabData(newWin));
@ -116,7 +112,7 @@ function test() {
// clean up
newWin.close();
is(browserWindowsCount(), 1, "Only one browser window should be open eventually");
gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
Services.prefs.clearUserPref("browser.sessionstore.max_tabs_undo");
finish();
}, false);
}

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

@ -37,11 +37,6 @@
function test() {
/** Test for Bug 463206 **/
try {
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
}
catch (ex) { }
waitForExplicitFinish();
let testURL = "http://mochi.test:8888/browser/" +

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

@ -37,7 +37,6 @@
function test() {
/** Test for Bug 465215 **/
let ss = Cc["@mozilla.org/suite/sessionstore;1"].getService(Ci.nsISessionStore);
waitForExplicitFinish();
let uniqueName = "bug 465215";

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

@ -50,8 +50,6 @@ function test() {
/** Test for Bug 465223 **/
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
// test setup
let ss = Cc["@mozilla.org/suite/sessionstore;1"].getService(Ci.nsISessionStore);
waitForExplicitFinish();
let uniqueKey1 = "bug 465223.1";

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

@ -37,11 +37,6 @@
function test() {
/** Test for Bug 466937 **/
try {
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
}
catch (ex) { }
waitForExplicitFinish();
var file = Components.classes["@mozilla.org/file/directory_service;1"]

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

@ -39,8 +39,6 @@ function test() {
waitForExplicitFinish();
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let testURL = "http://mochi.test:8888/browser/" +
"suite/common/tests/browser/browser_476161_sample.html";
let tab = getBrowser().addTab(testURL);
@ -62,8 +60,8 @@ function test() {
"input events were only dispatched for modified text fields");
// clean up
gBrowser.removeTab(tab2);
gBrowser.removeTab(tab);
getBrowser().removeTab(tab2);
getBrowser().removeTab(tab);
finish();
}, true);

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

@ -52,9 +52,6 @@ function test() {
if ("nsILocalFileMac" in Components.interfaces)
return;
// test setup
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
waitForExplicitFinish();
let newWin = openDialog(location, "_blank", "chrome,all,dialog=no");

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

@ -39,12 +39,9 @@ function test() {
waitForExplicitFinish();
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
// Test that starting a new session loads a blank page if Firefox is
// configured to display a blank page at startup (browser.startup.page = 0)
gPrefService.setIntPref("browser.startup.page", 0);
Services.prefs.setIntPref("browser.startup.page", 0);
let tab = getBrowser().addTab("about:sessionrestore");
getBrowser().selectedTab = tab;
let browser = tab.linkedBrowser;
@ -63,8 +60,8 @@ function test() {
// Test that starting a new session loads the homepage (set to http://mochi.test:8888)
// if Firefox is configured to display a homepage at startup (browser.startup.page = 1)
let homepage = "http://mochi.test:8888/";
gPrefService.setCharPref("browser.startup.homepage", homepage);
gPrefService.setIntPref("browser.startup.page", 1);
Services.prefs.setCharPref("browser.startup.homepage", homepage);
Services.prefs.setIntPref("browser.startup.page", 1);
getBrowser().loadURI("about:sessionrestore");
browser.addEventListener("load", function(aEvent) {
browser.removeEventListener("load", arguments.callee, true);
@ -82,9 +79,9 @@ function test() {
getBrowser().removeTab(tab);
// we need this if-statement because if there is no user set value,
// clearUserPref throws a uncatched exception and finish is not called
if (gPrefService.prefHasUserValue("browser.startup.page"))
gPrefService.clearUserPref("browser.startup.page");
gPrefService.clearUserPref("browser.startup.homepage");
if (Services.prefs.prefHasUserValue("browser.startup.page"))
Services.prefs.clearUserPref("browser.startup.page");
Services.prefs.clearUserPref("browser.startup.homepage");
finish();
}, true);
}, true);

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

@ -1,9 +1,6 @@
function test() {
/** Test for Bug 483330 **/
// test setup
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
waitForExplicitFinish();
let tab = getBrowser().addTab();

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

@ -37,9 +37,6 @@
function test() {
/** Test for Bug 485482, ported by Bug 487922 **/
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
waitForExplicitFinish();
let uniqueValue = Math.random();

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

@ -51,23 +51,13 @@ function test() {
/** Test for Bug 490040, ported by Bug 511640 **/
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
let ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
waitForExplicitFinish();
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
function testWithState(aState) {
// Ensure we can store the window if needed.
let curClosedWindowCount = ss.getClosedWindowCount();
gPrefService.setIntPref("browser.sessionstore.max_windows_undo",
curClosedWindowCount + 1);
Services.prefs.setIntPref("browser.sessionstore.max_windows_undo",
curClosedWindowCount + 1);
var origWin;
function windowObserver(aSubject, aTopic, aData) {
@ -101,7 +91,7 @@ function test() {
break;
case "domwindowclosed":
ww.unregisterNotification(windowObserver);
Services.ww.unregisterNotification(windowObserver);
// Use executeSoon to ensure this happens after SS observer.
executeSoon(function () {
is(ss.getClosedWindowCount(),
@ -113,12 +103,12 @@ function test() {
break;
}
}
ww.registerNotification(windowObserver);
ww.openWindow(null,
location,
"_blank",
"chrome,all,dialog=no",
null);
Services.ww.registerNotification(windowObserver);
Services.ww.openWindow(null,
location,
"_blank",
"chrome,all,dialog=no",
null);
}
// Only windows with open tabs are restorable. Windows where a lone tab is
@ -170,8 +160,8 @@ function test() {
testWithState(state);
}
else {
if (gPrefService.prefHasUserValue("browser.sessionstore.max_windows_undo"))
gPrefService.clearUserPref("browser.sessionstore.max_windows_undo");
if (Services.prefs.prefHasUserValue("browser.sessionstore.max_windows_undo"))
Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo");
is(browserWindowsCount(), 1, "Only one browser window should be open eventually");
finish();
}

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

@ -36,9 +36,7 @@
function browserWindowsCount() {
let count = 0;
let e = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator)
.getEnumerator("navigator:browser");
let e = Services.wm.getEnumerator("navigator:browser");
while (e.hasMoreElements()) {
if (!e.getNext().closed)
++count;
@ -48,18 +46,11 @@ function browserWindowsCount() {
function test() {
// make sure we use sessionstore for undoClosetab
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
gPrefService.setIntPref("browser.tabs.max_tabs_undo", 0);
Services.prefs.setIntPref("browser.tabs.max_tabs_undo", 0);
/** Test for Bug 491168, ported by Bug 524369 **/
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
// test setup
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
let ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
waitForExplicitFinish();
const REFERRER1 = "http://example.org/?" + Date.now();
@ -93,13 +84,13 @@ function test() {
is(browserWindowsCount(), 1, "Only one browser window should be open eventually");
// clean up
if (gPrefService.prefHasUserValue("browser.tabs.max_tabs_undo"))
gPrefService.clearUserPref("browser.tabs.max_tabs_undo");
if (Services.prefs.prefHasUserValue("browser.tabs.max_tabs_undo"))
Services.prefs.clearUserPref("browser.tabs.max_tabs_undo");
finish();
}, true);
}, true);
},true);
let referrerURI = ioService.newURI(REFERRER1, null, null);
let referrerURI = Services.io.newURI(REFERRER1, null, null);
browser.loadURI("http://example.org", referrerURI, null);
}

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

@ -36,9 +36,7 @@
function browserWindowsCount() {
let count = 0;
let e = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getEnumerator("navigator:browser");
let e = Services.wm.getEnumerator("navigator:browser");
while (e.hasMoreElements()) {
if (!e.getNext().closed)
++count;
@ -51,9 +49,6 @@ function test() {
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let tab = getBrowser().addTab();
tab.linkedBrowser.stop();
let tabState = JSON.parse(ss.getTabState(tab));

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

@ -94,8 +94,6 @@ function test() {
// Tests session restore functionality of history.pushState and
// history.replaceState(). (Bug 500328)
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
waitForExplicitFinish();
// We open a new blank window, let it load, and then load in

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

@ -38,11 +38,6 @@
function test() {
/** Test for Bug 509315 (Wallpaper) **/
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
waitForExplicitFinish();
let state = {
@ -81,17 +76,17 @@ function test() {
break;
case "domwindowclosed":
ww.unregisterNotification(this);
Services.ww.unregisterNotification(this);
finish();
break;
}
}
}
ww.registerNotification(windowObserver);
ww.openWindow(null,
location,
"_blank",
"chrome,all,dialog=no",
null);
Services.ww.registerNotification(windowObserver);
Services.ww.openWindow(null,
location,
"_blank",
"chrome,all,dialog=no",
null);
}

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

@ -52,9 +52,6 @@ function test() {
waitForExplicitFinish();
requestLongerTimeout(2);
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
// This tests the following use case:
// User opens a new tab which gets focus. The user types something into the
// address bar, then crashes or quits.

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

@ -49,8 +49,6 @@ function test() {
/** Test for Bug 524745, ported by bug 558638 **/
is(browserWindowsCount(), 1, "Only one browser window should be open initially");
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let uniqKey = "bug524745";
let uniqVal = Date.now();

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

@ -38,18 +38,13 @@
function test() {
/** Test for Bug 526613, porting done in Bug 548211 **/
// test setup
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
waitForExplicitFinish();
function browserWindowsCount(expected) {
let count = 0;
let e = wm.getEnumerator("navigator:browser");
let e = Services.wm.getEnumerator("navigator:browser");
while (e.hasMoreElements()) {
if (!e.getNext().closed)
++count;
@ -87,7 +82,7 @@ function test() {
// let the first window be focused (see above)
function pollMostRecentWindow() {
if (wm.getMostRecentWindow("navigator:browser") == window) {
if (Services.wm.getMostRecentWindow("navigator:browser") == window) {
ss.setBrowserState(oldState);
} else {
info("waiting for the current window to become active");
@ -100,11 +95,11 @@ function test() {
else {
browserWindowsCount(1);
ok(!window.closed, "Restoring the old state should have left this window open");
os.removeObserver(observer, "sessionstore-browser-state-restored");
Services.obs.removeObserver(observer, "sessionstore-browser-state-restored");
finish();
}
}
os.addObserver(observer, "sessionstore-browser-state-restored", false);
Services.obs.addObserver(observer, "sessionstore-browser-state-restored", false);
// set browser to test state
ss.setBrowserState(JSON.stringify(testState));

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

@ -1,11 +1,6 @@
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
function browserWindowsCount(expected) {
var count = 0;
var e = wm.getEnumerator("navigator:browser");
var e = Services.wm.getEnumerator("navigator:browser");
while (e.hasMoreElements()) {
if (!e.getNext().closed)
++count;

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

@ -38,9 +38,6 @@
// 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 ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let tab;
function test() {
waitForExplicitFinish();

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

@ -35,10 +35,6 @@
*
* ***** END LICENSE BLOCK ***** */
Components.utils.import("resource://gre/modules/Services.jsm");
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let stateBackup = ss.getBrowserState();
const TAB_STATE_NEEDS_RESTORE = 1;

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

@ -35,9 +35,6 @@
*
* ***** END LICENSE BLOCK ***** */
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let stateBackup = ss.getBrowserState();
function test() {

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

@ -38,10 +38,6 @@
const TAB_STATE_NEEDS_RESTORE = 1;
const TAB_STATE_RESTORING = 2;
Components.utils.import("resource://gre/modules/Services.jsm");
var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let stateBackup = ss.getBrowserState();
function cleanup() {
@ -60,6 +56,7 @@ function test() {
// Set the pref to 0 so we know exactly how many tabs should be restoring at
// any given time. This guarantees that a finishing load won't start another.
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 0);
Services.prefs.setIntPref("browser.tabs.max_tabs_undo", 0);
// We have our own progress listener for this test, which we'll attach before our state is set
let progressListener = {

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

@ -35,10 +35,6 @@
*
* ***** END LICENSE BLOCK ***** */
Components.utils.import("resource://gre/modules/Services.jsm");
const ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
const stateBackup = ss.getBrowserState();
const testState = {
windows: [{
@ -290,6 +286,7 @@ function test_setWindowState() {
function test_setBrowserState() {
// We'll track events per window so we are sure that they are each happening once
// pre window.
let newWindow;
let windowEvents = {};
windowEvents[getOuterWindowID(window)] = { busyEventCount: 0, readyEventCount: 0 };
@ -297,9 +294,10 @@ function test_setBrowserState() {
// the listeners we want here, so do it ourselves.
function windowObserver(aSubject, aTopic, aData) {
if (aTopic == "domwindowopened") {
let newWindow = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
newWindow = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
newWindow.addEventListener("load", function() {
newWindow.removeEventListener("load", arguments.callee, false);
Services.ww.unregisterNotification(windowObserver);
windowEvents[getOuterWindowID(newWindow)] = { busyEventCount: 0, readyEventCount: 0 };
@ -335,6 +333,8 @@ function test_setBrowserState() {
"[test_setBrowserState] checked 2 windows");
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy, false);
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady, false);
newWindow.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy, false);
newWindow.removeEventListener("SSWindowStateReady", onSSWindowStateReady, false);
runNextTest();
});
}
@ -346,7 +346,7 @@ function test_undoCloseWindow() {
function firstWindowObserver(aSubject, aTopic, aData) {
if (aTopic == "domwindowopened") {
newWindow = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
Services.ww.unregisterNotification(windowObserver);
Services.ww.unregisterNotification(firstWindowObserver);
}
}
Services.ww.registerNotification(firstWindowObserver);
@ -360,6 +360,7 @@ function test_undoCloseWindow() {
reopenedWindow.addEventListener("load", function() {
reopenedWindow.removeEventListener("load", arguments.callee, false);
reopenedWindow.getBrowser().tabContainer.addEventListener("SSTabRestored", onSSTabRestored, false);
}, false);
});

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

@ -39,9 +39,6 @@
// Specifically, that session store does not rely on an invalid cache when
// constructing data for a tab which is loading.
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
// The newly created tab which we load a URL into and try closing/undoing.
let tab;

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

@ -1,11 +1,7 @@
// Workaround until Application.prefs can be used safely. (Bug 534647)
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
getBrowser().selectedTab = gBrowser.addTab();
// Navigate to a site with a broken cert
window.addEventListener("DOMContentLoaded", testBrokenCert, true);
@ -24,11 +20,11 @@ function testBrokenCert() {
ok(expertDiv.hasAttribute("collapsed"), "Expert content should be collapsed by default");
// Tweak the expert mode pref
gPrefService.setBoolPref("browser.xul.error_pages.expert_bad_cert", true);
Services.prefs.setBoolPref("browser.xul.error_pages.expert_bad_cert", true);
// Application.prefs.setValue("browser.xul.error_pages.expert_bad_cert", true);
window.addEventListener("DOMContentLoaded", testExpertPref, true);
gBrowser.reload();
getBrowser().reload();
}
function testExpertPref() {
@ -40,9 +36,9 @@ function testExpertPref() {
ok(!technicalDiv.hasAttribute("collapsed"), "Technical content should not be collapsed with the expert mode pref set");
// Clean up
gBrowser.removeCurrentTab();
if (gPrefService.prefHasUserValue("browser.xul.error_pages.expert_bad_cert"))
gPrefService.clearUserPref("browser.xul.error_pages.expert_bad_cert");
getBrowser().removeCurrentTab();
if (Services.prefs.prefHasUserValue("browser.xul.error_pages.expert_bad_cert"))
Services.prefs.clearUserPref("browser.xul.error_pages.expert_bad_cert");
// Application.prefs.get("browser.xul.error_pages.expert_bad_cert").reset();
finish();
}

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

@ -52,8 +52,6 @@ function test() {
// See Bug 518970.
requestLongerTimeout(2);
// test setup
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
waitForExplicitFinish();
function test_basic(callback) {

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

@ -35,9 +35,8 @@
*
* ***** END LICENSE BLOCK ***** */
Components.utils.import("resource://gre/modules/Services.jsm");
const SS_SVC = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
// This assumes that tests will at least have some state/entries
function waitForBrowserState(aState, aSetStateCallback) {
@ -46,6 +45,8 @@ function waitForBrowserState(aState, aSetStateCallback) {
let expectedTabsRestored = 0;
let expectedWindows = aState.windows.length;
let windowsOpen = 1;
let listening = false;
let windowObserving = false;
aState.windows.forEach(function(winState) expectedTabsRestored += winState.tabs.length);
@ -55,6 +56,7 @@ function waitForBrowserState(aState, aSetStateCallback) {
windows.forEach(function(win) {
win.getBrowser().tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, true);
});
listening = false;
info("running " + aSetStateCallback.name);
executeSoon(aSetStateCallback);
}
@ -68,8 +70,10 @@ function waitForBrowserState(aState, aSetStateCallback) {
newWindow.addEventListener("load", function() {
newWindow.removeEventListener("load", arguments.callee, false);
if (++windowsOpen == expectedWindows)
if (++windowsOpen == expectedWindows) {
Services.ww.unregisterNotification(windowObserver);
windowObserving = false;
}
// Track this window so we can remove the progress listener later
windows.push(newWindow);
@ -80,16 +84,70 @@ function waitForBrowserState(aState, aSetStateCallback) {
}
// We only want to register the notification if we expect more than 1 window
if (expectedWindows > 1)
if (expectedWindows > 1) {
registerCleanupFunction(function() {
if (windowObserving) {
Services.ww.unregisterNotification(windowObserver);
}
});
windowObserving = true;
Services.ww.registerNotification(windowObserver);
}
registerCleanupFunction(function() {
if (listening) {
windows.forEach(function(win) {
win.getBrowser().tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, true);
});
}
});
// Add the event listener for this window as well.
listening = true;
getBrowser().tabContainer.addEventListener("SSTabRestored", onSSTabRestored, true);
// Finally, call setBrowserState
SS_SVC.setBrowserState(JSON.stringify(aState));
ss.setBrowserState(JSON.stringify(aState));
}
// waitForSaveState waits for a state write but not necessarily for the state to
// turn dirty.
function waitForSaveState(aSaveStateCallback) {
let observing = false;
let topic = "sessionstore-state-write";
let sessionSaveTimeout = 1000 +
Services.prefs.getIntPref("browser.sessionstore.interval");
function removeObserver() {
if (!observing)
return;
Services.obs.removeObserver(observer, topic, false);
observing = false;
}
let timeout = setTimeout(function () {
removeObserver();
aSaveStateCallback();
}, sessionSaveTimeout);
function observer(aSubject, aTopic, aData) {
removeObserver();
timeout = clearTimeout(timeout);
executeSoon(aSaveStateCallback);
}
registerCleanupFunction(function() {
removeObserver();
if (timeout) {
clearTimeout(timeout);
}
});
observing = true;
Services.obs.addObserver(observer, topic, false);
};
var gUniqueCounter = 0;
function r() {
return Date.now() + Math.random();
return Date.now() + "-" + (++gUniqueCounter);
}