summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_optionsPage_links_open_in_tabs.js
blob: 147754b344352623c2bb96d9e0bd5dc5dae5131e (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_options_links() {
  async function backgroundScript() {
    browser.runtime.openOptionsPage();
  }

  function optionsScript() {
    browser.test.sendMessage("options-page:loaded", document.documentURI);
  }

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

    manifest: {
      options_ui: {
        page: "options.html",
      },
    },
    files: {
      "options.html": `<!DOCTYPE html>
        <html>
          <head>
            <meta charset="utf-8">
            <script src="options.js" type="text/javascript"></script>
          </head>
          <body style="height: 100px;">
            <h1>Extensions Options</h1>
            <a href="https://example.com/options-page-link">options page link</a>
          </body>
        </html>`,
      "options.js": optionsScript,
    },
    background: backgroundScript,
  });

  const aboutAddonsTab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "about:addons"
  );

  await extension.startup();

  await extension.awaitMessage("options-page:loaded");

  const optionsBrowser = getInlineOptionsBrowser(gBrowser.selectedBrowser);

  const promiseNewTabOpened = BrowserTestUtils.waitForNewTab(
    gBrowser,
    "https://example.com/options-page-link"
  );
  await SpecialPowers.spawn(optionsBrowser, [], () =>
    content.document.querySelector("a").click()
  );
  info(
    "Expect a new tab to be opened when a link is clicked in the options_page embedded inside about:addons"
  );
  const newTab = await promiseNewTabOpened;
  ok(newTab, "Got a new tab created on the expected url");
  BrowserTestUtils.removeTab(newTab);

  BrowserTestUtils.removeTab(aboutAddonsTab);

  await extension.unload();
});