-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathpartitioned-popins.partitions.tentative.https.window.js
354 lines (307 loc) · 14.1 KB
/
partitioned-popins.partitions.tentative.https.window.js
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
// META: script=/common/dispatcher/dispatcher.js
// META: script=/common/get-host-info.sub.js
// META: script=/common/utils.js
// META: script=/common/subset-tests-by-key.js
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
// META: variant=?include=variant-1-test
// META: variant=?include=variant-2-test
// META: variant=?include=variant-3-test
// META: variant=?include=variant-4-test
// META: variant=?include=variant-5-test
// META: variant=?include=variant-6-test
// META: variant=?include=variant-7-test
// META: variant=?include=variant-8-test
// META: variant=?include=variant-9-test
// META: variant=?include=variant-10-test
// META: variant=?include=variant-11-test
// META: timeout=long
'use strict';
const TEST_VALUE = "popin-partition-test";
async function seedPartition(remoteContextWrapper, name) {
await remoteContextWrapper.executeScript((name, TEST_VALUE) => {
window.localStorage.setItem(name, TEST_VALUE);
document.cookie = name + "-strict=" + TEST_VALUE + "; SameSite=Strict; Secure";
document.cookie = name + "-lax=" + TEST_VALUE + "; SameSite=Lax; Secure";
document.cookie = name + "-none=" + TEST_VALUE + "; SameSite=None; Secure";
document.cookie = name + "-partitioned-strict=" + TEST_VALUE + "; Partitioned; SameSite=Strict; Secure";
document.cookie = name + "-partitioned-lax=" + TEST_VALUE + "; Partitioned; SameSite=Lax; Secure";
document.cookie = name + "-partitioned-none=" + TEST_VALUE + "; Partitioned; SameSite=None; Secure";
}, [name, TEST_VALUE]);
}
async function openPopin(test, remoteContextWrapper, origin) {
const popin = await remoteContextWrapper.addWindow(
/*extraConfig=*/ origin ? { origin } : null,
/*options=*/ { features: "popin" });
assert_equals(await popin.executeScript(() => window.popinContextType()), "partitioned");
test.add_cleanup(async () => {
await popin.executeScript(() => window.close());
});
return popin;
}
async function getCookies(remoteContextWrapper) {
return await remoteContextWrapper.executeScript((TEST_VALUE) => {
if (!document.cookie) {
return [];
}
const cookies = document.cookie.split(";");
let cookieNames = [];
for (let i = 0; i < cookies.length; i++) {
let cookieName = cookies[i].split("=")[0].trim();
let cookieValue = cookies[i].split("=")[1].trim();
if (cookieValue === TEST_VALUE) {
cookieNames.push(cookieName);
}
}
return cookieNames.sort();
}, [TEST_VALUE]);
}
async function getLocalStorage(remoteContextWrapper) {
return await remoteContextWrapper.executeScript((TEST_VALUE) => {
let storageNames = [];
for (let i = 0; i < window.localStorage.length; i++) {
if (window.localStorage.getItem(window.localStorage.key(i)) === TEST_VALUE) {
storageNames.push(window.localStorage.key(i));
}
}
return storageNames.sort();
}, [TEST_VALUE]);
}
const rcHelper = new RemoteContextHelper();
const handles = {};
promise_setup(async () => {
assert_in_array("partitioned", window.popinContextTypesSupported());
handles.main = await rcHelper.addWindow();
handles.frameSameSite = await handles.main.addIframe();
handles.frameCrossSite = await handles.main.addIframe(
/*extraConfig=*/ {
origin: "HTTPS_NOTSAMESITE_ORIGIN",
},
/*attributes=*/ {
allow: "popins",
}
);
handles.frameSameSiteWithCrossSiteAncestor =
await handles.frameCrossSite.addIframe(
/*extraConfig=*/ null,
/*attributes=*/ {
allow: "popins",
}
);
handles.crossSite = await rcHelper.addWindow(
/*extraConfig=*/ {
origin: "HTTPS_NOTSAMESITE_ORIGIN",
}
);
handles.crossSiteFrameSameSite = await handles.crossSite.addIframe();
Object.freeze(handles);
await seedPartition(handles.main, "main");
await seedPartition(handles.frameSameSite, "frameSameSite");
await seedPartition(handles.frameCrossSite, "frameCrossSite");
await seedPartition(handles.frameSameSiteWithCrossSiteAncestor, "frameSameSiteWithCrossSiteAncestor");
await seedPartition(handles.crossSite, "crossSite");
await seedPartition(handles.crossSiteFrameSameSite, "crossSiteFrameSameSite");
});
subsetTestByKey("variant-1-test", promise_test, async t => {
const popin = await openPopin(t, handles.main);
// The popin, it's opener and all their ancestors are same-site, so the popin
// should have access to all cookies and storage of the main host.
assert_array_equals(
await getCookies(popin),
[
"crossSiteFrameSameSite-none",
"frameSameSite-lax",
"frameSameSite-none",
"frameSameSite-partitioned-lax",
"frameSameSite-partitioned-none",
"frameSameSite-partitioned-strict",
"frameSameSite-strict",
"frameSameSiteWithCrossSiteAncestor-none",
"main-lax",
"main-none",
"main-partitioned-lax",
"main-partitioned-none",
"main-partitioned-strict",
"main-strict",
]);
assert_array_equals(await getLocalStorage(popin), ["frameSameSite", "main"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Main site opens same-site popin.");
subsetTestByKey("variant-2-test", promise_test, async t => {
const popin = await openPopin(t, handles.main, "HTTPS_NOTSAMESITE_ORIGIN");
// The popin is cross-site to its opener, so the popin should only have access
// to the local storage variable and SameSite=None cookies of the cross-site
// frame, and the unpartitioned SameSite=None cookie of the cross-site window.
assert_array_equals(await getCookies(popin), ["crossSite-none", "frameCrossSite-none", "frameCrossSite-partitioned-none"]);
assert_array_equals(await getLocalStorage(popin), ["frameCrossSite"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Main site opens cross-site popin.");
subsetTestByKey("variant-3-test", promise_test, async t => {
const popin = await openPopin(t, handles.frameSameSite);
// The popin, it's opener and all their ancestors are same-site, so the popin
// should have access to all cookies and storage of the main host.
assert_array_equals(
await getCookies(popin),
[
"crossSiteFrameSameSite-none",
"frameSameSite-lax",
"frameSameSite-none",
"frameSameSite-partitioned-lax",
"frameSameSite-partitioned-none",
"frameSameSite-partitioned-strict",
"frameSameSite-strict",
"frameSameSiteWithCrossSiteAncestor-none",
"main-lax",
"main-none",
"main-partitioned-lax",
"main-partitioned-none",
"main-partitioned-strict",
"main-strict",
]);
assert_array_equals(await getLocalStorage(popin), ["frameSameSite", "main"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Same-site frame opens same-site popin.");
subsetTestByKey("variant-4-test", promise_test, async t => {
const popin = await openPopin(t, handles.frameCrossSite);
// The main-host popin has a cross-site ancestor, so it should only have
// access to the local storage variable and SameSite=None cookies set in a
// cross-site ancestor context, and the unpartitioned SameSite=None cookies of
// the main-host contexts.
assert_array_equals(await getCookies(popin),
[
"crossSiteFrameSameSite-none",
"frameSameSite-none",
"frameSameSiteWithCrossSiteAncestor-none",
"frameSameSiteWithCrossSiteAncestor-partitioned-none",
"main-none",
]);
assert_array_equals(await getLocalStorage(popin), ["frameSameSiteWithCrossSiteAncestor"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Cross-site frame opens main-host popin.");
subsetTestByKey("variant-5-test", promise_test, async t => {
const popin = await openPopin(t, handles.frameCrossSite, "HTTPS_NOTSAMESITE_ORIGIN");
// The popin and its opener is cross-site to the main frame, so the popin
// should only have access to the local storage variable and SameSite=None
// cookies of the cross-site frame, and the unpartitioned SameSite=None cookie
// of the cross-site window.
assert_array_equals(await getCookies(popin), ["crossSite-none", "frameCrossSite-none", "frameCrossSite-partitioned-none"]);
assert_array_equals(await getLocalStorage(popin), ["frameCrossSite"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Cross-site frame opens alternative-host popin.");
subsetTestByKey("variant-6-test", promise_test, async t => {
const popin = await openPopin(t, handles.frameSameSiteWithCrossSiteAncestor);
// The main-host popin has a cross-site ancestor, so it should only have
// access to the local storage variable and SameSite=None cookies set in a
// cross-site ancestor context, and the unpartitioned SameSite=None cookies of
// the main-host contexts.
assert_array_equals(await getCookies(popin),
[
"crossSiteFrameSameSite-none",
"frameSameSite-none",
"frameSameSiteWithCrossSiteAncestor-none",
"frameSameSiteWithCrossSiteAncestor-partitioned-none",
"main-none",
]);
assert_array_equals(await getLocalStorage(popin), ["frameSameSiteWithCrossSiteAncestor"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Same-site frame with cross-site ancestor opens main-host popin.");
subsetTestByKey("variant-7-test", promise_test, async t => {
const popin = await openPopin(t, handles.main);
// The frame in the popin, the popin, it's opener and all their ancestors are
// same-site, so the popin should have access to all cookies and storage of
// the main host.
const popinFrame = await popin.addIframe();
assert_array_equals(
await getCookies(popinFrame),
[
"crossSiteFrameSameSite-none",
"frameSameSite-lax",
"frameSameSite-none",
"frameSameSite-partitioned-lax",
"frameSameSite-partitioned-none",
"frameSameSite-partitioned-strict",
"frameSameSite-strict",
"frameSameSiteWithCrossSiteAncestor-none",
"main-lax",
"main-none",
"main-partitioned-lax",
"main-partitioned-none",
"main-partitioned-strict",
"main-strict",
]);
assert_array_equals(await getLocalStorage(popinFrame), ["frameSameSite", "main"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Main site opens same-site popin with same-site frame.");
subsetTestByKey("variant-8-test", promise_test, async t => {
const popin = await openPopin(t, handles.main);
const popinFrame = await popin.addIframe(
/*extraConfig=*/ {
origin: "HTTPS_NOTSAMESITE_ORIGIN",
},
/*attributes=*/ {
allow: "popins",
}
);
// The frame in the popin is cross-site to the main frame, so the popin should
// only have access to the local storage variable and SameSite=None cookies of
// the cross-site frame, and the unpartitioned SameSite=None cookie of the
// cross-site window.
assert_array_equals(await getCookies(popinFrame), ["crossSite-none", "frameCrossSite-none", "frameCrossSite-partitioned-none"]);
assert_array_equals(await getLocalStorage(popinFrame), ["frameCrossSite"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Main site opens same-site popin with cross-site frame.");
subsetTestByKey("variant-9-test", promise_test, async t => {
const popin = await openPopin(t, handles.main, "HTTPS_NOTSAMESITE_ORIGIN");
const popinFrame = await popin.addIframe();
// The main-host frame in the popin has a cross-site ancestor, so it should
// only have access to the local storage variable and SameSite=None cookies
// set in a cross-site ancestor context, and the unpartitioned SameSite=None
// cookies of the main-host contexts.
assert_array_equals(await getCookies(popinFrame),
[
"crossSiteFrameSameSite-none",
"frameSameSite-none",
"frameSameSiteWithCrossSiteAncestor-none",
"frameSameSiteWithCrossSiteAncestor-partitioned-none",
"main-none",
]);
assert_array_equals(await getLocalStorage(popinFrame), ["frameSameSiteWithCrossSiteAncestor"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Main site opens cross-site popin with main-host frame.");
subsetTestByKey("variant-10-test", promise_test, async t => {
const popin = await openPopin(t, handles.frameCrossSite);
const popinFrame = await popin.addIframe(
/*extraConfig=*/ {
origin: "HTTPS_NOTSAMESITE_ORIGIN",
},
/*attributes=*/ {
allow: "popins",
}
);
// The frame in the popin is cross-site to the main frame, so the popin should
// only have access to the local storage variable and SameSite=None cookies of
// the cross-site frame, and the unpartitioned SameSite=Nonecookie of the
// cross-site window.
assert_array_equals(await getCookies(popinFrame), ["crossSite-none", "frameCrossSite-none", "frameCrossSite-partitioned-none"]);
assert_array_equals(await getLocalStorage(popinFrame), ["frameCrossSite"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Cross-site frame opens main-host popin with cross-site frame.");
subsetTestByKey("variant-11-test", promise_test, async t => {
const popin = await openPopin(t, handles.frameCrossSite, "HTTPS_NOTSAMESITE_ORIGIN");
const popinFrame = await popin.addIframe();
// The main-host frame in the popin has a cross-site ancestor, so it should
// only have access to the local storage variable and SameSite=None cookies
//set in a cross-site ancestor context, and the unpartitioned SameSite=None
// cookies of the main-host contexts.
assert_array_equals(await getCookies(popinFrame),
[
"crossSiteFrameSameSite-none",
"frameSameSite-none",
"frameSameSiteWithCrossSiteAncestor-none",
"frameSameSiteWithCrossSiteAncestor-partitioned-none",
"main-none",
]);
assert_array_equals(await getLocalStorage(popinFrame), ["frameSameSiteWithCrossSiteAncestor"]);
t.done();
}, "Verify Partitioned Popins have access to the proper cookie/storage partitions - Cross-site frame opens alternative-host popin with main-host frame.");