blob: 26c06bfbb200e3c3fec1649f0f3d0bcc56a50f94 [file] [log] [blame] [edit]
<!DOCTYPE html><!-- webkit-test-runner [ OptInPartitionedCookiesEnabled=true ] -->
<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 only partitioned third-party cookies are allowed, unpartitioned third-party cookies are blocked.");
jsTestIsAsync = true;
const partitionHost = "127.0.0.1:8443";
const partitionOrigin = "https://" + partitionHost;
const thirdPartyOrigin = "https://localhost:8443";
const resourcePath = "/resourceLoadStatistics/resources";
const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath;
const firstPartyCookieName = "firstPartyCookie";
const subPathToSetFirstPartyCookie = "/set-cookie.py?name=" + firstPartyCookieName + "&value=value";
const partitionedCookieName = "partitionedCookie";
const subPathToSetPartitionedCookie = "/set-cookie.py?name=" + partitionedCookieName + "&value=value&partitioned=1";
const returnUrl = partitionOrigin + "/resourceLoadStatistics/only-partitioned-third-party-cookies.https.html";
const subPathToGetCookies = "/get-cookies.py?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.
testRunner.setStatisticsHasHadUserInteraction(partitionOrigin, true, function() {
// Check that the cookie is still blocked for localhost under 127.0.0.1.
openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After user interaction, should receive no cookies.", runTest);
});
break;
case "#step4":
document.location.hash = "step5";
openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Setting partitioned cookie.", runTest);
break;
case "#step5":
document.location.hash = "step6";
// Check that the cookie is blocked for localhost under 127.0.0.1, but partitioned cookies is present.
openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After setting partitioned cookie, should have one cookie.", runTest);
break;
case "#step6":
testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
setEnableFeature(false, finishJSTest);
});
break;
}
}
if (document.location.hash === "") {
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, false, true);
});
} else {
runTest();
}
</script>
</body>
</html>