Bug 1001167 - Don't let invalid sessionstore.js files break sessionstore. r=smacleod, a=lsblakk
authorTim Taubert <ttaubert@mozilla.com>
Fri, 25 Apr 2014 14:34:03 +0200
changeset 258646 67b273f17641
parent 258645 b14554c010ad
child 258647 2d371f067965
push id4700
push userryanvm@gmail.com
push date2015-04-21 23:53 +0000
treeherdermozilla-beta@d27c9211ebb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmacleod, lsblakk
bugs1001167
milestone29.0
Bug 1001167 - Don't let invalid sessionstore.js files break sessionstore. r=smacleod, a=lsblakk
browser/components/sessionstore/src/nsSessionStartup.js
browser/components/sessionstore/test/unit/data/sessionstore_invalid.js
browser/components/sessionstore/test/unit/test_startup_invalid_session.js
browser/components/sessionstore/test/unit/xpcshell.ini
--- a/browser/components/sessionstore/src/nsSessionStartup.js
+++ b/browser/components/sessionstore/src/nsSessionStartup.js
@@ -119,25 +119,26 @@ SessionStartup.prototype = {
     // No valid session found.
     if (!stateString) {
       this._sessionType = Ci.nsISessionStartup.NO_SESSION;
       Services.obs.notifyObservers(null, "sessionstore-state-finalized", "");
       gOnceInitializedDeferred.resolve();
       return;
     }
 
-    this._initialState =  this._parseStateString(stateString);
+    this._initialState = this._parseStateString(stateString);
 
     let shouldResumeSessionOnce = Services.prefs.getBoolPref("browser.sessionstore.resume_session_once");
     let shouldResumeSession = shouldResumeSessionOnce ||
           Services.prefs.getIntPref("browser.startup.page") == BROWSER_STARTUP_RESUME_SESSION;
 
     // If this is a normal restore then throw away any previous session
-    if (!shouldResumeSessionOnce)
+    if (!shouldResumeSessionOnce && this._initialState) {
       delete this._initialState.lastSessionState;
+    }
 
     let resumeFromCrash = Services.prefs.getBoolPref("browser.sessionstore.resume_from_crash");
 
     CrashMonitor.previousCheckpoints.then(checkpoints => {
       if (checkpoints) {
         // If the previous session finished writing the final state, we'll
         // assume there was no crash.
         this._previousSessionCrashed = !checkpoints["sessionstore-final-state-write-complete"];
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/data/sessionstore_invalid.js
@@ -0,0 +1,3 @@
+{
+  "windows": // invalid json
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/test_startup_invalid_session.js
@@ -0,0 +1,21 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test() {
+  let profd = do_get_profile();
+
+  let sourceSession = do_get_file("data/sessionstore_invalid.js");
+  sourceSession.copyTo(profd, "sessionstore.js");
+
+  let sourceCheckpoints = do_get_file("data/sessionCheckpoints_all.json");
+  sourceCheckpoints.copyTo(profd, "sessionCheckpoints.json");
+
+  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();
+  });
+}
--- a/browser/components/sessionstore/test/unit/xpcshell.ini
+++ b/browser/components/sessionstore/test/unit/xpcshell.ini
@@ -1,12 +1,14 @@
 [DEFAULT]
 head = head.js
 tail =
 firefox-appdir = browser
 support-files =
   data/sessionCheckpoints_all.json
+  data/sessionstore_invalid.js
   data/sessionstore_valid.js
 
 [test_backup.js]
 [test_backup_once.js]
 [test_startup_nosession_async.js]
 [test_startup_session_async.js]
+[test_startup_invalid_session.js]