blob: 9308d0b9e0582973296b13197c1cbc06a0db11ec [file] [log] [blame]
<html>
<head>
<script src="../inspector-test.js"></script>
<script src="../network-test.js"></script>
<script>
var image;
function loadFirstImage() {
if (!window.internals) {
console.log("This test can not be run as window.internals is not available.");
return;
}
// Make sure there is no enough space to save content in resource agent's storage.
internals.setInspectorResourcesDataSizeLimits(100, 100);
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()
{
var imageRequest;
InspectorTest.addConsoleSniffer(step2);
InspectorTest.evaluateInPage("loadFirstImage()");
function step2()
{
imageRequest = WebInspector.panel("network").requests[WebInspector.panel("network").requests.length - 1];
imageRequest.requestContent(step3);
}
function step3()
{
InspectorTest.addResult(imageRequest.url);
InspectorTest.addResult("request.type: " + imageRequest.type);
InspectorTest.addResult("request.content.length after requesting content: " + 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 after requesting content: " + imageRequest.content);
InspectorTest.assertTrue(!imageRequest.content, "Content available after CachedResource was destroyed.");
InspectorTest.resetInspectorResourcesData(step8);
}
function step8()
{
InspectorTest.completeTest();
}
}
</script>
</head>
<body onload="runTest()">
<p>Tests cached resource content is discarded when cached resource is destroyed if content size is too big for the resource agent's data storage.</p>
<a href="https://bugs.webkit.org/show_bug.cgi?id=92108">Bug 92108</a>
</body>
</html>