blob: 4e42181e718b494b2f4348eca29f942879fa72cf (
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
|
"use strict";
const server = createHttpServer({ hosts: ["example.com"] });
server.registerDirectory("/data/", do_get_file("data"));
add_task(async function test_contentscript_api_injection() {
let extensionData = {
manifest: {
content_scripts: [
{
matches: ["http://example.com/data/file_sample.html"],
js: ["content_script.js"],
},
],
web_accessible_resources: ["content_script_iframe.html"],
},
files: {
"content_script.js"() {
let iframe = document.createElement("iframe");
iframe.src = browser.runtime.getURL("content_script_iframe.html");
document.body.appendChild(iframe);
},
"content_script_iframe.js"() {
window.location = `http://example.com/data/file_privilege_escalation.html`;
},
"content_script_iframe.html": `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="content_script_iframe.js"></script>
</head>
</html>`,
},
};
let extension = ExtensionTestUtils.loadExtension(extensionData);
let awaitConsole = new Promise(resolve => {
Services.console.registerListener(function listener(message) {
if (/WebExt Privilege Escalation/.test(message.message)) {
Services.console.unregisterListener(listener);
resolve(message);
}
});
});
await extension.startup();
let contentPage = await ExtensionTestUtils.loadContentPage(
"http://example.com/data/file_sample.html"
);
let message = await awaitConsole;
ok(
message.message.includes(
"WebExt Privilege Escalation: typeof(browser) = undefined"
),
"Document does not have `browser` APIs."
);
await contentPage.close();
await extension.unload();
});
|