summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_tabs_attention.js
blob: 0f267460f33d046cff1c5debd0e59058b0799075 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

add_task(async function tabsAttention() {
  let tab1 = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "http://example.com/?2",
    true
  );
  let tab2 = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "http://example.com/?1",
    true
  );
  gBrowser.selectedTab = tab2;

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      permissions: ["tabs", "http://example.com/*"],
    },

    background: async function () {
      function onActive(tabId, changeInfo, tab) {
        browser.test.assertFalse(
          changeInfo.attention,
          "changeInfo.attention should be false"
        );
        browser.test.assertFalse(
          tab.attention,
          "tab.attention should be false"
        );
        browser.test.assertTrue(tab.active, "tab.active should be true");
        browser.test.notifyPass("tabsAttention");
      }

      function onUpdated(tabId, changeInfo, tab) {
        browser.test.assertTrue(
          changeInfo.attention,
          "changeInfo.attention should be true"
        );
        browser.test.assertTrue(tab.attention, "tab.attention should be true");
        browser.tabs.onUpdated.removeListener(onUpdated);
        browser.tabs.onUpdated.addListener(onActive);
        browser.tabs.update(tabId, { active: true });
      }

      browser.tabs.onUpdated.addListener(onUpdated, {
        properties: ["attention"],
      });
      const tabs = await browser.tabs.query({ index: 1 });
      browser.tabs.executeScript(tabs[0].id, {
        code: `alert("tab attention")`,
      });
    },
  });

  await extension.startup();
  await extension.awaitFinish("tabsAttention");
  await extension.unload();

  BrowserTestUtils.removeTab(tab1);
  BrowserTestUtils.removeTab(tab2);
});