Bug 805068 - Make browser chrome tests more self-contained by giving each test a new blank tab. r=ttaubert, a=test-only
authorDão Gottwald <dao@mozilla.com>
Mon, 12 May 2014 22:05:00 -0400
changeset 199174 37037e7a19e8b2fc4dcd2485e0dfbc72685870e2
parent 199173 cc69ae439121fffe4120eb18e82477caa3203f81
child 199175 34458ec41195dd281a8d39c44a0a1a13370bc25e
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert, test-only
bugs805068
milestone31.0a2
Bug 805068 - Make browser chrome tests more self-contained by giving each test a new blank tab. r=ttaubert, a=test-only
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_bug519216.js
browser/base/content/test/general/browser_save_video.js
browser/components/tabview/test/head.js
browser/devtools/debugger/test/browser.ini
browser/devtools/webconsole/test/browser_console.js
browser/devtools/webconsole/test/head.js
testing/mochitest/browser-test.js
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -400,17 +400,17 @@ skip-if = e10s # Bug ????? - test calls 
 skip-if = e10s # Bug ?????? - FHR tests failing (either with "no data for today" or "2 records for today")
 [browser_utilityOverlay.js]
 [browser_visibleFindSelection.js]
 skip-if = e10s # Bug ?????? - test directly manipulates content
 [browser_visibleLabel.js]
 [browser_visibleTabs.js]
 skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
 [browser_visibleTabs_bookmarkAllPages.js]
-skip-if = e10s # Bug ?????? - bizarre problem with hidden tab having _mouseenter called, via _setPositionalAttributes, and tab not being found resulting in 'candidate is undefined'
+skip-if = true # Bug 1005420 - fails intermittently. also with e10s enabled: bizarre problem with hidden tab having _mouseenter called, via _setPositionalAttributes, and tab not being found resulting in 'candidate is undefined'
 [browser_visibleTabs_bookmarkAllTabs.js]
 skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
 [browser_visibleTabs_contextMenu.js]
 skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
 [browser_visibleTabs_tabPreview.js]
 skip-if = e10s # Bug ????? - thumbnail captures need e10s love (tabPreviews_capture fails with Argument 1 of CanvasRenderingContext2D.drawWindow does not implement interface Window.)
 [browser_windowopen_reflows.js]
 [browser_wyciwyg_urlbarCopying.js]
--- a/browser/base/content/test/general/browser_bug519216.js
+++ b/browser/base/content/test/general/browser_bug519216.js
@@ -1,11 +1,10 @@
 function test() {
   waitForExplicitFinish();
-  gBrowser.stop();
   gBrowser.addProgressListener(progressListener1);
   gBrowser.addProgressListener(progressListener2);
   gBrowser.addProgressListener(progressListener3);
   gBrowser.loadURI("data:text/plain,bug519216");
 }
 
 var calledListener1 = false;
 var progressListener1 = {
@@ -36,15 +35,11 @@ var progressListener3 = {
   }
 };
 
 var expectListener4 = false;
 var progressListener4 = {
   onLocationChange: function onLocationChange() {
     ok(expectListener4, "didn't call progressListener4 for the first location change");
     gBrowser.removeProgressListener(this);
-    executeSoon(function () {
-      gBrowser.addTab();
-      gBrowser.removeCurrentTab();
-      finish();
-    });
+    executeSoon(finish);
   }
 };
