Bug 532150 - Test main thread fallback for session file. r=Felipe
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Wed, 19 Dec 2012 20:04:53 -0500
changeset 116572 1181ba5295b9f9c24776bba26ac870491751aa4f
parent 116571 c99c3ab37f9562a89227e30c875a83474bfcc242
child 116573 0fca3f2c263b8144bc5d74eb113157f68648510c
push idunknown
push userunknown
push dateunknown
reviewersFelipe
bugs532150
milestone20.0a1
Bug 532150 - Test main thread fallback for session file. r=Felipe
browser/components/sessionstore/test/Makefile.in
browser/components/sessionstore/test/unit/data/sessionstore_valid.js
browser/components/sessionstore/test/unit/head.js
browser/components/sessionstore/test/unit/test_startup_nosession_async.js
browser/components/sessionstore/test/unit/test_startup_nosession_sync.js
browser/components/sessionstore/test/unit/test_startup_session_async.js
browser/components/sessionstore/test/unit/test_startup_session_sync.js
browser/components/sessionstore/test/unit/xpcshell.ini
testing/xpcshell/xpcshell.ini
--- a/browser/components/sessionstore/test/Makefile.in
+++ b/browser/components/sessionstore/test/Makefile.in
@@ -11,16 +11,20 @@ relativesrcdir  = @relativesrcdir@
 include $(DEPTH)/config/autoconf.mk
 
 # browser_506482.js is disabled because of frequent failures (bug 538672)
 # browser_526613.js is disabled because of frequent failures (bug 534489)
 # browser_589246.js is disabled for leaking browser windows (bug 752467)
 # 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 \
 	browser_form_restore_events_sample.html \
 	browser_formdata_format.js \
 	browser_formdata_format_sample.html \
 	browser_248970_b_sample.html \
 	browser_339445.js \
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/data/sessionstore_valid.js
@@ -0,0 +1,3 @@
+{
+  "windows": []
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/head.js
@@ -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);
+};
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/test_startup_nosession_async.js
@@ -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();
+  });
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/test_startup_nosession_sync.js
@@ -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);
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/test_startup_session_async.js
@@ -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();
+  });
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/test_startup_session_sync.js
@@ -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);
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/xpcshell.ini
@@ -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]
\ No newline at end of file
--- a/testing/xpcshell/xpcshell.ini
+++ b/testing/xpcshell/xpcshell.ini
@@ -92,16 +92,17 @@ skip-if = os == "android"
 # Bug 676978: tests hang on Android
 skip-if = os == "android"
 [include:browser/components/dirprovider/tests/unit/xpcshell.ini]
 [include:browser/components/downloads/test/unit/xpcshell.ini]
 [include:browser/components/feeds/test/unit/xpcshell.ini]
 [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]
 [include:extensions/spellcheck/hunspell/tests/unit/xpcshell.ini]
 [include:toolkit/components/search/tests/xpcshell/xpcshell.ini]
 [include:toolkit/components/osfile/tests/xpcshell/xpcshell.ini]
 [include:toolkit/mozapps/shared/test/unit/xpcshell.ini]
 [include:services/crypto/component/tests/unit/xpcshell.ini]