Web Inspector: Create JavaScriptSources based on network resources.
[WebKit-https.git] / LayoutTests / inspector / debugger / resource-script-mapping.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/debugger-test.js"></script>
5 <script src="../../http/tests/inspector/workspace-test.js"></script>
6 <script>
7 function test()
8 {
9     var workspace;
10     function createResourceScriptMapping()
11     {
12         InspectorTest.createWorkspace();
13         var resourceScriptMapping = new WebInspector.ResourceScriptMapping(InspectorTest.testWorkspace);
14         return resourceScriptMapping;
15     }
16
17     InspectorTest.runTestSuite([
18         function testScriptWithPendingResource(next)
19         {
20             var script;
21             WebInspector.debuggerModel._reset();
22             var resourceScriptMapping = createResourceScriptMapping();
23             var url = "foo.js";
24             step1();
25
26             function step1()
27             {
28                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
29                 InspectorTest.addResult("Adding script for pending request.");
30                 script = InspectorTest.createScriptMock(url, 0, 0, true, "<content script source>");
31                 resourceScriptMapping.addScript(script);
32             }
33
34             function uiSourceCodeAdded(uiSourceCode)
35             {
36                 InspectorTest.checkUILocation(uiSourceCode, 0, 5, script.rawLocationToUILocation(0, 5));
37                 InspectorTest.checkRawLocation(script, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
38                 InspectorTest.dumpUISourceCode(uiSourceCode, step2);
39             }
40
41             function step2()
42             {
43                 InspectorTest.addResult("Adding uiSourceCode for finished resource.");
44                 InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent(uiSourceCodeReplacedWithResource);
45                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(function() { });
46                 InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Script, "<content script resource content>");
47             }
48
49             function uiSourceCodeReplacedWithResource(uiSourceCode, oldUISourceCode)
50             {
51                 InspectorTest.checkUILocation(uiSourceCode, 0, 5, script.rawLocationToUILocation(0, 5));
52                 InspectorTest.checkRawLocation(script, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
53                 InspectorTest.dumpUISourceCode(uiSourceCode, next);
54             }
55         },
56
57         function testScriptWithFinishedResource(next)
58         {
59             var script;
60             WebInspector.debuggerModel._reset();
61             var mockUISourceCode;
62             var resourceScriptMapping = createResourceScriptMapping();
63             var url = "foo.js";
64             step1();
65
66             function step1()
67             {
68                 InspectorTest.addResult("Adding uiSourceCode for finished resource.");
69                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeForResourceAdded);
70                 InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Script, "<script resource content>");
71             }
72
73             function uiSourceCodeForResourceAdded(uiSourceCode)
74             {
75                 mockUISourceCode = uiSourceCode;
76                 InspectorTest.dumpUISourceCode(uiSourceCode, step2);
77             }
78
79             function step2()
80             {
81                 InspectorTest.addResult("Adding script for finished request.");
82                 script = InspectorTest.createScriptMock(url, 0, 0, false, "<script source>");
83                 resourceScriptMapping.addScript(script);
84                 InspectorTest.checkUILocation(mockUISourceCode, 0, 5, script.rawLocationToUILocation(0, 5));
85                 InspectorTest.checkRawLocation(script, 10, 0, mockUISourceCode.uiLocationToRawLocation(10, 0));
86                 InspectorTest.dumpUISourceCode(mockUISourceCode, next);
87             }
88         },
89
90         function testHTMLWithPendingResource(next)
91         {
92             var script1;
93             var script2;
94             WebInspector.debuggerModel._reset();
95             var resourceScriptMapping = createResourceScriptMapping();
96             var url = "index.html";
97             step1();
98
99             function step1()
100             {
101                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
102                 InspectorTest.addResult("Adding first script for pending request.");
103                 script1 = InspectorTest.createScriptMock(url, 0, 10, false, "<script source 1>");
104                 resourceScriptMapping.addScript(script1);
105             }
106
107             function uiSourceCodeAdded(uiSourceCode)
108             {
109                 InspectorTest.checkUILocation(uiSourceCode, 0, 5, script1.rawLocationToUILocation(0, 5));
110                 InspectorTest.checkRawLocation(script1, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
111                 InspectorTest.dumpUISourceCode(uiSourceCode, step2);
112             }
113
114             function step2()
115             {
116                 InspectorTest.addResult("Adding second script for pending request.");
117                 InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent(uiSourceCodeReplaced);
118                 script2 = InspectorTest.createScriptMock(url, 0, 45, false, "<script source 2>");
119                 resourceScriptMapping.addScript(script2);
120             }
121
122             function uiSourceCodeReplaced(uiSourceCode, oldUISourceCode)
123             {
124                 InspectorTest.checkUILocation(uiSourceCode, 0, 5, script2.rawLocationToUILocation(0, 5));
125                 InspectorTest.checkRawLocation(script1, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
126                 InspectorTest.dumpUISourceCode(uiSourceCode, step3);
127             }
128
129             function step3()
130             {
131                 InspectorTest.addResult("Adding uiSourceCode for finished resource.");
132                 InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent(uiSourceCodeReplacedWithResource);
133                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(function() { });
134                 InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Document, "<resource content>");
135             }
136
137             function uiSourceCodeReplacedWithResource(uiSourceCode, oldUISourceCode)
138             {
139                 InspectorTest.checkUILocation(uiSourceCode, 0, 5, script1.rawLocationToUILocation(0, 5));
140                 InspectorTest.checkRawLocation(script1, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
141                 InspectorTest.dumpUISourceCode(uiSourceCode, next);
142             }
143         },
144
145         function testHTMLWithFinishedResource(next)
146         {
147             var script1;
148             var script2;
149             WebInspector.debuggerModel._reset();
150             var mockUISourceCode;
151             var resourceScriptMapping = createResourceScriptMapping();
152             var url = "index.html";
153             step1();
154
155             function step1()
156             {
157                 InspectorTest.addResult("Adding uiSourceCode for finished resource.");
158                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeForResourceAdded);
159                 InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Document, "<resource content>");
160             }
161
162             function uiSourceCodeForResourceAdded(uiSourceCode)
163             {
164                 mockUISourceCode = uiSourceCode;
165                 InspectorTest.dumpUISourceCode(uiSourceCode, step2);
166             }
167
168             function step2()
169             {
170                 InspectorTest.addResult("Adding first script for finished request.");
171                 script1 = InspectorTest.createScriptMock(url, 1, 10, false, "<script source 1>");
172                 resourceScriptMapping.addScript(script1);
173                 InspectorTest.checkUILocation(mockUISourceCode, 1, 20, script1.rawLocationToUILocation(1, 20));
174                 InspectorTest.checkRawLocation(script1, 1, 0, mockUISourceCode.uiLocationToRawLocation(1, 0));
175                 InspectorTest.checkRawLocation(script1, 6, 0, mockUISourceCode.uiLocationToRawLocation(6, 0));
176                 InspectorTest.dumpUISourceCode(mockUISourceCode, step3);
177             }
178
179             function step3()
180             {
181                 InspectorTest.addResult("Adding second script for finished request.");
182                 script2 = InspectorTest.createScriptMock(url, 5, 45, false, "<script\nsource\n2>");
183                 resourceScriptMapping.addScript(script2);
184                 InspectorTest.checkUILocation(mockUISourceCode, 1, 20, script1.rawLocationToUILocation(1, 20));
185                 InspectorTest.checkRawLocation(script1, 1, 0, mockUISourceCode.uiLocationToRawLocation(1, 0));
186                 InspectorTest.checkRawLocation(script2, 6, 0, mockUISourceCode.uiLocationToRawLocation(6, 0));
187                 InspectorTest.dumpUISourceCode(mockUISourceCode, next);
188             }
189         }
190     ]);
191 };
192
193 </script>
194 </head>
195 <body onload="runTest()">
196 <p>Tests ResourceScriptMapping class.</p>
197 </body>
198 </html>