summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/mochitest/test_ext_script_filenames.html
blob: de0993c33d1ba9c5ba5ff3cf7fe81816fb670bd1 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Script Filenames Test</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
  <script type="text/javascript" src="head.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>

<script type="text/javascript">
"use strict";

add_task(async function test_tabs_executeScript() {
  let validFileName = "script.js";
  let invalidFileName = "script.xyz";

  async function background() {
    await browser.tabs.executeScript({ file: "script.js" });

    await browser.test.assertRejects(
      browser.tabs.executeScript({ file: "script.xyz" }),
      Error,
      "invalid filename does not execute"
    );
    browser.test.notifyPass("execute-script");
  }

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      permissions: ["<all_urls>"],
    },

    background,

    files: {
      [validFileName]: function contentScript1() {
        browser.test.sendMessage("content-script-loaded");
      },
      [invalidFileName]: function contentScript2() {
        browser.test.fail("this script should not be loaded");
      },
    },
  });

  let tab = await AppTestDelegate.openNewForegroundTab(
    window,
    "http://mochi.test:8888/",
    true
  );
  await extension.startup();

  await extension.awaitMessage("content-script-loaded");
  await extension.awaitFinish("execute-script");

  await extension.unload();
  await AppTestDelegate.removeTab(window, tab);
});
</script>
</body>
</html>