Bug 726521. (Dv1) Port bug 658738 comment 102 (split browser_394759.js into three tests). r=Neil a=Callek
authorSerge Gautherie <sgautherie.bz@free.fr>
Fri, 30 Mar 2012 16:39:46 +0200
changeset 11248 2e0666f06d6b08f302c74e15f2bb9b9a8796b138
parent 11247 4f865952d02beb9d993bf77fd9304af9a5c4b490
child 11249 a86f9d4fc2a7cdc8ebc5736552745d4799bf290a
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil, Callek
bugs726521, 658738
Bug 726521. (Dv1) Port bug 658738 comment 102 (split browser_394759.js into three tests). r=Neil a=Callek
suite/common/tests/browser/Makefile.in
suite/common/tests/browser/browser_394759.js
suite/common/tests/browser/browser_394759_basic.js
suite/common/tests/browser/browser_394759_behavior.js
--- a/suite/common/tests/browser/Makefile.in
+++ b/suite/common/tests/browser/Makefile.in
@@ -52,17 +52,18 @@ include $(topsrcdir)/config/rules.mk
 	browser_339445_sample.html \
 	browser_345898.js \
 	browser_346337.js \
 	browser_346337_sample.html \
 	browser_350525.js \
 	browser_354894.js \
 	browser_367052.js \
 	browser_393716.js \
-	browser_394759.js \
+	browser_394759_basic.js \
+	browser_394759_behavior.js \
 	browser_408470.js \
 	browser_408470_sample.html \
 	browser_423132.js \
 	browser_423132_sample.html \
 	browser_bug431826.js \
 	browser_447951.js \
 	browser_447951_sample.html \
 	browser_448741.js \
rename from suite/common/tests/browser/browser_394759.js
rename to suite/common/tests/browser/browser_394759_basic.js
--- a/suite/common/tests/browser/browser_394759.js
+++ b/suite/common/tests/browser/browser_394759_basic.js
@@ -30,181 +30,107 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * 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 ***** */
 
