<!DOCTYPE html>
<html>
<head>
    <script src="/cookies/resources/cookie-utilities.js"></script>
    <script src="resources/util.js"></script>
</head>
<body onload="setTimeout('runTest()', 0)">
<div id="description">Check correct UI data gets reported with no storage access granted.</div>
<br>
<div id="output"></div>
<br>
<script>
    testRunner.waitUntilDone();
    testRunner.dumpAsText();

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

    const subOrigin1 = "http://subframe1:8000";
    const subOrigin2  = "http://subframe2:8000";
    const subOrigin3  = "http://subframe3:8000";
    
    const topFrameOrigin1 = "http://topframe1:8000";
    const topFrameOrigin2 = "http://topframe2:8000";
    const topFrameOrigin3 = "http://topframe3:8000";
    const topFrameOrigin4 = "http://topframe4:8000";

    function runTest() {
        setEnableFeature(true, function () {
            testRunner.setStatisticsPrevalentResource(subOrigin1, true, function () {
                testRunner.setStatisticsPrevalentResource(subOrigin2, true, function () {
                    testRunner.setStatisticsPrevalentResource(subOrigin3, true, function () {
                       // subOrigin1 will be logged under 2 top frames. Should appear second
                       testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin1, topFrameOrigin1);
                       testRunner.setStatisticsSubresourceUniqueRedirectTo(subOrigin1, topFrameOrigin2);

                       // subOrigin2 will be logged under 1 top frame. Should appear third
                       testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin2, topFrameOrigin1);

                       // subOrigin3 will be logged under 4 top frames. Should appear first
                       testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin3, topFrameOrigin1);
                       testRunner.setStatisticsSubresourceUniqueRedirectTo(subOrigin3, topFrameOrigin2);
                       testRunner.setStatisticsSubresourceUnderTopFrameOrigin(subOrigin3, topFrameOrigin3);
                       testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin3, topFrameOrigin4);

                       setTimeout(function () { finishTest() }, 500);
                    });
                });
            });
        });
    }
</script>
</body>
</html>
