Source code

Revision control

Other Tools

1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
<title>Tabs getCurrent 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
add_task(async function() {
16
let extension = ExtensionTestUtils.loadExtension({
17
manifest: {
18
"permissions": ["tabs"],
19
},
20
21
files: {
22
"tab.js": function() {
23
let url = document.location.href;
24
25
browser.tabs.getCurrent().then(currentTab => {
26
browser.test.assertEq(currentTab.url, url, "getCurrent in non-active background tab");
27
28
// Activate the tab.
29
browser.tabs.onActivated.addListener(function listener({tabId}) {
30
if (tabId == currentTab.id) {
31
browser.tabs.onActivated.removeListener(listener);
32
33
browser.tabs.getCurrent().then(currentTab => {
34
browser.test.assertEq(currentTab.id, tabId, "in active background tab");
35
browser.test.assertEq(currentTab.url, url, "getCurrent in non-active background tab");
36
37
browser.test.sendMessage("tab-finished");
38
});
39
}
40
});
41
browser.tabs.update(currentTab.id, {active: true});
42
});
43
},
44
45
"tab.html": `<head><meta charset="utf-8"><script src="tab.js"><\/script></head>`,
46
},
47
48
background: function() {
49
browser.tabs.getCurrent().then(tab => {
50
browser.test.assertEq(tab, undefined, "getCurrent in background script");
51
browser.test.sendMessage("background-finished");
52
});
53
54
browser.tabs.create({url: "tab.html", active: false});
55
},
56
});
57
58
await extension.startup();
59
60
await extension.awaitMessage("background-finished");
61
await extension.awaitMessage("tab-finished");
62
63
// The extension tab is automatically closed when the extension unloads.
64
await extension.unload();
65
});
66
</script>
67
68
</body>
69
</html>