Backed out changeset 7b156069de68 (bug 936065) for causing bug 950320 r=smacleod a=lsblakk
authorTim Taubert <ttaubert@mozilla.com>
Sat, 14 Dec 2013 09:38:07 +0100
changeset 174485 6c6fd43f57a44b9ace0dfe5d062755f180dee660
parent 174484 dbdd87455003d8dc9a11d24fc8ad46b470daf39e
child 174486 39533c25c43cae0e7af1afa9868fb16730e16ad5
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmacleod, lsblakk
bugs936065, 950320
milestone28.0a2
backs out7b156069de688cd3d054db9c89e4b22a4ef4bc75
Backed out changeset 7b156069de68 (bug 936065) for causing bug 950320 r=smacleod a=lsblakk
browser/components/sessionstore/src/SessionStore.jsm
browser/components/sessionstore/test/browser_491577.js
--- a/browser/components/sessionstore/src/SessionStore.jsm
+++ b/browser/components/sessionstore/src/SessionStore.jsm
@@ -1495,44 +1495,22 @@ let SessionStoreInternal = {
     if (DyingWindowCache.has(aWindow)) {
       let data = DyingWindowCache.get(aWindow);
       return this._toJSONString({ windows: [data] });
     }
 
     throw Components.Exception("Window is not tracked", Cr.NS_ERROR_INVALID_ARG);
   },
 
