Bug 741070. (Dv1-SM) browser_394759_basic.js: Resync' with fixed Firefox test. r=Neil a=Callek
authorSerge Gautherie <sgautherie.bz@free.fr>
Wed, 02 May 2012 04:28:00 -0400
changeset 11325 9c608274d11632c3979e3e6e4bdbad07460b0515
parent 11324 b26e8f8161e27ec3c7726e39e739dbfb4980ec0a
child 11326 cb351f3a6c597adb82e7c62d9f350dee86627276
push id498
push userCallek@gmail.com
push dateMon, 21 May 2012 05:25:57 +0000
treeherdercomm-beta@cd00c74eef12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil, Callek
bugs741070
Bug 741070. (Dv1-SM) browser_394759_basic.js: Resync' with fixed Firefox test. r=Neil a=Callek
suite/common/tests/browser/browser_394759_basic.js
suite/common/tests/browser/browser_394759_behavior.js
suite/common/tests/browser/head.js
--- a/suite/common/tests/browser/browser_394759_basic.js
+++ b/suite/common/tests/browser/browser_394759_basic.js
@@ -32,61 +32,33 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /** Test for Bug 394759, ported in Bug 510890 **/
 
-function provideWindow(aCallback, aURL, aFeatures) {
-  function callback() {
-    executeSoon(function () {
-      aCallback(win);
-    });
-  }
-
-  let win = openDialog(getBrowserURL(), "", aFeatures || "chrome,all,dialog=no", aURL);
-
-  whenWindowLoaded(win, function () {
-    if (!aURL) {
-      callback();
-      return;
-    }
-
-    win.getBrowser().selectedBrowser.addEventListener("load", function loadListener_pW_wWL() {
-      win.getBrowser().selectedBrowser.removeEventListener("load", loadListener_pW_wWL, true);
-      callback();
-    }, true);
-  });
-}
-
-function whenWindowLoaded(aWin, aCallback) {
-  aWin.addEventListener("load", function loadListener_wWL() {
-    aWin.removeEventListener("load", loadListener_wWL, false);
-    executeSoon(function () {
-      aCallback(aWin);
-    });
-  }, false);
-}
-
 function test() {
   waitForExplicitFinish();
 
   let testURL = "about:config";
   let uniqueKey = "bug 394759";
   let uniqueValue = "unik" + Date.now();
   let uniqueText = "pi != " + Math.random();
 
+  // Be consistent: let the page actually display, as we are "interacting" with it.
+  Services.prefs.setBoolPref("general.warnOnAboutConfig", false);
+
   // make sure that the next closed window will increase getClosedWindowCount
   let max_windows_undo = Services.prefs.getIntPref("browser.sessionstore.max_windows_undo");
   Services.prefs.setIntPref("browser.sessionstore.max_windows_undo", max_windows_undo + 1);
   let closedWindowCount = ss.getClosedWindowCount();
 
-  provideWindow(function (newWin) {
+  provideWindow(function onTestURLLoaded(newWin) {
     newWin.getBrowser().addTab().linkedBrowser.stop();
 
     // mark the window with some unique data to be restored later on
     ss.setWindowValue(newWin, uniqueKey, uniqueValue);
     let textbox = newWin.content.document.getElementById("textbox");
     textbox.value = uniqueText;
 
     newWin.close();
@@ -103,34 +75,36 @@ function test() {
     ok(newWin2 instanceof ChromeWindow,
        "undoCloseWindow actually returned a window");
     is(ss.getClosedWindowCount(), closedWindowCount,
        "The reopened window was removed from Recently Closed Windows");
 
     // SSTabRestored will fire more than once, so we need to make sure we count them
     let restoredTabs = 0;
     let expectedTabs = data.tabs.length;
-    whenWindowLoaded(newWin2, function () {
-      newWin2.getBrowser().tabContainer.addEventListener("SSTabRestored", function sstabrestoredListener(aEvent) {
-        if (++restoredTabs < expectedTabs)
-          return;
+    newWin2.addEventListener("SSTabRestored", function sstabrestoredListener(aEvent) {
+      ++restoredTabs;
+      info("Restored tab " + restoredTabs + "/" + expectedTabs);
+      if (restoredTabs < expectedTabs) {
+        return;
+      }
 
-        newWin2.getBrowser().tabContainer.removeEventListener("SSTabRestored", sstabrestoredListener, true);
-
-        is(newWin2.getBrowser().tabs.length, 2,
-           "The window correctly restored 2 tabs");
-        is(newWin2.getBrowser().currentURI.spec, testURL,
-           "The window correctly restored the URL");
+      newWin2.removeEventListener("SSTabRestored", sstabrestoredListener, true);
 
-        let textbox = newWin2.content.document.getElementById("textbox");
-        is(textbox.value, uniqueText,
-           "The window correctly restored the form");
-        is(ss.getWindowValue(newWin2, uniqueKey), uniqueValue,
-           "The window correctly restored the data associated with it");
+      is(newWin2.getBrowser().tabs.length, 2,
+         "The window correctly restored 2 tabs");
+      is(newWin2.getBrowser().currentURI.spec, testURL,
+         "The window correctly restored the URL");
 
-        // clean up
-        newWin2.close();
-        Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo");
-        finish();
-      }, true);
-    });
+      let textbox = newWin2.content.document.getElementById("textbox");
+      is(textbox.value, uniqueText,
+         "The window correctly restored the form");
+      is(ss.getWindowValue(newWin2, uniqueKey), uniqueValue,
+         "The window correctly restored the data associated with it");
+
+      // clean up
+      newWin2.close();
+      Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo");
+      Services.prefs.clearUserPref("general.warnOnAboutConfig");
+      finish();
+    }, true);
   }, testURL);
 }
--- a/suite/common/tests/browser/browser_394759_behavior.js
+++ b/suite/common/tests/browser/browser_394759_behavior.js
@@ -32,47 +32,16 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /** Test for Bug 394759, ported in Bug 510890 **/
 
-function provideWindow(aCallback, aURL, aFeatures) {
-  function callback() {
-    executeSoon(function () {
-      aCallback(win);
-    });
-  }
-
-  let win = openDialog(getBrowserURL(), "", aFeatures || "chrome,all,dialog=no", aURL);
-
-  whenWindowLoaded(win, function () {
-    if (!aURL) {
-      callback();
-      return;
-    }
-
-    win.getBrowser().selectedBrowser.addEventListener("load", function loadListener_pW_wWL() {
-      win.getBrowser().selectedBrowser.removeEventListener("load", loadListener_pW_wWL, true);
-      callback();
-    }, true);
-  });
-}
-
-function whenWindowLoaded(aWin, aCallback) {
-  aWin.addEventListener("load", function loadListener_wWL() {
-    aWin.removeEventListener("load", loadListener_wWL, false);
-    executeSoon(function () {
-      aCallback(aWin);
-    });
-  }, false);
-}
-
 function test() {
   // This test takes quite some time, and timeouts frequently, so we require
   // more time to run.
   // See Bug 518970.
   requestLongerTimeout(2);
 
   waitForExplicitFinish();
 
@@ -99,17 +68,17 @@ function test() {
     }
 
     // hack to force window to be considered a popup (toolbar=no didn't work)
     let winData = windowsToOpen.shift();
     let settings = "chrome,dialog=no," +
                    (winData.isPopup ? "all=no" : "all");
     let url = "http://example.com/?window=" + windowsToOpen.length;
 
-    provideWindow(function (win) {
+    provideWindow(function onTestURLLoaded(win) {
       win.close();
       openWindowRec(windowsToOpen, expectedResults, recCallback);
     }, url, settings);
   }
 
   let windowsToOpen = [{isPopup: false},
                        {isPopup: false},
                        {isPopup: true},
--- a/suite/common/tests/browser/head.js
+++ b/suite/common/tests/browser/head.js
@@ -33,16 +33,38 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 let ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
                    .getService(Components.interfaces.nsISessionStore);
 
+function provideWindow(aCallback, aURL, aFeatures) {
+  function callbackSoon(aWindow) {
+    executeSoon(function executeCallbackSoon() {
+      aCallback(aWindow);
+    });
+  }
+
+  let win = openDialog(getBrowserURL(), "", aFeatures || "chrome,all,dialog=no", aURL);
+  whenWindowLoaded(win, function onWindowLoaded(aWin) {
+    if (!aURL) {
+      info("Loaded a blank window.");
+      callbackSoon(aWin);
+      return;
+    }
+
+    aWin.gBrowser.selectedBrowser.addEventListener("load", function selectedBrowserLoadListener() {
+      aWin.gBrowser.selectedBrowser.removeEventListener("load", selectedBrowserLoadListener, true);
+      callbackSoon(aWin);
+    }, true);
+  });
+}
+
 // This assumes that tests will at least have some state/entries
 function waitForBrowserState(aState, aSetStateCallback) {
   let windows = [window];
   let tabsRestored = 0;
   let expectedTabsRestored = 0;
   let expectedWindows = aState.windows.length;
   let windowsOpen = 1;
   let listening = false;
@@ -142,12 +164,21 @@ function waitForSaveState(aSaveStateCall
       clearTimeout(timeout);
     }
   });
 
   observing = true;
   Services.obs.addObserver(observer, topic, false);
 };
 
+function whenWindowLoaded(aWindow, aCallback) {
+  aWindow.addEventListener("load", function windowLoadListener() {
+    aWindow.removeEventListener("load", windowLoadListener, false);
+    executeSoon(function executeWhenWindowLoaded() {
+      aCallback(aWindow);
+    });
+  }, false);
+}
+
 var gUniqueCounter = 0;
 function r() {
   return Date.now() + "-" + (++gUniqueCounter);
 }