summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_slow_script.js
blob: bd9369a904e6e367a3af252c386eb909594c3597 (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
61
62
63
64
65
66
67
68
69
70
71
72
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

const DEFAULT_PROCESS_COUNT = Services.prefs
  .getDefaultBranch(null)
  .getIntPref("dom.ipc.processCount");

add_task(async function test_slow_content_script() {
  // Make sure we get a new process for our tab, or our reportProcessHangs
  // preferences value won't apply to it.
  await SpecialPowers.pushPrefEnv({
    set: [
      ["dom.ipc.processCount", 1],
      ["dom.ipc.keepProcessesAlive.web", 0],
    ],
  });
  await SpecialPowers.popPrefEnv();

  await SpecialPowers.pushPrefEnv({
    set: [
      ["dom.ipc.processCount", DEFAULT_PROCESS_COUNT * 2],
      ["dom.ipc.processPrelaunch.enabled", false],
      ["dom.ipc.reportProcessHangs", true],
      ["dom.max_script_run_time.require_critical_input", false],
    ],
  });

  let extension = ExtensionTestUtils.loadExtension({
    useAddonManager: "temporary",

    manifest: {
      name: "Slow Script Extension",

      content_scripts: [
        {
          matches: ["http://example.com/"],
          js: ["content.js"],
        },
      ],
    },

    files: {
      "content.js": function () {
        while (true) {
          // Busy wait.
        }
      },
    },
  });

  await extension.startup();

  let alert = BrowserTestUtils.waitForGlobalNotificationBar(
    window,
    "process-hang"
  );

  BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");

  let notification = await alert;
  let text = notification.messageText.textContent;

  ok(text.includes("\u201cSlow Script Extension\u201d"), "Label is correct");

  let stopButton = notification.buttonContainer.querySelector("[label='Stop']");
  stopButton.click();

  BrowserTestUtils.removeTab(gBrowser.selectedTab);

  await extension.unload();
});