blob: cd7046dd9e2054374a0730a94e251f746c6e52b9 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<script>
description("Tests that blocking is removed mid-flight in redirects.");
jsTestIsAsync = true;
function setEnableFeature(enable) {
if (!enable)
testRunner.statisticsResetToConsistentState();
internals.setResourceLoadStatisticsEnabled(enable);
testRunner.setCookieStoragePartitioningEnabled(enable);
}
const partitionHost = "127.0.0.1:8000";
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 = "http://" + partitionHost + "/resourceLoadStatistics/remove-blocking-in-redirect.html";
const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + partitionedCookieName;
const redirectChainUrl = thirdPartyOrigin + resourcePath + "/redirect.php?redirectTo=http://" + partitionHost + resourcePath + subPathToGetCookies;
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 cookies for 127.0.0.1 and localhost.
document.cookie = firstPartyCookieName + "=127.0.0.1;path='/'";
document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step2";
break;
case "#step2":
// Check that the cookie gets sent for localhost under 127.0.0.1 since localhost is not prevalent.
document.location.hash = "step3";
openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
break;
case "#step3":
document.location.hash = "step4";
// 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.
openIframe(redirectChainUrl + "&message=Redirect case 1, should receive first-party cookie for 127.0.0.1.", runTest);
break;
case "#step4":
// Set localhost as prevalent and with non-recent user interaction to put it in the blocking category.
document.location.hash = "step5";
testRunner.setStatisticsPrevalentResource("http://localhost", true);
if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
testFailed("Host did not get set as prevalent resource.");
testRunner.statisticsUpdateCookiePartitioning(function() {
runTest();
});
break;
case "#step5":
// Set partitioned cookie for localhost under 127.0.0.1.
document.location.hash = "step6";
openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Set partitioned, third-party cookie.", runTest);
break;
case "#step6":
// Check that no cookie gets sent for localhost under 127.0.0.1 since localhost's cookies are blocked.
document.location.hash = "step7";
openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive no cookie.", runTest);
break;
case "#step7":
// 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.
document.location.hash = "step8";
openIframe(redirectChainUrl + "&message=Redirect case 2, should receive first-party cookie for 127.0.0.1.", runTest);
break;
case "#step8":
setEnableFeature(false);
finishJSTest();
break;
}
}
if (document.location.hash === "") {
setEnableFeature(true);
if (testRunner.isStatisticsPrevalentResource("http://localhost"))
testFailed("Localhost was classified as prevalent resource before the test starts.");
testRunner.dumpChildFramesAsText();
document.location.hash = "step1";
// Make sure the network process is up-to-date.
testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false, runTest);
} else {
runTest();
}
</script>
</body>
</html>