summaryrefslogtreecommitdiffstats
path: root/toolkit/components/alerts/test/browser_bug1682866.js
blob: 7ac776d5b544ca07fa332a5fcaea6e63a9f8ed20 (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
const baseURL = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content",
  "http://example.com"
);

const alertURL = `${baseURL}file_bug1682866.html`;

add_task(async function testAlertForceClosed() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    alertURL,
    true /* waitForLoad */
  );

  // Open a second which is in the same process as tab
  let secondTabIsLoaded = BrowserTestUtils.waitForNewTab(
    gBrowser,
    alertURL,
    true,
    false
  );

  let isSuspendedAfterAlert = await SpecialPowers.spawn(
    tab.linkedBrowser.browsingContext,
    [alertURL],
    url => {
      content.open(url);
      var utils = SpecialPowers.getDOMWindowUtils(content);
      return utils.isInputTaskManagerSuspended;
    }
  );

  await secondTabIsLoaded;

  let secondTab = gBrowser.tabs[2];

  is(
    isSuspendedAfterAlert,
    Services.prefs.getBoolPref("dom.input_events.canSuspendInBCG.enabled"),
    "InputTaskManager should be suspended because alert is opened"
  );

  let alertClosed = BrowserTestUtils.waitForEvent(
    tab.linkedBrowser,
    "DOMModalDialogClosed"
  );

  BrowserTestUtils.loadURIString(tab.linkedBrowser, "about:newtab");

  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

  await alertClosed;

  gBrowser.removeTab(tab);
  gBrowser.removeTab(secondTab);
});