--- a/browser/base/content/test/general/browser_save_video.js
+++ b/browser/base/content/test/general/browser_save_video.js
@@ -9,21 +9,16 @@ MockFilePicker.init(window);
  * <https://bugzilla.mozilla.org/show_bug.cgi?id=564387>
  */
 function test() {
   waitForExplicitFinish();
   var fileName;
 
   gBrowser.loadURI("http://mochi.test:8888/browser/browser/base/content/test/general/bug564387.html");
 
-  registerCleanupFunction(function () {
-    gBrowser.addTab();
-    gBrowser.removeCurrentTab();
-  });
-
   gBrowser.addEventListener("pageshow", function pageShown(event) {
     if (event.target.location == "about:blank")
       return;
     gBrowser.removeEventListener("pageshow", pageShown);
 
     executeSoon(function () {
       document.addEventListener("popupshown", contextMenuOpened);
 
--- a/browser/components/tabview/test/head.js
+++ b/browser/components/tabview/test/head.js
@@ -137,18 +137,17 @@ function afterAllTabsLoaded(callback, wi
   for (let a = 0; a < win.gBrowser.tabs.length; a++) {
     let tab = win.gBrowser.tabs[a];
     let browser = tab.linkedBrowser;
 
     let isRestorable = !(tab.hidden && !restoreHiddenTabs &&
                          browser.__SS_restoreState &&
                          browser.__SS_restoreState == TAB_STATE_NEEDS_RESTORE);
 
-    if (isRestorable && browser.contentDocument.readyState != "complete" ||
-        browser.webProgress.isLoadingDocument) {
+    if (isRestorable && browser.webProgress.isLoadingDocument) {
       stillToLoad++;
       browser.addEventListener("load", onLoad, true);
     }
   }
 
   if (!stillToLoad)
     executeSoon(callback);
 }
--- a/browser/devtools/debugger/test/browser.ini
+++ b/browser/devtools/debugger/test/browser.ini
@@ -115,16 +115,17 @@ support-files =
 [browser_dbg_breakpoints-contextmenu.js]
 [browser_dbg_breakpoints-disabled-reload.js]
 [browser_dbg_breakpoints-editor.js]
 [browser_dbg_breakpoints-highlight.js]
 [browser_dbg_breakpoints-new-script.js]
 [browser_dbg_breakpoints-pane.js]
 [browser_dbg_chrome-debugging.js]
 [browser_dbg_clean-exit-window.js]
+skip-if = true # Bug 933950 (leaky test)
 [browser_dbg_clean-exit.js]
 [browser_dbg_closure-inspection.js]
 [browser_dbg_cmd-blackbox.js]
 [browser_dbg_cmd-break.js]
 [browser_dbg_cmd-dbg.js]
 [browser_dbg_conditional-breakpoints-01.js]
 [browser_dbg_conditional-breakpoints-02.js]
 [browser_dbg_conditional-breakpoints-03.js]
--- a/browser/devtools/webconsole/test/browser_console.js
+++ b/browser/devtools/webconsole/test/browser_console.js
@@ -18,17 +18,17 @@ function test()
     is(aSubject.data, hud.hudId, "notification hudId is correct");
 
     executeSoon(() => consoleOpened(hud));
   }, "web-console-created", false);
 
   let hud = HUDService.getBrowserConsole();
   ok(!hud, "browser console is not open");
   info("wait for the browser console to open with ctrl-shift-j");
-  EventUtils.synthesizeKey("j", { accelKey: true, shiftKey: true }, content);
+  EventUtils.synthesizeKey("j", { accelKey: true, shiftKey: true }, window);
 }
 
 function consoleOpened(hud)
 {
   hud.jsterm.clearOutput(true);
 
   expectUncaughtException();
   executeSoon(() => {
--- a/browser/devtools/webconsole/test/head.js
+++ b/browser/devtools/webconsole/test/head.js
@@ -93,17 +93,17 @@ function afterAllTabsLoaded(callback, wi
     this.removeEventListener("load", onLoad, true);
     stillToLoad--;
     if (!stillToLoad)
       callback();
   }
 
   for (let a = 0; a < win.gBrowser.tabs.length; a++) {
     let browser = win.gBrowser.tabs[a].linkedBrowser;
-    if (browser.contentDocument.readyState != "complete") {
+    if (browser.webProgress.isLoadingDocument) {
       stillToLoad++;
       browser.addEventListener("load", onLoad, true);
     }
   }
 
   if (!stillToLoad)
     callback();
 }
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -184,26 +184,35 @@ Tester.prototype = {
   },
 
   waitForWindowsState: function Tester_waitForWindowsState(aCallback) {
     let timedOut = this.currentTest && this.currentTest.timedOut;
     let baseMsg = timedOut ? "Found a {elt} after previous test timed out"
                            : this.currentTest ? "Found an unexpected {elt} at the end of test run"
                                               : "Found an unexpected {elt}";
 
+    // Remove stale tabs
     if (this.currentTest && window.gBrowser && gBrowser.tabs.length > 1) {
       while (gBrowser.tabs.length > 1) {
         let lastTab = gBrowser.tabContainer.lastChild;
         let msg = baseMsg.replace("{elt}", "tab") +
                   ": " + lastTab.linkedBrowser.currentURI.spec;
         this.currentTest.addResult(new testResult(false, msg, "", false));
         gBrowser.removeTab(lastTab);
       }
     }
 
+    // Replace the last tab with a fresh one
+    if (window.gBrowser) {
+      gBrowser.addTab("about:blank", { skipAnimation: true });
+      gBrowser.removeCurrentTab();
+      gBrowser.stop();
+    }
+
+    // Remove stale windows
     this.dumper.dump("TEST-INFO | checking window state\n");
     let windowsEnum = Services.wm.getEnumerator(null);
     while (windowsEnum.hasMoreElements()) {
       let win = windowsEnum.getNext();
       if (win != window && !win.closed &&
           win.document.documentElement.getAttribute("id") != "browserTestHarness") {
         let type = win.document.documentElement.getAttribute("windowtype");
         switch (type) {
@@ -435,26 +444,16 @@ Tester.prototype = {
       this.currentTest.scope = null;
     }
 
     // Check the window state for the current test before moving to the next one.
     // This also causes us to check before starting any tests, since nextTest()
     // is invoked to start the tests.
     this.waitForWindowsState((function () {
       if (this.done) {
-        // Many tests randomly add and remove tabs, resulting in the original
-        // tab being replaced by a new one. The last test in the suite doing this
-        // will erroneously be blamed for leaking this new tab's DOM window and
-        // docshell until shutdown. We can prevent this by removing this tab now
-        // that all tests are done.
-        if (window.gBrowser) {
-          gBrowser.addTab();
-          gBrowser.removeCurrentTab();
-        }
-
         // Uninitialize a few things explicitly so that they can clean up
         // frames and browser intentionally kept alive until shutdown to
         // eliminate false positives.
         if (gConfig.testRoot == "browser") {
           // Replace the document currently loaded in the browser's sidebar.
           // This will prevent false positives for tests that were the last
           // to touch the sidebar. They will thus not be blamed for leaking
           // a document.
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -718,18 +718,19 @@ SimpleTest.waitForFocus = function (call
     }
 
     // If the current document is about:blank and we are not expecting a blank
     // page (or vice versa), and the document has not yet loaded, wait for the
     // page to load. A common situation is to wait for a newly opened window
     // to load its content, and we want to skip over any intermediate blank
     // pages that load. This issue is described in bug 554873.
     SimpleTest.waitForFocus_loaded =
-        (expectBlankPage == (getHref(targetWindow) == "about:blank")) &&
-        targetWindow.document.readyState == "complete";
+        expectBlankPage ?
+            getHref(targetWindow) == "about:blank" :
+            getHref(targetWindow) != "about:blank" && targetWindow.document.readyState == "complete";
     if (!SimpleTest.waitForFocus_loaded) {
         info("must wait for load");
         targetWindow.addEventListener("load", waitForEvent, true);
     }
 
     // Check if the desired window is already focused.
     var focusedChildWindow = { };
     if (SpecialPowers.activeWindow()) {