blob: 5ba0fa3d7d86751385783c947e22d522a8cb72bd [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
<script src="/resourceLoadStatistics/resources/util.js"></script>
<script>
description("Tests document.hasStorageAccess() for a 3rd-party with cookies under general third-party cookie blocking.");
jsTestIsAsync = true;
const firstPartyUrl = "http://127.0.0.1:8000";
const thirdPartyUrl = "http://localhost:8000";
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event) {
if (event.origin === thirdPartyUrl) {
if (event.data.indexOf("PASS") !== -1)
testPassed(event.data.replace("PASS ", ""));
else
testFailed(event.data.replace("FAIL ", ""));
} else
testFailed("Received a message from an unexpected origin: " + event.origin);
if (document.location.hash === "#lastStep") {
testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
setEnableFeature(false, finishJSTest);
});
} else
runTests();
}
function runTests() {
switch (document.location.hash) {
case "":
setEnableFeature(true, function () {
if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
testFailed("Third-party started out as prevalent resource.");
if (testRunner.isStatisticsHasHadUserInteraction(thirdPartyUrl))
testFailed("Third-party started out logged for user interaction.");
if (testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
testFailed("First-party started out logged for user interaction.");
document.location.hash = "step1";
// Set a cookie for the third-party and continue.
document.location.href = thirdPartyUrl + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#" + firstPartyUrl + "/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie.html#step1";
});
break;
case "#step1":
document.location.hash = "step2";
// No general third-party cookie blocking, no user interaction, not prevalent.
let iframeElement = document.createElement("iframe");
iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldGrantAccess";
document.body.appendChild(iframeElement);
break;
case "#step2":
document.location.hash = "step3";
// No general third-party cookie blocking, third-party user interaction, not prevalent.
testRunner.setStatisticsHasHadUserInteraction(thirdPartyUrl, true, function() {
if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyUrl))
testFailed("Third-party did not get logged for user interaction.");
let iframeElement = document.createElement("iframe");
iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldGrantAccess";
document.body.appendChild(iframeElement);
});
break;
case "#step3":
document.location.hash = "step4";
// No general third-party cookie blocking, first- and third-party user interaction, not prevalent.
testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, true, function() {
if (!testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
testFailed("First-party did not get logged for user interaction.");
let iframeElement = document.createElement("iframe");
iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldGrantAccess";
document.body.appendChild(iframeElement);
});
break;
case "#step4":
document.location.hash = "step5";
// Third-party cookie blocking under first-parties without user interaction, only third-party user interaction, not prevalent.
testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, false, function() {
if (testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
testFailed("First-party got logged for user interaction.");
let iframeElement = document.createElement("iframe");
iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldNotGrantAccess";
document.body.appendChild(iframeElement);
});
}, true);
break;
case "#step5":
document.location.hash = "step6";
// General third-party cookie blocking, first- and third-party user interaction, not prevalent.
testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, true, function() {
if (!testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
testFailed("First-party did not get logged for user interaction.");
let iframeElement = document.createElement("iframe");
iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldNotGrantAccess";
document.body.appendChild(iframeElement);
});
}, false);
break;
case "#step6":
document.location.hash = "lastStep";
// General third-party cookie blocking, first- and third-party user interaction, prevalent.
testRunner.setStatisticsPrevalentResource(thirdPartyUrl, true, function() {
if (!testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
testFailed("Third-party not set as prevalent resource.");
testRunner.statisticsUpdateCookieBlocking(function() {
let iframeElement = document.createElement("iframe");
iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldNotGrantAccess";
document.body.appendChild(iframeElement);
});
});
break;
}
}
</script>
</head>
<body onload="runTests()">
</body>
</html>