| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="/js-test-resources/js-test.js"></script> |
| </head> |
| <body> |
| <script> |
| description("Tests support for Referrer-Policy HTTP header."); |
| jsTestIsAsync = true; |
| |
| const sourceOrigin = "https://127.0.0.1:8443/"; |
| const crossOrigin = "https://localhost:8443/"; |
| const downgradedOrigin = "http://127.0.0.1:8000/"; |
| const fullSourceURL = "fullSourceURL"; |
| |
| // [Referrer-Policy header, expected referrer, destination origin]. |
| let tests = [ |
| ["no-referrer", "", crossOrigin], |
| ["no-referrer", "", sourceOrigin], |
| ["no-referrer", "", downgradedOrigin], |
| ["origin", sourceOrigin, crossOrigin], |
| ["origin", sourceOrigin, sourceOrigin], |
| ["origin", sourceOrigin, downgradedOrigin], |
| ["unsafe-url", fullSourceURL, crossOrigin], |
| ["unsafe-url", fullSourceURL, sourceOrigin], |
| ["unsafe-url", fullSourceURL, downgradedOrigin], |
| ["no-referrer-when-downgrade", fullSourceURL, crossOrigin], |
| ["no-referrer-when-downgrade", fullSourceURL, sourceOrigin], |
| ["no-referrer-when-downgrade", "", downgradedOrigin], |
| ["same-origin", "", crossOrigin], |
| ["same-origin", fullSourceURL, sourceOrigin], |
| ["same-origin", "", downgradedOrigin], |
| ["strict-origin", sourceOrigin, crossOrigin], |
| ["strict-origin", sourceOrigin, sourceOrigin], |
| ["strict-origin", "", downgradedOrigin], |
| ["strict-origin-when-cross-origin", sourceOrigin, crossOrigin], |
| ["strict-origin-when-cross-origin", fullSourceURL, sourceOrigin], |
| ["strict-origin-when-cross-origin", "", downgradedOrigin], |
| ["origin-when-cross-origin", sourceOrigin, crossOrigin], |
| ["origin-when-cross-origin", fullSourceURL, sourceOrigin], |
| ["origin-when-cross-origin", sourceOrigin, downgradedOrigin], |
| ["invalid", fullSourceURL, crossOrigin], |
| ["invalid", fullSourceURL, sourceOrigin], |
| ["invalid", "", downgradedOrigin], |
| ["", fullSourceURL, crossOrigin], |
| ["", fullSourceURL, sourceOrigin], |
| ["", "", downgradedOrigin], |
| ]; |
| |
| let currentTestIndex = 0; |
| let isTestingMultipart = false; |
| |
| onmessage = (msg) => { |
| actualReferrer = msg.data; |
| if (currentTest[1] === fullSourceURL) |
| shouldBeEqualToString("actualReferrer", sourceOrigin + "security/resources/serve-referrer-policy-and-test.php?value=" + currentTest[0] + "&destinationOrigin=" + currentTest[2] + "&isTestingMultipart=" + (isTestingMultipart ? "1" : "0")); |
| else |
| shouldBeEqualToString("actualReferrer", "" + currentTest[1]); |
| debug(""); |
| |
| frame.remove(); |
| currentTestIndex++; |
| runNextTest(); |
| } |
| |
| function runNextTest() |
| { |
| if (currentTestIndex >= tests.length) { |
| if (!isTestingMultipart) { |
| isTestingMultipart = true; |
| currentTestIndex = 0; |
| } else { |
| finishJSTest(); |
| return; |
| } |
| } |
| |
| currentTest = tests[currentTestIndex]; |
| debug("Testing 'Referrer-Policy: " + currentTest[0] + "' - referrer origin: " + sourceOrigin + " - destination origin: " + currentTest[2] + " - isMultipartResponse? " + isTestingMultipart); |
| frame = document.createElement("iframe"); |
| frame.src = sourceOrigin + "security/resources/serve-referrer-policy-and-test.php?value=" + currentTest[0] + "&destinationOrigin=" + currentTest[2] + "&isTestingMultipart=" + (isTestingMultipart ? "1" : "0"); |
| document.body.appendChild(frame); |
| } |
| |
| runNextTest(); |
| </script> |
| </body> |
| </html> |