Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / sources / debugger / resource-script-mapping.html
blobde2e07bd5d597c42f545bbf063d696a59e74eb79
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()
9 var defaultScriptMapping;
10 var target = InspectorTest.debuggerModel.target();
12 function createResourceScriptMapping()
14 InspectorTest.createWorkspace();
15 InspectorTest.testTargetManager.addTarget(target);
16 defaultScriptMapping = new WebInspector.DefaultScriptMapping(InspectorTest.debuggerModel, InspectorTest.testWorkspace, InspectorTest.testDebuggerWorkspaceBinding);
17 var resourceScriptMapping = new WebInspector.ResourceScriptMapping(InspectorTest.debuggerModel, InspectorTest.testWorkspace, InspectorTest.testNetworkMapping, InspectorTest.testDebuggerWorkspaceBinding);
18 return resourceScriptMapping;
21 function uiLocation(script, lineNumber, columnNumber)
23 var location = script.debuggerModel.createRawLocation(script, lineNumber, columnNumber);
24 return InspectorTest.testDebuggerWorkspaceBinding.rawLocationToUILocation(location);
27 function resetModels()
29 InspectorTest.debuggerModel._reset();
32 InspectorTest.runTestSuite([
33 function testScriptWithPendingResource(next)
35 var script;
36 resetModels();
37 var resourceScriptMapping = createResourceScriptMapping();
38 var url = "foo.js";
39 step1();
41 function step1()
43 InspectorTest.addResult("Adding script for pending request.");
44 script = InspectorTest.createScriptMock(url, 0, 0, true, "<content script source>");
45 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUISourceCodeAdded);
46 defaultScriptMapping.addScript(script);
47 resourceScriptMapping.addScript(script);
49 var originalUISourceCode;
50 uiLocation(script, 0, 5);
52 function originalUISourceCodeAdded(uiSourceCode)
54 originalUISourceCode = uiSourceCode;
57 InspectorTest.checkUILocation(originalUISourceCode, 0, 5, uiLocation(script, 0, 5));
58 InspectorTest.checkRawLocation(script, 10, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, originalUISourceCode, 10, 0));
59 InspectorTest.dumpUISourceCode(originalUISourceCode, step2);
62 function step2()
64 InspectorTest.addResult("Adding uiSourceCode for finished resource.");
65 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
66 InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Script, "<content script resource content>");
68 function uiSourceCodeAdded(uiSourceCode)
70 InspectorTest.checkUILocation(uiSourceCode, 0, 5, uiLocation(script, 0, 5));
71 InspectorTest.checkRawLocation(script, 10, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode, 10, 0));
72 InspectorTest.dumpUISourceCode(uiSourceCode, next);
77 function testScriptWithFinishedResource(next)
79 var script;
80 resetModels();
81 var mockUISourceCode;
82 var resourceScriptMapping = createResourceScriptMapping();
83 var url = "foo.js";
84 step1();
86 function step1()
88 InspectorTest.addResult("Adding uiSourceCode for finished resource.");
89 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeForResourceAdded);
90 InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Script, "<script resource content>");
93 function uiSourceCodeForResourceAdded(uiSourceCode)
95 mockUISourceCode = uiSourceCode;
96 InspectorTest.dumpUISourceCode(uiSourceCode, step2);
99 function step2()
101 InspectorTest.addResult("Adding script for finished request.");
102 script = InspectorTest.createScriptMock(url, 0, 0, false, "<script source>");
103 resourceScriptMapping.addScript(script);
104 InspectorTest.checkUILocation(mockUISourceCode, 0, 5, uiLocation(script, 0, 5));
105 InspectorTest.checkRawLocation(script, 10, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 10, 0));
106 InspectorTest.dumpUISourceCode(mockUISourceCode, next);
110 function testHTMLWithPendingResource(next)
112 var script1;
113 var script2;
114 resetModels();
115 var resourceScriptMapping = createResourceScriptMapping();
116 var originalUISourceCode1;
117 var originalUISourceCode2;
118 var url = "index.html";
119 step1();
121 function step1()
123 InspectorTest.addResult("Adding first script for pending request.");
124 script1 = InspectorTest.createScriptMock(url, 0, 10, false, "<script source 1>");
125 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUISourceCodeAdded);
126 defaultScriptMapping.addScript(script1);
127 resourceScriptMapping.addScript(script1);
129 uiLocation(script1, 0, 5);
131 function originalUISourceCodeAdded(uiSourceCode)
133 originalUISourceCode1 = uiSourceCode;
136 InspectorTest.checkUILocation(originalUISourceCode1, 0, 5, uiLocation(script1, 0, 5));
137 InspectorTest.checkRawLocation(script1, 10, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, originalUISourceCode1, 10, 0));
138 InspectorTest.dumpUISourceCode(originalUISourceCode1, step2);
141 function step2()
143 InspectorTest.addResult("Adding second script for pending request.");
144 script2 = InspectorTest.createScriptMock(url, 0, 45, false, "<script source 2>");
145 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUISourceCodeAdded);
146 defaultScriptMapping.addScript(script2);
147 resourceScriptMapping.addScript(script2);
149 function originalUISourceCodeAdded(uiSourceCode)
151 originalUISourceCode2 = uiSourceCode;
153 InspectorTest.checkUILocation(originalUISourceCode2, 0, 45, uiLocation(script2, 0, 45));
154 InspectorTest.checkRawLocation(script1, 10, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, originalUISourceCode1, 10, 0));
155 InspectorTest.dumpUISourceCode(originalUISourceCode2, step3);
158 function step3()
160 InspectorTest.addResult("Adding uiSourceCode for finished resource.");
161 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
162 InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Document, "<resource content>");
164 function uiSourceCodeAdded(uiSourceCode)
166 InspectorTest.checkUILocation(uiSourceCode, 0, 5, uiLocation(script1, 0, 5));
167 InspectorTest.checkRawLocation(script1, 10, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode, 10, 0));
168 InspectorTest.dumpUISourceCode(uiSourceCode, next);
173 function testHTMLWithFinishedResource(next)
175 var script1;
176 var script2;
177 resetModels();
178 var mockUISourceCode;
179 var resourceScriptMapping = createResourceScriptMapping();
180 var url = "index.html";
181 step1();
183 function step1()
185 InspectorTest.addResult("Adding uiSourceCode for finished resource.");
186 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeForResourceAdded);
187 InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Document, "<resource content>");
190 function uiSourceCodeForResourceAdded(uiSourceCode)
192 mockUISourceCode = uiSourceCode;
193 InspectorTest.dumpUISourceCode(uiSourceCode, step2);
196 function step2()
198 InspectorTest.addResult("Adding first script for finished request.");
199 script1 = InspectorTest.createScriptMock(url, 1, 10, false, "<script source 1>");
200 resourceScriptMapping.addScript(script1);
201 InspectorTest.checkUILocation(mockUISourceCode, 1, 20, uiLocation(script1, 1, 20));
202 InspectorTest.checkRawLocation(script1, 1, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 1, 0));
203 InspectorTest.checkRawLocation(script1, 6, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 6, 0));
204 InspectorTest.dumpUISourceCode(mockUISourceCode, step3);
207 function step3()
209 InspectorTest.addResult("Adding second script for finished request.");
210 script2 = InspectorTest.createScriptMock(url, 5, 45, false, "<script\nsource\n2>");
211 resourceScriptMapping.addScript(script2);
212 InspectorTest.checkUILocation(mockUISourceCode, 1, 20, uiLocation(script1, 1, 20));
213 InspectorTest.checkRawLocation(script1, 1, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 1, 0));
214 InspectorTest.checkRawLocation(script2, 6, 0, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 6, 0));
215 InspectorTest.dumpUISourceCode(mockUISourceCode, next);
220 </script>
221 </head>
222 <body onload="runTest()">
223 <p>Tests ResourceScriptMapping class.</p>
224 </body>
225 </html>