Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tabs create Test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="text/javascript">
"use strict";
add_task(async function test_query_index() {
const extension = ExtensionTestUtils.loadExtension({
background: function() {
browser.tabs.onCreated.addListener(async function({index, windowId, id}) {
browser.test.assertThrows(
() => browser.tabs.query({index: -1}),
/-1 is too small \(must be at least 0\)/,
"tab indices must be non-negative");
let tabs = await browser.tabs.query({index, windowId});
browser.test.assertEq(tabs.length, 1, `Got one tab at index ${index}`);
browser.test.assertEq(tabs[0].id, id, "The tab is the right one");
tabs = await browser.tabs.query({index: 1e5, windowId});
browser.test.assertEq(tabs.length, 0, "There is no tab at this index");
browser.test.notifyPass("tabs.query");
});
},
});
await extension.startup();
const win = window.open("http://example.com");
await extension.awaitFinish("tabs.query");
win.close();
await extension.unload();
});
// On desktop Firefox, window.open() with the popup feature opens a tab in a
// new window with windowType "popup". On Android, there is no distinction
// between normal windows and popup windows, so treat them as type "normal".
add_task(async function test_query_windowType() {
const extension = ExtensionTestUtils.loadExtension({
background: function() {
browser.tabs.onCreated.addListener(async ({ id }) => {
let tabs = await browser.tabs.query({ windowType: "normal" });
browser.test.assertEq(
tabs.filter(t => t.id === id).length,
1,
"window.open() with popup is a normal type, not a popup"
);
browser.test.assertDeepEq(
await browser.tabs.query({ windowType: "popup" }),
[],
"There are no tabs with windowType popup on Android"
);
browser.test.sendMessage("done");
});
},
});
await extension.startup();
const win = window.open("http://example.com", "", "popup");
await extension.awaitMessage("done");
win.close();
await extension.unload();
});
</script>
</body>
</html>