blob: ac4450ca9b385e1f064f9026932bcabdde492f89 [file] [log] [blame]
<!-- webkit-test-runner [ useEphemeralSession=true ] -->
<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
<script src="/resourceLoadStatistics/resources/util.js"></script>
</head>
<body onload="run()">
<script>
description("Tests that a cross-origin window from a prevalent domain with previous user interaction gets storage access under its opener if it gets user interaction (ephemeral).");
jsTestIsAsync = true;
function finishTest() {
testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function () {
setEnableFeature(false, finishJSTest);
});
}
function openIframe(url, onLoadHandler) {
const element = document.createElement("iframe");
element.src = url;
if (onLoadHandler) {
element.onload = onLoadHandler;
}
document.body.appendChild(element);
}
function receiveMessage(event) {
if (event.origin === "http://localhost:8000") {
if (event.data.indexOf("PASS") !== -1)
testPassed(event.data.replace("PASS ", ""));
else
testFailed(event.data);
} else
testFailed("Received a message from an unexpected origin: " + event.origin);
newWin.close();
openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", finishTest);
}
const thirdPartyOrigin = "http://localhost:8000";
const resourcePath = "/storageAccess/resources";
const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath;
const firstPartyCookieName = "firstPartyCookie";
const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName;
let newWin;
function run() {
setEnableFeature(true, function () {
window.addEventListener("message", receiveMessage, false);
testRunner.setCanOpenWindows();
testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, true, function() {
if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyOrigin))
testFailed("Host did not get logged for user interaction.");
testRunner.dumpChildFramesAsText();
testRunner.setCloseRemainingWindowsWhenComplete(true);
testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function () {
newWin = window.open(thirdPartyOrigin + "/storageAccess/resources/produce-user-gesture-set-cookie-and-report-back.html", "testWindow");
});
});
});
}
</script>
</body>
</html>