summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabPrompts/browser_abort_when_in_modal_state.js
blob: cb3a1f72d672abd4f457b8422146dffa7a61994c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const { PromiseTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/PromiseTestUtils.sys.mjs"
);

/**
 * Check that if we're using a window-modal prompt,
 * the next synchronous window-internal modal prompt aborts rather than
 * leaving us in a deadlock about how to enter modal state.
 */
add_task(async function test_check_multiple_prompts() {
  await SpecialPowers.pushPrefEnv({
    set: [["prompts.windowPromptSubDialog", true]],
  });
  let container = document.getElementById("window-modal-dialog");
  let dialogPromise = BrowserTestUtils.promiseAlertDialogOpen();

  let firstDialogClosedPromise = new Promise(resolve => {
    // Avoid blocking the test on the (sync) alert by sticking it in a timeout:
    setTimeout(() => {
      Services.prompt.alertBC(
        window.browsingContext,
        Ci.nsIPrompt.MODAL_TYPE_WINDOW,
        "Some title",
        "some message"
      );
      resolve();
    }, 0);
  });
  let dialogWin = await dialogPromise;

  // Check circumstances of opening.
  ok(
    !dialogWin.docShell.chromeEventHandler,
    "Should not have embedded the dialog."
  );

  PromiseTestUtils.expectUncaughtRejection(/could not be shown/);
  let rv = Services.prompt.confirm(
    window,
    "I should not appear",
    "because another prompt was open"
  );
  is(rv, false, "Prompt should have been canceled.");

  info("Accepting dialog");
  dialogWin.document.querySelector("dialog").acceptDialog();

  await firstDialogClosedPromise;

  await BrowserTestUtils.waitForMutationCondition(
    container,
    { childList: true, attributes: true },
    () => !container.hasChildNodes() && !container.open
  );
});