Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / network / long-script-content.html
1 <html>
2 <head>
3 <script src="../inspector-test.js"></script>
4 <script src="../network-test.js"></script>
5 <script src="../debugger-test.js"></script>
6 <script>
7
8 var scriptElement;
9 function loadScript()
10 {
11     scriptElement = document.createElement("script");
12     scriptElement.src = "resources/long_script.cgi";
13     document.head.appendChild(scriptElement);
14 }
15
16 function unloadScript()
17 {
18     scriptElement.parentElement.removeChild(scriptElement);
19 }
20
21 function gc()
22 {
23     if (window.internals)
24         window.internals.garbageCollectDocumentResources(document);
25     // In Oilpan, Resource objects are not destructed until GC.
26     if (window.GCController)
27         GCController.collectAll();
28 }
29
30 function test()
31 {
32     InspectorTest.hardReloadPage(step1);
33
34     function step1()
35     {
36         InspectorTest.addConsoleSniffer(step2);
37         InspectorTest.evaluateInPage("loadScript()");
38     }
39
40     function step2(event)
41     {
42         InspectorTest.evaluateInPage("unloadScript()", step3);
43     }
44
45     function step3()
46     {
47         InspectorTest.waitForScriptSource("long_script.cgi", step4);
48     }
49
50     function step4(uiSourceCode)
51     {
52         InspectorTest.evaluateInPage("gc()", step5.bind(null, uiSourceCode));
53     }
54
55     function step5(uiSourceCode)
56     {
57         function requestContent()
58         {
59             InspectorTest.addResult("Fallback content is requested.");
60         }
61         InspectorTest.addSniffer(WebInspector.Script.prototype, "requestContent", requestContent);
62
63         uiSourceCode.requestContent(step6);
64     }
65
66     function step6(loadedScript)
67     {
68         var expected = "console.log('finished');\n";
69         InspectorTest.assertTrue(!!loadedScript, "No script content");
70         InspectorTest.assertEquals(1024 * 10240 + expected.length, loadedScript.length, "Loaded script length mismatch");
71         var actual = loadedScript.substring(loadedScript.length - expected.length);
72         InspectorTest.assertEquals(expected, actual, "Loaded script is corrupted");
73
74         InspectorTest.completeTest();
75     }
76 }
77 </script>
78 </head>
79 <body onload="runTest()">
80     <p> Tests long script content is correctly shown in source panel after page reload.</p>
81 </body>
82 </html>
83