blob: b3895b8cdf36b82eb377aa12b71c0752bcafb960 [file] [log] [blame]
<html>
<head>
<script src="../inspector-test.js"></script>
<script src="../network-test.js"></script>
<script>
var image;
function loadFirstImage() {
image = new Image();
image.onload = firstImageLoaded;
document.body.appendChild(image);
image.src = "resources/resource.php?type=image&random=1&size=400";
}
function firstImageLoaded()
{
console.log("Done1.");
}
function loadSecondImage() {
image.onload = secondImageLoaded;
image.src = "resources/resource.php?type=image&random=1&size=200";
}
function secondImageLoaded()
{
console.log("Done2.");
}
function forceCachedResourceLoaderGC() {
if (window.internals)
window.internals.garbageCollectDocumentResources();
}
function test()
{
// Since this test could be run together with other inspector backend cache
// tests, we need to reset size limits to default ones.
InspectorTest.resetInspectorResourcesData(step1);
var imageRequest;
function step1()
{
InspectorTest.addConsoleSniffer(step2);
InspectorTest.evaluateInPage("loadFirstImage()");
}
function step2()
{
imageRequest = WebInspector.panel("network").requests[WebInspector.panel("network").requests.length - 1];
imageRequest.requestContent(step3);
}
var originalContentLength;
function step3()
{
InspectorTest.addResult(imageRequest.url);
InspectorTest.addResult("request.type: " + imageRequest.type);
InspectorTest.addResult("request.content.length after requesting content: " + imageRequest.content.length);
originalContentLength = imageRequest.content.length;
InspectorTest.assertTrue(imageRequest.content.length > 0, "No content before destroying CachedResource.");
InspectorTest.addResult("Releasing cached resource.");
// Loading another image to the same image element so that the original image cached resource is released.
InspectorTest.addConsoleSniffer(step4);
InspectorTest.evaluateInPage("loadSecondImage()");
}
function step4(msg)
{
// Disable-enable cache to force MemoryCache::evictResources().
NetworkAgent.setCacheDisabled(true, step5);
}
function step5(msg)
{
NetworkAgent.setCacheDisabled(false, step6);
}
function step6()
{
// Force CachedResourceLoader garbage collector run.
InspectorTest.evaluateInPage("forceCachedResourceLoaderGC()");
// Re-request content now that CachedResource should have been destroyed.
delete imageRequest._content;
imageRequest.requestContent(step7);
}
function step7()
{
InspectorTest.addResult("request.content.length after requesting content: " + imageRequest.content.length);
originalContentLength = imageRequest.content.length;
InspectorTest.assertTrue(imageRequest.content.length === originalContentLength, "Content changed after cached resource was destroyed");
InspectorTest.resetInspectorResourcesData(step8);
}
function step8()
{
InspectorTest.completeTest();
}
}
</script>
</head>
<body onload="runTest()">
<p>Tests content is moved from cached resource to resource agent's data storage when cached resource is destroyed.</p>
<a href="https://bugs.webkit.org/show_bug.cgi?id=92108">Bug 92108</a>
</body>
</html>