<!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 non-recent user interaction doesn't get storage access under its opener if it just loads and auto-dismisses.");
    jsTestIsAsync = true;

    function finishTest() {
        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 not 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;
    var newWin;

    function run() {
        setEnableFeature(true, function() {
            window.addEventListener("message", receiveMessage, false);

            testRunner.setCanOpenWindows();

            testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, true, function() {
                if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
                    testFailed("Host did not get set as prevalent resource.");
                testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, true, function() {
                    if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyOrigin))
                        testFailed("Host did not get logged for user interaction.");
                    testRunner.dumpChildFramesAsText();
                    testRunner.setCloseRemainingWindowsWhenComplete(true);

                    testRunner.statisticsUpdateCookieBlocking(function () {
                        newWin = window.open(thirdPartyOrigin + "/storageAccess/resources/set-cookie-and-report-back.html", "testWindow");
                    });
                });
            });
        });
    }
</script>
</body>
</html>
