5 <script src="/js-test-resources/js-test.js"></script>
9 description("Tests that partitioning 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-partitioning-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 partitioning 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.setStatisticsHasHadNonRecentUserInteraction("http://localhost");
64 testRunner.statisticsUpdateCookiePartitioning(function() {
69 // Set partitioned cookie for localhost under 127.0.0.1.
70 document.location.hash = "step6";
71 openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Set partitioned, third-party cookie.", runTest);
74 // Check that partitioned cookie gets sent for localhost under 127.0.0.1 since localhost is partitioned.
75 document.location.hash = "step7";
76 openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive partitioned cookie.", runTest);
79 // 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.
80 document.location.hash = "step8";
81 openIframe(redirectChainUrl + "&message=Redirect case 2, should receive first-party cookie for 127.0.0.1.", runTest);
84 setEnableFeature(false);
90 if (document.location.hash === "") {
91 setEnableFeature(true);
92 if (testRunner.isStatisticsPrevalentResource("http://localhost"))
93 testFailed("Localhost was classified as prevalent resource before the test starts.");
94 testRunner.dumpChildFramesAsText();
95 document.location.hash = "step1";
96 // Make sure the network process is up-to-date.
97 testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false, runTest);