forked from mirrors/gecko-dev
Bug 1916659, a=diannaS
Original Revision: https://phabricator.services.mozilla.com/D222629 Differential Revision: https://phabricator.services.mozilla.com/D222934
This commit is contained in:
parent
770ca42976
commit
99a9aef629
3 changed files with 61 additions and 2 deletions
|
|
@ -107,8 +107,29 @@ async function testUploadPrompt(confirmUpload) {
|
|||
// Wait for confirmation prompt
|
||||
let prompt = await promptPromise;
|
||||
ok(prompt, "Shown upload confirmation prompt");
|
||||
|
||||
is(prompt.ui.button0.label, "Upload", "Accept button label");
|
||||
ok(
|
||||
prompt.ui.button0.disabled,
|
||||
"Accept button should be disabled by the security delay initially."
|
||||
);
|
||||
|
||||
ok(prompt.ui.button1.hasAttribute("default"), "Cancel is default button");
|
||||
ok(
|
||||
!prompt.ui.button1.disabled,
|
||||
"Cancel button should not be disabled by the security delay."
|
||||
);
|
||||
|
||||
info("Wait for the security delay to pass.");
|
||||
let delayTime = Services.prefs.getIntPref("security.dialog_enable_delay");
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
await new Promise(resolve => setTimeout(resolve, delayTime + 100));
|
||||
|
||||
ok(
|
||||
!prompt.ui.button0.disabled,
|
||||
"Accept button should no longer be disabled."
|
||||
);
|
||||
ok(!prompt.ui.button1.disabled, "Cancel button should remain enabled.");
|
||||
|
||||
// Close confirmation prompt
|
||||
await PromptTestUtils.handlePrompt(prompt, {
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ export class PromptCollection {
|
|||
Services.prompt.MODAL_TYPE_TAB,
|
||||
title,
|
||||
message,
|
||||
buttonFlags,
|
||||
buttonFlags | Ci.nsIPrompt.BUTTON_DELAY_ENABLE,
|
||||
acceptLabel,
|
||||
null,
|
||||
null,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,45 @@
|
|||
|
||||
let dialogObserverTopic = "common-dialog-loaded";
|
||||
|
||||
function dialogObserver(subj) {
|
||||
function waitForButtonEnabledState(button) {
|
||||
return new Promise(resolve => {
|
||||
// Check if the button is already enabled (not disabled)
|
||||
if (!button.disabled) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a MutationObserver instance
|
||||
let win = button.ownerGlobal;
|
||||
let { MutationObserver } = win;
|
||||
const observer = new MutationObserver(mutationsList => {
|
||||
for (const mutation of mutationsList) {
|
||||
if (
|
||||
mutation.type === "attributes" &&
|
||||
mutation.attributeName === "disabled"
|
||||
) {
|
||||
if (!button.disabled) {
|
||||
// Resolve the promise when the button is enabled
|
||||
observer.disconnect(); // Stop observing
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Start observing the button for changes to the 'disabled' attribute
|
||||
observer.observe(button, {
|
||||
attributes: true,
|
||||
attributeFilter: ["disabled"],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function dialogObserver(subj) {
|
||||
let dialog = subj.document.querySelector("dialog");
|
||||
let acceptButton = dialog.getButton("accept");
|
||||
await waitForButtonEnabledState(acceptButton);
|
||||
|
||||
subj.document.querySelector("dialog").acceptDialog();
|
||||
sendAsyncMessage("promptAccepted");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue