Bug 947570 - Rewrite browser_597071.js to fix intermittent timeouts. r=smacleod, a=test-only
☠☠ backed out by 3b49d533319a ☠ ☠
authorTim Taubert <tim@timtaubert.de>
Thu, 12 Dec 2013 12:44:33 +0100
changeset 175242 950c5b2c5bcd81b663511526c49e8dc5eb7aac5b
parent 175241 dfae9c83bfbc57b28747d89f74677d820e3ca27d
child 175243 f9f15a1dceaea6ee221b6918652b458d8eca4553
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmacleod, test-only
bugs947570
milestone28.0a2
Bug 947570 - Rewrite browser_597071.js to fix intermittent timeouts. r=smacleod, a=test-only
browser/components/sessionstore/test/browser_597071.js
browser/components/sessionstore/test/head.js
--- a/browser/components/sessionstore/test/browser_597071.js
+++ b/browser/components/sessionstore/test/browser_597071.js
@@ -1,53 +1,38 @@
-/* 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/. */
-
-function test() {
-  /** Test for Bug 597071 **/
-
-  waitForExplicitFinish();
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-  // set the pref to 1 greater than it currently is so we have room for an extra
-  // closed window
-  let closedWindowCount = ss.getClosedWindowCount();
-  Services.prefs.setIntPref("browser.sessionstore.max_windows_undo",
-                            closedWindowCount + 1);
+/**
+ * Bug 597071 - Closed windows should only be resurrected when there is a single
+ * popup window
+ */
+add_task(function test_close_last_nonpopup_window() {
+  // Purge the list of closed windows.
+  while (ss.getClosedWindowCount()) {
+    ss.forgetClosedWindow(0);
+  }
 
-  let currentState = ss.getBrowserState();
-  let popupState = { windows:[
-    { tabs:[ {entries:[] }], isPopup: true, hidden: "toolbar" }
-  ] };
+  let oldState = ss.getWindowState(window);
 
-  // set this window to be a popup.
+  let popupState = {windows: [
+    {tabs: [{entries: []}], isPopup: true, hidden: "toolbar"}
+  ]};
+
+  // Set this window to be a popup.
   ss.setWindowState(window, JSON.stringify(popupState), true);
 
-  // open a new non-popup window
-  let newWin = openDialog(location, "", "chrome,all,dialog=no", "http://example.com");
-  newWin.addEventListener("load", function(aEvent) {
-    newWin.removeEventListener("load", arguments.callee, false);
-
-    newWin.gBrowser.addEventListener("load", function(aEvent) {
-      newWin.gBrowser.removeEventListener("load", arguments.callee, true);
-
-      newWin.gBrowser.addTab().linkedBrowser.stop();
-
-      // make sure sessionstore sees this window
-      let state = JSON.parse(ss.getBrowserState());
-      is(state.windows.length, 2, "sessionstore knows about this window");
+  // Open a new window with a tab.
+  let win = yield promiseNewWindowLoaded({private: false});
+  let tab = win.gBrowser.addTab("http://example.com/");
+  yield promiseBrowserLoaded(tab.linkedBrowser);
 
-      newWin.close();
-      newWin.addEventListener("unload", function(aEvent) {
-        newWin.removeEventListener("unload", arguments.callee, false);
-
-        is(ss.getClosedWindowCount(), closedWindowCount + 1,
-           "increased closed window count");
+  // Make sure sessionstore sees this window.
+  let state = JSON.parse(ss.getBrowserState());
+  is(state.windows.length, 2, "sessionstore knows about this window");
 
-        Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo");
-        ss.setBrowserState(currentState);
-        executeSoon(finish);
+  // Closed the window and check the closed window count.
+  yield promiseWindowClosed(win);
+  is(ss.getClosedWindowCount(), 1, "correct closed window count");
 
-      }, false);
-    }, true);
-  }, false);
-}
-
+  // Cleanup.
+  ss.setWindowState(window, oldState, true);
+});
--- a/browser/components/sessionstore/test/head.js
+++ b/browser/components/sessionstore/test/head.js
@@ -407,18 +407,41 @@ function closeAllButPrimaryWindow() {
  * further if parts of the window's initialization process take more time than
  * expected (e.g. reading a big session state from disk).
  */
 function whenNewWindowLoaded(aOptions, aCallback) {
   let win = OpenBrowserWindow(aOptions);
   whenDelayedStartupFinished(win, () => aCallback(win));
   return win;
 }
+function promiseNewWindowLoaded(aOptions) {
+  let deferred = Promise.defer();
+  whenNewWindowLoaded(aOptions, deferred.resolve);
+  return deferred.promise;
+}
 
 /**
+ * Chrome windows aren't closed synchronously. Provide a helper method to close
+ * a window and wait until we received the "domwindowclosed" notification for it.
+ */
+function promiseWindowClosed(win) {
+  let deferred = Promise.defer();
+
+  Services.obs.addObserver(function obs(subject, topic) {
+    if (subject == win) {
+      Services.obs.removeObserver(obs, topic);
+      deferred.resolve();
+    }
+  }, "domwindowclosed", false);
+
+  win.close();
+  return deferred.promise;
+}
+
++/**
  * This waits for the browser-delayed-startup-finished notification of a given
  * window. It indicates that the windows has loaded completely and is ready to
  * be used for testing.
  */
 function whenDelayedStartupFinished(aWindow, aCallback) {
   Services.obs.addObserver(function observer(aSubject, aTopic) {
     if (aWindow == aSubject) {
       Services.obs.removeObserver(observer, aTopic);