summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_tabs_incognito_not_allowed.js
blob: e998f64afc9ed192308cf65edf7bb96150aba9e2 (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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

add_task(async function testExecuteScriptIncognitoNotAllowed() {
  const url =
    "http://mochi.test:8888/browser/browser/components/extensions/test/browser/file_iframe_document.html";

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      // captureTab requires all_urls permission
      permissions: ["<all_urls>", "tabs", "tabHide"],
    },
    background() {
      browser.test.onMessage.addListener(async pbw => {
        // expect one tab from the non-pb window
        let tabs = await browser.tabs.query({ windowId: pbw.windowId });
        browser.test.assertEq(
          0,
          tabs.length,
          "unable to query tabs in private window"
        );
        tabs = await browser.tabs.query({ active: true });
        browser.test.assertEq(
          1,
          tabs.length,
          "unable to query active tab in private window"
        );
        browser.test.assertTrue(
          tabs[0].windowId != pbw.windowId,
          "unable to query active tab in private window"
        );

        // apis that take a tabId
        let tabIdAPIs = [
          "captureTab",
          "detectLanguage",
          "duplicate",
          "get",
          "hide",
          "reload",
          "getZoomSettings",
          "getZoom",
          "toggleReaderMode",
        ];
        for (let name of tabIdAPIs) {
          await browser.test.assertRejects(
            browser.tabs[name](pbw.tabId),
            /Invalid tab ID/,
            `should not be able to ${name}`
          );
        }
        await browser.test.assertRejects(
          browser.tabs.captureVisibleTab(pbw.windowId),
          /Invalid window ID/,
          "should not be able to duplicate"
        );
        await browser.test.assertRejects(
          browser.tabs.create({
            windowId: pbw.windowId,
            url: "http://mochi.test/",
          }),
          /Invalid window ID/,
          "unable to create tab in private window"
        );
        await browser.test.assertRejects(
          browser.tabs.executeScript(pbw.tabId, { code: "document.URL" }),
          /Invalid tab ID/,
          "should not be able to executeScript"
        );
        let currentTab = await browser.tabs.getCurrent();
        browser.test.assertTrue(
          !currentTab,
          "unable to get current tab in private window"
        );
        await browser.test.assertRejects(
          browser.tabs.highlight({ windowId: pbw.windowId, tabs: [pbw.tabId] }),
          /Invalid window ID/,
          "should not be able to highlight"
        );
        await browser.test.assertRejects(
          browser.tabs.insertCSS(pbw.tabId, {
            code: "* { background: rgb(42, 42, 42) }",
          }),
          /Invalid tab ID/,
          "should not be able to insertCSS"
        );
        await browser.test.assertRejects(
          browser.tabs.move(pbw.tabId, {
            index: 0,
            windowId: tabs[0].windowId,
          }),
          /Invalid tab ID/,
          "unable to move tab to private window"
        );
        await browser.test.assertRejects(
          browser.tabs.move(tabs[0].id, { index: 0, windowId: pbw.windowId }),
          /Invalid window ID/,
          "unable to move tab to private window"
        );
        await browser.test.assertRejects(
          browser.tabs.printPreview(),
          /Cannot access activeTab/,
          "unable to printpreview tab"
        );
        await browser.test.assertRejects(
          browser.tabs.removeCSS(pbw.tabId, {}),
          /Invalid tab ID/,
          "unable to remove tab css"
        );
        await browser.test.assertRejects(
          browser.tabs.sendMessage(pbw.tabId, "test"),
          /Could not establish connection/,
          "unable to sendmessage"
        );
        await browser.test.assertRejects(
          browser.tabs.setZoomSettings(pbw.tabId, {}),
          /Invalid tab ID/,
          "should not be able to set zoom settings"
        );
        await browser.test.assertRejects(
          browser.tabs.setZoom(pbw.tabId, 3),
          /Invalid tab ID/,
          "should not be able to set zoom"
        );
        await browser.test.assertRejects(
          browser.tabs.update(pbw.tabId, {}),
          /Invalid tab ID/,
          "should not be able to update tab"
        );
        await browser.test.assertRejects(
          browser.tabs.moveInSuccession([pbw.tabId], tabs[0].id),
          /Invalid tab ID/,
          "should not be able to moveInSuccession"
        );
        await browser.test.assertRejects(
          browser.tabs.moveInSuccession([tabs[0].id], pbw.tabId),
          /Invalid tab ID/,
          "should not be able to moveInSuccession"
        );

        browser.test.notifyPass("pass");
      });
    },
  });

  let winData = await getIncognitoWindow(url);
  await extension.startup();

  extension.sendMessage(winData.details);

  await extension.awaitFinish("pass");
  await BrowserTestUtils.closeWindow(winData.win);
  await extension.unload();
});