Bug 694378 - session restore fails when selectedWindow > number of windows [r=dietrich]
authorPaul O’Shannessy <paul@oshannessy.com>
Tue, 25 Oct 2011 10:19:29 -0700
changeset 79187 5d7c2550a61e9e4c031dde19624fff8235e73db0
parent 79186 78c921e2b56bf559a9efa5cf3ce4c6579da2dedf
child 79188 7ba9a146e1e8ac18b4711393db1dd5040f623486
push id251
push userposhannessy@mozilla.com
push dateTue, 25 Oct 2011 21:54:29 +0000
treeherderfx-team@5d7c2550a61e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdietrich
bugs694378
milestone10.0a1
Bug 694378 - session restore fails when selectedWindow > number of windows [r=dietrich]
browser/components/sessionstore/src/nsSessionStore.js
browser/components/sessionstore/test/browser/Makefile.in
browser/components/sessionstore/test/browser/browser_694378.js
--- a/browser/components/sessionstore/src/nsSessionStore.js
+++ b/browser/components/sessionstore/src/nsSessionStore.js
@@ -2572,17 +2572,17 @@ SessionStoreService.prototype = {
     // We're not returning from this before we end up calling restoreHistoryPrecursor
     // for this window, so make sure we send the SSWindowStateBusy event.
     this._setWindowStateBusy(aWindow);
 
     if (root._closedWindows)
       this._closedWindows = root._closedWindows;
 
     var winData;
-    if (!root.selectedWindow) {
+    if (!root.selectedWindow || root.selectedWindow > root.windows.length) {
       root.selectedWindow = 0;
     } else {
       // put the selected window at the beginning of the array to ensure that
       // it gets restored first
       root.windows.unshift(root.windows.splice(root.selectedWindow - 1, 1)[0]);
     }
     // open new windows for all further window entries of a multi-window session
     // (unless they don't contain any tab data)
--- a/browser/components/sessionstore/test/browser/Makefile.in
+++ b/browser/components/sessionstore/test/browser/Makefile.in
@@ -149,16 +149,17 @@ include $(topsrcdir)/config/rules.mk
 	browser_628270.js \
 	browser_635418.js \
 	browser_636279.js \
 	browser_645428.js \
 	browser_659591.js \
 	browser_662812.js \
 	browser_665702-state_session.js \
 	browser_682507.js \
+	browser_694378.js \
 	$(NULL)
 
 ifneq ($(OS_ARCH),Darwin)
 _BROWSER_TEST_FILES += \
 	browser_597071.js \
 	browser_625016.js \
 	$(NULL)
 endif
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser/browser_694378.js
@@ -0,0 +1,35 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test Summary:
+// 1.  call ss.setWindowState with a broken state
+// 1a. ensure that it doesn't throw.
+
+function test() {
+  waitForExplicitFinish();
+
+  let brokenState = {
+    windows: [
+      { tabs: [{ entries: [{ url: "about:mozilla" }] }] }
+      //{ tabs: [{ entries: [{ url: "about:robots" }] }] },
+    ],
+    selectedWindow: 2
+  };
+  let brokenStateString = JSON.stringify(brokenState);
+
+  let gotError = false;
+  try {
+    ss.setWindowState(window, brokenStateString, true);
+  }
+  catch (ex) {
+    gotError = true;
+    info(ex);
+  }
+
+  ok(!gotError, "ss.setWindowState did not throw an error");
+
+  // Make sure that we reset the state. Use a full state just in case things get crazy.
+  let blankState = { windows: [{ tabs: [{ entries: [{ url: "about:blank" }] }]}]};
+  waitForBrowserState(blankState, finish);
+}
+