OLD | NEW |
| (Empty) |
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 src="../../../http/tests/inspector/isolated-filesystem-test.js"></script
> | |
7 <script src="../../../http/tests/inspector/live-edit-test.js"></script> | |
8 <script> | |
9 function test() | |
10 { | |
11 var target; | |
12 var resourceScriptMapping; | |
13 var defaultScriptMapping; | |
14 var fileSystemProjectId = WebInspector.FileSystemWorkspaceBinding.projectId(
"file:///var/www"); | |
15 WebInspector.networkMapping.dispose(); | |
16 | |
17 function createWorkspaceWithTarget() | |
18 { | |
19 target = InspectorTest.createWorkspaceWithTarget(false); | |
20 var entry = InspectorTest.testDebuggerWorkspaceBinding._targetToData.get
(target); | |
21 resourceScriptMapping = entry._resourceMapping; | |
22 defaultScriptMapping = entry._defaultMapping; | |
23 } | |
24 | |
25 function suspendStateChanged() | |
26 { | |
27 InspectorTest.addResult("(suspend state changed: " + InspectorTest.testT
argetManager.allTargetsSuspended() + ")"); | |
28 } | |
29 | |
30 function dumpFileSystemUISourceCodesMappings() | |
31 { | |
32 var uiSourceCodes = InspectorTest.testWorkspace.project(fileSystemProjec
tId).uiSourceCodes(); | |
33 InspectorTest.addResult("UISourceCode uri to url mappings:"); | |
34 for (var i = 0; i < uiSourceCodes.length; ++i) { | |
35 var networkURL = InspectorTest.testNetworkMapping.networkURL(uiSourc
eCodes[i]); | |
36 InspectorTest.addResult(" " + uiSourceCodes[i].url() + " -> " + n
etworkURL); | |
37 } | |
38 } | |
39 | |
40 InspectorTest.runTestSuite([ | |
41 function testAutomaticMapping(next) | |
42 { | |
43 createWorkspaceWithTarget(); | |
44 | |
45 InspectorTest.addResult("Adding file system."); | |
46 var fs = new InspectorTest.TestFileSystem("file:///var/www"); | |
47 fs.root.mkdir("html").addFile("foo.js", "<foo content>"); | |
48 fs.root.addFile("bar.js", "<bar content>"); | |
49 fs.reportCreated(fileSystemCreated1); | |
50 var networkUISourceCode; | |
51 | |
52 function fileSystemCreated1() | |
53 { | |
54 InspectorTest.addResult("Adding network resource."); | |
55 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ht
ml/foo.js", WebInspector.resourceTypes.Script, "<foo content>", target); | |
56 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ba
r.js", WebInspector.resourceTypes.Script, "<foo content>", target); | |
57 dumpFileSystemUISourceCodesMappings(); | |
58 | |
59 var uiSourceCode = InspectorTest.testWorkspace.uiSourceCode(file
SystemProjectId, "file:///var/www/html/foo.js"); | |
60 networkUISourceCode = InspectorTest.testWorkspace.uiSourceCode(W
ebInspector.NetworkProject.projectId(target, target.resourceTreeModel.mainFrame,
false), "http://localhost/html/foo.js"); | |
61 InspectorTest.addResult("Adding mapping between network and file
system resources."); | |
62 InspectorTest.testNetworkMapping.addMapping(networkUISourceCode,
uiSourceCode); | |
63 var setting = JSON.stringify(WebInspector.fileSystemMapping._fil
eSystemMappingSetting.get()); | |
64 | |
65 InspectorTest.addResult("Emulate reloading inspector."); | |
66 fs.reportRemoved(); | |
67 createWorkspaceWithTarget(); | |
68 WebInspector.fileSystemMapping._fileSystemMappingSetting.set(JSO
N.parse(setting)); | |
69 WebInspector.fileSystemMapping._loadFromSettings(); | |
70 fs.reportCreated(fileSystemCreated2); | |
71 } | |
72 | |
73 function fileSystemCreated2() | |
74 { | |
75 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ht
ml/foo.js", WebInspector.resourceTypes.Script, "<foo content>", target); | |
76 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ba
r.js", WebInspector.resourceTypes.Script, "<foo content>", target); | |
77 dumpFileSystemUISourceCodesMappings(); | |
78 | |
79 InspectorTest.addResult("Removing mapping between network and fi
le system resources."); | |
80 var uiSourceCode = InspectorTest.testWorkspace.uiSourceCode(file
SystemProjectId, "file:///var/www/html/foo.js"); | |
81 InspectorTest.testNetworkMapping.removeMapping(uiSourceCode); | |
82 | |
83 InspectorTest.addResult("Emulate reloading inspector."); | |
84 fs.reportRemoved(); | |
85 createWorkspaceWithTarget(); | |
86 fs.reportCreated(fileSystemCreated3); | |
87 } | |
88 | |
89 function fileSystemCreated3() | |
90 { | |
91 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ht
ml/foo.js", WebInspector.resourceTypes.Script, "<foo content>", target); | |
92 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ba
r.js", WebInspector.resourceTypes.Script, "<foo content>", target); | |
93 dumpFileSystemUISourceCodesMappings(); | |
94 | |
95 var networkURL = InspectorTest.testNetworkMapping.networkURL(net
workUISourceCode); | |
96 WebInspector.fileSystemMapping.removeMappingForURL(networkURL); | |
97 fs.reportRemoved(); | |
98 next(); | |
99 } | |
100 }, | |
101 | |
102 function testScriptFileOnReloadWithDirtyFile(next) | |
103 { | |
104 var originalFileContent = "<foo content>"; | |
105 var scriptURL = "http://localhost/html/foo.js"; | |
106 var scriptContent = originalFileContent + "\n //# sourceURL=" + scr
iptURL + " \n "; | |
107 function unloadScript() | |
108 { | |
109 resourceScriptMapping._debuggerReset(); | |
110 defaultScriptMapping._debuggerReset(); | |
111 } | |
112 | |
113 function loadScript() | |
114 { | |
115 script = InspectorTest.createScriptMock(scriptURL, 0, 0, false,
scriptContent, InspectorTest.testTargetManager.targets()[0]); | |
116 defaultScriptMapping.addScript(script); | |
117 resourceScriptMapping.addScript(script); | |
118 } | |
119 | |
120 var uiSourceCode; | |
121 | |
122 createWorkspaceWithTarget(); | |
123 | |
124 InspectorTest._originalDebuggerBinding = WebInspector.debuggerWorksp
aceBinding; | |
125 WebInspector.debuggerWorkspaceBinding = InspectorTest.testDebuggerWo
rkspaceBinding; | |
126 var target = InspectorTest.testTargetManager.targets()[0]; | |
127 WebInspector._originalTargetManager = WebInspector.targetManager; | |
128 WebInspector.targetManager = InspectorTest.testTargetManager; | |
129 | |
130 InspectorTest.addResult("Adding file system."); | |
131 var fs = new InspectorTest.TestFileSystem("file:///var/www"); | |
132 fs.root.mkdir("html").addFile("foo.js", originalFileContent); | |
133 fs.root.addFile("bar.js", "<bar content>"); | |
134 InspectorTest.addResult("Adding file system mapping."); | |
135 fs.addFileMapping("http://localhost/", "/"); | |
136 fs.reportCreated(fileSystemCreated); | |
137 var sourceFrame; | |
138 | |
139 function waitForMappingsCheck(callback) | |
140 { | |
141 InspectorTest.addSniffer(WebInspector.ResourceScriptFile.prototy
pe, "_mappingCheckedForTest", onMappingChecked); | |
142 | |
143 function onMappingChecked() | |
144 { | |
145 setImmediate(callback); | |
146 } | |
147 } | |
148 | |
149 function fileSystemCreated() | |
150 { | |
151 loadScript(); | |
152 | |
153 uiSourceCode = InspectorTest.testWorkspace.uiSourceCode(fileSyst
emProjectId, "file:///var/www/html/foo.js"); | |
154 InspectorTest.showUISourceCode(uiSourceCode, sf => sourceFrame =
sf); | |
155 waitForMappingsCheck(didShowScriptSource); | |
156 } | |
157 | |
158 function dumpUISourceCodeAndScriptContents() | |
159 { | |
160 InspectorTest.addResult("Dumping uiSourceCode and script content
:"); | |
161 InspectorTest.addResult(" uiSourceCode: " + uiSourceCode.work
ingCopy()); | |
162 InspectorTest.addResult(" script: " + scriptContent); | |
163 } | |
164 | |
165 function didShowScriptSource() | |
166 { | |
167 dumpUISourceCodeAndScriptContents(); | |
168 InspectorTest.addResult(" - hasDivergedFromVM: " + !!resourceScr
iptMapping.scriptFile(uiSourceCode).hasDivergedFromVM()); | |
169 InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFram
e._muted); | |
170 | |
171 InspectorTest.addResult("Editing uiSourceCode:"); | |
172 waitForMappingsCheck(onMappingChecked1); | |
173 uiSourceCode.setWorkingCopy("<foo content edited>"); | |
174 } | |
175 | |
176 function onMappingChecked1() | |
177 { | |
178 InspectorTest.addResult(" - hasDivergedFromVM: " + !!resourceScr
iptMapping.scriptFile(uiSourceCode).hasDivergedFromVM()); | |
179 InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFram
e._muted); | |
180 | |
181 function setScriptSourceOverrideFailure(scriptId, newContent, ca
llback) | |
182 { | |
183 callback("error"); | |
184 } | |
185 InspectorTest.override(WebInspector.DebuggerModel.prototype, "se
tScriptSource", setScriptSourceOverrideFailure); | |
186 | |
187 InspectorTest.addResult("Committing uiSourceCode with live edit
failure:"); | |
188 waitForMappingsCheck(onMappingChecked2); | |
189 uiSourceCode.commitWorkingCopy(); | |
190 } | |
191 | |
192 function onMappingChecked2() | |
193 { | |
194 dumpUISourceCodeAndScriptContents(); | |
195 InspectorTest.addResult(" - hasDivergedFromVM: " + !!resourceScr
iptMapping.scriptFile(uiSourceCode).hasDivergedFromVM()); | |
196 InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFram
e._muted); | |
197 | |
198 InspectorTest.addResult("Reloading with saved but diverged uiSou
rceCode:"); | |
199 unloadScript(); | |
200 InspectorTest.addResult("UISourceCode should not have script fil
e after unloading scripts: " + !resourceScriptMapping.scriptFile(uiSourceCode)); | |
201 InspectorTest.addResult("Saved but diverged source frame should
not be muted: " + !sourceFrame._muted); | |
202 | |
203 InspectorTest.addResult("Loading script."); | |
204 waitForMappingsCheck(onMappingChecked3); | |
205 loadScript(); | |
206 } | |
207 | |
208 function onMappingChecked3() | |
209 { | |
210 dumpUISourceCodeAndScriptContents(); | |
211 InspectorTest.addResult(" - hasDivergedFromVM: " + !!resourceScr
iptMapping.scriptFile(uiSourceCode).hasDivergedFromVM()); | |
212 InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFram
e._muted); | |
213 | |
214 InspectorTest.addResult("Editing uiSourceCode again:"); | |
215 waitForMappingsCheck(onMappingChecked4); | |
216 uiSourceCode.setWorkingCopy("<foo content edited again>"); | |
217 } | |
218 | |
219 function onMappingChecked4() | |
220 { | |
221 InspectorTest.addResult(" - hasDivergedFromVM: " + !!resourceScr
iptMapping.scriptFile(uiSourceCode).hasDivergedFromVM()); | |
222 InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFram
e._muted); | |
223 | |
224 function setScriptSourceOverrideSuccess(scriptId, newContent, ca
llback) | |
225 { | |
226 scriptContent = newContent; | |
227 callback(); | |
228 } | |
229 InspectorTest.override(WebInspector.DebuggerModel.prototype, "se
tScriptSource", setScriptSourceOverrideSuccess); | |
230 | |
231 InspectorTest.addResult("Committing uiSourceCode again (with liv
e edit success now):"); | |
232 waitForMappingsCheck(onMappingChecked5); | |
233 uiSourceCode.commitWorkingCopy(); | |
234 } | |
235 | |
236 function onMappingChecked5() | |
237 { | |
238 dumpUISourceCodeAndScriptContents(); | |
239 InspectorTest.addResult(" - hasDivergedFromVM: " + !!resourceScr
iptMapping.scriptFile(uiSourceCode).hasDivergedFromVM()); | |
240 InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFram
e._muted); | |
241 | |
242 InspectorTest.addResult("Reloading page:"); | |
243 unloadScript(); | |
244 InspectorTest.addResult("UISourceCode should not have script fil
e after unloading scripts: " + !resourceScriptMapping.scriptFile(uiSourceCode)); | |
245 InspectorTest.addResult("Saved and merged source frame should no
t be muted: " + !sourceFrame._muted); | |
246 InspectorTest.addResult("Loading script."); | |
247 waitForMappingsCheck(onMappingChecked6); | |
248 loadScript(); | |
249 } | |
250 | |
251 function onMappingChecked6() | |
252 { | |
253 InspectorTest.addResult(" - hasDivergedFromVM: " + !!resourceScr
iptMapping.scriptFile(uiSourceCode).hasDivergedFromVM()); | |
254 InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFram
e._muted); | |
255 | |
256 InspectorTest.addResult("Editing uiSourceCode again and reloadin
g while it is dirty:"); | |
257 uiSourceCode.setWorkingCopy("<foo content edited and dirty>"); | |
258 unloadScript(); | |
259 InspectorTest.addResult("UISourceCode should not have script fil
e after unloading scripts: " + !resourceScriptMapping.scriptFile(uiSourceCode)); | |
260 InspectorTest.addResult("Dirty source frame should be muted: " +
sourceFrame._muted); | |
261 InspectorTest.addResult("Loading script."); | |
262 waitForMappingsCheck(onMappingChecked7); | |
263 loadScript(); | |
264 } | |
265 | |
266 function onMappingChecked7() | |
267 { | |
268 InspectorTest.addResult(" - hasDivergedFromVM: " + !!resourceScr
iptMapping.scriptFile(uiSourceCode).hasDivergedFromVM()); | |
269 InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFram
e._muted); | |
270 | |
271 unloadScript(); | |
272 loadScript; | |
273 | |
274 WebInspector.debuggerWorkspaceBinding = InspectorTest._originalD
ebuggerBinding; | |
275 fs.reportRemoved(); | |
276 next(); | |
277 } | |
278 }, | |
279 | |
280 function testRemoveProject(next) | |
281 { | |
282 function dumpWorkspaceUISourceCodes() | |
283 { | |
284 InspectorTest.addResult("Dumping uiSourceCodes origin URLs:"); | |
285 var uiSourceCodes = InspectorTest.testWorkspace.uiSourceCodes(); | |
286 for (var i = 0; i < uiSourceCodes.length; ++i) | |
287 InspectorTest.addResult(" - " + uiSourceCodes[i].url()); | |
288 } | |
289 | |
290 createWorkspaceWithTarget(); | |
291 | |
292 InspectorTest.addResult("Adding file system."); | |
293 var fs = new InspectorTest.TestFileSystem("file:///var/www"); | |
294 fs.root.addFile("foo.js", ""); | |
295 fs.reportCreated(fileSystemCreated); | |
296 | |
297 function fileSystemCreated() | |
298 { | |
299 dumpWorkspaceUISourceCodes(); | |
300 InspectorTest.addResult("Removing project:"); | |
301 InspectorTest.testWorkspace.addEventListener(WebInspector.Worksp
ace.Events.ProjectRemoved, projectRemoved); | |
302 InspectorTest.testTargetManager.removeTarget(target); | |
303 target = null; | |
304 } | |
305 | |
306 function projectRemoved() | |
307 { | |
308 InspectorTest.testWorkspace.removeEventListener(WebInspector.Wor
kspace.Events.ProjectRemoved, projectRemoved); | |
309 InspectorTest.addResult("Received project removed event."); | |
310 fs.reportRemoved(); | |
311 setImmediate(next); | |
312 } | |
313 }, | |
314 | |
315 function testURLAfterRenaming(next) | |
316 { | |
317 var index = 0; | |
318 var oldURL; | |
319 | |
320 createWorkspaceWithTarget(); | |
321 | |
322 InspectorTest.addResult("Adding file system."); | |
323 var fs = new InspectorTest.TestFileSystem("file:///var/www"); | |
324 fs.root.mkdir("html").addFile("foo.js", "<foo content>"); | |
325 fs.root.addFile("bar.js", "<bar content>"); | |
326 fs.root.mkdir("foo").mkdir("bar").addFile("baz.js", "<baz content>")
; | |
327 InspectorTest.addResult("Adding file system mapping."); | |
328 fs.addFileMapping("http://localhost/", "/"); | |
329 fs.reportCreated(fileSystemCreated); | |
330 var uiSourceCodes; | |
331 | |
332 function fileSystemCreated() | |
333 { | |
334 InspectorTest.addResult("Renaming files:"); | |
335 uiSourceCodes = InspectorTest.testWorkspace.uiSourceCodes(); | |
336 renameNextFile(); | |
337 } | |
338 | |
339 function renameNextFile() | |
340 { | |
341 var uiSourceCode = uiSourceCodes[index]; | |
342 oldURL = InspectorTest.testNetworkMapping.networkURL(uiSourceCod
e); | |
343 uiSourceCodes[index].rename("newName.js", fileRenamed); | |
344 } | |
345 | |
346 function fileRenamed() | |
347 { | |
348 var uiSourceCode = uiSourceCodes[index]; | |
349 var networkURL = InspectorTest.testNetworkMapping.networkURL(uiS
ourceCode); | |
350 InspectorTest.addResult(" uiSourceCode URL change after renam
ing: " + oldURL + " -> " + networkURL); | |
351 ++index; | |
352 if (index < uiSourceCodes.length) | |
353 renameNextFile(); | |
354 else { | |
355 fs.reportRemoved(); | |
356 next(); | |
357 } | |
358 } | |
359 }, | |
360 | |
361 function testProjectBasedMapping(next) | |
362 { | |
363 createWorkspaceWithTarget(); | |
364 InspectorTest.testTargetManager.addEventListener(WebInspector.Target
Manager.Events.SuspendStateChanged, suspendStateChanged); | |
365 | |
366 InspectorTest.addResult("Adding file system."); | |
367 var fs = new InspectorTest.TestFileSystem("file:///var/www"); | |
368 fs.root.mkdir("html").addFile("foo.js", "<foo content>"); | |
369 fs.root.mkdir("html2").addFile("bar.js", "<bar content>"); | |
370 fs.root.addFile(".devtools", JSON.stringify({ mappings: [ { folder:
"/html/", url: "http://localhost/h1/" }, { folder: "/html2/", url: "http://local
host/h2/" } ]})); | |
371 fs.reportCreated(fileSystemCreated); | |
372 | |
373 function fileSystemCreated() | |
374 { | |
375 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/h1
/foo.js", WebInspector.resourceTypes.Script, "<foo content>", target); | |
376 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/h2
/bar.js", WebInspector.resourceTypes.Script, "<bar content>", target); | |
377 dumpFileSystemUISourceCodesMappings(); | |
378 fs.reportRemoved(); | |
379 next(); | |
380 } | |
381 }, | |
382 | |
383 function testNodeJSWrapper(next) | |
384 { | |
385 createWorkspaceWithTarget(); | |
386 InspectorTest.addResult("Adding file system."); | |
387 var fs = new InspectorTest.TestFileSystem("file:///var/www"); | |
388 var content = "var a = 1;" | |
389 var folder = fs.root.mkdir("html"); | |
390 folder.addFile("foo.js", "#!/usr/bin/env node;\n" + content); | |
391 folder.addFile("bar.js", content); | |
392 fs.root.addFile(".devtools", JSON.stringify({ mappings: [ { folder:
"/html/", url: "http://localhost/h1/" } ]})); | |
393 fs.reportCreated(fileSystemCreated); | |
394 | |
395 function fileSystemCreated() | |
396 { | |
397 debugger; | |
398 var uiSourceCodeFoo = InspectorTest.testWorkspace.uiSourceCode(f
ileSystemProjectId, "file:///var/www/html/foo.js"); | |
399 var uiSourceCodeBar = InspectorTest.testWorkspace.uiSourceCode(f
ileSystemProjectId, "file:///var/www/html/bar.js"); | |
400 | |
401 var nodePrefix = "(function (exports, require, module, __filenam
e, __dirname) { \n"; | |
402 var nodeSuffix = "\n});"; | |
403 | |
404 var scriptFoo = InspectorTest.createScriptMock("http://localhost
/h1/foo.js", 0, 0, false, nodePrefix + content + nodeSuffix, InspectorTest.testT
argetManager.targets()[0]); | |
405 defaultScriptMapping.addScript(scriptFoo); | |
406 resourceScriptMapping.addScript(scriptFoo); | |
407 InspectorTest.addResult("Is diverged: " + resourceScriptMapping.
scriptFile(uiSourceCodeFoo)._isDiverged()); | |
408 | |
409 var scriptBar = InspectorTest.createScriptMock("http://localhost
/h1/bar.js", 0, 0, false, nodePrefix + content + nodeSuffix, InspectorTest.testT
argetManager.targets()[0]); | |
410 defaultScriptMapping.addScript(scriptBar); | |
411 resourceScriptMapping.addScript(scriptBar); | |
412 InspectorTest.addResult("Is diverged: " + resourceScriptMapping.
scriptFile(uiSourceCodeBar)._isDiverged()); | |
413 next(); | |
414 } | |
415 } | |
416 ]); | |
417 }; | |
418 </script> | |
419 </head> | |
420 <body onload="runTest()"> | |
421 <p>Tests file system project mappings.</p> | |
422 </body> | |
423 </html> | |
OLD | NEW |