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
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
add_task(async function test_tab_options_privileges() {
function backgroundScript() {
browser.runtime.onMessage.addListener(async ({ msgName, tab }) => {
if (msgName == "removeTab") {
try {
const [activeTab] = await browser.tabs.query({ active: true });
browser.test.assertEq(
tab.id,
activeTab.id,
"tabs.getCurrent has got the expected tabId"
);
browser.test.assertEq(
tab.windowId,
activeTab.windowId,
"tabs.getCurrent has got the expected windowId"
);
await browser.tabs.remove(tab.id);
browser.test.notifyPass("options-ui-privileges");
} catch (error) {
browser.test.log(`Error: ${error} :: ${error.stack}`);
browser.test.notifyFail("options-ui-privileges");
}
}
});
browser.runtime.openOptionsPage();
}
async function optionsScript() {
try {
let [tab] = await browser.tabs.query({ url: "http://example.com/" });
browser.test.assertEq(
"http://example.com/",
tab.url,
"Got the expect tab"
);
tab = await browser.tabs.getCurrent();
browser.runtime.sendMessage({ msgName: "removeTab", tab });
} catch (error) {
browser.test.log(`Error: ${error} :: ${error.stack}`);
browser.test.notifyFail("options-ui-privileges");
}
}
const ID = "options_privileges@tests.mozilla.org";
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "temporary",
manifest: {
browser_specific_settings: { gecko: { id: ID } },
permissions: ["tabs"],
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>
</html>`,
"options.js": optionsScript,
},
background: backgroundScript,
});
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"http://example.com/"
);
await extension.startup();
await extension.awaitFinish("options-ui-privileges");
await extension.unload();
BrowserTestUtils.removeTab(tab);
});
|