Skip to content

Commit 04da785

Browse files
[ServiceWorker] Separate referrer policy tests into fetch-event-referrer-policy.https.html
In order to test "no-referrer-when-downgrade" policy, referrer policy tests in fetch-event.https.html need to perform fetching HTTP urls from an HTTPS iframe, but the fetch will be rejected because of Mixed Content violation. This CL moves referrer policy tests from fetch-event.https.html into a new test file fetch-event-referrer-policy.https.html, and then changes testharnessreport.js to let test runner allow Mixed Content when running this specific file. BUG=738336 TEST=blink_tests external/wpt/service-workers/service-worker/fetch-event.https.html external/wpt/service-workers/service-worker/fetch-event-referrer-policy.https.html Change-Id: I0bbc11a74343413da6ad9002959e96c0e0777c59 Reviewed-on: https://chromium-review.googlesource.com/567963 Commit-Queue: Han Leon <[email protected]> Reviewed-by: Matt Falkenhagen <[email protected]> Reviewed-by: Kent Tamura <[email protected]> Cr-Commit-Position: refs/heads/master@{#486264} WPT-Export-Revision: a30f26d0855a4ce72890b690c600c3b302fb9b4b
1 parent 54af823 commit 04da785

File tree

2 files changed

+266
-255
lines changed

2 files changed

