|
| 1 | +<!DOCTYPE html> |
| 2 | +<title>link rel=compression-dictionary, referrerpolicy attribute</title> |
| 3 | +<meta name="timeout" content="long"/> |
| 4 | +<link rel="help" href="http://github.com/whatwg/html/pull/11620"> |
| 5 | +<link rel="help" href="https://html.spec.whatwg.org/#create-link-options-from-element"> |
| 6 | +<link rel="help" href="https://w3c.github.io/webappsec-referrer-policy/#referrer-policy"> |
| 7 | +<link rel="help" href="https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer"> |
| 8 | +<script src="/resources/testharness.js"></script> |
| 9 | +<script src="/resources/testharnessreport.js"></script> |
| 10 | +<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> |
| 11 | +<script src="./resources/compression-dictionary-util.sub.js"></script> |
| 12 | +<script> |
| 13 | +let frame; |
| 14 | + |
| 15 | +// Set up the service worker and the frame. |
| 16 | +const kScope = 'resources/empty.https.html'; |
| 17 | +promise_test(t => { |
| 18 | + const kScript = 'resources/fetch-options-worker.js'; |
| 19 | + return service_worker_unregister_and_register(t, kScript, kScope) |
| 20 | + .then(registration => { |
| 21 | + add_completion_callback(() => { |
| 22 | + registration.unregister(); |
| 23 | + }); |
| 24 | + |
| 25 | + return wait_for_state(t, registration.installing, 'activated'); |
| 26 | + }) |
| 27 | + .then(() => { |
| 28 | + return with_iframe(kScope); |
| 29 | + }) |
| 30 | + .then(f => { |
| 31 | + frame = f; |
| 32 | + add_completion_callback(() => { f.remove(); }); |
| 33 | + }); |
| 34 | + }, 'Initialize global state'); |
| 35 | + |
| 36 | +function expectedReferrer(referrerPolicyAttributeValue) { |
| 37 | + switch(referrerPolicyAttributeValue) { |
| 38 | + case "no-referrer": |
| 39 | + return ""; |
| 40 | + case "origin": |
| 41 | + case "strict-origin": |
| 42 | + return `${location.origin}/`; |
| 43 | + default: |
| 44 | + return (new URL(kScope, `${location.origin}${location.pathname}`)).href; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +function expectedReferrerPolicy(referrerPolicyAttributeValue) { |
| 49 | +if (referrerPolicyAttributeValue === null || |
| 50 | + referrerPolicyAttributeValue === "" || |
| 51 | + referrerPolicyAttributeValue === "invalid") { |
| 52 | + return "strict-origin-when-cross-origin"; |
| 53 | + } |
| 54 | + return referrerPolicyAttributeValue; |
| 55 | +} |
| 56 | + |
| 57 | +[ |
| 58 | + null, |
| 59 | + "", |
| 60 | + "no-referrer", |
| 61 | + "no-referrer-when-downgrade", |
| 62 | + "same-origin", |
| 63 | + "origin", |
| 64 | + "strict-origin", |
| 65 | + "origin-when-cross-origin", |
| 66 | + "strict-origin-when-cross-origin", |
| 67 | + "unsafe-url", |
| 68 | + "invalid", |
| 69 | +].forEach(referrerPolicy => { |
| 70 | + const test_name = referrerPolicy !== null ? `referrerpolicy='${referrerPolicy}'` : "no referrerpolicy attribute"; |
| 71 | + compression_dictionary_promise_test(async t => { |
| 72 | + await new Promise((resolve, reject) => { |
| 73 | + let node = frame.contentWindow.document.createElement("link"); |
| 74 | + node.rel = "compression-dictionary"; |
| 75 | + node.onload = resolve; |
| 76 | + node.onerror = reject; |
| 77 | + if (referrerPolicy !== null) |
| 78 | + node.setAttribute("referrerpolicy", referrerPolicy); |
| 79 | + node.href = `dummy?referrerPolicy=${expectedReferrerPolicy(referrerPolicy)}&referrer=${expectedReferrer(referrerPolicy)}`; |
| 80 | + frame.contentWindow.document.body.appendChild(node); |
| 81 | + }).catch(() => { |
| 82 | + assert_unreached("Fetch errored."); |
| 83 | + }); |
| 84 | + }, `HTMLLinkElement rel=compression-dictionary (${test_name})`); |
| 85 | +}); |
| 86 | +</script> |
0 commit comments