summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/browser/browser_ext_windows_popup_title.js
blob: 21ef6bf460cd0a7a8066ddbb1893a49b1ad8300e (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
"use strict";

// Check that extension popup windows contain the name of the extension
// as well as the title of the loaded document, but not the URL.
add_task(async function test_popup_title() {
  const name = "custom_title_number_9_please";
  const docTitle = "popup-test-title";

  const extension = ExtensionTestUtils.loadExtension({
    manifest: {
      name,
      permissions: ["tabs"],
    },

    async background() {
      let popup;

      // Called after the popup loads
      browser.runtime.onMessage.addListener(async ({ docTitle }) => {
        const { id } = await popup;
        const { title } = await browser.windows.get(id);
        browser.windows.remove(id);

        browser.test.assertTrue(
          title.includes(name),
          "popup title must include extension name"
        );
        browser.test.assertTrue(
          title.includes(docTitle),
          "popup title must include extension document title"
        );
        browser.test.assertFalse(
          title.includes("moz-extension:"),
          "popup title must not include extension URL"
        );

        browser.test.notifyPass("popup-window-title");
      });

      popup = browser.windows.create({
        url: "/index.html",
        type: "popup",
      });
    },
    files: {
      "index.html": `<!doctype html>
        <meta charset="utf-8">
        <title>${docTitle}</title>,
        <script src="index.js"></script>
      `,
      "index.js": `addEventListener(
          "load",
          () => browser.runtime.sendMessage({docTitle: document.title})
         );`,
    },
  });

  await extension.startup();
  await extension.awaitFinish("popup-window-title");
  await extension.unload();
});