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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
"use strict";
requestLongerTimeout(5);
/**
* Opens windows from content using window.open with several features patterns.
*/
add_task(async function test_popup_conditions() {
const PATTERNS = [
{ features: "", popup: false },
// If features isn't empty, the following should be true to open tab/window:
// * location or toolbar (defaults to false)
// * menubar (defaults to false)
// * resizable (defaults to true)
// * scrollbars (defaults to false)
// * status (defaults to false)
// and also the following shouldn't be specified:
// * left or screenX
// * top or screenY
// * width or innerWidth
// * height or innerHeight
{ features: "location,menubar,resizable,scrollbars,status", popup: false },
{ features: "toolbar,menubar,resizable,scrollbars,status", popup: false },
{
features: "location,menubar,toolbar,resizable,scrollbars,status",
popup: false,
},
// resizable defaults to true.
{ features: "location,menubar,scrollbars,status", popup: false },
// The following testcases use "location,menubar,scrollbars,status"
// as the base non-popup case, and test the boundary between popup
// vs non-popup.
// If either location or toolbar is true, not popup.
{
features: "location=0,toolbar,menubar,resizable,scrollbars,status",
popup: false,
},
{
features: "location,toolbar=0,menubar,resizable,scrollbars,status",
popup: false,
},
{
features: "location,toolbar,menubar,resizable,scrollbars,status",
popup: false,
},
// If both location and toolbar are false, popup.
{
features: "location=0,toolbar=0,menubar,resizable,scrollbars,status",
popup: true,
},
{ features: "menubar,scrollbars,status", popup: true },
// If menubar is false, popup.
{ features: "location,resizable,scrollbars,status", popup: true },
{ features: "location,menubar=0,resizable,scrollbars,status", popup: true },
// If resizable is true, not popup.
{
features: "location,menubar,resizable=yes,scrollbars,status",
popup: false,
},
// If resizable is false, popup.
{ features: "location,menubar,resizable=0,scrollbars,status", popup: true },
// If scrollbars is false, popup.
{ features: "location,menubar,resizable,status", popup: true },
{ features: "location,menubar,resizable,scrollbars=0,status", popup: true },
// If status is false, popup.
{ features: "location,menubar,resizable,scrollbars", popup: true },
{ features: "location,menubar,resizable,scrollbars,status=0", popup: true },
// If either width or innerWidth is specified, popup.
{ features: "location,menubar,scrollbars,status,width=100", popup: true },
{
features: "location,menubar,scrollbars,status,innerWidth=100",
popup: true,
},
// outerWidth has no effect.
{
features: "location,menubar,scrollbars,status,outerWidth=100",
popup: false,
},
// left or screenX alone doesn't make it a popup.
{
features: "location,menubar,scrollbars,status,left=100",
popup: false,
},
{
features: "location,menubar,scrollbars,status,screenX=100",
popup: false,
},
// top or screenY alone doesn't make it a popup.
{
features: "location,menubar,scrollbars,status,top=100",
popup: false,
},
{
features: "location,menubar,scrollbars,status,screenY=100",
popup: false,
},
// height or innerHeight alone doesn't make it a popup.
{
features: "location,menubar,scrollbars,status,height=100",
popup: false,
},
{
features: "location,menubar,scrollbars,status,innerHeight=100",
popup: false,
},
// outerHeight has no effect.
{
features: "location,menubar,scrollbars,status,outerHeight=100",
popup: false,
},
// Most feature defaults to false if the feature is not empty.
// Specifying only some of them opens a popup.
{ features: "location", popup: true },
{ features: "toolbar", popup: true },
{ features: "location,toolbar", popup: true },
{ features: "menubar", popup: true },
{ features: "location,toolbar,menubar", popup: true },
{ features: "resizable", popup: true },
{ features: "scrollbars", popup: true },
{ features: "status", popup: true },
{ features: "left=500", popup: true },
{ features: "top=500", popup: true },
{ features: "left=500,top=500", popup: true },
{ features: "width=500", popup: true },
{ features: "height=500", popup: true },
{ features: "width=500, height=500", popup: true },
// Specifying unknown feature makes the feature not empty.
{ features: "someunknownfeature", popup: true },
// personalbar have no effect.
{ features: "personalbar=0", popup: true },
{ features: "personalbar=yes", popup: true },
{
features: "location,menubar,resizable,scrollbars,status,personalbar=0",
popup: false,
},
{
features: "location,menubar,resizable,scrollbars,status,personalbar=yes",
popup: false,
},
// noopener is removed before testing if feature is empty.
{ features: "noopener", popup: false },
// noreferrer is removed before testing if feature is empty.
{ features: "noreferrer", popup: false },
];
const WINDOW_FLAGS = {
CHROME_WINDOW_BORDERS: true,
CHROME_WINDOW_CLOSE: true,
CHROME_WINDOW_RESIZE: true,
CHROME_LOCATIONBAR: true,
CHROME_STATUSBAR: true,
CHROME_SCROLLBARS: true,
CHROME_TITLEBAR: true,
CHROME_MENUBAR: true,
CHROME_TOOLBAR: true,
CHROME_PERSONAL_TOOLBAR: true,
};
const POPUP_FLAGS = {
CHROME_WINDOW_BORDERS: true,
CHROME_WINDOW_CLOSE: true,
CHROME_WINDOW_RESIZE: true,
CHROME_LOCATIONBAR: true,
CHROME_STATUSBAR: true,
CHROME_SCROLLBARS: true,
CHROME_TITLEBAR: true,
CHROME_MENUBAR: false,
CHROME_TOOLBAR: false,
CHROME_PERSONAL_TOOLBAR: false,
};
async function test_patterns({ nonPopup }) {
for (const { features, popup } of PATTERNS) {
const BLANK_PAGE = "data:text/html,";
const OPEN_PAGE = "data:text/plain,hello";
const SCRIPT_PAGE = `data:text/html,<script>window.open("${OPEN_PAGE}", "", "${features}");</script>`;
async function testNewWindow(flags) {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: BLANK_PAGE,
},
async function(browser) {
const newWinPromise = BrowserTestUtils.waitForNewWindow();
BrowserTestUtils.loadURI(gBrowser, SCRIPT_PAGE);
const win = await newWinPromise;
const parentChromeFlags = getParentChromeFlags(win);
for (const [name, visible] of Object.entries(flags)) {
if (visible) {
Assert.equal(
!!(parentChromeFlags & Ci.nsIWebBrowserChrome[name]),
true,
`${name} should be present for features "${features}"`
);
} else {
Assert.equal(
!!(parentChromeFlags & Ci.nsIWebBrowserChrome[name]),
false,
`${name} should not be present for features "${features}"`
);
}
}
await BrowserTestUtils.closeWindow(win);
}
);
}
async function testNewTab() {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: BLANK_PAGE,
},
async function(browser) {
const newTabPromise = BrowserTestUtils.waitForNewTab(
gBrowser,
OPEN_PAGE
);
BrowserTestUtils.loadURI(gBrowser, SCRIPT_PAGE);
let tab = await newTabPromise;
BrowserTestUtils.removeTab(tab);
}
);
}
async function testCurrentTab() {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: BLANK_PAGE,
},
async function(browser) {
const pagePromise = BrowserTestUtils.browserLoaded(
browser,
false,
OPEN_PAGE
);
BrowserTestUtils.loadURI(gBrowser, SCRIPT_PAGE);
await pagePromise;
}
);
}
if (!popup) {
if (nonPopup == "window") {
await testNewWindow(WINDOW_FLAGS);
} else if (nonPopup == "tab") {
await testNewTab();
} else {
// current tab
await testCurrentTab();
}
} else {
await testNewWindow(POPUP_FLAGS);
}
}
}
// Non-popup is opened in a new tab (default behavior).
await SpecialPowers.pushPrefEnv({
set: [["browser.link.open_newwindow", 3]],
});
await test_patterns({ nonPopup: "tab" });
await SpecialPowers.popPrefEnv();
// Non-popup is opened in a current tab.
await SpecialPowers.pushPrefEnv({
set: [["browser.link.open_newwindow", 1]],
});
await test_patterns({ nonPopup: "current" });
await SpecialPowers.popPrefEnv();
// Non-popup is opened in a new window.
await SpecialPowers.pushPrefEnv({
set: [["browser.link.open_newwindow", 2]],
});
await test_patterns({ nonPopup: "window" });
await SpecialPowers.popPrefEnv();
});
|