-function browserWindowsCount() {
-  let count = 0;
-  let e = Services.wm.getEnumerator("navigator:browser");
-  while (e.hasMoreElements()) {
-    if (!e.getNext().closed)
-      ++count;
+/** Test for Bug 394759, ported in Bug 510890 **/
+
+function provideWindow(aCallback, aURL, aFeatures) {
+  function callback() {
+    executeSoon(function () {
+      aCallback(win);
+    });
   }
-  return count;
+
+  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() {
-  /** Test for Bug 394759, ported in Bug 510890 **/
-  // This test takes quite some time, and timeouts frequently, so we require
-  // more time to run.
-  // See Bug 518970.
-  requestLongerTimeout(2);
-
   waitForExplicitFinish();
 
-  function test_basic(callback) {
-    let testURL = "about:config";
-    let uniqueKey = "bug 394759";
-    let uniqueValue = "unik" + Date.now();
-    let uniqueText = "pi != " + Math.random();
+  let testURL = "about:config";
+  let uniqueKey = "bug 394759";
+  let uniqueValue = "unik" + Date.now();
+  let uniqueText = "pi != " + Math.random();
 
-    // 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();
+  // 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();
 
-    let newWin = openDialog(location, "", "chrome,all,dialog=no", testURL);
-    newWin.addEventListener("load", function loadListener1(aEvent) {
-      newWin.removeEventListener("load", loadListener1, false);
-
-      newWin.getBrowser().selectedBrowser.addEventListener("load", function loadListener2(aEvent) {
-        newWin.getBrowser().selectedBrowser.removeEventListener("load", loadListener2, true);
+  provideWindow(function (newWin) {
+    newWin.getBrowser().addTab().linkedBrowser.stop();
 
-        executeSoon(function() {
-          newWin.getBrowser().addTab().linkedBrowser.stop();
-          executeSoon(function() {
-            // 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;
+    // 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();
 
-            newWin.close();
+    is(ss.getClosedWindowCount(), closedWindowCount + 1,
+       "The closed window was added to Recently Closed Windows");
+    let data = JSON.parse(ss.getClosedWindowData())[0];
+    ok(data.title == testURL && JSON.stringify(data).indexOf(uniqueText) > -1,
+       "The closed window data was stored correctly");
 
-            is(ss.getClosedWindowCount(), closedWindowCount + 1,
-               "The closed window was added to Recently Closed Windows");
-            let data = JSON.parse(ss.getClosedWindowData())[0];
-            ok(data.title == testURL && JSON.stringify(data).indexOf(uniqueText) > -1,
-               "The closed window data was stored correctly");
-
-            // reopen the closed window and ensure its integrity
-            let newWin2 = ss.undoCloseWindow(0);
+    // reopen the closed window and ensure its integrity
+    let newWin2 = ss.undoCloseWindow(0);
 
-            ok(newWin2 instanceof ChromeWindow,
-               "undoCloseWindow actually returned a window");
-            is(ss.getClosedWindowCount(), closedWindowCount,
-               "The reopened window was removed from Recently Closed Windows");
+    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;
-            newWin2.addEventListener("load", function loadListener3(aEvent) {
-              newWin2.removeEventListener("load", loadListener3, false);
+    // 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.getBrowser().tabContainer.addEventListener("SSTabRestored", function sstabrestoredListener4(aEvent) {
-                if (++restoredTabs < expectedTabs)
-                  return;
-
-                newWin2.getBrowser().tabContainer.removeEventListener("SSTabRestored", sstabrestoredListener4, true);
+        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");
+        is(newWin2.getBrowser().tabs.length, 2,
+           "The window correctly restored 2 tabs");
+        is(newWin2.getBrowser().currentURI.spec, testURL,
+           "The window correctly restored the URL");
 
-                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");
+        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();
-                if (Services.prefs.prefHasUserValue("browser.sessionstore.max_windows_undo"))
-                  Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo");
-                executeSoon(callback);
-              }, true);
-            }, false);
-          });
-        });
+        // clean up
+        newWin2.close();
+        Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo");
+        finish();
       }, true);
-    }, false);
-  }
-
-  function test_behavior (callback) {
-    // helper function that does the actual testing
-    function openWindowRec(windowsToOpen, expectedResults, recCallback) {
-      // do actual checking
-      if (!windowsToOpen.length) {
-        let closedWindowData = JSON.parse(ss.getClosedWindowData());
-        let numPopups = closedWindowData.filter(function(el, i, arr) {
-          return el.isPopup;
-        }).length;
-        let numNormal = ss.getClosedWindowCount() - numPopups;
-        // #ifdef doesn't work in browser-chrome tests, so do a simple regex on platform
-        let oResults = navigator.platform.match(/Mac/) ? expectedResults.mac
-                                                       : expectedResults.other;
-        is(numPopups, oResults.popup,
-           "There were " + oResults.popup + " popup windows to repoen");
-        is(numNormal, oResults.normal,
-           "There were " + oResults.normal + " normal windows to repoen");
-
-        // cleanup & return
-        executeSoon(recCallback);
-        return;
-      }
-      // 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;
-      let win = openDialog(location, "", settings, url);
-      win.addEventListener("load", function loadListener5(aEvent) {
-        win.removeEventListener("load", loadListener5, false);
-
-        win.getBrowser().selectedBrowser.addEventListener("DOMContentLoaded", function loadListener6(aEvent) {
-          win.getBrowser().selectedBrowser.removeEventListener("DOMContentLoaded", loadListener6, true);
-          // the window _should_ have state with a tab of url, but it doesn't
-          // always happend before window.close(). addTab ensure we don't treat
-          // this window as a stateless window
-          win.getBrowser().addTab();
-
-          executeSoon(function() {
-            win.close();
-            executeSoon(function() {
-              openWindowRec(windowsToOpen, expectedResults, recCallback);
-            });
-          });
-        }, true);
-      }, false);
-    }
-
-    let windowsToOpen = [{isPopup: false},
-                         {isPopup: false},
-                         {isPopup: true},
-                         {isPopup: true},
-                         {isPopup: true}];
-    let expectedResults = {mac: {popup: 3, normal: 0},
-                           other: {popup: 3, normal: 1}};
-    let windowsToOpen2 = [{isPopup: false},
-                          {isPopup: false},
-                          {isPopup: false},
-                          {isPopup: false},
-                          {isPopup: false}];
-    let expectedResults2 = {mac: {popup: 0, normal: 3},
-                            other: {popup: 0, normal: 3}};
-    openWindowRec(windowsToOpen, expectedResults, function() {
-      openWindowRec(windowsToOpen2, expectedResults2, callback);
     });
-  }
-
-  is(browserWindowsCount(), 1, "Only one browser window should be open initially");
-  test_basic(function() {
-    is(browserWindowsCount(), 1, "number of browser windows after test_basic");
-    test_behavior(function() {
-      is(browserWindowsCount(), 1, "number of browser windows after test_behavior");
-        finish();
-    });
-  });
+  }, testURL);
 }
copy from suite/common/tests/browser/browser_394759.js
copy to suite/common/tests/browser/browser_394759_behavior.js
--- a/suite/common/tests/browser/browser_394759.js
+++ b/suite/common/tests/browser/browser_394759_behavior.js
@@ -30,181 +30,101 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * 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 ***** */
 
-function browserWindowsCount() {
-  let count = 0;
-  let e = Services.wm.getEnumerator("navigator:browser");
-  while (e.hasMoreElements()) {
-    if (!e.getNext().closed)
-      ++count;
+/** Test for Bug 394759, ported in Bug 510890 **/
+
+function provideWindow(aCallback, aURL, aFeatures) {
+  function callback() {
+    executeSoon(function () {
+      aCallback(win);
+    });
   }
-  return count;
+
+  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() {
-  /** Test for Bug 394759, ported in Bug 510890 **/
   // This test takes quite some time, and timeouts frequently, so we require
   // more time to run.
   // See Bug 518970.
   requestLongerTimeout(2);
 
   waitForExplicitFinish();
 
-  function test_basic(callback) {
-    let testURL = "about:config";
-    let uniqueKey = "bug 394759";
-    let uniqueValue = "unik" + Date.now();
-    let uniqueText = "pi != " + Math.random();
-
-    // 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();
-
-    let newWin = openDialog(location, "", "chrome,all,dialog=no", testURL);
-    newWin.addEventListener("load", function loadListener1(aEvent) {
-      newWin.removeEventListener("load", loadListener1, false);
-
-      newWin.getBrowser().selectedBrowser.addEventListener("load", function loadListener2(aEvent) {
-        newWin.getBrowser().selectedBrowser.removeEventListener("load", loadListener2, true);
-
-        executeSoon(function() {
-          newWin.getBrowser().addTab().linkedBrowser.stop();
-          executeSoon(function() {
-            // 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();
-
-            is(ss.getClosedWindowCount(), closedWindowCount + 1,
-               "The closed window was added to Recently Closed Windows");
-            let data = JSON.parse(ss.getClosedWindowData())[0];
-            ok(data.title == testURL && JSON.stringify(data).indexOf(uniqueText) > -1,
-               "The closed window data was stored correctly");
-
-            // reopen the closed window and ensure its integrity
-            let newWin2 = ss.undoCloseWindow(0);
+  // helper function that does the actual testing
+  function openWindowRec(windowsToOpen, expectedResults, recCallback) {
+    // do actual checking
+    if (!windowsToOpen.length) {
+      let closedWindowData = JSON.parse(ss.getClosedWindowData());
+      let numPopups = closedWindowData.filter(function(el, i, arr) {
+        return el.isPopup;
+      }).length;
+      let numNormal = ss.getClosedWindowCount() - numPopups;
+      // #ifdef doesn't work in browser-chrome tests, so do a simple regex on platform
+      let oResults = navigator.platform.match(/Mac/) ? expectedResults.mac
+                                                     : expectedResults.other;
+      is(numPopups, oResults.popup,
+         "There were " + oResults.popup + " popup windows to repoen");
+      is(numNormal, oResults.normal,
+         "There were " + oResults.normal + " normal windows to repoen");
 
-            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;
-            newWin2.addEventListener("load", function loadListener3(aEvent) {
-              newWin2.removeEventListener("load", loadListener3, false);
-
-              newWin2.getBrowser().tabContainer.addEventListener("SSTabRestored", function sstabrestoredListener4(aEvent) {
-                if (++restoredTabs < expectedTabs)
-                  return;
-
-                newWin2.getBrowser().tabContainer.removeEventListener("SSTabRestored", sstabrestoredListener4, true);
+      // cleanup & return
+      executeSoon(recCallback);
+      return;
+    }
 
-                is(newWin2.getBrowser().tabs.length, 2,
-                   "The window correctly restored 2 tabs");
-                is(newWin2.getBrowser().currentURI.spec, testURL,
-                   "The window correctly restored the URL");
-
-                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");
+    // 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;
 
-                // clean up
-                newWin2.close();
-                if (Services.prefs.prefHasUserValue("browser.sessionstore.max_windows_undo"))
-                  Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo");
-                executeSoon(callback);
-              }, true);
-            }, false);
-          });
-        });
-      }, true);
-    }, false);
+    provideWindow(function (win) {
+      win.close();
+      openWindowRec(windowsToOpen, expectedResults, recCallback);
+    }, url, settings);
   }
 
-  function test_behavior (callback) {
-    // helper function that does the actual testing
-    function openWindowRec(windowsToOpen, expectedResults, recCallback) {
-      // do actual checking
-      if (!windowsToOpen.length) {
-        let closedWindowData = JSON.parse(ss.getClosedWindowData());
-        let numPopups = closedWindowData.filter(function(el, i, arr) {
-          return el.isPopup;
-        }).length;
-        let numNormal = ss.getClosedWindowCount() - numPopups;
-        // #ifdef doesn't work in browser-chrome tests, so do a simple regex on platform
-        let oResults = navigator.platform.match(/Mac/) ? expectedResults.mac
-                                                       : expectedResults.other;
-        is(numPopups, oResults.popup,
-           "There were " + oResults.popup + " popup windows to repoen");
-        is(numNormal, oResults.normal,
-           "There were " + oResults.normal + " normal windows to repoen");
-
-        // cleanup & return
-        executeSoon(recCallback);
-        return;
-      }
-      // 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;
-      let win = openDialog(location, "", settings, url);
-      win.addEventListener("load", function loadListener5(aEvent) {
-        win.removeEventListener("load", loadListener5, false);
-
-        win.getBrowser().selectedBrowser.addEventListener("DOMContentLoaded", function loadListener6(aEvent) {
-          win.getBrowser().selectedBrowser.removeEventListener("DOMContentLoaded", loadListener6, true);
-          // the window _should_ have state with a tab of url, but it doesn't
-          // always happend before window.close(). addTab ensure we don't treat
-          // this window as a stateless window
-          win.getBrowser().addTab();
-
-          executeSoon(function() {
-            win.close();
-            executeSoon(function() {
-              openWindowRec(windowsToOpen, expectedResults, recCallback);
-            });
-          });
-        }, true);
-      }, false);
-    }
-
-    let windowsToOpen = [{isPopup: false},
-                         {isPopup: false},
-                         {isPopup: true},
-                         {isPopup: true},
-                         {isPopup: true}];
-    let expectedResults = {mac: {popup: 3, normal: 0},
-                           other: {popup: 3, normal: 1}};
-    let windowsToOpen2 = [{isPopup: false},
-                          {isPopup: false},
-                          {isPopup: false},
-                          {isPopup: false},
-                          {isPopup: false}];
-    let expectedResults2 = {mac: {popup: 0, normal: 3},
-                            other: {popup: 0, normal: 3}};
-    openWindowRec(windowsToOpen, expectedResults, function() {
-      openWindowRec(windowsToOpen2, expectedResults2, callback);
-    });
-  }
-
-  is(browserWindowsCount(), 1, "Only one browser window should be open initially");
-  test_basic(function() {
-    is(browserWindowsCount(), 1, "number of browser windows after test_basic");
-    test_behavior(function() {
-      is(browserWindowsCount(), 1, "number of browser windows after test_behavior");
-        finish();
-    });
+  let windowsToOpen = [{isPopup: false},
+                       {isPopup: false},
+                       {isPopup: true},
+                       {isPopup: true},
+                       {isPopup: true}];
+  let expectedResults = {mac: {popup: 3, normal: 0},
+                         other: {popup: 3, normal: 1}};
+  let windowsToOpen2 = [{isPopup: false},
+                        {isPopup: false},
+                        {isPopup: false},
+                        {isPopup: false},
+                        {isPopup: false}];
+  let expectedResults2 = {mac: {popup: 0, normal: 3},
+                          other: {popup: 0, normal: 3}};
+  openWindowRec(windowsToOpen, expectedResults, function() {
+    openWindowRec(windowsToOpen2, expectedResults2, finish);
   });
 }