/** *Anutilityfunctiontowritesometextinthesearchinputbox *inacontentpage. * *@param{object}browser *Thebrowserthatcontainsthecontent. *@param{string}text *Thestringtowriteinthesearchfield. *@param{string}fieldName *Thenameofthefieldtowriteto.
*/
let typeInSearchField = async function (browser, text, fieldName) {
await SpecialPowers.spawn(
browser,
[fieldName, text],
async function (contentFieldName, contentText) { // Put the focus on the search box.
let searchInput = content.document.getElementById(contentFieldName);
searchInput.focus();
searchInput.value = contentText;
}
);
};
/** *Givena<xul:browser>atsomenon-internalwebpage, *returnsomethingthatresemblesannsIContentPermissionRequest, *usingthebrowserscurrentlyloadeddocumenttogetaprincipal. * *@parambrowser(<xul:browser>) *Thebrowserthatwe'llcreateansIContentPermissionRequest *for. *@returnsAnsIContentPermissionRequest-ishobject.
*/ function makeMockPermissionRequest(browser) {
let type = {
options: Cc["@mozilla.org/array;1"].createInstance(Ci.nsIArray),
QueryInterface: ChromeUtils.generateQI(["nsIContentPermissionType"]),
};
let types = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
types.appendElement(type);
let principal = browser.contentPrincipal;
let result = {
types,
isHandlingUserInput: false,
principal,
topLevelPrincipal: principal,
requester: null,
_cancelled: false,
cancel() { this._cancelled = true;
},
_allowed: false,
allow() { this._allowed = true;
},
getDelegatePrincipal() { return principal;
},
QueryInterface: ChromeUtils.generateQI(["nsIContentPermissionRequest"]),
};
// In the e10s-case, nsIContentPermissionRequest will have // element defined. window is defined otherwise. if (browser.isRemoteBrowser) {
result.element = browser;
} else {
result.window = browser.contentWindow;
}
return result;
}
/** *ForanopenedPopupNotification,clicksonthemainaction, *andwaitsforthepaneltofullyclose. * *@return{Promise} *Resolvesoncethepanelhasfiredthe"popuphidden" *event.
*/
async function clickMainAction() {
let removePromise = BrowserTestUtils.waitForEvent(
PopupNotifications.panel, "popuphidden"
);
let popupNotification = getPopupNotificationNode();
await popupNotification.button.updateComplete;
popupNotification.button.click(); return removePromise;
}
/** *ForanopenedPopupNotification,clicksonthesecondaryaction, *andwaitsforthepaneltofullyclose. * *@paramactionIndex(Number) *Theindexofthesecondaryactiontobeclicked.Thedefault *secondaryaction(thebuttonshowndirectlyinthepanel)is *treatedashavingindex0. * *@return{Promise} *Resolvesoncethepanelhasfiredthe"popuphidden" *event.
*/ function clickSecondaryAction(actionIndex) {
let removePromise = BrowserTestUtils.waitForEvent(
PopupNotifications.panel, "popuphidden"
);
let popupNotification = getPopupNotificationNode(); if (!actionIndex) {
popupNotification.secondaryButton.click(); return removePromise;
}
return (async function () { // Click the dropmarker arrow and wait for the menu to show up.
let dropdownPromise = BrowserTestUtils.waitForEvent(
popupNotification.menupopup, "popupshown"
);
await popupNotification.secondaryButton.updateComplete;
await EventUtils.synthesizeMouseAtCenter(
popupNotification.secondaryButton.chevronButtonEl,
{}
);
await dropdownPromise;
// The menuitems in the dropdown are accessible as direct children of the panel, // because they are injected into a <children> node in the XBL binding. // The target action is the menuitem at index actionIndex - 1, because the first // secondary action (index 0) is the button shown directly in the panel.
let actionMenuItem =
popupNotification.querySelectorAll("menuitem")[actionIndex - 1]; if (popupNotification.menupopup.isNativeMenu) {
popupNotification.menupopup.activateItem(actionMenuItem);
} else {
EventUtils.synthesizeMouseAtCenter(actionMenuItem, {});
}
await removePromise;
})();
}
/** *Makessurethat1(andonly1)<xul:popupnotification>isbeingdisplayed *byPopupNotification,andthenreturnsthat<xul:popupnotification>. * *@return{<xul:popupnotification>}
*/ function getPopupNotificationNode() { // PopupNotification is a bit overloaded here, so to be // clear, popupNotifications is a list of <xul:popupnotification> // nodes.
let popupNotifications = PopupNotifications.panel.childNodes; Assert.equal(
popupNotifications.length, 1, "Should be showing a <xul:popupnotification>"
); return popupNotifications[0];
}
/** *Disablenon-releasepageactions(thataretestedelsewhere). * *@returnvoid
*/
async function disableNonReleaseActions() { if (!["release", "esr"].includes(AppConstants.MOZ_UPDATE_CHANNEL)) {
SpecialPowers.Services.prefs.setBoolPref( "extensions.webcompat-reporter.enabled", false
);
}
}
function assertActivatedPageActionPanelHidden() { Assert.ok(
!document.getElementById(BrowserPageActions._activatedActionPanelID)
);
}
function promiseOpenPageActionPanel() {
let dwu = window.windowUtils; return TestUtils.waitForCondition(() => { // Wait for the main page action button to become visible. It's hidden for // some URIs, so depending on when this is called, it may not yet be quite // visible. It's up to the caller to make sure it will be visible.
info("Waiting for main page action button to have non-0 size");
let bounds = dwu.getBoundsWithoutFlushing(
BrowserPageActions.mainButtonNode
); return bounds.width > 0 && bounds.height > 0;
})
.then(() => { // Wait for the panel to become open, by clicking the button if necessary.
info("Waiting for main page action panel to be open"); if (BrowserPageActions.panelNode.state == "open") { return Promise.resolve();
}
let shownPromise = promisePageActionPanelShown();
EventUtils.synthesizeMouseAtCenter(BrowserPageActions.mainButtonNode, {}); return shownPromise;
})
.then(() => { // Wait for items in the panel to become visible. return promisePageActionViewChildrenVisible(
BrowserPageActions.mainViewNode
);
});
}
function promisePageActionPanelShown() { return promisePanelShown(BrowserPageActions.panelNode);
}
function promisePageActionPanelHidden() { return promisePanelHidden(BrowserPageActions.panelNode);
}
function promisePanelShown(panelIDOrNode) { return promisePanelEvent(panelIDOrNode, "popupshown");
}
function promisePanelHidden(panelIDOrNode) { return promisePanelEvent(panelIDOrNode, "popuphidden");
}
function promisePanelEvent(panelIDOrNode, eventType) { returnnew Promise(resolve => {
let panel = panelIDOrNode; if (typeof panel == "string") {
panel = document.getElementById(panelIDOrNode); if (!panel) { thrownew Error(`Panel with ID "${panelIDOrNode}" does not exist.`);
}
} if (
(eventType == "popupshown" && panel.state == "open") ||
(eventType == "popuphidden" && panel.state == "closed")
) {
executeSoon(resolve); return;
}
panel.addEventListener(
eventType,
() => {
executeSoon(resolve);
},
{ once: true }
);
});
}
function promisePageActionViewShown() {
info("promisePageActionViewShown waiting for ViewShown"); return BrowserTestUtils.waitForEvent(
BrowserPageActions.panelNode, "ViewShown"
).then(async event => {
let panelViewNode = event.originalTarget;
await promisePageActionViewChildrenVisible(panelViewNode); return panelViewNode;
});
}
async function promisePageActionViewChildrenVisible(panelViewNode) {
info( "promisePageActionViewChildrenVisible waiting for a child node to be visible"
);
await new Promise(requestAnimationFrame);
let dwu = window.windowUtils; return TestUtils.waitForCondition(() => {
let bodyNode = panelViewNode.firstElementChild; for (let childNode of bodyNode.children) {
let bounds = dwu.getBoundsWithoutFlushing(childNode); if (bounds.width > 0 && bounds.height > 0) { returntrue;
}
} returnfalse;
});
}
async function initPageActionsTest() {
await disableNonReleaseActions();
// Make the main button visible. It's not unless the window is narrow. This // test isn't concerned with that behavior. We have other tests for that.
BrowserPageActions.mainButtonNode.style.display = "flex";
registerCleanupFunction(() => {
BrowserPageActions.mainButtonNode.style.removeProperty("display");
});
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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.