5 <script src="/js-test-resources/js-test.js"></script>
9 description("Tests that blocking is removed mid-flight in redirects.");
12 function setEnableFeature(enable) {
14 testRunner.statisticsResetToConsistentState();
15 internals.setResourceLoadStatisticsEnabled(enable);
16 testRunner.setCookieStoragePartitioningEnabled(enable);
19 const partitionHost = "127.0.0.1:8000";
20 const thirdPartyOrigin = "http://localhost:8000";
21 const resourcePath = "/resourceLoadStatistics/resources";
22 const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath;
23 const firstPartyCookieName = "firstPartyCookie";
24 const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
25 const partitionedCookieName = "partitionedCookie";
26 const subPathToSetPartitionedCookie = "/set-cookie.php?name=" + partitionedCookieName + "&value=value";
27 const returnUrl = "http://" + partitionHost + "/resourceLoadStatistics/remove-blocking-in-redirect.html";
28 const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + partitionedCookieName;
29 const redirectChainUrl = thirdPartyOrigin + resourcePath + "/redirect.php?redirectTo=http://" + partitionHost + resourcePath + subPathToGetCookies;
31 function openIframe(url, onLoadHandler) {
32 const element = document.createElement("iframe");
35 element.onload = onLoadHandler;
37 document.body.appendChild(element);
41 switch (document.location.hash) {
43 // Set first-party cookies for 127.0.0.1 and localhost.
44 document.cookie = firstPartyCookieName + "=127.0.0.1;path='/'";
45 document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step2";
48 // Check that the cookie gets sent for localhost under 127.0.0.1 since localhost is not prevalent.
49 document.location.hash = "step3";
50 openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
53 document.location.hash = "step4";
54 // Load an iframe in a redirect chain that starts with localhost and ends with 127.0.0.1. Expect a cookie for 127.0.0.1.
55 openIframe(redirectChainUrl + "&message=Redirect case 1, should receive first-party cookie for 127.0.0.1.", runTest);
58 // Set localhost as prevalent and with non-recent user interaction to put it in the blocking category.
59 document.location.hash = "step5";
60 testRunner.setStatisticsPrevalentResource("http://localhost", true);
61 if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
62 testFailed("Host did not get set as prevalent resource.");
63 testRunner.statisticsUpdateCookiePartitioning(function() {
68 // Set partitioned cookie for localhost under 127.0.0.1.
69 document.location.hash = "step6";
70 openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Set partitioned, third-party cookie.", runTest);
73 // Check that no cookie gets sent for localhost under 127.0.0.1 since localhost's cookies are blocked.
74 document.location.hash = "step7";
75 openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive no cookie.", runTest);
78 // Load an iframe in a redirect chain that starts with localhost and ends with 127.0.0.1. Expect a cookie for 127.0.0.1.
79 document.location.hash = "step8";
80 openIframe(redirectChainUrl + "&message=Redirect case 2, should receive first-party cookie for 127.0.0.1.", runTest);
83 setEnableFeature(false);
89 if (document.location.hash === "") {
90 setEnableFeature(true);
91 if (testRunner.isStatisticsPrevalentResource("http://localhost"))
92 testFailed("Localhost was classified as prevalent resource before the test starts.");
93 testRunner.dumpChildFramesAsText();
94 document.location.hash = "step1";
95 // Make sure the network process is up-to-date.
96 testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false, runTest);