2011-07-04 Vsevolod Vlasov <vsevik@chromium.org>
[WebKit-https.git] / LayoutTests / http / tests / inspector / network / network-content-replacement-embed.html
1 <html>
2 <head>
3 <script src="../inspector-test.js"></script>
4 <script>
5
6 var loadedFirstURL = false;
7 function streamLoaded()
8 {
9     if (loadedFirstURL)
10         return;
11
12     loadedFirstURL = true;
13     loadURLs();
14 }
15
16 var snifferInstalled = false;
17 function onSnifferInstalled()
18 {
19     snifferInstalled = true;
20     loadURLs();
21 }
22
23 function loadURLs()
24 {
25     if (!snifferInstalled || !loadedFirstURL)
26         return;
27
28     if (!window.internals) {
29         console.log("This test can not be run as window.internals is not available.");
30         return;
31     }
32     // Each '*' symbol in original data will use two bytes in String object
33     // after decoding, hence multiplying by two.
34     internals.setInspectorResourcesDataSizeLimits(document, 2*300, 2*200);
35
36     // Here we test replacement logic. We save first two resources content,
37     // discard third resource content once we see its size exceeds limit,
38     // and finally replace first resource content with the last resource content.
39
40     plg.getURLNotify("resources/resource.php?size=200", null, "loadURL2");
41 }
42
43 function loadURL2()
44 {
45     plg.getURLNotify("resources/resource.php?size=100", null, "loadURL3");
46 }
47
48 function loadURL3()
49 {
50     plg.getURLNotify("resources/resource.php?size=201", null, "loadURL4");
51 }
52
53 function loadURL4()
54 {
55     plg.getURLNotify("resources/resource.php?size=100", null, "allURLsLoaded");
56 }
57
58 function allURLsLoaded()
59 {
60     console.log("Done.");
61 }
62
63 function test()
64 {
65     InspectorTest.addSniffer(WebInspector.ConsoleView.prototype, "addMessage", step1);
66     InspectorTest.evaluateInPage("onSnifferInstalled()");
67
68     function dumpResource(resource, callback)
69     {
70         if (!resource)
71             return callback();
72         InspectorTest.addResult(resource.url);
73
74         function contentLoaded()
75         {
76             InspectorTest.addResult("resource.content after requesting content: " + resource.content);
77             callback();
78         }
79
80         resource.requestContent(contentLoaded);
81     }
82
83     function step1()
84     {
85         var resource = WebInspector.panels.network.resources[WebInspector.panels.network.resources.length - 4];
86         dumpResource(resource, step2);
87     }
88
89     function step2()
90     {
91         var resource = WebInspector.panels.network.resources[WebInspector.panels.network.resources.length - 3];
92         dumpResource(resource, step3);
93     }
94
95     function step3()
96     {
97         var resource = WebInspector.panels.network.resources[WebInspector.panels.network.resources.length - 2];
98         dumpResource(resource, step4);
99     }
100
101     function step4()
102     {
103         var resource = WebInspector.panels.network.resources[WebInspector.panels.network.resources.length - 1];
104         dumpResource(resource, step5);
105     }
106
107     function step5()
108     {
109         InspectorTest.completeTest();
110     }
111 }
112 </script>
113 </head>
114 <body onload="runTest()">
115     <p>Tests NetworkResourcesData logic for embed content replacement.</p>
116     <embed name="plg" type="application/x-webkit-test-netscape" src="resources/resource.php?type=image" onstreamload="streamLoaded()"></embed>
117 </body>
118 </html>
119