| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <script src="/js-test-resources/js-test.js"></script> |
| <script src="resources/util.js"></script> |
| </head> |
| <body> |
| <script> |
| description("Tests that all third-party cookies are blocked under websites that have not received user interaction."); |
| jsTestIsAsync = true; |
| |
| const partitionHost = "127.0.0.1:8000"; |
| const partitionOrigin = "http://" + partitionHost; |
| const thirdPartyOrigin = "http://localhost:8000"; |
| const resourcePath = "/resourceLoadStatistics/resources"; |
| const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath; |
| const firstPartyCookieName = "firstPartyCookie"; |
| const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value"; |
| const partitionedCookieName = "partitionedCookie"; |
| const subPathToSetPartitionedCookie = "/set-cookie.php?name=" + partitionedCookieName + "&value=value"; |
| const returnUrl = partitionOrigin + "/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction.html"; |
| const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + partitionedCookieName; |
| |
| function openIframe(url, onLoadHandler) { |
| const element = document.createElement("iframe"); |
| element.src = url; |
| if (onLoadHandler) { |
| element.onload = onLoadHandler; |
| } |
| document.body.appendChild(element); |
| } |
| |
| function runTest() { |
| switch (document.location.hash) { |
| case "#step1": |
| // Set first-party cookie for localhost. |
| document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step2"; |
| break; |
| case "#step2": |
| document.location.hash = "step3"; |
| // Check that the cookie is blocked for localhost under 127.0.0.1 even though localhost is not prevalent. |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Before user interaction, should receive no cookies.", runTest); |
| break; |
| case "#step3": |
| document.location.hash = "step4"; |
| // Produce user interaction for the first-party to allow third-party cookie access. |
| testRunner.setStatisticsHasHadUserInteraction(partitionOrigin, true, function() { |
| // Check that the cookie is no longer blocked for localhost under 127.0.0.1. |
| openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After user interaction, should receive first-party cookie.", runTest); |
| }); |
| break; |
| case "#step4": |
| testRunner.setUseITPDatabase(false); |
| testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() { |
| setEnableFeature(false, finishJSTest); |
| }); |
| break; |
| } |
| } |
| |
| if (document.location.hash === "") { |
| testRunner.setUseITPDatabase(true); |
| setEnableFeature(true, function () { |
| if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin)) |
| testFailed("Localhost was classified as prevalent resource before the test starts."); |
| testRunner.dumpChildFramesAsText(); |
| document.location.hash = "step1"; |
| testRunner.setStatisticsShouldBlockThirdPartyCookies(true, runTest); |
| }); |
| } else { |
| runTest(); |
| } |
| </script> |
| </body> |
| </html> |