2012-05-03 23:42:29 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2013-07-09 10:30:58 -07:00
|
|
|
function whenNewWindowLoaded(aOptions, aCallback) {
|
|
|
|
let win = OpenBrowserWindow(aOptions);
|
|
|
|
let gotLoad = false;
|
2013-08-02 13:02:22 -07:00
|
|
|
let gotActivate = (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == win);
|
2013-07-09 10:30:58 -07:00
|
|
|
|
|
|
|
function maybeRunCallback() {
|
|
|
|
if (gotLoad && gotActivate) {
|
2013-08-02 13:02:22 -07:00
|
|
|
win.BrowserChromeTest.runWhenReady(function() {
|
|
|
|
executeSoon(function() { aCallback(win); });
|
|
|
|
});
|
2013-07-09 10:30:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gotActivate) {
|
|
|
|
win.addEventListener("activate", function onActivate() {
|
|
|
|
info("Got activate.");
|
|
|
|
win.removeEventListener("activate", onActivate, false);
|
|
|
|
gotActivate = true;
|
|
|
|
maybeRunCallback();
|
|
|
|
}, false);
|
|
|
|
} else {
|
|
|
|
info("Was activated.");
|
|
|
|
}
|
|
|
|
|
2013-08-02 13:02:22 -07:00
|
|
|
win.addEventListener("load", function onLoad() {
|
|
|
|
info("Got load");
|
|
|
|
win.removeEventListener("load", onLoad, false);
|
|
|
|
gotLoad = true;
|
|
|
|
maybeRunCallback();
|
|
|
|
}, false);
|
2013-07-09 10:30:58 -07:00
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
2012-05-03 23:42:29 -07:00
|
|
|
/**
|
|
|
|
* Recursively compare two objects and check that every property of expectedObj has the same value
|
|
|
|
* on actualObj.
|
|
|
|
*/
|
|
|
|
function isSubObjectOf(expectedObj, actualObj, name) {
|
|
|
|
for (let prop in expectedObj) {
|
|
|
|
if (typeof expectedObj[prop] == 'function')
|
|
|
|
continue;
|
|
|
|
if (expectedObj[prop] instanceof Object) {
|
|
|
|
is(actualObj[prop].length, expectedObj[prop].length, name + "[" + prop + "]");
|
|
|
|
isSubObjectOf(expectedObj[prop], actualObj[prop], name + "[" + prop + "]");
|
|
|
|
} else {
|
|
|
|
is(actualObj[prop], expectedObj[prop], name + "[" + prop + "]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-12 05:38:42 -07:00
|
|
|
|
|
|
|
function waitForPopupShown(aPopupId, aCallback) {
|
|
|
|
let popup = document.getElementById(aPopupId);
|
2013-03-13 19:23:03 -07:00
|
|
|
info("waitForPopupShown: got popup: " + popup.id);
|
2013-03-12 05:38:42 -07:00
|
|
|
function onPopupShown() {
|
2013-03-13 19:23:03 -07:00
|
|
|
info("onPopupShown");
|
|
|
|
removePopupShownListener();
|
2013-03-12 05:38:42 -07:00
|
|
|
SimpleTest.executeSoon(aCallback);
|
|
|
|
}
|
2013-03-13 19:23:03 -07:00
|
|
|
function removePopupShownListener() {
|
|
|
|
popup.removeEventListener("popupshown", onPopupShown);
|
|
|
|
}
|
2013-03-12 05:38:42 -07:00
|
|
|
popup.addEventListener("popupshown", onPopupShown);
|
2013-03-13 19:23:03 -07:00
|
|
|
registerCleanupFunction(removePopupShownListener);
|
2013-03-12 05:38:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function waitForBrowserContextMenu(aCallback) {
|
|
|
|
waitForPopupShown(gBrowser.selectedBrowser.contextMenu, aCallback);
|
|
|
|
}
|
2013-03-13 19:23:03 -07:00
|
|
|
|
|
|
|
function doOnloadOnce(aCallback) {
|
|
|
|
function doOnloadOnceListener(aEvent) {
|
|
|
|
info("doOnloadOnce: " + aEvent.originalTarget.location);
|
|
|
|
removeDoOnloadOnceListener();
|
2013-03-14 23:59:06 -07:00
|
|
|
SimpleTest.executeSoon(function doOnloadOnceCallback() {
|
|
|
|
aCallback(aEvent);
|
|
|
|
});
|
2013-03-13 19:23:03 -07:00
|
|
|
}
|
|
|
|
function removeDoOnloadOnceListener() {
|
2013-03-14 23:59:06 -07:00
|
|
|
gBrowser.removeEventListener("load", doOnloadOnceListener, true);
|
2013-03-13 19:23:03 -07:00
|
|
|
}
|
2013-03-14 23:59:06 -07:00
|
|
|
gBrowser.addEventListener("load", doOnloadOnceListener, true);
|
2013-03-13 19:23:03 -07:00
|
|
|
registerCleanupFunction(removeDoOnloadOnceListener);
|
|
|
|
}
|