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 src=
"resources/edit-me.js"></script>
14 var resourceScriptMapping
;
15 var defaultScriptMapping
;
17 function createObjects()
20 InspectorTest
.testTargetManager
.removeTarget(target
);
21 target
= InspectorTest
.createWorkspaceWithTarget();
22 manager
= InspectorTest
.createIsolatedFileSystemManager(InspectorTest
.testWorkspace
);
23 var entry
= InspectorTest
.testDebuggerWorkspaceBinding
._targetToData
.get(target
);
24 resourceScriptMapping
= entry
._resourceMapping
;
25 defaultScriptMapping
= entry
._defaultMapping
;
28 InspectorTest
.runTestSuite([
29 function testAutomaticMapping(next
)
31 function dumpFileSystemUISourceCodesMappings()
33 var uiSourceCodes
= InspectorTest
.testWorkspace
.project(fileSystemProjectId
).uiSourceCodes();
34 InspectorTest
.addResult("UISourceCode uri to url mappings:");
35 for (var i
= 0; i
< uiSourceCodes
.length
; ++i
) {
36 var networkURL
= InspectorTest
.testNetworkMapping
.networkURL(uiSourceCodes
[i
]);
37 InspectorTest
.addResult(" " + uiSourceCodes
[i
].uri() + " -> " + networkURL
);
41 var fileSystemPath
= "/var/www";
42 var fileSystemProjectId
= WebInspector
.FileSystemWorkspaceBinding
.projectId(fileSystemPath
);
43 var files
= {"/html/foo.js": "<foo content>", "/bar.js": "<bar content>"};
45 var networkUISourceCode
;
50 InspectorTest
.addResult("Adding file system.");
51 manager
.addMockFileSystem(fileSystemPath
);
52 manager
.addFiles(fileSystemPath
, files
);
53 InspectorTest
.addResult("Adding network resource.");
54 InspectorTest
.addMockUISourceCodeToWorkspace("http://localhost/html/foo.js", WebInspector
.resourceTypes
.Script
, "<foo content>");
55 InspectorTest
.addMockUISourceCodeToWorkspace("http://localhost/bar.js", WebInspector
.resourceTypes
.Script
, "<foo content>");
56 dumpFileSystemUISourceCodesMappings();
57 uiSourceCode
= InspectorTest
.testWorkspace
.uiSourceCode(fileSystemProjectId
, "html/foo.js");
58 networkUISourceCode
= InspectorTest
.testWorkspace
.uiSourceCode(WebInspector
.NetworkProject
.projectId(target
, "http://localhost"), "html/foo.js");
59 console
.error("networkUISourceCode: " + networkUISourceCode
);
60 InspectorTest
.override(WebInspector
.SourcesPanel
.prototype, "_suggestReload", function() { });
61 InspectorTest
.addResult("Adding mapping between network and file system resources.");
62 InspectorTest
.testNetworkMapping
.addMapping(networkUISourceCode
, uiSourceCode
, manager
.fileSystemWorkspaceBinding
);
63 setting
= InspectorTest
.testFileSystemMapping
._fileSystemMappingSetting
;
64 InspectorTest
.addResult("Emulate reloading inspector.");
68 InspectorTest
.testFileSystemMapping
._fileSystemMappingSetting
= setting
;
69 InspectorTest
.testFileSystemMapping
._loadFromSettings();
70 manager
.addMockFileSystem(fileSystemPath
, true);
71 manager
.addFiles(fileSystemPath
, files
);
72 dumpFileSystemUISourceCodesMappings();
73 InspectorTest
.addResult("Removing mapping between network and file system resources.");
74 uiSourceCode
= InspectorTest
.testWorkspace
.uiSourceCode(fileSystemProjectId
, "html/foo.js");
75 InspectorTest
.testNetworkMapping
.removeMapping(uiSourceCode
);
77 InspectorTest
.addResult("Emulate reloading inspector.");
81 manager
.addMockFileSystem(fileSystemPath
);
82 manager
.addFiles(fileSystemPath
, files
);
83 dumpFileSystemUISourceCodesMappings();
85 var networkURL
= InspectorTest
.testNetworkMapping
.networkURL(networkUISourceCode
);
86 InspectorTest
.testFileSystemMapping
.removeMappingForURL(networkURL
);
90 function testScriptFileOnReloadWithDirtyFile(next
)
92 var originalFileContent
= "<foo content>";
93 var scriptURL
= "http://localhost/html/foo.js";
94 var scriptContent
= originalFileContent
+ "\n //# sourceURL=" + scriptURL
+ " \n ";
95 function unloadScript()
97 resourceScriptMapping
._debuggerReset();
98 defaultScriptMapping
._debuggerReset();
101 function loadScript()
103 script
= InspectorTest
.createScriptMock(scriptURL
, 0, 0, false, scriptContent
, InspectorTest
.testTargetManager
.targets()[0]);
104 defaultScriptMapping
.addScript(script
);
105 resourceScriptMapping
.addScript(script
);
108 var fileSystemPath
= "/var/www";
109 var fileSystemProjectId
= WebInspector
.FileSystemWorkspaceBinding
.projectId(fileSystemPath
);
110 var files
= {"/html/foo.js": originalFileContent
, "/bar.js": "<bar content>"};
116 InspectorTest
._originalDebuggerBinding
= WebInspector
.debuggerWorkspaceBinding
;
117 WebInspector
.debuggerWorkspaceBinding
= InspectorTest
.testDebuggerWorkspaceBinding
;
118 target
= InspectorTest
.testTargetManager
.targets()[0];
119 WebInspector
._originalTargetManager
= WebInspector
.targetManager
;
120 WebInspector
.targetManager
= InspectorTest
.testTargetManager
;
121 InspectorTest
.addResult("Adding file system.");
122 manager
.addMockFileSystem(fileSystemPath
);
123 InspectorTest
.addResult("Adding file system mapping.");
124 InspectorTest
.testFileSystemMapping
.addFileMapping(fileSystemPath
, "http://localhost/", "/");
125 manager
.addFiles(fileSystemPath
, files
);
129 uiSourceCode
= InspectorTest
.testWorkspace
.uiSourceCode(fileSystemProjectId
, "html/foo.js");
130 InspectorTest
.showUISourceCode(uiSourceCode
, didShowScriptSource
);
132 function dumpUISourceCodeAndScriptContents()
134 InspectorTest
.addResult("Dumping uiSourceCode and script content:");
135 InspectorTest
.addResult(" uiSourceCode: " + uiSourceCode
.workingCopy());
136 InspectorTest
.addResult(" script: " + scriptContent
);
139 function didShowScriptSource(sourceFrame
)
141 dumpUISourceCodeAndScriptContents();
142 InspectorTest
.addResult(" - hasDivergedFromVM: " + !!resourceScriptMapping
.scriptFile(uiSourceCode
).hasDivergedFromVM());
143 InspectorTest
.addResult(" - sourceFrame._muted: " + !!sourceFrame
._muted
);
145 InspectorTest
.addResult("Editing uiSourceCode:");
146 uiSourceCode
.setWorkingCopy("<foo content edited>");
147 InspectorTest
.addResult(" - hasDivergedFromVM: " + !!resourceScriptMapping
.scriptFile(uiSourceCode
).hasDivergedFromVM());
148 InspectorTest
.addResult(" - sourceFrame._muted: " + !!sourceFrame
._muted
);
150 function setScriptSourceOverrideFailure(scriptId
, newContent
, callback
)
154 InspectorTest
.override(WebInspector
.DebuggerModel
.prototype, "setScriptSource", setScriptSourceOverrideFailure
);
156 InspectorTest
.addResult("Committing uiSourceCode with live edit failure:");
157 uiSourceCode
.commitWorkingCopy(function() { });
158 dumpUISourceCodeAndScriptContents();
159 InspectorTest
.addResult(" - hasDivergedFromVM: " + !!resourceScriptMapping
.scriptFile(uiSourceCode
).hasDivergedFromVM());
160 InspectorTest
.addResult(" - sourceFrame._muted: " + !!sourceFrame
._muted
);
162 InspectorTest
.addResult("Reloading with saved but diverged uiSourceCode:");
164 InspectorTest
.assertTrue(!resourceScriptMapping
.scriptFile(uiSourceCode
), "UISourceCode should not have script file after unloading scripts.");
165 InspectorTest
.assertTrue(!sourceFrame
._muted
, "Saved but diverged source frame should not be muted");
167 InspectorTest
.addResult("Loading script.");
169 dumpUISourceCodeAndScriptContents();
170 InspectorTest
.addResult(" - hasDivergedFromVM: " + !!resourceScriptMapping
.scriptFile(uiSourceCode
).hasDivergedFromVM());
171 InspectorTest
.addResult(" - sourceFrame._muted: " + !!sourceFrame
._muted
);
173 InspectorTest
.addResult("Editing uiSourceCode again:");
174 uiSourceCode
.setWorkingCopy("<foo content edited again>");
175 InspectorTest
.addResult(" - hasDivergedFromVM: " + !!resourceScriptMapping
.scriptFile(uiSourceCode
).hasDivergedFromVM());
176 InspectorTest
.addResult(" - sourceFrame._muted: " + !!sourceFrame
._muted
);
178 function setScriptSourceOverrideSuccess(scriptId
, newContent
, callback
)
180 scriptContent
= newContent
;
183 InspectorTest
.override(WebInspector
.DebuggerModel
.prototype, "setScriptSource", setScriptSourceOverrideSuccess
);
185 InspectorTest
.addResult("Committing uiSourceCode again (with live edit success now):");
186 uiSourceCode
.commitWorkingCopy(function() { });
187 dumpUISourceCodeAndScriptContents();
188 InspectorTest
.addResult(" - hasDivergedFromVM: " + !!resourceScriptMapping
.scriptFile(uiSourceCode
).hasDivergedFromVM());
189 InspectorTest
.addResult(" - sourceFrame._muted: " + !!sourceFrame
._muted
);
191 InspectorTest
.addResult("Reloading page:");
193 InspectorTest
.assertTrue(!resourceScriptMapping
.scriptFile(uiSourceCode
), "UISourceCode should not have script file after unloading scripts.");
194 InspectorTest
.assertTrue(!sourceFrame
._muted
, "Saved and merged source frame should not be muted");
195 InspectorTest
.addResult("Loading script.");
197 InspectorTest
.addResult(" - hasDivergedFromVM: " + !!resourceScriptMapping
.scriptFile(uiSourceCode
).hasDivergedFromVM());
198 InspectorTest
.addResult(" - sourceFrame._muted: " + !!sourceFrame
._muted
);
200 InspectorTest
.addResult("Editing uiSourceCode again and reloading while it is dirty:");
201 uiSourceCode
.setWorkingCopy("<foo content edited and dirty>");
203 InspectorTest
.assertTrue(!resourceScriptMapping
.scriptFile(uiSourceCode
), "UISourceCode should not have script file after unloading scripts.");
204 InspectorTest
.assertTrue(sourceFrame
._muted
, "Dirty source frame should be muted");
205 InspectorTest
.addResult("Loading script.");
207 InspectorTest
.addResult(" - hasDivergedFromVM: " + !!resourceScriptMapping
.scriptFile(uiSourceCode
).hasDivergedFromVM());
208 InspectorTest
.addResult(" - sourceFrame._muted: " + !!sourceFrame
._muted
);
213 InspectorTest
.testFileSystemMapping
.removeFileMapping(fileSystemPath
, "http://localhost/", "/");
214 WebInspector
.debuggerWorkspaceBinding
= InspectorTest
._originalDebuggerBinding
;
219 function testLiveEditReload(next
)
221 InspectorTest
.showScriptSource("edit-me.js", didShowScriptSource
);
223 function didShowScriptSource(sourceFrame
)
225 var scriptURL
= InspectorTest
.testNetworkMapping
.networkURL(sourceFrame
._uiSourceCode
);
227 var fileContent
= "function f()\n{\n return 0;\n}\n";
228 var fileSystemPath
= "/var/www";
229 var fileSystemProjectId
= WebInspector
.FileSystemWorkspaceBinding
.projectId(fileSystemPath
);
230 var filePath
= "/html/edit-me.js";
232 files
[filePath
] = fileContent
;
233 InspectorTest
.addResult("Adding file system.");
234 InspectorTest
.addMockFileSystem(fileSystemPath
)
235 InspectorTest
.addResult("Adding file system mapping.");
236 WebInspector
.isolatedFileSystemManager
.mapping().addMappingForResource(scriptURL
, fileSystemPath
, filePath
.substr(1));
237 InspectorTest
.addFilesToMockFileSystem(fileSystemPath
, files
);
238 // Now that we've set everything up, we need to reload a page to remove all network resources.
239 InspectorTest
.waitForWorkspaceUISourceCodeAddedEvent(function() {}, 7);
240 InspectorTest
.reloadPage(pageReloaded
);
243 function pageReloaded()
245 // Now reload again as part of test.
246 InspectorTest
.waitForWorkspaceUISourceCodeAddedEvent(function() {}, 7);
247 InspectorTest
.reloadPage(pageReloadedAgain
);
250 function pageReloadedAgain()
252 WebInspector
.targetManager
= WebInspector
._originalTargetManager
;
253 InspectorTest
.showScriptSource("edit-me.js", didShowFile
);
256 function didShowFile(sourceFrame
)
258 replaceInSource(sourceFrame
, "return 0;", "return \"live-edited string\";", didEditScriptSource
);
261 function didEditScriptSource()
263 InspectorTest
.evaluateInPage("f()", didEvaluateInPage
)
266 function didEvaluateInPage(result
)
268 InspectorTest
.assertEquals("live-edited string", result
.description
, "edited function returns wrong result");
269 var panel
= WebInspector
.panels
.sources
;
270 InspectorTest
.dumpSourceFrameContents(panel
.visibleView
);
274 function replaceInSource(sourceFrame
, string
, replacement
, callback
)
276 InspectorTest
.addSniffer(WebInspector
.DebuggerModel
.prototype, "_didEditScriptSource", callback
);
277 InspectorTest
.replaceInSource(sourceFrame
, string
, replacement
);
278 InspectorTest
.commitSource(sourceFrame
);
282 function testExcludingFolders(next
)
284 function dumpWorkspaceUISourceCodes()
286 InspectorTest
.addResult("Dumping uiSourceCodes origin URLs:");
287 var uiSourceCodes
= InspectorTest
.testWorkspace
.uiSourceCodes();
288 for (var i
= 0; i
< uiSourceCodes
.length
; ++i
)
289 InspectorTest
.addResult(" - " + uiSourceCodes
[i
].originURL());
292 var fileSystemPath
= "/var/www";
293 var fileSystemProjectId
= WebInspector
.FileSystemWorkspaceBinding
.projectId(fileSystemPath
);
294 var files
= {"/html/foo.js": "", "/.git/foogit.js": "", "/bar.js": "", "/html2/foo.js": ""};
298 InspectorTest
.addResult("Adding file system.");
299 manager
.addMockFileSystem(fileSystemPath
);
300 InspectorTest
.addResult("Adding exclusion pattern and excluded folder.");
301 InspectorTest
.testExcludedFolderManager
.addExcludedFolder(fileSystemPath
, "/html/");
302 manager
.addFiles(fileSystemPath
, files
);
303 dumpWorkspaceUISourceCodes();
304 InspectorTest
.addResult("Excluding html2 folder:");
305 InspectorTest
.testWorkspace
.uiSourceCodes()[0].project().excludeFolder("/html2/");
306 dumpWorkspaceUISourceCodes();
307 InspectorTest
.testExcludedFolderManager
.removeExcludedFolder(fileSystemPath
, "/html/");
311 function testRemoveProject(next
)
313 function dumpWorkspaceUISourceCodes()
315 InspectorTest
.addResult("Dumping uiSourceCodes origin URLs:");
316 var uiSourceCodes
= InspectorTest
.testWorkspace
.uiSourceCodes();
317 for (var i
= 0; i
< uiSourceCodes
.length
; ++i
)
318 InspectorTest
.addResult(" - " + uiSourceCodes
[i
].originURL());
321 var fileSystemPath
= "/var/www";
322 var fileSystemProjectId
= WebInspector
.FileSystemWorkspaceBinding
.projectId(fileSystemPath
);
323 var files
= {"/foo.js": ""};
326 InspectorTest
.addResult("Adding file system.");
327 manager
.addMockFileSystem(fileSystemPath
);
328 manager
.addFiles(fileSystemPath
, files
);
329 dumpWorkspaceUISourceCodes();
330 InspectorTest
.addResult("Removing project:");
331 InspectorTest
.testWorkspace
.addEventListener(WebInspector
.Workspace
.Events
.ProjectRemoved
, projectRemoved
);
332 InspectorTest
.testTargetManager
.removeTarget(target
);
335 function projectRemoved()
337 InspectorTest
.addResult("Received project removed event.");
342 function testURLAfterRenaming(next
)
344 var fileSystemPath
= "/var/www";
345 var fileSystemProjectId
= WebInspector
.FileSystemWorkspaceBinding
.projectId(fileSystemPath
);
346 var files
= {"/html/foo.js": "<foo content>", "/bar.js": "<bar content>", "/foo/bar/baz.js": "<baz content>"};
353 InspectorTest
.addResult("Adding file system.");
354 manager
.addMockFileSystem(fileSystemPath
);
355 InspectorTest
.addResult("Adding file system mapping.");
356 InspectorTest
.testFileSystemMapping
.addFileMapping(fileSystemPath
, "http://localhost/", "/");
357 manager
.addFiles(fileSystemPath
, files
);
359 InspectorTest
.addResult("Renaming files:");
360 uiSourceCodes
= InspectorTest
.testWorkspace
.uiSourceCodes();
363 function renameNextFile()
365 var uiSourceCode
= uiSourceCodes
[index
];
366 oldURL
= InspectorTest
.testNetworkMapping
.networkURL(uiSourceCode
);
367 uiSourceCodes
[index
].rename("newName.js", fileRenamed
);
370 function fileRenamed()
372 var uiSourceCode
= uiSourceCodes
[index
];
373 var networkURL
= InspectorTest
.testNetworkMapping
.networkURL(uiSourceCode
);
374 InspectorTest
.addResult(" uiSourceCode URL change after renaming: " + oldURL
+ " -> " + networkURL
);
376 if (index
< uiSourceCodes
.length
)
386 <body onload=
"runTest()">
387 <p>Tests file system project mappings.
</p>