Back out bug 896711 for potentially causing metro test timeouts, CLOSED TREE

This commit is contained in:
Gavin Sharp 2013-08-02 13:02:22 -07:00
Родитель 78284635cd
Коммит 193322fbe8
6 изменённых файлов: 98 добавлений и 92 удалений

Просмотреть файл

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

Просмотреть файл

@ -1,14 +1,13 @@
/* 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); });
});
}
}
@ -23,15 +22,12 @@ function whenNewWindowLoaded(aOptions, aCallback) {
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;
}

Просмотреть файл

@ -4,11 +4,13 @@
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); });
});
}
}
@ -23,15 +25,12 @@ function whenNewWindowLoaded(aOptions, aCallback) {
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;
}

Просмотреть файл

@ -44,51 +44,48 @@ 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()

Просмотреть файл

@ -1,6 +1,3 @@
/* 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";
@ -22,35 +19,30 @@ function test() {
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) {

Просмотреть файл

@ -13,17 +13,11 @@ 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("load", testOnLoad, false);
window.addEventListener("MozAfterPaint", function testOnMozAfterPaint() {
window.removeEventListener("MozAfterPaint", testOnMozAfterPaint);
function testOnLoad() {
window.removeEventListener("load", testOnLoad, false);
setTimeout(testInit, 0);
});
});
function testInit() {
gConfig = readConfig();
if (gConfig.testRoot == "browser" ||
gConfig.testRoot == "metro" ||
@ -99,6 +93,15 @@ 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();