Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / network / cached-resource-destroyed-too-big-discarded.html
1 <html>
2 <head>
3 <script src="../inspector-test.js"></script>
4 <script src="../network-test.js"></script>
5 <script>
6 var image;
7 function loadFirstImage() {
8     if (!window.internals) {
9         console.log("This test can not be run as window.internals is not available.");
10         return;
11     }
12     // Make sure there is no enough space to save content in resource agent's storage.
13     internals.setInspectorResourcesDataSizeLimits(100, 100);
14
15     image = new Image();
16     image.onload = firstImageLoaded;
17     document.body.appendChild(image);
18     image.src = "resources/resource.php?type=image&random=1&size=400";
19 }
20
21 function firstImageLoaded()
22 {
23     console.log("Done1.");
24 }
25
26 function loadSecondImage() {
27     image.onload = secondImageLoaded;
28     image.src = "resources/resource.php?type=image&random=1&size=200";
29 }
30
31 function secondImageLoaded()
32 {
33     console.log("Done2.");
34 }
35
36 function test()
37 {
38     var imageRequest;
39     InspectorTest.recordNetwork();
40     InspectorTest.addConsoleSniffer(step2);
41     InspectorTest.evaluateInPage("loadFirstImage()");
42
43     function step2()
44     {
45         imageRequest = InspectorTest.networkRequests().pop();
46         imageRequest.requestContent(step3);
47     }
48
49     function step3()
50     {
51         InspectorTest.addResult(imageRequest.url);
52         InspectorTest.addResult("request.type: " + imageRequest.resourceType());
53         InspectorTest.addResult("request.content.length after requesting content: " + imageRequest.content.length);
54         InspectorTest.assertTrue(imageRequest.content.length > 0, "No content before destroying CachedResource.");
55
56         InspectorTest.addResult("Releasing cached resource.");
57         // Loading another image to the same image element so that the original image cached resource is released.
58         InspectorTest.addConsoleSniffer(step4);
59         InspectorTest.evaluateInPage("loadSecondImage()");
60     }
61
62     function step4(msg)
63     {
64         // Disable-enable cache to force MemoryCache::evictResources().
65         NetworkAgent.setCacheDisabled(true, step5);
66     }
67
68     function step5(msg)
69     {
70         // In Oilpan, Resource objects are not destructed until GC.
71         InspectorTest.evaluateInPage("GCController.collectAll()");
72         NetworkAgent.setCacheDisabled(false, step6);
73     }
74
75     function step6()
76     {
77         // Re-request content now that CachedResource should have been destroyed.
78         delete imageRequest._content;
79         imageRequest.requestContent(step7);
80     }
81
82     function step7()
83     {
84         InspectorTest.addResult("request.content after requesting content: " + imageRequest.content);
85         InspectorTest.assertTrue(!imageRequest.content, "Content available after CachedResource was destroyed.");
86         InspectorTest.resetInspectorResourcesData(step8);
87     }
88
89     function step8()
90     {
91         InspectorTest.completeTest();
92     }
93 }
94 </script>
95 </head>
96 <body onload="runTest()">
97 <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>
98 <a href="https://bugs.webkit.org/show_bug.cgi?id=92108">Bug 92108</a>
99 </body>
100 </html>
101