[Mac] Fix build break on Apple win bot after r123711
[WebKit-https.git] / 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.addConsoleSniffer(step2);
44         InspectorTest.evaluateInPage("loadFirstImage()");
45     }
46
47     function step2()
48     {
49         imageRequest = WebInspector.panels.network.requests[WebInspector.panels.network.requests.length - 1];
50         imageRequest.requestContent(step3);
51     }
52
53     var originalContentLength;
54     function step3()
55     {
56         InspectorTest.addResult(imageRequest.url);
57         InspectorTest.addResult("request.type: " + imageRequest.type);
58         InspectorTest.addResult("request.content.length after requesting content: " + imageRequest.content.length);
59         originalContentLength = imageRequest.content.length;
60         InspectorTest.assertTrue(imageRequest.content.length > 0, "No content before destroying CachedResource.");
61
62         InspectorTest.addResult("Releasing cached resource.");
63         // Loading another image to the same image element so that the original image cached resource is released.
64         InspectorTest.addConsoleSniffer(step4);
65         InspectorTest.evaluateInPage("loadSecondImage()");
66     }
67
68     function step4(msg)
69     {
70         // Disable-enable cache to force MemoryCache::evictResources().
71         NetworkAgent.setCacheDisabled(true, step5);
72     }
73
74     function step5(msg)
75     {
76         NetworkAgent.setCacheDisabled(false, step6);
77     }
78
79     function step6()
80     {
81         // Force CachedResourceLoader garbage collector run.
82         InspectorTest.evaluateInPage("forceCachedResourceLoaderGC()");
83
84         // Re-request content now that CachedResource should have been destroyed.
85         delete imageRequest._content;
86         imageRequest.requestContent(step7);
87     }
88
89     function step7()
90     {
91         InspectorTest.addResult("request.content.length after requesting content: " + imageRequest.content.length);
92         originalContentLength = imageRequest.content.length;
93         InspectorTest.assertTrue(imageRequest.content.length === originalContentLength, "Content changed after cached resource was destroyed");
94         InspectorTest.resetInspectorResourcesData(step8);
95     }
96
97     function step8()
98     {
99         InspectorTest.completeTest();
100     }
101 }
102 </script>
103 </head>
104 <body onload="runTest()">
105 <p>Tests content is moved from cached resource to resource agent's data storage when cached resource is destroyed.</p>
106 <a href="https://bugs.webkit.org/show_bug.cgi?id=92108">Bug 92108</a>
107 </body>
108 </html>
109