blob: 4e9dee0d05c2ee501a40f0f0e8fa450f0a52a06d [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
<script src="/js-test-resources/ui-helper.js"></script>
<script src="/resourceLoadStatistics/resources/util.js"></script>
<script>
description("Tests that a cross-site iframe can not request storage access under general third-party cookie blocking if it has not received user interaction as first-party.");
jsTestIsAsync = true;
const firstPartyUrl = "http://127.0.0.1:8000";
const thirdPartyUrl = "http://localhost:8000";
function receiveMessage(event) {
if (event.origin === "http://localhost:8000") {
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);
testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
setEnableFeature(false, finishJSTest);
});
}
window.addEventListener("message", receiveMessage, false);
function activateElement(elementId) {
var element = document.getElementById(elementId);
var centerX = element.offsetLeft + element.offsetWidth / 2;
var centerY = element.offsetTop + element.offsetHeight / 2;
UIHelper.activateAt(centerX, centerY).then(
function () {
if (window.eventSender)
eventSender.keyDown("escape");
else {
testFailed("No eventSender.");
testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
setEnableFeature(false, finishJSTest);
});
}
},
function () {
testFailed("Promise rejected.");
testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
setEnableFeature(false, finishJSTest);
});
}
);
}
function runTest() {
if (document.location.hash !== "#cookieSet") {
setEnableFeature(true, function() {
document.location.href = thirdPartyUrl + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#" + firstPartyUrl + "/storageAccess/deny-due-to-no-interaction-under-general-third-party-cookie-blocking.html#cookieSet";
});
} else {
testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
testFailed("Third-party set as prevalent resource.");
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.onload = function() {
activateElement("TheIframeThatRequestsStorageAccess");
};
iframeElement.id = "TheIframeThatRequestsStorageAccess";
iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldNotBeConsulted,policyShouldNotGrantAccess,isNotSameOriginIframe";
document.body.appendChild(iframeElement);
});
});
}
}
</script>
</head>
<body onload="runTest()">
</body>
</html>