summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_sidebarAction_incognito.js
blob: 221447cf2ea4e510dd26fc31172feab7f26d813d (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
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

add_task(async function test_sidebarAction_not_allowed() {
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      sidebar_action: {
        default_panel: "sidebar.html",
      },
    },
    background() {
      browser.test.onMessage.addListener(async pbw => {
        await browser.test.assertRejects(
          browser.sidebarAction.setTitle({
            windowId: pbw.windowId,
            title: "test",
          }),
          /Invalid window ID/,
          "should not be able to set title with windowId"
        );
        await browser.test.assertRejects(
          browser.sidebarAction.setTitle({
            tabId: pbw.tabId,
            title: "test",
          }),
          /Invalid tab ID/,
          "should not be able to set title"
        );
        await browser.test.assertRejects(
          browser.sidebarAction.getTitle({
            windowId: pbw.windowId,
          }),
          /Invalid window ID/,
          "should not be able to get title with windowId"
        );
        await browser.test.assertRejects(
          browser.sidebarAction.getTitle({
            tabId: pbw.tabId,
          }),
          /Invalid tab ID/,
          "should not be able to get title with tabId"
        );

        await browser.test.assertRejects(
          browser.sidebarAction.setIcon({
            windowId: pbw.windowId,
            path: "test",
          }),
          /Invalid window ID/,
          "should not be able to set icon with windowId"
        );
        await browser.test.assertRejects(
          browser.sidebarAction.setIcon({
            tabId: pbw.tabId,
            path: "test",
          }),
          /Invalid tab ID/,
          "should not be able to set icon with tabId"
        );

        await browser.test.assertRejects(
          browser.sidebarAction.setPanel({
            windowId: pbw.windowId,
            panel: "test",
          }),
          /Invalid window ID/,
          "should not be able to set panel with windowId"
        );
        await browser.test.assertRejects(
          browser.sidebarAction.setPanel({
            tabId: pbw.tabId,
            panel: "test",
          }),
          /Invalid tab ID/,
          "should not be able to set panel with tabId"
        );
        await browser.test.assertRejects(
          browser.sidebarAction.getPanel({
            windowId: pbw.windowId,
          }),
          /Invalid window ID/,
          "should not be able to get panel with windowId"
        );
        await browser.test.assertRejects(
          browser.sidebarAction.getPanel({
            tabId: pbw.tabId,
          }),
          /Invalid tab ID/,
          "should not be able to get panel with tabId"
        );

        await browser.test.assertRejects(
          browser.sidebarAction.isOpen({
            windowId: pbw.windowId,
          }),
          /Invalid window ID/,
          "should not be able to determine openness with windowId"
        );

        browser.test.notifyPass("pass");
      });
    },
    files: {
      "sidebar.html": `
        <!DOCTYPE html>
        <html>
        <head><meta charset="utf-8"/>
        <script src="sidebar.js"></script>
        </head>
        <body>
          A Test Sidebar
        </body>
        </html>
      `,

      "sidebar.js": function () {
        window.onload = () => {
          browser.test.sendMessage("sidebar");
        };
      },
    },
  });

  await extension.startup();
  let sidebarID = `${makeWidgetId(extension.id)}-sidebar-action`;
  ok(SidebarUI.sidebars.has(sidebarID), "sidebar exists in non-private window");

  let winData = await getIncognitoWindow();

  let hasSidebar = winData.win.SidebarUI.sidebars.has(sidebarID);
  ok(!hasSidebar, "sidebar does not exist in private window");
  // Test API access to private window data.
  extension.sendMessage(winData.details);
  await extension.awaitFinish("pass");

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