+266
-255
lines changed
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="/common/get-host-info.sub.js"></script>
5+
<script src="resources/test-helpers.sub.js"></script>
6+
<body>
7+
<script>
8+
var worker = 'resources/fetch-event-test-worker.js';
9+
10+
function run_referrer_policy_tests(frame, referrer, href, origin) {
11+
return frame.contentWindow.fetch('resources/simple.html?referrerFull',
12+
{method: "GET", referrer: referrer})
13+
.then(function(response) { return response.text(); })
14+
.then(function(response_text) {
15+
assert_equals(
16+
response_text,
17+
'Referrer: ' + href + '\n' +
18+
'ReferrerPolicy: no-referrer-when-downgrade',
19+
'Service Worker should respond to fetch with the referrer URL when a member of RequestInit is present');
20+
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
21+
'/resources/simple.html?referrerFull';
22+
return frame.contentWindow.fetch(http_url,
23+
{method: "GET", referrer: referrer});
24+
})
25+
.then(function(response) { return response.text(); })
26+
.then(function(response_text) {
27+
assert_equals(
28+
response_text,
29+
'Referrer: \n' +
30+
'ReferrerPolicy: no-referrer-when-downgrade',
31+
'Service Worker should respond to fetch with no referrer when a member of RequestInit is present with an HTTP request');
32+
return frame.contentWindow.fetch('resources/simple.html?referrerFull',
33+
{referrerPolicy: "", referrer: referrer});
34+
})
35+
.then(function(response) { return response.text(); })
36+
.then(function(response_text) {
37+
assert_equals(
38+
response_text,
39+
'Referrer: ' + href + '\n' +
40+
'ReferrerPolicy: no-referrer-when-downgrade',
41+
'Service Worker should respond to fetch with the referrer with ""');
42+
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
43+
'/resources/simple.html?referrerFull';
44+
return frame.contentWindow.fetch(http_url,
45+
{referrerPolicy: "", referrer: referrer});
46+
})
47+
.then(function(response) { return response.text(); })
48+
.then(function(response_text) {
49+
assert_equals(
50+
response_text,
51+
'Referrer: \n' +
52+
'ReferrerPolicy: no-referrer-when-downgrade',
53+
'Service Worker should respond to fetch with no referrer with ""');
54+
return frame.contentWindow.fetch('resources/simple.html?referrerFull',
55+
{referrerPolicy: "origin", referrer: referrer});
56+
})
57+
.then(function(response) { return response.text(); })
58+
.then(function(response_text) {
59+
assert_equals(
60+
response_text,
61+
'Referrer: ' + origin + '/' + '\n' +
62+
'ReferrerPolicy: origin',
63+
'Service Worker should respond to fetch with the referrer origin with "origin" and a same origin request');
64+
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
65+
'/resources/simple.html?referrerFull';
66+
return frame.contentWindow.fetch(http_url,
67+
{referrerPolicy: "origin", referrer: referrer});
68+
})
69+
.then(function(response) { return response.text(); })
70+
.then(function(response_text) {
71+
assert_equals(
72+
response_text,
73+
'Referrer: ' + origin + '/' + '\n' +
74+
'ReferrerPolicy: origin',
75+
'Service Worker should respond to fetch with the referrer origin with "origin" and a cross origin request');
76+
return frame.contentWindow.fetch('resources/simple.html?referrerFull',
77+
{referrerPolicy: "origin-when-cross-origin", referrer: referrer});
78+
})
79+
.then(function(response) { return response.text(); })
80+
.then(function(response_text) {
81+
assert_equals(
82+
response_text,
83+
'Referrer: ' + href + '\n' +
84+
'ReferrerPolicy: origin-when-cross-origin',
85+
'Service Worker should respond to fetch with the referrer URL with "origin-when-cross-origin" and a same origin request');
86+
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
87+
'/resources/simple.html?referrerFull';
88+
return frame.contentWindow.fetch(http_url,
89+
{referrerPolicy: "origin-when-cross-origin", referrer: referrer});
90+
})
91+
.then(function(response) { return response.text(); })
92+
.then(function(response_text) {
93+
assert_equals(
94+
response_text,
95+
'Referrer: ' + origin + '/' + '\n' +
96+
'ReferrerPolicy: origin-when-cross-origin',
97+
'Service Worker should respond to fetch with the referrer origin with "origin-when-cross-origin" and a cross origin request');
98+
return frame.contentWindow.fetch('resources/simple.html?referrerFull',
99+
{referrerPolicy: "no-referrer-when-downgrade", referrer: referrer});
100+
})
101+
.then(function(response) { return response.text(); })
102+
.then(function(response_text) {
103+
assert_equals(
104+
response_text,
105+
'Referrer: ' + href + '\n' +
106+
'ReferrerPolicy: no-referrer-when-downgrade',
107+
'Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and a same origin request');
108+
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
109+
'/resources/simple.html?referrerFull';
110+
return frame.contentWindow.fetch(http_url,
111+
{referrerPolicy: "no-referrer-when-downgrade", referrer: referrer});
112+
})
113+
.then(function(response) { return response.text(); })
114+
.then(function(response_text) {
115+
assert_equals(
116+
response_text,
117+
'Referrer: \n' +
118+
'ReferrerPolicy: no-referrer-when-downgrade',
119+
'Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and an HTTP request');
120+
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
121+
'/resources/simple.html?referrerFull';
122+
return frame.contentWindow.fetch(http_url, {referrerPolicy: "unsafe-url", referrer: referrer});
123+
})
124+
.then(function(response) { return response.text(); })
125+
.then(function(response_text) {
126+
assert_equals(
127+
response_text,
128+
'Referrer: ' + href + '\n' +
129+
'ReferrerPolicy: unsafe-url',
130+
'Service Worker should respond to fetch with no referrer with "unsafe-url"');
131+
return frame.contentWindow.fetch('resources/simple.html?referrerFull',
132+
{referrerPolicy: "no-referrer", referrer: referrer});
133+
})
134+
.then(function(response) { return response.text(); })
135+
.then(function(response_text) {
136+
assert_equals(
137+
response_text,
138+
'Referrer: \n' +
139+
'ReferrerPolicy: no-referrer',
140+
'Service Worker should respond to fetch with no referrer URL with "no-referrer"');
141+
return frame.contentWindow.fetch('resources/simple.html?referrerFull',
142+
{referrerPolicy: "same-origin", referrer: referrer});
143+
})
144+
.then(function(response) { return response.text(); })
145+
.then(function(response_text) {
146+
assert_equals(
147+
response_text,
148+
'Referrer: ' + href + '\n' +
149+
'ReferrerPolicy: same-origin',
150+
'Service Worker should respond to fetch with referrer URL with "same-origin" and a same origin request');
151+
var http_url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() +
152+
'/resources/simple.html?referrerFull';
153+
return frame.contentWindow.fetch(http_url,
154+
{referrerPolicy: "same-origin", referrer: referrer});
155+
})
156+
.then(function(response) { return response.text(); })
157+
.then(function(response_text) {
158+
assert_equals(
159+
response_text,
160+
'Referrer: \n' +
161+
'ReferrerPolicy: same-origin',
162+
'Service Worker should respond to fetch with no referrer with "same-origin" and cross origin request');
163+
var http_url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() +
164+
'/resources/simple.html?referrerFull';
165+
return frame.contentWindow.fetch(http_url,
166+
{referrerPolicy: "strict-origin", referrer: referrer});
167+
})
168+
.then(function(response) { return response.text(); })
169+
.then(function(response_text) {
170+
assert_equals(
171+
response_text,
172+
'Referrer: ' + origin + '/' + '\n' +
173+
'ReferrerPolicy: strict-origin',
174+
'Service Worker should respond to fetch with the referrer origin with "strict-origin" and a HTTPS cross origin request');
175+
return frame.contentWindow.fetch('resources/simple.html?referrerFull',
176+
{referrerPolicy: "strict-origin", referrer: referrer});
177+
})
178+
.then(function(response) { return response.text(); })
179+
.then(function(response_text) {
180+
assert_equals(
181+
response_text,
182+
'Referrer: ' + origin + '/' + '\n' +
183+
'ReferrerPolicy: strict-origin',
184+
'Service Worker should respond to fetch with the referrer origin with "strict-origin" and a same origin request');
185+
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
186+
'/resources/simple.html?referrerFull';
187+
return frame.contentWindow.fetch(http_url,
188+
{referrerPolicy: "strict-origin", referrer: referrer});
189+
})
190+
.then(function(response) { return response.text(); })
191+
.then(function(response_text) {
192+
assert_equals(
193+
response_text,
194+
'Referrer: \n' +
195+
'ReferrerPolicy: strict-origin',
196+
'Service Worker should respond to fetch with no referrer with "strict-origin" and a HTTP request');
197+
return frame.contentWindow.fetch('resources/simple.html?referrerFull',
198+
{referrerPolicy: "strict-origin-when-cross-origin", referrer: referrer});
199+
})
200+
.then(function(response) { return response.text(); })
201+
.then(function(response_text) {
202+
assert_equals(
203+
response_text,
204+
'Referrer: ' + href + '\n' +
205+
'ReferrerPolicy: strict-origin-when-cross-origin',
206+
'Service Worker should respond to fetch with the referrer URL with "strict-origin-when-cross-origin" and a same origin request');
207+
var http_url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() +
208+
'/resources/simple.html?referrerFull';
209+
return frame.contentWindow.fetch(http_url,
210+
{referrerPolicy: "strict-origin-when-cross-origin", referrer: referrer});
211+
})
212+
.then(function(response) { return response.text(); })
213+
.then(function(response_text) {
214+
assert_equals(
215+
response_text,
216+
'Referrer: ' + origin + '/' + '\n' +
217+
'ReferrerPolicy: strict-origin-when-cross-origin',
218+
'Service Worker should respond to fetch with the referrer origin with "strict-origin-when-cross-origin" and a HTTPS cross origin request');
219+
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() +
220+
'/resources/simple.html?referrerFull';
221+
return frame.contentWindow.fetch(http_url,
222+
{referrerPolicy: "strict-origin-when-cross-origin", referrer: referrer});
223+
})
224+
.then(function(response) { return response.text(); })
225+
.then(function(response_text) {
226+
assert_equals(
227+
response_text,
228+
'Referrer: \n' +
229+
'ReferrerPolicy: strict-origin-when-cross-origin',
230+
'Service Worker should respond to fetch with no referrer with "strict-origin-when-cross-origin" and a HTTP request');
231+
});
232+
}
233+
234+
async_test(function(t) {
235+
var scope = 'resources/simple.html?referrerPolicy';
236+
var frame;
237+
service_worker_unregister_and_register(t, worker, scope)
238+
.then(function(reg) {
239+
return wait_for_state(t, reg.installing, 'activated');
240+
})
241+
.then(function() { return with_iframe(scope); })
242+
.then(function(f) {
243+
frame = f;
244+
assert_equals(
245+
frame.contentDocument.body.textContent,
246+
'ReferrerPolicy: no-referrer-when-downgrade',
247+
'Service Worker should respond to fetch with the default referrer policy');
248+
// First, run the referrer policy tests without passing a referrer in RequestInit.
249+
return run_referrer_policy_tests(frame, undefined, frame.contentDocument.location.href,
250+
frame.contentDocument.location.origin);
251+
})
252+
.then(function() {
253+
// Now, run the referrer policy tests while passing a referrer in RequestInit.
254+
var referrer = get_host_info()['HTTPS_ORIGIN'] + base_path() + 'fake-referrer';
255+
return run_referrer_policy_tests(frame, 'fake-referrer', referrer,
256+
frame.contentDocument.location.origin);
257+
})
258+
.then(function() {
259+
frame.remove();
260+
return service_worker_unregister_and_done(t, scope);
261+
})
262+
.catch(unreached_rejection(t));
263+
}, 'Service Worker responds to fetch event with the referrer policy');
264+
265+
</script>
266+
</body>

0 commit comments

Comments
 (0)