1
|
|
-// Make sure that we can open private browsing windows
|
|
1
|
+/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2
|
4
|
|
3
|
|
-function test() {
|
4
|
|
- waitForExplicitFinish();
|
5
|
|
- var nonPrivateWin = OpenBrowserWindow();
|
6
|
|
- ok(
|
7
|
|
- !PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin),
|
|
5
|
+add_task(async function testOpenBrowserWindow() {
|
|
6
|
+ let win = OpenBrowserWindow();
|
|
7
|
+ Assert.ok(
|
|
8
|
+ !PrivateBrowsingUtils.isWindowPrivate(win),
|
8
|
9
|
"OpenBrowserWindow() should open a normal window"
|
9
|
10
|
);
|
10
|
|
- nonPrivateWin.close();
|
|
11
|
+ await BrowserTestUtils.closeWindow(win);
|
11
|
12
|
|
12
|
|
- var privateWin = OpenBrowserWindow({ private: true });
|
13
|
|
- ok(
|
14
|
|
- PrivateBrowsingUtils.isWindowPrivate(privateWin),
|
|
13
|
+ win = OpenBrowserWindow({ private: true });
|
|
14
|
+ Assert.ok(
|
|
15
|
+ PrivateBrowsingUtils.isWindowPrivate(win),
|
15
|
16
|
"OpenBrowserWindow({private: true}) should open a private window"
|
16
|
17
|
);
|
|
18
|
+ await BrowserTestUtils.closeWindow(win);
|
17
|
19
|
|
18
|
|
- nonPrivateWin = OpenBrowserWindow({ private: false });
|
19
|
|
- ok(
|
20
|
|
- !PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin),
|
|
20
|
+ win = OpenBrowserWindow({ private: false });
|
|
21
|
+ Assert.ok(
|
|
22
|
+ !PrivateBrowsingUtils.isWindowPrivate(win),
|
21
|
23
|
"OpenBrowserWindow({private: false}) should open a normal window"
|
22
|
24
|
);
|
23
|
|
- nonPrivateWin.close();
|
|
25
|
+ await BrowserTestUtils.closeWindow(win);
|
24
|
26
|
|
25
|
|
- whenDelayedStartupFinished(privateWin, function () {
|
26
|
|
- nonPrivateWin = privateWin.OpenBrowserWindow({ private: false });
|
27
|
|
- ok(
|
28
|
|
- !PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin),
|
29
|
|
- "privateWin.OpenBrowserWindow({private: false}) should open a normal window"
|
30
|
|
- );
|
|
27
|
+ // In permanent browsing mode.
|
|
28
|
+ await SpecialPowers.pushPrefEnv({
|
|
29
|
+ set: [["browser.privatebrowsing.autostart", true]],
|
|
30
|
+ });
|
|
31
|
+
|
|
32
|
+ win = OpenBrowserWindow();
|
|
33
|
+ Assert.ok(
|
|
34
|
+ PrivateBrowsingUtils.isWindowPrivate(win),
|
|
35
|
+ "OpenBrowserWindow() in PBM should open a private window"
|
|
36
|
+ );
|
|
37
|
+ await BrowserTestUtils.closeWindow(win);
|
|
38
|
+
|
|
39
|
+ win = OpenBrowserWindow({ private: true });
|
|
40
|
+ Assert.ok(
|
|
41
|
+ PrivateBrowsingUtils.isWindowPrivate(win),
|
|
42
|
+ "OpenBrowserWindow({private: true}) in PBM should open a private window"
|
|
43
|
+ );
|
|
44
|
+ await BrowserTestUtils.closeWindow(win);
|
|
45
|
+
|
|
46
|
+ win = OpenBrowserWindow({ private: false });
|
|
47
|
+ Assert.ok(
|
|
48
|
+ PrivateBrowsingUtils.isWindowPrivate(win),
|
|
49
|
+ "OpenBrowserWindow({private: false}) in PBM should open a private window"
|
|
50
|
+ );
|
|
51
|
+ await BrowserTestUtils.closeWindow(win);
|
|
52
|
+
|
|
53
|
+ await SpecialPowers.popPrefEnv();
|
|
54
|
+});
|
31
|
55
|
|
32
|
|
- nonPrivateWin.close();
|
33
|
|
-
|
34
|
|
- [
|
35
|
|
- {
|
36
|
|
- normal: "menu_newNavigator",
|
37
|
|
- private: "menu_newPrivateWindow",
|
38
|
|
- accesskey: true,
|
39
|
|
- },
|
40
|
|
- {
|
41
|
|
- normal: "appmenu_newNavigator",
|
42
|
|
- private: "appmenu_newPrivateWindow",
|
43
|
|
- accesskey: false,
|
44
|
|
- },
|
45
|
|
- ].forEach(function (menu) {
|
46
|
|
- let newWindow = privateWin.document.getElementById(menu.normal);
|
47
|
|
- let newPrivateWindow = privateWin.document.getElementById(menu.private);
|
48
|
|
- if (newWindow && newPrivateWindow) {
|
49
|
|
- ok(
|
50
|
|
- !newPrivateWindow.hidden,
|
51
|
|
- "New Private Window menu item should be hidden"
|
52
|
|
- );
|
53
|
|
- isnot(
|
54
|
|
- newWindow.label,
|
55
|
|
- newPrivateWindow.label,
|
56
|
|
- "New Window's label shouldn't be overwritten"
|
57
|
|
- );
|
58
|
|
- if (menu.accesskey) {
|
59
|
|
- isnot(
|
60
|
|
- newWindow.accessKey,
|
61
|
|
- newPrivateWindow.accessKey,
|
62
|
|
- "New Window's accessKey shouldn't be overwritten"
|
63
|
|
- );
|
64
|
|
- }
|
65
|
|
- isnot(
|
66
|
|
- newWindow.command,
|
67
|
|
- newPrivateWindow.command,
|
68
|
|
- "New Window's command shouldn't be overwritten"
|
69
|
|
- );
|
70
|
|
- }
|
71
|
|
- });
|
72
|
|
-
|
73
|
|
- is(
|
74
|
|
- privateWin.gBrowser.tabs[0].label,
|
75
|
|
- "New Private Tab",
|
76
|
|
- "New tabs in the private browsing windows should have 'New Private Tab' as the title."
|
|
56
|
+/**
|
|
57
|
+ * Check that the "new window" menu items have the expected properties.
|
|
58
|
+ *
|
|
59
|
+ * @param {Element} newWindowItem - The "new window" item to check.
|
|
60
|
+ * @param {Element} privateWindowItem - The "new private window" item to check.
|
|
61
|
+ * @param {Object} expect - The expected properties.
|
|
62
|
+ * @param {boolean} expect.privateVisible - Whether we expect the private item
|
|
63
|
+ * to be visible or not.
|
|
64
|
+ * @param {string} expect.newWindowL10nId - The expected string ID used by the
|
|
65
|
+ * "new window" item.
|
|
66
|
+ * @param {string} expect.privateWindowL10nId - The expected string ID used by
|
|
67
|
+ * the "new private window" item.
|
|
68
|
+ * @param {boolean} [useIsVisible=true] - Whether to test the "true" visibility
|
|
69
|
+ * of the item. Otherwise only the "hidden" attribute is checked.
|
|
70
|
+ */
|
|
71
|
+function assertMenuItems(
|
|
72
|
+ newWindowItem,
|
|
73
|
+ privateWindowItem,
|
|
74
|
+ expect,
|
|
75
|
+ useIsVisible = true
|
|
76
|
+) {
|
|
77
|
+ Assert.ok(newWindowItem);
|
|
78
|
+ Assert.ok(privateWindowItem);
|
|
79
|
+
|
|
80
|
+ if (useIsVisible) {
|
|
81
|
+ Assert.ok(
|
|
82
|
+ BrowserTestUtils.isVisible(newWindowItem),
|
|
83
|
+ "New window item should be visible"
|
77
|
84
|
);
|
|
85
|
+ } else {
|
|
86
|
+ // The application menu is not accessible on macOS, just check the hidden
|
|
87
|
+ // attribute.
|
|
88
|
+ Assert.ok(!newWindowItem.hidden, "New window item should be visible");
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ Assert.equal(
|
|
92
|
+ newWindowItem.getAttribute("key"),
|
|
93
|
+ "key_newNavigator",
|
|
94
|
+ "New window item should use the same key"
|
|
95
|
+ );
|
|
96
|
+ Assert.equal(
|
|
97
|
+ newWindowItem.getAttribute("data-l10n-id"),
|
|
98
|
+ expect.newWindowL10nId
|
|
99
|
+ );
|
78
|
100
|
|
79
|
|
- privateWin.close();
|
80
|
|
-
|
81
|
|
- Services.prefs.setBoolPref("browser.privatebrowsing.autostart", true);
|
82
|
|
- privateWin = OpenBrowserWindow({ private: true });
|
83
|
|
- whenDelayedStartupFinished(privateWin, function () {
|
84
|
|
- [
|
85
|
|
- {
|
86
|
|
- normal: "menu_newNavigator",
|
87
|
|
- private: "menu_newPrivateWindow",
|
88
|
|
- accessKey: true,
|
89
|
|
- },
|
90
|
|
- {
|
91
|
|
- normal: "appmenu_newNavigator",
|
92
|
|
- private: "appmenu_newPrivateWindow",
|
93
|
|
- accessKey: false,
|
94
|
|
- },
|
95
|
|
- ].forEach(function (menu) {
|
96
|
|
- let newWindow = privateWin.document.getElementById(menu.normal);
|
97
|
|
- let newPrivateWindow = privateWin.document.getElementById(menu.private);
|
98
|
|
- if (newWindow && newPrivateWindow) {
|
99
|
|
- ok(
|
100
|
|
- newPrivateWindow.hidden,
|
101
|
|
- "New Private Window menu item should be hidden"
|
102
|
|
- );
|
103
|
|
- is(
|
104
|
|
- newWindow.label,
|
105
|
|
- newPrivateWindow.label,
|
106
|
|
- "New Window's label should be overwritten"
|
107
|
|
- );
|
108
|
|
- if (menu.accesskey) {
|
109
|
|
- is(
|
110
|
|
- newWindow.accessKey,
|
111
|
|
- newPrivateWindow.accessKey,
|
112
|
|
- "New Window's accessKey should be overwritten"
|
113
|
|
- );
|
114
|
|
- }
|
115
|
|
- is(
|
116
|
|
- newWindow.command,
|
117
|
|
- newPrivateWindow.command,
|
118
|
|
- "New Window's command should be overwritten"
|
119
|
|
- );
|
120
|
|
- }
|
121
|
|
- });
|
122
|
|
-
|
123
|
|
- is(
|
124
|
|
- privateWin.gBrowser.tabs[0].label,
|
125
|
|
- "New Tab",
|
126
|
|
- "Normal tab title is used also in the permanent private browsing mode."
|
|
101
|
+ if (!expect.privateVisible) {
|
|
102
|
+ if (useIsVisible) {
|
|
103
|
+ Assert.ok(
|
|
104
|
+ BrowserTestUtils.isHidden(privateWindowItem),
|
|
105
|
+ "Private window item should be hidden"
|
127
|
106
|
);
|
128
|
|
- privateWin.close();
|
129
|
|
- Services.prefs.clearUserPref("browser.privatebrowsing.autostart");
|
130
|
|
- finish();
|
131
|
|
- });
|
132
|
|
- });
|
|
107
|
+ } else {
|
|
108
|
+ Assert.ok(
|
|
109
|
+ privateWindowItem.hidden,
|
|
110
|
+ "Private window item should be hidden"
|
|
111
|
+ );
|
|
112
|
+ }
|
|
113
|
+ // Don't check attributes since hidden.
|
|
114
|
+ } else {
|
|
115
|
+ if (useIsVisible) {
|
|
116
|
+ Assert.ok(
|
|
117
|
+ BrowserTestUtils.isVisible(privateWindowItem),
|
|
118
|
+ "Private window item should be visible"
|
|
119
|
+ );
|
|
120
|
+ } else {
|
|
121
|
+ Assert.ok(
|
|
122
|
+ !privateWindowItem.hidden,
|
|
123
|
+ "Private window item should be visible"
|
|
124
|
+ );
|
|
125
|
+ }
|
|
126
|
+ Assert.equal(
|
|
127
|
+ privateWindowItem.getAttribute("key"),
|
|
128
|
+ "key_privatebrowsing",
|
|
129
|
+ "Private window item should use the same key"
|
|
130
|
+ );
|
|
131
|
+ Assert.equal(
|
|
132
|
+ privateWindowItem.getAttribute("data-l10n-id"),
|
|
133
|
+ expect.privateWindowL10nId
|
|
134
|
+ );
|
|
135
|
+ }
|
|
136
|
+}
|
|
137
|
+
|
|
138
|
+/**
|
|
139
|
+ * Check that a window has the expected "new window" items in the "File" and app
|
|
140
|
+ * menus.
|
|
141
|
+ *
|
|
142
|
+ * @param {Window} win - The window to check.
|
|
143
|
+ * @param {boolean} expectBoth - Whether we expect the window to contain both
|
|
144
|
+ * "new window" and "new private window" as separate controls.
|
|
145
|
+ */
|
|
146
|
+async function checkWindowMenus(win, expectBoth) {
|
|
147
|
+ // Check the File menu.
|
|
148
|
+ assertMenuItems(
|
|
149
|
+ win.document.getElementById("menu_newNavigator"),
|
|
150
|
+ win.document.getElementById("menu_newPrivateWindow"),
|
|
151
|
+ {
|
|
152
|
+ privateVisible: expectBoth,
|
|
153
|
+ // If in permanent private browsing, expect the new window item to use the
|
|
154
|
+ // "New private window" string.
|
|
155
|
+ newWindowL10nId: expectBoth
|
|
156
|
+ ? "menu-file-new-window"
|
|
157
|
+ : "menu-file-new-private-window",
|
|
158
|
+ privateWindowL10nId: "menu-file-new-private-window",
|
|
159
|
+ },
|
|
160
|
+ // The file menu is difficult to open cross-platform, so we do not open it
|
|
161
|
+ // for this test.
|
|
162
|
+ false
|
|
163
|
+ );
|
|
164
|
+
|
|
165
|
+ // Open the app menu.
|
|
166
|
+ let appMenuButton = win.document.getElementById("PanelUI-menu-button");
|
|
167
|
+ let appMenu = win.document.getElementById("appMenu-popup");
|
|
168
|
+ let menuShown = BrowserTestUtils.waitForEvent(appMenu, "popupshown");
|
|
169
|
+ EventUtils.synthesizeMouseAtCenter(appMenuButton, {}, win);
|
|
170
|
+ await menuShown;
|
|
171
|
+
|
|
172
|
+ // Check the app menu.
|
|
173
|
+ assertMenuItems(
|
|
174
|
+ win.document.getElementById("appMenu-new-window-button2"),
|
|
175
|
+ win.document.getElementById("appMenu-new-private-window-button2"),
|
|
176
|
+ {
|
|
177
|
+ privateVisible: expectBoth,
|
|
178
|
+ // If in permanent private browsing, expect the new window item to use the
|
|
179
|
+ // "New private window" string.
|
|
180
|
+ newWindowL10nId: expectBoth
|
|
181
|
+ ? "appmenuitem-new-window"
|
|
182
|
+ : "appmenuitem-new-private-window",
|
|
183
|
+ privateWindowL10nId: "appmenuitem-new-private-window",
|
|
184
|
+ }
|
|
185
|
+ );
|
|
186
|
+
|
|
187
|
+ appMenu.hidePopup();
|
133
|
188
|
}
|
|
189
|
+
|
|
190
|
+add_task(async function testNewWindowMenuItems() {
|
|
191
|
+ // In non-private window, expect both menu items.
|
|
192
|
+ let win = await BrowserTestUtils.openNewBrowserWindow({
|
|
193
|
+ private: false,
|
|
194
|
+ });
|
|
195
|
+ await checkWindowMenus(win, true);
|
|
196
|
+ Assert.equal(win.gBrowser.currentURI.spec, "about:blank");
|
|
197
|
+ await BrowserTestUtils.closeWindow(win);
|
|
198
|
+
|
|
199
|
+ // In non-permanent private window, still expect both menu items.
|
|
200
|
+ win = await BrowserTestUtils.openNewBrowserWindow({
|
|
201
|
+ private: true,
|
|
202
|
+ });
|
|
203
|
+ await checkWindowMenus(win, true);
|
|
204
|
+ Assert.equal(win.gBrowser.currentURI.spec, "about:privatebrowsing");
|
|
205
|
+ await BrowserTestUtils.closeWindow(win);
|
|
206
|
+
|
|
207
|
+ // In permanent private browsing, expect only one menu item.
|
|
208
|
+ await SpecialPowers.pushPrefEnv({
|
|
209
|
+ set: [["browser.privatebrowsing.autostart", true]],
|
|
210
|
+ });
|
|
211
|
+
|
|
212
|
+ win = await BrowserTestUtils.openNewBrowserWindow();
|
|
213
|
+ await checkWindowMenus(win, false);
|
|
214
|
+ Assert.equal(win.gBrowser.currentURI.spec, "about:blank");
|
|
215
|
+ await BrowserTestUtils.closeWindow(win);
|
|
216
|
+
|
|
217
|
+ await SpecialPowers.popPrefEnv();
|
|
218
|
+}); |