Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / network / cached-resource-destroyed-moved-to-storage.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     image = new Image();
9     image.onload = firstImageLoaded;
10     document.body.appendChild(image);
11     image.src = "resources/resource.php?type=image&random=1&size=400";
12 }
13
14 function firstImageLoaded()
15 {
16     console.log("Done1.");
17 }
18
19 function loadSecondImage() {
20     image.onload = secondImageLoaded;
21     image.src = "resources/resource.php?type=image&random=1&size=200";
22 }
23
24 function secondImageLoaded()
25 {
26     console.log("Done2.");
27 }
28
29 function forceCachedResourceLoaderGC() {
30     if (window.internals)
31         window.internals.garbageCollectDocumentResources();
32 }
33
34 function test()
35 {
36     // Since this test could be run together with other inspector backend cache
37     // tests, we need to reset size limits to default ones.
38     InspectorTest.resetInspectorResourcesData(step1);
39
40     var imageRequest;
41     function step1()
42     {
43         InspectorTest.recordNetwork();
44         InspectorTest.addConsoleSniffer(step2);
45         InspectorTest.evaluateInPage("loadFirstImage()");
46     }
47
48     function step2()
49     {
50         imageRequest = InspectorTest.networkRequests().pop();
51         imageRequest.requestContent(step3);
52     }
53
54     var originalContentLength;
55     function step3()
56     {
57         InspectorTest.addResult(imageRequest.url);
58         InspectorTest.addResult("request.type: " + imageRequest.resourceType());
59         InspectorTest.addResult("request.content.length after requesting content: " + imageRequest.content.length);
60         originalContentLength = imageRequest.content.length;
61         InspectorTest.assertTrue(imageRequest.content.length > 0, "No content before destroying CachedResource.");
62
63         InspectorTest.addResult("Releasing cached resource.");
64         // Loading another image to the same image element so that the original image cached resource is released.
65         InspectorTest.addConsoleSniffer(step4);
66         InspectorTest.evaluateInPage("loadSecondImage()");
67     }
68
69     function step4(msg)
70     {
71         // Disable-enable cache to force MemoryCache::evictResources().
72         NetworkAgent.setCacheDisabled(true, step5);
73     }
74
75     function step5(msg)
76     {
77         NetworkAgent.setCacheDisabled(false, step6);
78     }
79
80     function step6()
81     {
82         // Force CachedResourceLoader garbage collector run.
83         InspectorTest.evaluateInPage("forceCachedResourceLoaderGC()");
84
85         // Re-request content now that CachedResource should have been destroyed.
86         delete imageRequest._content;
87         imageRequest.requestContent(step7);
88     }
89
90     function step7()
91     {
92         InspectorTest.addResult("request.content.length after requesting content: " + imageRequest.content.length);
93         originalContentLength = imageRequest.content.length;
94         InspectorTest.assertTrue(imageRequest.content.length === originalContentLength, "Content changed after cached resource was destroyed");
95         InspectorTest.resetInspectorResourcesData(step8);
96     }
97
98     function step8()
99     {
100         InspectorTest.completeTest();
101     }
102 }
103 </script>
104 </head>
105 <body onload="runTest()">
106 <p>Tests content is moved from cached resource to resource agent's data storage when cached resource is destroyed.</p>
107 <a href="https://bugs.webkit.org/show_bug.cgi?id=92108">Bug 92108</a>
108 </body>
109 </html>
110