Bug 532150 - Test main thread fallback for session file. r=Felipe

This commit is contained in:
David Rajchenbach-Teller 2012-12-19 20:04:53 -05:00
parent 07967936e4
commit bf9e5fa6d4
9 changed files with 119 additions and 0 deletions

View File

@ -16,6 +16,10 @@ include $(DEPTH)/config/autoconf.mk
# browser_580512.js is disabled for leaking browser windows (bug 752467)
# browser_586068-reload.js is disabled due to generally being broken (bug 809123, 797263)
XPCSHELL_TESTS = \
unit \
$(NULL)
MOCHITEST_BROWSER_FILES = \
head.js \
browser_form_restore_events.js \

View File

@ -0,0 +1,3 @@
{
"windows": []
}

View File

@ -0,0 +1,26 @@
let Cu = Components.utils;
let Cc = Components.classes;
let Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/Services.jsm");
// Call a function once initialization of SessionStartup is complete
let afterSessionStartupInitialization =
function afterSessionStartupInitialization(cb) {
do_print("Waiting for session startup initialization");
let observer = function() {
try {
do_print("Session startup initialization observed");
Services.obs.removeObserver(observer, "sessionstore-state-finalized");
cb();
} catch (ex) {
do_throw(ex);
}
};
let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
getService(Ci.nsIObserver);
Services.obs.addObserver(startup, "final-ui-startup", false);
Services.obs.addObserver(startup, "quit-application", false);
Services.obs.notifyObservers(null, "final-ui-startup", "");
Services.obs.addObserver(observer, "sessionstore-state-finalized", false);
};

View File

@ -0,0 +1,22 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test nsISessionStartup.sessionType in the following scenario:
// - no sessionstore.js;
// - the session store has been loaded, so no need to go
// through the synchronous fallback
function run_test() {
do_get_profile();
// Initialize the profile (the session startup uses it)
do_test_pending();
let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
getService(Ci.nsISessionStartup);
afterSessionStartupInitialization(function cb() {
do_check_eq(startup.sessionType, Ci.nsISessionStartup.NO_SESSION);
do_test_finished();
});
}

View File

@ -0,0 +1,15 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test nsISessionStartup.sessionType in the following scenario:
// - no sessionstore.js;
// - the session store has not been loaded yet, so we have to trigger
// synchronous fallback
function run_test() {
do_get_profile();
let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
getService(Ci.nsISessionStartup);
do_check_eq(startup.sessionType, Ci.nsISessionStartup.NO_SESSION);
}

View File

@ -0,0 +1,23 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test nsISessionStartup.sessionType in the following scenario:
// - valid sessionstore.js;
// - the session store has been loaded, so no need to go
// through the synchronous fallback
function run_test() {
let profd = do_get_profile();
let source = do_get_file("data/sessionstore_valid.js");
source.copyTo(profd, "sessionstore.js");
do_test_pending();
let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
getService(Ci.nsISessionStartup);
afterSessionStartupInitialization(function cb() {
do_check_eq(startup.sessionType, Ci.nsISessionStartup.DEFER_SESSION);
do_test_finished();
});
}

View File

@ -0,0 +1,17 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test nsISessionStartup.sessionType in the following scenario:
// - valid sessionstore.js;
// - the session store has not been loaded yet, so we have to trigger
// synchronous fallback
function run_test() {
let profd = do_get_profile();
let source = do_get_file("data/sessionstore_valid.js");
source.copyTo(profd, "sessionstore.js");
let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
getService(Ci.nsISessionStartup);
do_check_eq(startup.sessionType, Ci.nsISessionStartup.DEFER_SESSION);
}

View File

@ -0,0 +1,8 @@
[DEFAULT]
head = head.js
tail =
[test_startup_nosession_sync.js]
[test_startup_nosession_async.js]
[test_startup_session_sync.js]
[test_startup_session_async.js]

View File

@ -97,6 +97,7 @@ skip-if = os == "android"
[include:browser/components/migration/tests/unit/xpcshell.ini]
[include:browser/components/places/tests/unit/xpcshell.ini]
[include:browser/components/privatebrowsing/test/unit/xpcshell.ini]
[include:browser/components/sessionstore/test/unit/xpcshell.ini]
[include:browser/components/shell/test/unit/xpcshell.ini]
[include:browser/devtools/shared/test/unit/xpcshell.ini]
[include:browser/modules/test/unit/xpcshell.ini]