blob: b1fc4d8bdeb6260aae9aec0a246bea5f216a016c [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-origin iframe can open a window if storage access is denied without prompt.");
jsTestIsAsync = true;
const hostUnderTest = "localhost:8000";
const statisticsUrl = "http://" + hostUnderTest + "/temp";
window.addEventListener("message", receiveMessage, false);
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);
setEnableFeature(false, finishJSTest);
}
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.");
setEnableFeature(false, finishJSTest);
}
},
function () {
testFailed("Promise rejected.");
setEnableFeature(false, finishJSTest);
}
);
}
function runTest() {
setEnableFeature(true, function() {
testRunner.setCanOpenWindows(false);
testRunner.setPopupBlockingEnabled(true);
testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
testFailed("Host did not get set as prevalent resource.");
testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, false, function() {
if (testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
testFailed("Host did get logged for user interaction.");
testRunner.statisticsUpdateCookieBlocking(function() {
let iframeElement = document.createElement("iframe");
iframeElement.onload = function() {
activateElement("TheIframeThatRequestsStorageAccess");
};
iframeElement.id = "TheIframeThatRequestsStorageAccess";
iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe-and-pop-window.html#userShouldNotGrantAccess,userShouldNotBeConsulted,policyShouldNotGrantAccess,isNotSameOriginIframe";
document.body.appendChild(iframeElement);
});
});
});
});
}
</script>
</head>
<body onload="runTest()">
</body>
</html>