-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ServiceWorker] Separate referrer policy tests into fetch-event-refer…
…rer-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
- Loading branch information
1 parent
54af823
commit 04da785
Showing
2 changed files
with
266 additions
and
255 deletions.
There are no files selected for viewing
266 changes: 266 additions & 0 deletions
266
service-workers/service-worker/fetch-event-referrer-policy.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,266 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<script src="resources/test-helpers.sub.js"></script> | ||
<body> | ||
<script> | ||
var worker = 'resources/fetch-event-test-worker.js'; | ||
|
||
function run_referrer_policy_tests(frame, referrer, href, origin) { | ||
return frame.contentWindow.fetch('resources/simple.html?referrerFull', | ||
{method: "GET", referrer: referrer}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + href + '\n' + | ||
'ReferrerPolicy: no-referrer-when-downgrade', | ||
'Service Worker should respond to fetch with the referrer URL when a member of RequestInit is present'); | ||
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{method: "GET", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: \n' + | ||
'ReferrerPolicy: no-referrer-when-downgrade', | ||
'Service Worker should respond to fetch with no referrer when a member of RequestInit is present with an HTTP request'); | ||
return frame.contentWindow.fetch('resources/simple.html?referrerFull', | ||
{referrerPolicy: "", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + href + '\n' + | ||
'ReferrerPolicy: no-referrer-when-downgrade', | ||
'Service Worker should respond to fetch with the referrer with ""'); | ||
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{referrerPolicy: "", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: \n' + | ||
'ReferrerPolicy: no-referrer-when-downgrade', | ||
'Service Worker should respond to fetch with no referrer with ""'); | ||
return frame.contentWindow.fetch('resources/simple.html?referrerFull', | ||
{referrerPolicy: "origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + origin + '/' + '\n' + | ||
'ReferrerPolicy: origin', | ||
'Service Worker should respond to fetch with the referrer origin with "origin" and a same origin request'); | ||
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{referrerPolicy: "origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + origin + '/' + '\n' + | ||
'ReferrerPolicy: origin', | ||
'Service Worker should respond to fetch with the referrer origin with "origin" and a cross origin request'); | ||
return frame.contentWindow.fetch('resources/simple.html?referrerFull', | ||
{referrerPolicy: "origin-when-cross-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + href + '\n' + | ||
'ReferrerPolicy: origin-when-cross-origin', | ||
'Service Worker should respond to fetch with the referrer URL with "origin-when-cross-origin" and a same origin request'); | ||
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{referrerPolicy: "origin-when-cross-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + origin + '/' + '\n' + | ||
'ReferrerPolicy: origin-when-cross-origin', | ||
'Service Worker should respond to fetch with the referrer origin with "origin-when-cross-origin" and a cross origin request'); | ||
return frame.contentWindow.fetch('resources/simple.html?referrerFull', | ||
{referrerPolicy: "no-referrer-when-downgrade", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + href + '\n' + | ||
'ReferrerPolicy: no-referrer-when-downgrade', | ||
'Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and a same origin request'); | ||
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{referrerPolicy: "no-referrer-when-downgrade", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: \n' + | ||
'ReferrerPolicy: no-referrer-when-downgrade', | ||
'Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and an HTTP request'); | ||
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, {referrerPolicy: "unsafe-url", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + href + '\n' + | ||
'ReferrerPolicy: unsafe-url', | ||
'Service Worker should respond to fetch with no referrer with "unsafe-url"'); | ||
return frame.contentWindow.fetch('resources/simple.html?referrerFull', | ||
{referrerPolicy: "no-referrer", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: \n' + | ||
'ReferrerPolicy: no-referrer', | ||
'Service Worker should respond to fetch with no referrer URL with "no-referrer"'); | ||
return frame.contentWindow.fetch('resources/simple.html?referrerFull', | ||
{referrerPolicy: "same-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + href + '\n' + | ||
'ReferrerPolicy: same-origin', | ||
'Service Worker should respond to fetch with referrer URL with "same-origin" and a same origin request'); | ||
var http_url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{referrerPolicy: "same-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: \n' + | ||
'ReferrerPolicy: same-origin', | ||
'Service Worker should respond to fetch with no referrer with "same-origin" and cross origin request'); | ||
var http_url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{referrerPolicy: "strict-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + origin + '/' + '\n' + | ||
'ReferrerPolicy: strict-origin', | ||
'Service Worker should respond to fetch with the referrer origin with "strict-origin" and a HTTPS cross origin request'); | ||
return frame.contentWindow.fetch('resources/simple.html?referrerFull', | ||
{referrerPolicy: "strict-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + origin + '/' + '\n' + | ||
'ReferrerPolicy: strict-origin', | ||
'Service Worker should respond to fetch with the referrer origin with "strict-origin" and a same origin request'); | ||
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{referrerPolicy: "strict-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: \n' + | ||
'ReferrerPolicy: strict-origin', | ||
'Service Worker should respond to fetch with no referrer with "strict-origin" and a HTTP request'); | ||
return frame.contentWindow.fetch('resources/simple.html?referrerFull', | ||
{referrerPolicy: "strict-origin-when-cross-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + href + '\n' + | ||
'ReferrerPolicy: strict-origin-when-cross-origin', | ||
'Service Worker should respond to fetch with the referrer URL with "strict-origin-when-cross-origin" and a same origin request'); | ||
var http_url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{referrerPolicy: "strict-origin-when-cross-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: ' + origin + '/' + '\n' + | ||
'ReferrerPolicy: strict-origin-when-cross-origin', | ||
'Service Worker should respond to fetch with the referrer origin with "strict-origin-when-cross-origin" and a HTTPS cross origin request'); | ||
var http_url = get_host_info()['HTTP_ORIGIN'] + base_path() + | ||
'/resources/simple.html?referrerFull'; | ||
return frame.contentWindow.fetch(http_url, | ||
{referrerPolicy: "strict-origin-when-cross-origin", referrer: referrer}); | ||
}) | ||
.then(function(response) { return response.text(); }) | ||
.then(function(response_text) { | ||
assert_equals( | ||
response_text, | ||
'Referrer: \n' + | ||
'ReferrerPolicy: strict-origin-when-cross-origin', | ||
'Service Worker should respond to fetch with no referrer with "strict-origin-when-cross-origin" and a HTTP request'); | ||
}); | ||
} | ||
|
||
async_test(function(t) { | ||
var scope = 'resources/simple.html?referrerPolicy'; | ||
var frame; | ||
service_worker_unregister_and_register(t, worker, scope) | ||
.then(function(reg) { | ||
return wait_for_state(t, reg.installing, 'activated'); | ||
}) | ||
.then(function() { return with_iframe(scope); }) | ||
.then(function(f) { | ||
frame = f; | ||
assert_equals( | ||
frame.contentDocument.body.textContent, | ||
'ReferrerPolicy: no-referrer-when-downgrade', | ||
'Service Worker should respond to fetch with the default referrer policy'); | ||
// First, run the referrer policy tests without passing a referrer in RequestInit. | ||
return run_referrer_policy_tests(frame, undefined, frame.contentDocument.location.href, | ||
frame.contentDocument.location.origin); | ||
}) | ||
.then(function() { | ||
// Now, run the referrer policy tests while passing a referrer in RequestInit. | ||
var referrer = get_host_info()['HTTPS_ORIGIN'] + base_path() + 'fake-referrer'; | ||
return run_referrer_policy_tests(frame, 'fake-referrer', referrer, | ||
frame.contentDocument.location.origin); | ||
}) | ||
.then(function() { | ||
frame.remove(); | ||
return service_worker_unregister_and_done(t, scope); | ||
}) | ||
.catch(unreached_rejection(t)); | ||
}, 'Service Worker responds to fetch event with the referrer policy'); | ||
|
||
</script> | ||
</body> |
Oops, something went wrong.