Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / sources / debugger / file-system-project-mapping.html
blobc299497207d3c7117db7d46220878c5fc8d9c14a
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 src="resources/edit-me.js"></script>
9 <script>
10 function test()
12 var target;
13 var manager;
14 var resourceScriptMapping;
15 var defaultScriptMapping;
17 function createObjects()
19 if (target)
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>"};
44 var uiSourceCode;
45 var networkUISourceCode;
46 var setting;
48 createObjects();
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.");
66 createObjects();
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.");
79 createObjects();
81 manager.addMockFileSystem(fileSystemPath);
82 manager.addFiles(fileSystemPath, files);
83 dumpFileSystemUISourceCodesMappings();
85 var networkURL = InspectorTest.testNetworkMapping.networkURL(networkUISourceCode);
86 InspectorTest.testFileSystemMapping.removeMappingForURL(networkURL);
87 next();
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>"};
111 var uiSourceCode;
112 var target;
114 createObjects();
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);
127 loadScript();
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)
152 callback("error");
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:");
163 unloadScript();
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.");
168 loadScript();
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;
181 callback();
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:");
192 unloadScript();
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.");
196 loadScript();
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>");
202 unloadScript();
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.");
206 loadScript();
207 InspectorTest.addResult(" - hasDivergedFromVM: " + !!resourceScriptMapping.scriptFile(uiSourceCode).hasDivergedFromVM());
208 InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFrame._muted);
210 unloadScript();
211 loadScript;
213 InspectorTest.testFileSystemMapping.removeFileMapping(fileSystemPath, "http://localhost/", "/");
214 WebInspector.debuggerWorkspaceBinding = InspectorTest._originalDebuggerBinding;
215 next();
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";
231 var files = {};
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);
271 next();
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": ""};
296 createObjects();
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/");
308 next();
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": ""};
324 createObjects();
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);
333 target = null;
335 function projectRemoved()
337 InspectorTest.addResult("Received project removed event.");
338 setImmediate(next);
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>"};
347 var uiSourceCodes;
348 var index = 0;
349 var oldURL;
351 createObjects();
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();
361 renameNextFile();
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);
375 ++index;
376 if (index < uiSourceCodes.length)
377 renameNextFile();
378 else
379 next();
384 </script>
385 </head>
386 <body onload="runTest()">
387 <p>Tests file system project mappings.</p>
388 </body>
389 </html>