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>
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
)
37 var resourceScriptMapping
= createResourceScriptMapping();
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
);
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
)
82 var resourceScriptMapping
= createResourceScriptMapping();
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
);
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
)
115 var resourceScriptMapping
= createResourceScriptMapping();
116 var originalUISourceCode1
;
117 var originalUISourceCode2
;
118 var url
= "index.html";
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
);
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
);
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
)
178 var mockUISourceCode
;
179 var resourceScriptMapping
= createResourceScriptMapping();
180 var url
= "index.html";
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
);
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
);
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
);
222 <body onload=
"runTest()">
223 <p>Tests ResourceScriptMapping class.
</p>