Skip to content
Snippets Groups Projects
Verified Commit 4731a528 authored by Emma Zuehlcke's avatar Emma Zuehlcke Committed by Pier Angelo Vendrame
Browse files

Bug 1916659, a=diannaS

parent 06eb6c02
Branches
Tags
1 merge request!1453TB 43587: Rebased legacy onto 115.22.0esr
......@@ -101,8 +101,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, {
......
......@@ -156,7 +156,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, topic, data) {
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");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment