OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("../resources/utils.js"); |
| 4 importScripts("/common/get-host-info.sub.js") |
| 5 } |
| 6 |
| 7 function runTest(url, init, expectedReferrer, title) { |
| 8 promise_test(function(test) { |
| 9 url += (url.indexOf('?') !== -1 ? '&' : '?') + "headers=referer&cors"; |
| 10 |
| 11 return fetch(url , init).then(function(resp) { |
| 12 assert_equals(resp.status, 200, "HTTP status is 200"); |
| 13 assert_equals(resp.headers.get("x-request-referer"), expectedReferre
r, "Request's referrer is correct"); |
| 14 }); |
| 15 }, title); |
| 16 } |
| 17 |
| 18 var fetchedUrl = RESOURCES_DIR + "inspect-headers.py"; |
| 19 var corsFetchedUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.path
name) + RESOURCES_DIR + "inspect-headers.py"; |
| 20 var redirectUrl = RESOURCES_DIR + "redirect.py?location=" ; |
| 21 var corsRedirectUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.path
name) + RESOURCES_DIR + "redirect.py?location="; |
| 22 |
| 23 runTest(fetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, location.toSt
ring(), "origin-when-cross-origin policy on a same-origin URL"); |
| 24 runTest(corsFetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, get_host_
info().HTTP_ORIGIN + "/", "origin-when-cross-origin policy on a cross-origin URL
"); |
| 25 runTest(redirectUrl + corsFetchedUrl, { referrerPolicy: "origin-when-cross-origi
n"}, get_host_info().HTTP_ORIGIN + "/", "origin-when-cross-origin policy on a cr
oss-origin URL after same-origin redirection"); |
| 26 runTest(corsRedirectUrl + fetchedUrl, { referrerPolicy: "origin-when-cross-origi
n"}, get_host_info().HTTP_ORIGIN + "/", "origin-when-cross-origin policy on a sa
me-origin URL after cross-origin redirection"); |
| 27 |
| 28 |
| 29 var referrerUrlWithCredentials = get_host_info().HTTP_ORIGIN.replace("http://",
"http://username:password@"); |
| 30 runTest(fetchedUrl, {referrer: referrerUrlWithCredentials}, get_host_info().HTTP
_ORIGIN + "/", "Referrer with credentials should be stripped"); |
| 31 var referrerUrlWithFragmentIdentifier = get_host_info().HTTP_ORIGIN + "#fragment
Identifier"; |
| 32 runTest(fetchedUrl, {referrer: referrerUrlWithFragmentIdentifier}, get_host_info
().HTTP_ORIGIN + "/", "Referrer with fragment ID should be stripped"); |
| 33 |
| 34 done(); |
| 35 |
OLD | NEW |