summaryrefslogtreecommitdiffstats
path: root/mobile/android/components/extensions/test/mochitest/test_ext_tabs_query.html
blob: 9a907f47de2ccde07936a4e2b3dd12e9a1902fa9 (plain)
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
<!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();
});
</script>

</body>
</html>