Verified Commit a22b191f authored by Emma Zuehlcke's avatar Emma Zuehlcke Committed by ma1
Browse files

Bug 1916659, a=diannaS

parent 55489055
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -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, {
+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ export class PromptCollection {
        Services.prompt.MODAL_TYPE_TAB,
        title,
        message,
        buttonFlags,
        buttonFlags | Ci.nsIPrompt.BUTTON_DELAY_ENABLE,
        acceptLabel,
        null,
        null,
+39 −1
Original line number Diff line number Diff line
@@ -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");
}