5 <script src="/js-test-resources/js-test.js"></script>
7 <body onload="runTest()">
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 if (document.location.hash === "") {
20 setEnableFeature(true);
21 if (testRunner.isStatisticsPrevalentResource("http://localhost"))
22 testFailed("Localhost was classified as prevalent resource before the test starts.");
23 testRunner.dumpChildFramesAsText();
24 document.location.hash = "step1";
27 const partitionHost = "127.0.0.1:8000";
28 const thirdPartyOrigin = "http://localhost:8000";
29 const resourcePath = "/resourceLoadStatistics/resources";
30 const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath;
31 const partitionBaseUrl = "http://" + partitionHost + resourcePath;
32 const firstPartyCookieName = "firstPartyCookie";
33 const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
34 const partitionedCookieName = "partitionedCookie";
35 const returnUrl = "http://" + partitionHost + "/resourceLoadStatistics/remove-partitioning-from-redirect.html";
36 const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + partitionedCookieName;
37 const redirectChainUrl = thirdPartyBaseUrl + "/redirect.php?redirectTo=" + partitionBaseUrl + subPathToGetCookies;
39 function openIframe(url, onLoadHandler) {
40 const element = document.createElement("iframe");
43 element.onload = onLoadHandler;
45 document.body.appendChild(element);
49 switch (document.location.hash) {
51 // Set localhost as prevalent.
52 document.location.hash = "step2";
53 testRunner.setStatisticsPrevalentResource("http://localhost", true);
54 testRunner.statisticsUpdateCookiePartitioning();
55 if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
56 testFailed("Host did not get set as prevalent resource.");
60 // Set first-party cookie for 127.0.0.1.
61 document.location.href = partitionBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step3";
64 // Check that the cookie gets sent for 127.0.0.1 under 127.0.0.1.
65 document.location.hash = "step4";
66 openIframe(partitionBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
69 document.location.hash = "step5";
70 // 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.
71 openIframe(redirectChainUrl + "&message=Redirect case, should receive first-party cookie.", runTest);
74 setEnableFeature(false);