Bug 896711: remove BrowserChromeTests.runWhenReady because it's being abused, r=dao/ttaubert

--HG--
extra : transplant_source : %9D%F5%0D/%105%29%20%BCW%EC%BEs%BB%22vgO%9B%87
This commit is contained in:
Gavin Sharp 2013-07-27 17:32:40 -07:00
parent b41199fdb5
commit 68214b0668
6 changed files with 92 additions and 98 deletions

View File

@ -1277,8 +1277,6 @@ var gBrowserInit = {
goSetCommandEnabled("Browser:RestoreLastSession", true);
TabView.init();
setTimeout(function () { BrowserChromeTest.markAsReady(); }, 0);
});
Services.obs.notifyObservers(window, "browser-delayed-startup-finished", "");
@ -7318,20 +7316,3 @@ function focusNextFrame(event) {
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;
}
};

View File

@ -1,13 +1,14 @@
/* 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 = (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == win);
let gotActivate = Services.focus.activeWindow == win;
function maybeRunCallback() {
if (gotLoad && gotActivate) {
win.BrowserChromeTest.runWhenReady(function() {
executeSoon(function() { aCallback(win); });
});
executeSoon(function() { aCallback(win); });
}
}
@ -22,12 +23,15 @@ function whenNewWindowLoaded(aOptions, aCallback) {
info("Was activated.");
}
win.addEventListener("load", function onLoad() {
info("Got load");
win.removeEventListener("load", onLoad, false);
gotLoad = true;
maybeRunCallback();
}, false);
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);
return win;
}

View File

@ -4,13 +4,11 @@
function whenNewWindowLoaded(aOptions, aCallback) {
let win = OpenBrowserWindow(aOptions);
let gotLoad = false;
let gotActivate = (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == win);
let gotActivate = Services.focus.activeWindow == win;
function maybeRunCallback() {
if (gotLoad && gotActivate) {
win.BrowserChromeTest.runWhenReady(function() {
executeSoon(function() { aCallback(win); });
});
executeSoon(function() { aCallback(win); });
}
}
@ -25,12 +23,15 @@ function whenNewWindowLoaded(aOptions, aCallback) {
info("Was activated.");
}
win.addEventListener("load", function onLoad() {
info("Got load");
win.removeEventListener("load", onLoad, false);
gotLoad = true;
maybeRunCallback();
}, false);
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);
return win;
}

View File

@ -44,48 +44,51 @@ function test_open_window()
gSecondWindow = window.open(TAB2_URL, "secondWindow");
ok(!!gSecondWindow, "Second window created.");
gSecondWindow.focus();
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 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 gotLoad = false;
let gotActivate = (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == main2);
let gotActivate = Services.focus.activeWindow == chromeWin;
function maybeWindowLoadedAndActive() {
if (gotLoad && gotActivate) {
top.BrowserChromeTest.runWhenReady(function() {
executeSoon(function() {
gClient.listTabs(function(aResponse) {
is(aResponse.selected, 2, "Tab2 is selected.");
test_focus_first();
});
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) {
main2.addEventListener("activate", function() {
main2.removeEventListener("activate", arguments.callee, true);
gotActivate = 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;
chromeWin.addEventListener("activate", function onactivate() {
info("activate event");
chromeWin.removeEventListener("activate", onactivate, true);
gotActivate = true;
maybeWindowLoadedAndActive();
},
true
);
}, 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);
}
function test_focus_first()

View File

@ -1,3 +1,6 @@
/* 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";
@ -19,30 +22,35 @@ function test() {
function testOnWindow(aIsPrivate, aCallback) {
let win = OpenBrowserWindow({private: aIsPrivate});
let gotLoad = false;
let gotActivate =
(Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == win);
let gotActivate = Services.focus.activeWindow == win;
function maybeRunCallback() {
if (gotLoad && gotActivate) {
windowsToClose.push(win);
executeSoon(function() { aCallback(win); });
}
}
if (!gotActivate) {
win.addEventListener("activate", function onActivate() {
info("got activate");
win.removeEventListener("activate", onActivate, true);
gotActivate = true;
if (gotLoad) {
windowsToClose.push(win);
win.BrowserChromeTest.runWhenReady(function() { aCallback(win) });
}
maybeRunCallback();
}, true);
} else {
info("Was activated");
}
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);
Services.obs.addObserver(function observer(aSubject, aTopic) {
if (win == aSubject) {
info("Delayed startup finished");
Services.obs.removeObserver(observer, aTopic);
gotLoad = true;
maybeRunCallback();
}
}, true);
}, "browser-delayed-startup-finished", false);
}
testOnWindow(false, function(aNormalWindow) {

View File

@ -13,11 +13,17 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
window.addEventListener("load", testOnLoad, false);
window.addEventListener("load", function testOnLoad() {
window.removeEventListener("load", testOnLoad);
function testOnLoad() {
window.removeEventListener("load", testOnLoad, false);
window.addEventListener("MozAfterPaint", function testOnMozAfterPaint() {
window.removeEventListener("MozAfterPaint", testOnMozAfterPaint);
setTimeout(testInit, 0);
});
});
function testInit() {
gConfig = readConfig();
if (gConfig.testRoot == "browser" ||
gConfig.testRoot == "metro" ||
@ -93,15 +99,6 @@ Tester.prototype = {
},
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();