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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const DUMMY_PAGE =
"http://example.com/browser/browser/components/extensions/test/browser/file_dummy.html";
add_task(async function testPageActionFocus() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
page_action: {
default_popup: "popup.html",
show_matches: ["<all_urls>"],
},
},
files: {
"popup.html": `<!DOCTYPE html><html><head><meta charset="utf-8">
<script src="popup.js"></script>
</head><body>
</body></html>
`,
"popup.js": function () {
window.addEventListener(
"focus",
() => {
browser.test.log("extension popup received focus event");
browser.test.assertEq(
true,
document.hasFocus(),
"document should be focused"
);
browser.test.notifyPass("focused");
},
{ once: true }
);
browser.test.log(`extension popup loaded`);
},
},
});
await extension.startup();
await BrowserTestUtils.withNewTab(DUMMY_PAGE, async () => {
await clickPageAction(extension);
await extension.awaitFinish("focused");
await closePageAction(extension);
});
await extension.unload();
});
add_task(async function testBrowserActionFocus() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
browser_action: { default_popup: "popup.html" },
},
files: {
"popup.html": `<!DOCTYPE html><html><head><meta charset="utf-8">
<script src="popup.js"></script>
</head><body>
</body></html>
`,
"popup.js": function () {
window.addEventListener(
"focus",
() => {
browser.test.log("extension popup received focus event");
browser.test.assertEq(
true,
document.hasFocus(),
"document should be focused"
);
browser.test.notifyPass("focused");
},
{ once: true }
);
browser.test.log(`extension popup loaded`);
},
},
});
await extension.startup();
await clickBrowserAction(extension);
await extension.awaitFinish("focused");
await closeBrowserAction(extension);
await extension.unload();
});
|