// Press an accesskey in the child document while the chrome is focused.
let focusedId = await performAccessKey(tab1.linkedBrowser, "y");
is(focusedId, "button", "button accesskey");
// Press an accesskey in the child document while the content document is focused.
focusedId = await performAccessKey(tab1.linkedBrowser, "z");
is(focusedId, "checkbox", "checkbox accesskey");
// Add an element with an accesskey to the chrome and press its accesskey while the chrome is focused.
let newButton = document.createXULElement("button");
newButton.id = "chromebutton";
newButton.setAttribute("aria-label", "chromebutton");
newButton.setAttribute("accesskey", "z");
document.documentElement.appendChild(newButton);
Services.focus.clearFocus(window);
newButton.getBoundingClientRect(); // Accesskey registration happens during frame construction.
// Add a second tab and ensure that accesskey from the first tab is not used. const gPageURL2 = "data:text/html," + "" + "";
let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, gPageURL2);
// Press the accesskey for the chrome element while the content document is focused.
focusedId = await performAccessKeyForChrome("z");
is(focusedId, "chromebutton", "chromebutton accesskey");
// Test whether access key for the newButton isn't available when content // consumes the key event.
// When content in the tab3 consumes all keydown events. const gPageURL3 = "data:text/html," + "" + "";
let tab3 = await BrowserTestUtils.openNewForegroundTab(gBrowser, gPageURL3);
Services.focus.clearFocus(window);
focusedId = await performAccessKey(tab3.linkedBrowser, "y");
is(focusedId, "tab3button", "button accesskey in tab3 should be focused");
newButton.onfocus = () => {
ok(false, "chromebutton shouldn't get focus during testing with tab3");
};
// Press the accesskey for the chrome element while the content document is focused.
focusedId = await performAccessKey(tab3.linkedBrowser, "z");
is(
focusedId, "tab3body", "button accesskey in tab3 should keep having focus"
);
newButton.onfocus = null;
gBrowser.removeTab(tab3);
// When content in the tab4 consumes all keypress events. const gPageURL4 = "data:text/html," + "" + "";
let tab4 = await BrowserTestUtils.openNewForegroundTab(gBrowser, gPageURL4);
Services.focus.clearFocus(window);
focusedId = await performAccessKey(tab4.linkedBrowser, "y");
is(focusedId, "tab4button", "button accesskey in tab4 should be focused");
newButton.onfocus = () => { // EventStateManager handles accesskey before dispatching keypress event // into the DOM tree, therefore, chrome accesskey always wins focus from // content. However, this is different from shortcut keys.
todo(false, "chromebutton shouldn't get focus during testing with tab4");
};
// Press the accesskey for the chrome element while the content document is focused.
focusedId = await performAccessKey(tab4.linkedBrowser, "z");
is(
focusedId, "tab4body", "button accesskey in tab4 should keep having focus"
);
newButton.onfocus = null;
gBrowser.removeTab(tab4);
newButton.remove();
});
function performAccessKey(browser, key) { returnnew Promise(resolve => {
let removeFocus, removeKeyDown, removeKeyUp; function callback() {
removeFocus();
removeKeyUp();
removeKeyDown();
// Spawn an no-op content task to better ensure that the messages // for adding the event listeners above get handled.
SpecialPowers.spawn(browser, [], () => {}).then(() => {
EventUtils.synthesizeKey(key, { altKey: true, shiftKey: true });
});
});
}
// This version is used when a chrome element is expected to be found for an accesskey.
async function performAccessKeyForChrome(key) {
let waitFocusChangePromise = BrowserTestUtils.waitForEvent(
document, "focus", true
);
EventUtils.synthesizeKey(key, { altKey: true, shiftKey: true });
await waitFocusChangePromise; return document.activeElement.id;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.68 Sekunden
(vorverarbeitet)
¤
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.