gecko/browser/components/search/test/head.js
Matthew Noorenberghe c2e58bd3d3 Bug 851040 - Try to fix intermittent browser/components/search/test/browser_contextmenu.js. a=test-only
--HG--
extra : rebase_source : b147ecee975683729e21d1fdc231b33e026865c8
2013-03-14 23:59:06 -07:00

54 lines
1.8 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* 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 + "]");
}
}
}
function waitForPopupShown(aPopupId, aCallback) {
let popup = document.getElementById(aPopupId);
info("waitForPopupShown: got popup: " + popup.id);
function onPopupShown() {
info("onPopupShown");
removePopupShownListener();
SimpleTest.executeSoon(aCallback);
}
function removePopupShownListener() {
popup.removeEventListener("popupshown", onPopupShown);
}
popup.addEventListener("popupshown", onPopupShown);
registerCleanupFunction(removePopupShownListener);
}
function waitForBrowserContextMenu(aCallback) {
waitForPopupShown(gBrowser.selectedBrowser.contextMenu, aCallback);
}
function doOnloadOnce(aCallback) {
function doOnloadOnceListener(aEvent) {
info("doOnloadOnce: " + aEvent.originalTarget.location);
removeDoOnloadOnceListener();
SimpleTest.executeSoon(function doOnloadOnceCallback() {
aCallback(aEvent);
});
}
function removeDoOnloadOnceListener() {
gBrowser.removeEventListener("load", doOnloadOnceListener, true);
}
gBrowser.addEventListener("load", doOnloadOnceListener, true);
registerCleanupFunction(removeDoOnloadOnceListener);
}