<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Tests for Prevalent Resource With User Interaction</title>
    <script src="/js-test-resources/js-test.js"></script>
    <script src="resources/util.js"></script>
</head>
<body onload="setTimeout('setUpAndRun()', 0)">
<script>
    if (testRunner)
        testRunner.waitUntilDone();

    const hostUnderTest = "127.0.0.1:8000";
    const statisticsUrl = "http://" + hostUnderTest + "/temp";
    const otherPrevalentUrl = "http://localhost:8000/temp";
    function runTestRunnerTest() {
        if (document.cookie !== "")
            testFailed("document.cookie not empty.");
        const cookie = "testCookie=testValue";
        document.cookie = cookie + "; max-age=100;";
        if (document.cookie !== cookie)
            testFailed("document.cookie did not get set.");

        testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
            if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
                testFailed("Host did not get set as prevalent resource.");

            // This is done to not have an empty set of prevalent resources.
            // Otherwise data records are never scanned.
            testRunner.setStatisticsPrevalentResource(otherPrevalentUrl, true, function() {
                if (!testRunner.isStatisticsPrevalentResource(otherPrevalentUrl))
                    testFailed("Other host did not get set as prevalent resource.");

                testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() {
                    if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
                        testFailed("Host did not get logged for user interaction.");

                    testRunner.installStatisticsDidModifyDataRecordsCallback(function() {
                        if (document.cookie === cookie)
                            testPassed("Cookie not deleted.");
                        else
                            testFailed("Cookie deleted or document.cookie contains other cookies: " + document.cookie);
                        setEnableFeature(false, function() {
                            testRunner.notifyDone();
                        });
                    });
                    testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
                    testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
                    testRunner.statisticsProcessStatisticsAndDataRecords();
                });
            });
        });
    }

    function setUpAndRun() {
        if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
            setEnableFeature(true, function () {
                runTestRunnerTest();
            });
        } else {
            testFailed("Wrong host, no testRunner, or no internals.");
            setEnableFeature(false, function() {
                testRunner.notifyDone();
            });
        }
    }
</script>
</body>
</html>
