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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
add_task(async function testQuery() {
let extension = ExtensionTestUtils.loadExtension({
files: {
"background.js": async () => {
// There should be a single mailtab at startup.
let tabs = await browser.tabs.query({});
browser.test.assertEq(1, tabs.length, "Found one tab at startup");
browser.test.assertEq("mail", tabs[0].type, "Tab is mail tab");
let mailTab = tabs[0];
// Create a content tab.
let contentTab = await browser.tabs.create({ url: "test.html" });
browser.test.assertTrue(
contentTab.id != mailTab.id,
"Id of content tab is different from mail tab"
);
// Query spaces.
let spaces = await browser.spaces.query({ id: mailTab.spaceId });
browser.test.assertEq(1, spaces.length, "Found one matching space");
browser.test.assertEq(
"mail",
spaces[0].name,
"Space is the mail space"
);
// Query for all tabs.
tabs = await browser.tabs.query({});
browser.test.assertEq(2, tabs.length, "Found two tabs");
// Query for the content tab.
tabs = await browser.tabs.query({ type: "content" });
browser.test.assertEq(1, tabs.length, "Found one content tab");
browser.test.assertEq(
contentTab.id,
tabs[0].id,
"Id of content tab is correct"
);
// Query for the mail tab using spaceId.
tabs = await browser.tabs.query({ spaceId: mailTab.spaceId });
browser.test.assertEq(1, tabs.length, "Found one mail tab");
browser.test.assertEq(
mailTab.id,
tabs[0].id,
"Id of mail tab is correct"
);
// Query for the mail tab using type.
tabs = await browser.tabs.query({ type: "mail" });
browser.test.assertEq(1, tabs.length, "Found one mail tab");
browser.test.assertEq(
mailTab.id,
tabs[0].id,
"Id of mail tab is correct"
);
// Query for the mail tab using mailTab.
tabs = await browser.tabs.query({ mailTab: true });
browser.test.assertEq(1, tabs.length, "Found one mail tab");
browser.test.assertEq(
mailTab.id,
tabs[0].id,
"Id of mail tab is correct"
);
// Query for the content tab but also using mailTab.
tabs = await browser.tabs.query({ mailTab: true, type: "content" });
browser.test.assertEq(1, tabs.length, "Found one mail tab");
browser.test.assertEq(
mailTab.id,
tabs[0].id,
"Id of mail tab is correct"
);
// Query for active tab.
tabs = await browser.tabs.query({ active: true });
browser.test.assertEq(1, tabs.length, "Found one mail tab");
browser.test.assertEq(
contentTab.id,
tabs[0].id,
"Id of mail tab is correct"
);
// Query for highlighted tab.
tabs = await browser.tabs.query({ highlighted: true });
browser.test.assertEq(1, tabs.length, "Found one mail tab");
browser.test.assertEq(
contentTab.id,
tabs[0].id,
"Id of mail tab is correct"
);
await browser.tabs.remove(contentTab.id);
browser.test.notifyPass();
},
"test.html": "<html><body>I'm a real page!</body></html>",
"utils.js": await getUtilsJS(),
},
manifest: {
background: { scripts: ["utils.js", "background.js"] },
},
});
await extension.startup();
await extension.awaitFinish();
await extension.unload();
});
|