Bug 1000198 - Fix sessionstore tests that remove the original tab. r=smacleod, a=test-only
authorTim Taubert <ttaubert@mozilla.com>
Fri, 25 Apr 2014 18:01:46 +0200
changeset 192185 e078f53fd234
parent 192184 0678e5469636
child 192186 d20b23d033e4
push id3515
push userryanvm@gmail.com
push date2014-05-01 17:32 +0000
treeherdermozilla-beta@66518d59cdbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmacleod, test-only
bugs1000198
milestone30.0
Bug 1000198 - Fix sessionstore tests that remove the original tab. r=smacleod, a=test-only
browser/components/sessionstore/test/browser_522545.js
browser/components/sessionstore/test/browser_600545.js
browser/components/sessionstore/test/browser_601955.js
browser/components/sessionstore/test/head.js
--- a/browser/components/sessionstore/test/browser_522545.js
+++ b/browser/components/sessionstore/test/browser_522545.js
@@ -241,26 +241,25 @@ function test() {
     });
   }
 
 
   let tests = [test_newTabFocused, test_newTabNotFocused,
                test_existingSHEnd_noClear, test_existingSHMiddle_noClear,
                test_getBrowserState_lotsOfTabsOpening,
                test_getBrowserState_userTypedValue, test_userTypedClearLoadURI];
-  let originalState = ss.getBrowserState();
+  let originalState = JSON.parse(ss.getBrowserState());
   let state = {
     windows: [{
       tabs: [{ entries: [{ url: "about:blank" }] }]
     }]
   };
   function runNextTest() {
     if (tests.length) {
       waitForBrowserState(state, tests.shift());
     } else {
-      ss.setBrowserState(originalState);
-      executeSoon(finish);
+      waitForBrowserState(originalState, finish);
     }
   }
 
   // Run the tests!
   runNextTest();
 }
--- a/browser/components/sessionstore/test/browser_600545.js
+++ b/browser/components/sessionstore/test/browser_600545.js
@@ -1,13 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-let stateBackup = ss.getBrowserState();
+let stateBackup = JSON.parse(ss.getBrowserState());
 
 function test() {
   /** Test for Bug 600545 **/
   waitForExplicitFinish();
   testBug600545();
 }
 
 function testBug600545() {
@@ -66,18 +66,17 @@ function done() {
   // use waitForFocus() because apparently it's buggy. See bug 599253.
   let windowsEnum = Services.wm.getEnumerator("navigator:browser");
   while (windowsEnum.hasMoreElements()) {
     let currentWindow = windowsEnum.getNext();
     if (currentWindow != window)
       currentWindow.close();
   }
 
-  ss.setBrowserState(stateBackup);
-  executeSoon(finish);
+  waitForBrowserState(stateBackup, finish);
 }
 
 // Count up the number of tabs in the state data
 function getStateTabCount(aState) {
   let tabCount = 0;
   for (let i in aState.windows)
     tabCount += aState.windows[i].tabs.length;
   return tabCount;
--- a/browser/components/sessionstore/test/browser_601955.js
+++ b/browser/components/sessionstore/test/browser_601955.js
@@ -41,14 +41,14 @@ function testBug601955_3() {
   let state = JSON.parse(ss.getBrowserState());
   ok(!state.windows[0].tabs[0].pinned, "first tab should not be pinned");
   ok(!state.windows[0].tabs[1].pinned, "second tab should not be pinned");
 
   done();
 }
 
 function done() {
-  gBrowser.removeTab(window.gBrowser.tabs[0]);
+  gBrowser.removeTab(window.gBrowser.tabs[1]);
 
   Services.prefs.clearUserPref("browser.sessionstore.interval");
 
   executeSoon(finish);
 }
--- a/browser/components/sessionstore/test/head.js
+++ b/browser/components/sessionstore/test/head.js
@@ -159,16 +159,19 @@ function waitForBrowserState(aState, aSe
         win.gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, true);
       });
     }
   });
   // Add the event listener for this window as well.
   listening = true;
   gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, true);
 
+  // Ensure setBrowserState() doesn't remove the initial tab.
+  gBrowser.selectedTab = gBrowser.tabs[0];
+
   // Finally, call setBrowserState
   ss.setBrowserState(JSON.stringify(aState));
 }
 
 // Doesn't assume that the tab needs to be closed in a cleanup function.
 // If that's the case, the test author should handle that in the test.
 function waitForTabState(aTab, aState, aCallback) {
   let listening = true;
@@ -522,16 +525,17 @@ let TestRunner = {
     }
   },
 
   /**
    * Finishes all tests and cleans up.
    */
   finish: function () {
     closeAllButPrimaryWindow();
+    gBrowser.selectedTab = gBrowser.tabs[0];
     waitForBrowserState(this.backupState, finish);
   }
 };
 
 function next() {
   TestRunner.next();
 }