Skip to content

Commit

Permalink
Bug 532150 - Test main thread fallback for session file. r=Felipe
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rajchenbach-Teller committed Dec 20, 2012
1 parent f3d3046 commit cb312ca
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 0 deletions.
4 changes: 4 additions & 0 deletions browser/components/sessionstore/test/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"windows": []
}
26 changes: 26 additions & 0 deletions browser/components/sessionstore/test/unit/head.js
Original file line number Diff line number Diff line change
@@ -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);
};
Original file line number Diff line number Diff line change
@@ -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();
});
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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();
});
}
Original file line number Diff line number Diff line change
@@ -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);
}
8 changes: 8 additions & 0 deletions browser/components/sessionstore/test/unit/xpcshell.ini
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions testing/xpcshell/xpcshell.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit cb312ca

Please sign in to comment.