Source code

Revision control

Other Tools

1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
<title>Tabs executeScript Good Test</title>
5
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6
<script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
7
<script type="text/javascript" src="head.js"></script>
8
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
9
</head>
10
<body>
11
12
<script type="text/javascript">
13
"use strict";
14
15
async function testHasPermission(params) {
16
let contentSetup = params.contentSetup || (() => Promise.resolve());
17
18
async function background(contentSetup) {
19
browser.runtime.onMessage.addListener((msg, sender) => {
20
browser.test.assertEq(msg, "script ran", "script ran");
21
browser.test.notifyPass("executeScript");
22
});
23
24
browser.test.onMessage.addListener(msg => {
25
browser.test.assertEq(msg, "execute-script");
26
27
browser.tabs.executeScript({
28
file: "script.js",
29
});
30
});
31
32
await contentSetup();
33
34
browser.test.sendMessage("ready");
35
}
36
37
let extension = ExtensionTestUtils.loadExtension({
38
manifest: params.manifest,
39
40
background: `(${background})(${contentSetup})`,
41
42
files: {
43
"script.js": function() {
44
browser.runtime.sendMessage("script ran");
45
},
46
},
47
});
48
49
await extension.startup();
50
await extension.awaitMessage("ready");
51
52
if (params.setup) {
53
await params.setup(extension);
54
}
55
56
extension.sendMessage("execute-script");
57
58
await extension.awaitFinish("executeScript");
59
60
if (params.tearDown) {
61
await params.tearDown(extension);
62
}
63
64
await extension.unload();
65
}
66
67
add_task(async function testGoodPermissions() {
68
let win = window.open("http://mochi.test:8888/");
69
70
info("Test explicit host permission");
71
await testHasPermission({
72
manifest: {"permissions": ["http://mochi.test/"]},
73
});
74
75
info("Test explicit host subdomain permission");
76
await testHasPermission({
77
manifest: {"permissions": ["http://*.mochi.test/"]},
78
});
79
80
info("Test explicit <all_urls> permission");
81
await testHasPermission({
82
manifest: {"permissions": ["<all_urls>"]},
83
});
84
85
win.close();
86
});
87
</script>
88
89
</body>
90
</html>