-  /**
-   * Restores the given state |aState| for a given window |aWindow|.
-   *
-   * @param aWindow (xul window)
-   *        The window that the given state will be restored to.
-   * @param aState (string)
-   *        The state that will be applied to the given window.
-   * @param aOverwrite (bool)
-   *        When true, existing tabs in the given window will be re-used or
-   *        removed. When false, only new tabs will be added, no existing ones
-   8        will be removed or overwritten.
-   */
   setWindowState: function ssi_setWindowState(aWindow, aState, aOverwrite) {
     if (!aWindow.__SSi) {
       throw Components.Exception("Window is not tracked", Cr.NS_ERROR_INVALID_ARG);
     }
 
-    let winState = JSON.parse(aState);
-    if (!winState) {
-      throw Components.Exception("Invalid state string: not JSON", Cr.NS_ERROR_INVALID_ARG);
-    }
-
-    if (!winState.windows || !winState.windows[0]) {
-      throw Components.Exception("Invalid window state passed", Cr.NS_ERROR_INVALID_ARG);
-    }
-
-    let state = {windows: [winState.windows[0]]};
-    this.restoreWindow(aWindow, state, {overwriteTabs: aOverwrite});
+    this.restoreWindow(aWindow, aState, {overwriteTabs: aOverwrite});
   },
 
   getTabState: function ssi_getTabState(aTab) {
     if (!aTab.ownerDocument) {
       throw Components.Exception("Invalid tab object: no ownerDocument", Cr.NS_ERROR_INVALID_ARG);
     }
     if (!aTab.ownerDocument.defaultView.__SSi) {
       throw Components.Exception("Default view is not tracked", Cr.NS_ERROR_INVALID_ARG);
@@ -2260,17 +2238,17 @@ let SessionStoreInternal = {
 
   /* ........ Restoring Functionality .............. */
 
   /**
    * restore features to a single window
    * @param aWindow
    *        Window reference
    * @param aState
-   *        JS object
+   *        JS object or its eval'able source
    * @param aOptions
    *        {overwriteTabs: true} to overwrite existing tabs w/ new ones
    *        {isFollowUp: true} if this is not the restoration of the 1st window
    *        {firstWindow: true} if this is the first non-private window we're
    *                            restoring in this session, that might open an
    *                            external link as well
    */
   restoreWindow: function ssi_restoreWindow(aWindow, aState, aOptions = {}) {
@@ -2280,20 +2258,27 @@ let SessionStoreInternal = {
 
     if (isFollowUp) {
       this.windowToFocus = aWindow;
     }
     // initialize window if necessary
     if (aWindow && (!aWindow.__SSi || !this._windows[aWindow.__SSi]))
       this.onLoad(aWindow);
 
-    var root = aState;
-    if (!root.windows[0]) {
+    try {
+      var root = typeof aState == "string" ? JSON.parse(aState) : aState;
+      if (!root.windows[0]) {
+        this._sendRestoreCompletedNotifications();
+        return; // nothing to restore
+      }
+    }
+    catch (ex) { // invalid state object - don't restore anything
+      debug(ex);
       this._sendRestoreCompletedNotifications();
-      return; // nothing to restore
+      return;
     }
 
     TelemetryStopwatch.start("FX_SESSION_RESTORE_RESTORE_WINDOW_MS");
 
     // We're not returning from this before we end up calling restoreTabs
     // for this window, so make sure we send the SSWindowStateBusy event.
     this._setWindowStateBusy(aWindow);
 
--- a/browser/components/sessionstore/test/browser_491577.js
+++ b/browser/components/sessionstore/test/browser_491577.js
@@ -73,43 +73,49 @@ function test() {
       aFunction();
       return false;
     }
     catch (ex) {
       return ex.name == "NS_ERROR_ILLEGAL_VALUE";
     }
   }
 
-  gPrefService.setIntPref("browser.sessionstore.max_windows_undo",
-                          test_state._closedWindows.length);
-  ss.setBrowserState(JSON.stringify(test_state), true);
+  // open a window and add the above closed window list
+  let newWin = openDialog(location, "_blank", "chrome,all,dialog=no");
+  newWin.addEventListener("load", function(aEvent) {
+    this.removeEventListener("load", arguments.callee, false);
+    gPrefService.setIntPref("browser.sessionstore.max_windows_undo",
+                            test_state._closedWindows.length);
+    ss.setWindowState(newWin, JSON.stringify(test_state), true);
 
-  let closedWindows = JSON.parse(ss.getClosedWindowData());
-  is(closedWindows.length, test_state._closedWindows.length,
-     "Closed window list has the expected length");
-  is(countByTitle(closedWindows, FORGET),
-     test_state._closedWindows.length - remember_count,
-     "The correct amount of windows are to be forgotten");
-  is(countByTitle(closedWindows, REMEMBER), remember_count,
-     "Everything is set up.");
+    let closedWindows = JSON.parse(ss.getClosedWindowData());
+    is(closedWindows.length, test_state._closedWindows.length,
+       "Closed window list has the expected length");
+    is(countByTitle(closedWindows, FORGET),
+       test_state._closedWindows.length - remember_count,
+       "The correct amount of windows are to be forgotten");
+    is(countByTitle(closedWindows, REMEMBER), remember_count,
+       "Everything is set up.");
 
-  // all of the following calls with illegal arguments should throw NS_ERROR_ILLEGAL_VALUE
-  ok(testForError(function() ss.forgetClosedWindow(-1)),
-     "Invalid window for forgetClosedWindow throws");
-  ok(testForError(function() ss.forgetClosedWindow(test_state._closedWindows.length + 1)),
-     "Invalid window for forgetClosedWindow throws");
+    // all of the following calls with illegal arguments should throw NS_ERROR_ILLEGAL_VALUE
+    ok(testForError(function() ss.forgetClosedWindow(-1)),
+       "Invalid window for forgetClosedWindow throws");
+    ok(testForError(function() ss.forgetClosedWindow(test_state._closedWindows.length + 1)),
+       "Invalid window for forgetClosedWindow throws");
 
-  // Remove third window, then first window
-  ss.forgetClosedWindow(2);
-  ss.forgetClosedWindow(null);
+    // Remove third window, then first window
+    ss.forgetClosedWindow(2);
+    ss.forgetClosedWindow(null);
 
-  closedWindows = JSON.parse(ss.getClosedWindowData());
-  is(closedWindows.length, remember_count,
-     "The correct amount of windows were removed");
-  is(countByTitle(closedWindows, FORGET), 0,
-     "All windows specifically forgotten were indeed removed");
-  is(countByTitle(closedWindows, REMEMBER), remember_count,
-     "... and windows not specifically forgetten weren't.");
+    closedWindows = JSON.parse(ss.getClosedWindowData());
+    is(closedWindows.length, remember_count,
+       "The correct amount of windows were removed");
+    is(countByTitle(closedWindows, FORGET), 0,
+       "All windows specifically forgotten were indeed removed");
+    is(countByTitle(closedWindows, REMEMBER), remember_count,
+       "... and windows not specifically forgetten weren't.");
 
-  // clean up
-  gPrefService.clearUserPref("browser.sessionstore.max_windows_undo");
-  finish();
+    // clean up
+    newWin.close();
+    gPrefService.clearUserPref("browser.sessionstore.max_windows_undo");
+    finish();
+  }, false);
 }