<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="resources/cached-script.js"></script>
<script src="../resources/inspector-test.js"></script>
<script src="resources/resource-size-test.js"></script>
<script>
TestPage.dispatchEventToFrontend("LoadComplete");

function test()
{
    let suite = InspectorTest.createAsyncSuite("Resource.Size.MemoryCache");

    addResourceSizeTest(suite, {
        name: "Resource.Size.MemoryCache.Basic",
        description: "Sizes of a cached script resource with a validation request",
        statusCode: 304,
        compressed: false,
        responseSource: WI.Resource.ResponseSource.MemoryCache,
        headers: true,
        resourceLoader() {
            const ignoreCache = false;
            const revalidateAllResources = true;
            const pattern = /cached-script\.js$/;
            InspectorTest.reloadPage({ignoreCache, revalidateAllResources});
            return InspectorTest.awaitEvent("LoadComplete").then((event) => {
                let resource = null;
                for (let item of WI.networkManager.mainFrame.resourceCollection) {
                    if (pattern.test(item.url)) {
                        resource = item;
                        break;
                    }
                }
                if (!resource) {
                    InspectorTest.fail("Failed to find specific resource.");
                    throw "Fail";
                }
                return resource;
            });
        }
    });

    suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Test for Resource size values (transfer size, decoded size, header size, request and response) for resources served from the memory cache.</p>
</body>
</html>
