<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Tests that removal of website data deletes ITP data</title>
    <script src="/js-test-resources/js-test.js"></script>
    <script src="resources/util.js"></script>
</head>
<body>
<script>
    const hostUnderTest = "127.0.0.1";
    const statisticsUrl = "http://" + hostUnderTest + "/temp";
    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
    const topFrameOrigin4 = "http://127.0.0.5:8000/temp";

    function completeTest() {
        if (testRunner.isStatisticsRegisteredAsSubFrameUnder(statisticsUrl, topFrameOrigin1)
                || testRunner.isStatisticsRegisteredAsSubresourceUnder(topFrameOrigin2, statisticsUrl)
                || testRunner.isStatisticsRegisteredAsSubresourceUnder(statisticsUrl, topFrameOrigin3)
                || testRunner.isStatisticsRegisteredAsRedirectingTo(statisticsUrl, topFrameOrigin4))
            testFailed("Host not deleted from memory store.");
        else
            testPassed("Host deleted from memory store.");

        setEnableFeature(false, function() {
            testRunner.notifyDone();
        });
    }

    function runTestRunnerTest() {
        // Create entries in multiple database tables with the hostUnderTest.
        testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
        testRunner.setStatisticsSubresourceUnderTopFrameOrigin(topFrameOrigin2, statisticsUrl);
        testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin3);
        testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin4);

        if (!testRunner.isStatisticsRegisteredAsSubFrameUnder(statisticsUrl, topFrameOrigin1)
                || !testRunner.isStatisticsRegisteredAsSubresourceUnder(topFrameOrigin2, statisticsUrl)
                || !testRunner.isStatisticsRegisteredAsSubresourceUnder(statisticsUrl, topFrameOrigin3)
                || !testRunner.isStatisticsRegisteredAsRedirectingTo(statisticsUrl, topFrameOrigin4))
            testFailed("Failed to register subStatistics.");

        testRunner.clearStatisticsDataForDomain(hostUnderTest);
        completeTest();
    }

    if (window.testRunner && window.internals) {
        testRunner.waitUntilDone();
        setEnableFeature(true, runTestRunnerTest);
    }
</script>
</body>
</html>
