blob: d4350802fd8f754d9479042b80e12da62bc82291 [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("Check correct UI data gets reported with storage access granted.");
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) {
testRunner.setStatisticsPrevalentResource(thirdPartyUrl, true, function () {
testRunner.dumpResourceLoadStatistics();
testPassed(event.data.replace("PASS ", ""));
testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
setEnableFeature(false, finishJSTest);
});
});
return;
} 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/aggregate-sorted-data-with-storage-access.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.");
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.onload = function() {
activateElement("TheIframeThatRequestsStorageAccess");
};
iframeElement.id = "TheIframeThatRequestsStorageAccess";
iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
document.body.appendChild(iframeElement);
});
});
});
}
}
</script>
</head>
<body onload="runTest()">
</body>
</html>