async function runTest() {
let win = window.browsingContext.topChromeWindow.open("file_edit_contextmenu.xhtml", "_blank", "chrome,width=600,height=600");
await new Promise(r => win.addEventListener("load", r, { once: true }));
await SimpleTest.promiseFocus(win);
const elements = [
win.document.querySelector("textarea"),
win.document.querySelector("input"),
win.document.querySelector("search-textbox"),
win.document.querySelector("shadow-input").shadowRoot.querySelector("input"),
// Intentionally twice to test revealing and un-revealing.
win.document.querySelector("input[type=password]"),
win.document.querySelector("input[type=password]"),
];
for (const element of elements) {
await testElement(element, win);
}
win.close();
SimpleTest.finish();
}
async function testElement(element, win) {
ok(element, "element exists");
info("Synthesizing a key so 'Undo' will be enabled");
element.focus();
synthesizeKey("x", {}, win);
is(element.value, "x", "initial value");
element.select();
synthesizeKey("c", { accelKey: true }, win); // copy to clipboard
synthesizeKey("KEY_ArrowRight", {}, win); // drop selection to disable cut and copy context menu items
win.document.addEventListener("contextmenu", (e) => {
info("Calling prevent default on the first contextmenu event");
e.preventDefault();
}, { once: true });
synthesizeMouseAtCenter(element, {type: "contextmenu"}, win);
ok(!win.document.getElementById("textbox-contextmenu"), "contextmenu with preventDefault() doesn't run");
let popupshown = new Promise(r => win.addEventListener("popupshown", r, { once: true }));
synthesizeMouseAtCenter(element, {type: "contextmenu"}, win);
let contextmenu = win.document.getElementById("textbox-contextmenu");
ok(contextmenu, "context menu exists after right click");
await popupshown;
// Check that we only got the one context menu, and not two.
let outerContextmenu = win.document.getElementById("outer-context-menu");
ok(outerContextmenu.state == "closed", "the outer context menu state is is not closed, it's: " + outerContextmenu.state);
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.