Back out bug 896711 for potentially causing metro test timeouts, CLOSED TREE
authorGavin Sharp <gavin@gavinsharp.com>
Fri, 02 Aug 2013 13:02:22 -0700
changeset 153493 1bf269457c6b57df30ed37539073ff1b2e0aa8ad
parent 153492 37a90c3f8cfe0b129c606df6561fc491642ec5c9
child 153494 3a02eb487583883a33522dc97bc7b2269890da80
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs896711
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Back out bug 896711 for potentially causing metro test timeouts, CLOSED TREE
browser/base/content/browser.js
browser/components/privatebrowsing/test/browser/head.js
browser/components/search/test/head.js
browser/devtools/debugger/test/browser_dbg_multiple-windows.js
dom/tests/browser/browser_geolocation_privatebrowsing_perwindowpb.js
testing/mochitest/browser-test.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1272,16 +1272,18 @@ var gBrowserInit = {
 
     SessionStore.promiseInitialized.then(() => {
       // Enable the Restore Last Session command if needed
       if (SessionStore.canRestoreLastSession &&
           !PrivateBrowsingUtils.isWindowPrivate(window))
         goSetCommandEnabled("Browser:RestoreLastSession", true);
 
       TabView.init();
+
+      setTimeout(function () { BrowserChromeTest.markAsReady(); }, 0);
     });
 
     Services.obs.notifyObservers(window, "browser-delayed-startup-finished", "");
     TelemetryTimestamps.add("delayedStartupFinished");
   },
 
   // Returns the URI(s) to load at startup.
   _getUriToLoad: function () {
@@ -7311,8 +7313,25 @@ var MousePosTracker = {
 
 function focusNextFrame(event) {
   let fm = Services.focus;
   let dir = event.shiftKey ? fm.MOVEFOCUS_BACKWARDDOC : fm.MOVEFOCUS_FORWARDDOC;
   let element = fm.moveFocus(window, null, dir, fm.FLAG_BYKEY);
   if (element.ownerDocument == document)
     focusAndSelectUrlBar();
 }
+let BrowserChromeTest = {
+  _cb: null,
+  _ready: false,
+  markAsReady: function () {
+    this._ready = true;
+    if (this._cb) {
+      this._cb();
+      this._cb = null;
+    }
+  },
+  runWhenReady: function (cb) {
+    if (this._ready)
+      cb();
+    else
+      this._cb = cb;
+  }
+};
--- a/browser/components/privatebrowsing/test/browser/head.js
+++ b/browser/components/privatebrowsing/test/browser/head.js
@@ -1,42 +1,38 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
 function whenNewWindowLoaded(aOptions, aCallback) {
   let win = OpenBrowserWindow(aOptions);
   let gotLoad = false;
-  let gotActivate = Services.focus.activeWindow == win;
+  let gotActivate = (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == win);
 
   function maybeRunCallback() {
     if (gotLoad && gotActivate) {
-      executeSoon(function() { aCallback(win); });
+      win.BrowserChromeTest.runWhenReady(function() {
+        executeSoon(function() { aCallback(win); });
+      });
     }
   }
 
   if (!gotActivate) {
     win.addEventListener("activate", function onActivate() {
       info("Got activate.");
       win.removeEventListener("activate", onActivate, false);
       gotActivate = true;
       maybeRunCallback();
     }, false);
   } else {
     info("Was activated.");
   }
 
-  Services.obs.addObserver(function observer(aSubject, aTopic) {
-    if (win == aSubject) {
-      info("Delayed startup finished");
-      Services.obs.removeObserver(observer, aTopic);
-      gotLoad = true;
-      maybeRunCallback();
-    }
-  }, "browser-delayed-startup-finished", false);
-
+  win.addEventListener("load", function onLoad() {
+    info("Got load");
+    win.removeEventListener("load", onLoad, false);
+    gotLoad = true;
+    maybeRunCallback();
+  }, false);
   return win;
 }
 
 function openWindow(aParent, aOptions, a3) {
   let { Promise: { defer } } = Components.utils.import("resource://gre/modules/Promise.jsm", {});
   let { promise, resolve } = defer();
 
   let win = aParent.OpenBrowserWindow(aOptions);
--- a/browser/components/search/test/head.js
+++ b/browser/components/search/test/head.js
@@ -1,42 +1,41 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function whenNewWindowLoaded(aOptions, aCallback) {
   let win = OpenBrowserWindow(aOptions);
   let gotLoad = false;
-  let gotActivate = Services.focus.activeWindow == win;
+  let gotActivate = (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == win);
 
   function maybeRunCallback() {
     if (gotLoad && gotActivate) {
-      executeSoon(function() { aCallback(win); });
+      win.BrowserChromeTest.runWhenReady(function() {
+        executeSoon(function() { aCallback(win); });
+      });
     }
   }
 
   if (!gotActivate) {
     win.addEventListener("activate", function onActivate() {
       info("Got activate.");
       win.removeEventListener("activate", onActivate, false);
       gotActivate = true;
       maybeRunCallback();
     }, false);
   } else {
     info("Was activated.");
   }
 
-  Services.obs.addObserver(function observer(aSubject, aTopic) {
-    if (win == aSubject) {
-      info("Delayed startup finished");
-      Services.obs.removeObserver(observer, aTopic);
-      gotLoad = true;
-      maybeRunCallback();
-    }
-  }, "browser-delayed-startup-finished", false);
-
+  win.addEventListener("load", function onLoad() {
+    info("Got load");
+    win.removeEventListener("load", onLoad, false);
+    gotLoad = true;
+    maybeRunCallback();
+  }, false);
   return win;
 }
 
 /**
  * Recursively compare two objects and check that every property of expectedObj has the same value
  * on actualObj.
  */
 function isSubObjectOf(expectedObj, actualObj, name) {
--- a/browser/devtools/debugger/test/browser_dbg_multiple-windows.js
+++ b/browser/devtools/debugger/test/browser_dbg_multiple-windows.js
@@ -39,61 +39,58 @@ function test_first_tab()
   });
 }
 
 function test_open_window()
 {
   gSecondWindow = window.open(TAB2_URL, "secondWindow");
   ok(!!gSecondWindow, "Second window created.");
   gSecondWindow.focus();
-
-  let topWin = windowMediator.getMostRecentWindow("navigator:browser");
-  var chromeWin = gSecondWindow.QueryInterface(Ci.nsIInterfaceRequestor)
-                               .getInterface(Ci.nsIWebNavigation)
-                               .QueryInterface(Ci.nsIDocShellTreeItem)
-                               .rootTreeItem
-                               .QueryInterface(Ci.nsIInterfaceRequestor)
-                               .getInterface(Ci.nsIDOMWindow);
-  is(topWin, chromeWin, "The second window is on top.");
-
+  let top = windowMediator.getMostRecentWindow("navigator:browser");
+  var main2 = gSecondWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+                   .getInterface(Components.interfaces.nsIWebNavigation)
+                   .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
+                   .rootTreeItem
+                   .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+                   .getInterface(Components.interfaces.nsIDOMWindow);
+  is(top, main2, "The second window is on top.");
   let gotLoad = false;
-  let gotActivate = Services.focus.activeWindow == chromeWin;
-
+  let gotActivate = (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == main2);
   function maybeWindowLoadedAndActive() {
     if (gotLoad && gotActivate) {
-      executeSoon(function() {
-        gClient.listTabs(function(aResponse) {
-          is(aResponse.selected, 2, "Tab2 is selected.");
-          test_focus_first();
+      top.BrowserChromeTest.runWhenReady(function() {
+        executeSoon(function() {
+          gClient.listTabs(function(aResponse) {
+            is(aResponse.selected, 2, "Tab2 is selected.");
+            test_focus_first();
+          });
         });
-      });
+      })
     }
   }
 
-  // Wait for chrome window activation, if necessary
   if (!gotActivate) {
-    chromeWin.addEventListener("activate", function onactivate() {
-      info("activate event");
-
-      chromeWin.removeEventListener("activate", onactivate, true);
-      gotActivate = true;
-      maybeWindowLoadedAndActive();
-    }, true);
+    main2.addEventListener("activate", function() {
+        main2.removeEventListener("activate", arguments.callee, true);
+        gotActivate = true;
+        maybeWindowLoadedAndActive();
+      },
+      true
+    );
   }
-
-  // Wait for the requested content document to load
-  chromeWin.document.addEventListener("load", function onload(e) {
-    if (e.target.documentURI != TAB2_URL) {
-      return;
-    }
-    info("content loaded");
-    chromeWin.document.removeEventListener("load", onload, true);
-    gotLoad = true;
-    maybeWindowLoadedAndActive();
-  }, true);
+  main2.document.addEventListener("load", function(e) {
+      if (e.target.documentURI != TAB2_URL) {
+        return;
+      }
+      main2.document.removeEventListener("load", arguments.callee, true);
+      gotLoad = true;
+      maybeWindowLoadedAndActive();
+    },
+    true
+  );
 }
 
 function test_focus_first()
 {
   window.content.addEventListener("focus", function onFocus() {
     window.content.removeEventListener("focus", onFocus, false);
     let top = windowMediator.getMostRecentWindow("navigator:browser");
     var main1 = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
--- a/dom/tests/browser/browser_geolocation_privatebrowsing_perwindowpb.js
+++ b/dom/tests/browser/browser_geolocation_privatebrowsing_perwindowpb.js
@@ -1,11 +1,8 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
 function test() {
   var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
   let baseProvider = "http://mochi.test:8888/browser/dom/tests/browser/network_geolocation.sjs";
   prefs.setCharPref("geo.wifi.uri", baseProvider + "?desired_access_token=fff");
 
   prefs.setBoolPref("geo.prompt.testing", true);
   prefs.setBoolPref("geo.prompt.testing.allow", true);
   var origScanValue = true; // same default in NetworkGeolocationProvider.js.
@@ -17,45 +14,40 @@ function test() {
   const testPageURL = "http://mochi.test:8888/browser/" +
     "dom/tests/browser/browser_geolocation_privatebrowsing_page.html";
   waitForExplicitFinish();
 
   var windowsToClose = [];
   function testOnWindow(aIsPrivate, aCallback) {
     let win = OpenBrowserWindow({private: aIsPrivate});
     let gotLoad = false;
-    let gotActivate = Services.focus.activeWindow == win;
-
-    function maybeRunCallback() {
-      if (gotLoad && gotActivate) {
-        windowsToClose.push(win);
-        executeSoon(function() { aCallback(win); });
-      }
-    }
-
+    let gotActivate = 
+      (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == win);
     if (!gotActivate) {
       win.addEventListener("activate", function onActivate() {
         info("got activate");
         win.removeEventListener("activate", onActivate, true);
         gotActivate = true;
-        maybeRunCallback();
+        if (gotLoad) {
+          windowsToClose.push(win);
+          win.BrowserChromeTest.runWhenReady(function() { aCallback(win) });
+        }
       }, true);
     } else {
       info("Was activated");
     }
-
-    Services.obs.addObserver(function observer(aSubject, aTopic) {
-      if (win == aSubject) {
-        info("Delayed startup finished");
-        Services.obs.removeObserver(observer, aTopic);
-        gotLoad = true;
-        maybeRunCallback();
+    win.addEventListener("load", function onLoad() {
+      info("Got load");
+      win.removeEventListener("load", onLoad, true);
+      gotLoad = true;
+      if (gotActivate) {
+        windowsToClose.push(win);
+        setTimeout(function() { aCallback(win) }, 1000);
       }
-    }, "browser-delayed-startup-finished", false);
-
+    }, true);
   }
 
   testOnWindow(false, function(aNormalWindow) {
     aNormalWindow.gBrowser.selectedBrowser.addEventListener("georesult", function load(ev) {
       aNormalWindow.gBrowser.selectedBrowser.removeEventListener("georesult", load, false);
       is(ev.detail, 200, "unexpected access token");
 
       prefs.setCharPref("geo.wifi.uri", baseProvider + "?desired_access_token=ggg");
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -8,27 +8,21 @@ if (Cc === undefined) {
   var Cu = Components.utils;
 }
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
   "resource://gre/modules/Services.jsm");
 
-window.addEventListener("load", function testOnLoad() {
-  window.removeEventListener("load", testOnLoad);
-
-  window.addEventListener("MozAfterPaint", function testOnMozAfterPaint() {
-    window.removeEventListener("MozAfterPaint", testOnMozAfterPaint);
+window.addEventListener("load", testOnLoad, false);
 
-    setTimeout(testInit, 0);
-  });
-});
+function testOnLoad() {
+  window.removeEventListener("load", testOnLoad, false);
 
-function testInit() {
   gConfig = readConfig();
   if (gConfig.testRoot == "browser" ||
       gConfig.testRoot == "metro" ||
       gConfig.testRoot == "webapprtChrome") {
     // Make sure to launch the test harness for the first opened window only
     var prefs = Services.prefs;
     if (prefs.prefHasUserValue("testing.browserTestHarness.running"))
       return;
@@ -94,16 +88,25 @@ Tester.prototype = {
   get currentTest() {
     return this.tests[this.currentTestIndex];
   },
   get done() {
     return this.currentTestIndex == this.tests.length - 1;
   },
 
   start: function Tester_start() {
+    // Check whether this window is ready to run tests.
+    if (window.BrowserChromeTest) {
+      BrowserChromeTest.runWhenReady(this.actuallyStart.bind(this));
+      return;
+    }
+    this.actuallyStart();
+  },
+
+  actuallyStart: function Tester_actuallyStart() {
     //if testOnLoad was not called, then gConfig is not defined
     if (!gConfig)
       gConfig = readConfig();
 
     if (gConfig.runUntilFailure)
       this.runUntilFailure = true;
 
     if (gConfig.repeat)