let dialogClosed = BrowserTestUtils.waitForEvent(
browserWin, "DOMModalDialogClosed"
);
let promptState; if (isSelect) {
promptState = getSelectState(ui);
dismissSelect(ui, action);
} else {
promptState = getPromptState(ui);
dismissPrompt(ui, action);
}
// Wait until the prompt has been closed before sending callback msg. // Unless the test explicitly doesn't request a button click. if (action.buttonClick !== "none") {
await dialogClosed;
}
let treeOwner =
ui.prompt && ui.prompt.docShell && ui.prompt.docShell.treeOwner; if (treeOwner && treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)) { // Check that the dialog is modal, chrome and dependent; // We can't just check window.opener because that'll be // a content window, which therefore isn't exposed (it'll lie and // be null).
let flags = treeOwner.getInterface(Ci.nsIAppWindow).chromeFlags;
state.chrome = (flags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_CHROME) != 0;
state.dialog = (flags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_DIALOG) != 0;
state.chromeDependent =
(flags & Ci.nsIWebBrowserChrome.CHROME_DEPENDENT) != 0;
let wbc = treeOwner.getInterface(Ci.nsIWebBrowserChrome);
state.isWindowModal = wbc.isWindowModal();
}
// Check the dialog is a common dialog document and has been embedded.
let isEmbedded = !!ui.prompt?.docShell?.chromeEventHandler;
let isCommonDialogDoc =
getDialogDoc()?.location.href.includes("commonDialog.xhtml");
state.isSubDialogPrompt = isCommonDialogDoc && isEmbedded;
state.showCallerOrigin = ui.prompt.args.showCallerOrigin;
return state;
}
function dismissSelect(ui, action) {
let dialog = ui.getElementsByTagName("dialog")[0];
let listbox = ui.getElementById("list");
if (action.selectItem) {
listbox.selectedIndex = 1;
}
function dismissPrompt(ui, action) { if (action.setCheckbox) { // Annoyingly, the prompt code is driven by oncommand.
ui.checkbox.checked = true;
ui.checkbox.doCommand();
}
if ("textField" in action) {
ui.loginTextbox.setAttribute("value", action.textField);
}
if ("passField" in action) {
ui.password1Textbox.setAttribute("value", action.passField);
}
switch (action.buttonClick) { case"ok": case 0:
ui.button0.click(); break; case"cancel": case 1:
ui.button1.click(); break; case 2:
ui.button2.click(); break; case"ESC": { // XXX This is assuming tab-modal.
let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
EventUtils.synthesizeKey("KEY_Escape", {}, browserWin); break;
} case"pollOK": { // Buttons are disabled at the moment, poll until they're reenabled. // Can't use setInterval here, because the window's in a modal state // and thus DOM events are suppressed.
let interval = setInterval(() => { if (ui.button0.disabled) { return;
}
ui.button0.click();
clearInterval(interval);
}, 100); break;
} case"abort_dialogs": {
let abortDialogEvent = new ui.prompt.CustomEvent("dialogclosing", {
bubbles: true,
detail: { abort: true },
});
ui.prompt.close(abortDialogEvent); break;
} case"none": break;
function getDialogDoc() { // Trudge through all the open windows, until we find the one // that has either commonDialog.xhtml or selectDialog.xhtml loaded. // var enumerator = Services.wm.getEnumerator("navigator:browser"); for (let { docShell } of Services.wm.getEnumerator(null)) { var containedDocShells = docShell.getAllDocShellsInSubtree(
docShell.typeChrome,
docShell.ENUMERATE_FORWARDS
); for (let childDocShell of containedDocShells) { // Get the corresponding document for this docshell // We don't want it if it's not done loading. if (childDocShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE) { continue;
} var childDoc = childDocShell.docViewer.DOMDocument;
// We're expecting the dialog to be focused. If it's not yet, try later. // (In particular, this is needed on Linux to reliably check focused elements.) if (Services.focus.focusedWindow != childDoc.defaultView) { continue;
}
return childDoc;
}
}
returnnull;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.11 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.