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
|
function openWindow(t, url) {
return new Promise(resolve => {
let win = window.open(url, '_blank');
t.add_cleanup(() => win.close());
window.onmessage = e => {
assert_equals(e.data, 'LOADED');
resolve(win);
};
});
}
// Run a referrer policy test with the given settings.
//
// Example:
// settings = {
// workletType: 'paint',
// fetchType: 'top-level' or 'descendant',
// referrerPolicy: 'no-referrer',
// scriptsOrigins: { topLevel: 'same', descendant: 'remote' }
// };
function runReferrerTest(t, settings) {
const kWindowURL =
'resources/referrer-window.html' +
`?pipe=header(Referrer-Policy,${settings.referrerPolicy})`;
return openWindow(t, kWindowURL).then(win => {
const promise = new Promise(resolve => window.onmessage = resolve);
win.postMessage(settings, '*');
return promise;
}).then(msg_event => assert_equals(msg_event.data, 'RESOLVED'));
}
// Runs a series of tests related to the referrer policy on a worklet.
//
// Usage:
// runReferrerTests("paint");
function runReferrerTests(workletType) {
const worklet = get_worklet(workletType);
// Tests for top-level script fetch -----------------------------------------
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'top-level',
referrerPolicy: 'no-referrer',
scriptOrigins: { topLevel: 'same' } });
}, 'Importing a same-origin script from a page that has "no-referrer" ' +
'referrer policy should not send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'top-level',
referrerPolicy: 'no-referrer',
scriptOrigins: { topLevel: 'remote' } });
}, 'Importing a remote-origin script from a page that has "no-referrer" ' +
'referrer policy should not send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'top-level',
referrerPolicy: 'origin',
scriptOrigins: { topLevel: 'same' } });
}, 'Importing a same-origin script from a page that has "origin" ' +
'referrer policy should send only an origin as referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'top-level',
referrerPolicy: 'origin',
scriptOrigins: { topLevel: 'remote' } });
}, 'Importing a remote-origin script from a page that has "origin" ' +
'referrer policy should send only an origin as referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'top-level',
referrerPolicy: 'same-origin',
scriptOrigins: { topLevel: 'same' } });
}, 'Importing a same-origin script from a page that has "same-origin" ' +
'referrer policy should send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'top-level',
referrerPolicy: 'same-origin',
scriptOrigins: { topLevel: 'remote' } });
}, 'Importing a remote-origin script from a page that has "same-origin" ' +
'referrer policy should not send referrer.');
// Tests for descendant script fetch -----------------------------------------
// Referrer policy: no-referrer.
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'no-referrer',
scriptOrigins: { topLevel: 'same',
descendant: 'same' } });
}, 'Importing a same-origin script from a same-origin worklet script that ' +
'has "no-referrer" referrer policy should not send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'no-referrer',
scriptOrigins: { topLevel: 'same',
descendant: 'remote' } });
}, 'Importing a remote-origin script from a same-origin worklet script ' +
'that has "no-referrer" referrer policy should not send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'no-referrer',
scriptOrigins: { topLevel: 'remote',
descendant: 'same' } });
}, 'Importing a same-origin script from a remote-origin worklet script ' +
'that has "no-referrer" referrer policy should not send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'no-referrer',
scriptOrigins: { topLevel: 'remote',
descendant: 'remote' } });
}, 'Importing a remote-origin script from a remote-origin worklet script ' +
'that has "no-referrer" referrer policy should not send referrer.');
// Referrer policy: origin.
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'origin',
scriptOrigins: { topLevel: 'same',
descendant: 'same' } });
}, 'Importing a same-origin script from a same-origin worklet script that ' +
'has "origin" referrer policy should send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'origin',
scriptOrigins: { topLevel: 'same',
descendant: 'remote' } });
}, 'Importing a remote-origin script from a same-origin worklet script ' +
'that has "origin" referrer policy should send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'origin',
scriptOrigins: { topLevel: 'remote',
descendant: 'same' } });
}, 'Importing a same-origin script from a remote-origin worklet script ' +
'that has "origin" referrer policy should send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'origin',
scriptOrigins: { topLevel: 'remote',
descendant: 'remote' } });
}, 'Importing a remote-origin script from a remote-origin worklet script ' +
'that has "origin" referrer policy should send referrer.');
// Referrer policy: same-origin.
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'same-origin',
scriptOrigins: { topLevel: 'same',
descendant: 'same' } });
}, 'Importing a same-origin script from a same-origin worklet script that ' +
'has "same-origin" referrer policy should send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'same-origin',
scriptOrigins: { topLevel: 'same',
descendant: 'remote' } });
}, 'Importing a remote-origin script from a same-origin worklet script ' +
'that has "same-origin" referrer policy should not send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'same-origin',
scriptOrigins: { topLevel: 'remote',
descendant: 'same' } });
}, 'Importing a same-origin script from a remote-origin worklet script ' +
'that has "same-origin" referrer policy should not send referrer.');
promise_test(t => {
return runReferrerTest(t, { workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'same-origin',
scriptOrigins: { topLevel: 'remote',
descendant: 'remote' } });
}, 'Importing a remote-origin script from a remote-origin worklet script ' +
'that has "same-origin" referrer policy should send referrer.');
}
|