/** * Wait for a <notification> to be closed then call the specified callback.
*/ function waitForNotificationClose(notification, cb) {
let observer = new MutationObserver(function onMutatations(mutations) { for (let mutation of mutations) { for (let i = 0; i < mutation.removedNodes.length; i++) {
let node = mutation.removedNodes.item(i); if (node != notification) { continue;
}
observer.disconnect();
cb();
}
}
});
observer.observe(notification.control.stack, { childList: true });
}
function closeAllNotifications() { if (!gNotificationBox.currentNotification) { return Promise.resolve();
}
returnnew Promise(resolve => { for (let notification of gNotificationBox.allNotifications) {
waitForNotificationClose(notification, function () { if (gNotificationBox.allNotifications.length === 0) {
resolve();
}
});
notification.close();
}
});
}
function whenDelayedStartupFinished(aWindow, aCallback) {
Services.obs.addObserver(function observer(aSubject, aTopic) { if (aWindow == aSubject) {
Services.obs.removeObserver(observer, aTopic);
executeSoon(aCallback);
}
}, "browser-delayed-startup-finished");
}
function openToolbarCustomizationUI(aCallback, aBrowserWin) { if (!aBrowserWin) {
aBrowserWin = window;
}
/** * Allows setting focus on a window, and waiting for that window to achieve * focus. * * @param aWindow * The window to focus and wait for. * * @return {Promise} * @resolves When the window is focused. * @rejects Never.
*/ function promiseWaitForFocus(aWindow) { returnnew Promise(resolve => {
waitForFocus(resolve, aWindow);
});
}
function pushPrefs(...aPrefs) { return SpecialPowers.pushPrefEnv({ set: aPrefs });
}
function popPrefs() { return SpecialPowers.popPrefEnv();
}
function promiseWindowClosed(win) {
let promise = BrowserTestUtils.domWindowClosed(win);
win.close(); return promise;
}
async function whenNewTabLoaded(aWindow, aCallback) {
aWindow.BrowserCommands.openTab();
let expectedURL = AboutNewTab.newTabURL;
let browser = aWindow.gBrowser.selectedBrowser;
let loadPromise = BrowserTestUtils.browserLoaded(browser, false, expectedURL);
let alreadyLoaded = await SpecialPowers.spawn(browser, [expectedURL], url => {
let doc = content.document; return doc && doc.readyState === "complete" && doc.location.href == url;
}); if (!alreadyLoaded) {
await loadPromise;
}
aCallback();
}
function whenTabLoaded(aTab, aCallback) {
promiseTabLoadEvent(aTab).then(aCallback);
}
/** * Waits for a load (or custom) event to finish in a given tab. If provided * load an uri into the tab. * * @param tab * The tab to load into. * @param [optional] url * The url to load, or the current url. * @return {Promise} resolved when the event is handled. * @resolves to the received event * @rejects if a valid load event is not received within a meaningful interval
*/ function promiseTabLoadEvent(tab, url) {
info("Wait tab event: load");
function handle(loadedUrl) { if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) {
info(`Skipping spurious load event for ${loadedUrl}`); returnfalse;
}
info("Tab event received: load"); returntrue;
}
let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle);
if (url) {
BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, url);
}
return loaded;
}
function is_hidden(element) { var style = element.ownerGlobal.getComputedStyle(element); if (style.display == "none") { returntrue;
} if (style.visibility != "visible") { returntrue;
} if (XULPopupElement.isInstance(element)) { return ["hiding", "closed"].includes(element.state);
}
// Hiding a parent element will hide all its children if (element.parentNode != element.ownerDocument) { return is_hidden(element.parentNode);
}
returnfalse;
}
function is_element_visible(element, msg) {
isnot(element, null, "Element should not be null, when checking visibility");
ok(BrowserTestUtils.isVisible(element), msg || "Element should be visible");
}
function is_element_hidden(element, msg) {
isnot(element, null, "Element should not be null, when checking visibility");
ok(is_hidden(element), msg || "Element should be hidden");
}
function promisePopupShown(popup) { return BrowserTestUtils.waitForPopupEvent(popup, "shown");
}
function promisePopupHidden(popup) { return BrowserTestUtils.waitForPopupEvent(popup, "hidden");
}
function promiseNotificationShown(notification) {
let win = notification.browser.ownerGlobal; if (win.PopupNotifications.panel.state == "open") { return Promise.resolve();
}
let panelPromise = promisePopupShown(win.PopupNotifications.panel);
notification.reshow(); return panelPromise;
}
/** * Resolves when a bookmark with the given uri is added.
*/ function promiseOnBookmarkItemAdded(aExpectedURI) { returnnew Promise((resolve, reject) => {
let listener = events => {
is(events.length, 1, "Should only receive one event.");
info("Added a bookmark to " + events[0].url);
PlacesUtils.observers.removeListener(["bookmark-added"], listener); if (events[0].url == aExpectedURI.spec) {
resolve();
} else {
reject(new Error("Added an unexpected bookmark"));
}
};
info("Waiting for a bookmark to be added");
PlacesUtils.observers.addListener(["bookmark-added"], listener);
});
}
async function loadBadCertPage(url, feltPrivacy = false) {
let loaded = BrowserTestUtils.waitForErrorPage(gBrowser.selectedBrowser);
BrowserTestUtils.startLoadingURIString(gBrowser.selectedBrowser, url);
await loaded;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.