| <html> |
| <head> |
| <script src="../../http/tests/inspector/inspector-test.js"></script> |
| <script src="../../http/tests/inspector/debugger-test.js"></script> |
| <script src="../../http/tests/inspector/workspace-test.js"></script> |
| <script src="../../http/tests/inspector/isolated-filesystem-test.js"></script> |
| <script> |
| function test() |
| { |
| function dumpUISourceCodes(uiSourceCodes, next) |
| { |
| innerDumpUISourceCodes(uiSourceCodes, 0, next); |
| |
| function innerDumpUISourceCodes(uiSourceCodes, startIndex, next) |
| { |
| InspectorTest.addResult(""); |
| if (startIndex === uiSourceCodes.length) { |
| next(); |
| return; |
| } |
| InspectorTest.dumpUISourceCode(uiSourceCodes[startIndex], innerDumpUISourceCodes.bind(this, uiSourceCodes, startIndex + 1, next)); |
| } |
| } |
| |
| var manager; |
| var resourceScriptMapping; |
| var defaultScriptMapping; |
| function createObjects() |
| { |
| InspectorTest.createWorkspace(); |
| manager = InspectorTest.createIsolatedFileSystemManager(InspectorTest.testWorkspace, InspectorTest.testFileSystemMapping); |
| resourceScriptMapping = new WebInspector.ResourceScriptMapping(InspectorTest.testWorkspace); |
| defaultScriptMapping = new WebInspector.DefaultScriptMapping(InspectorTest.testWorkspace); |
| } |
| |
| InspectorTest.runTestSuite([ |
| function testAutomaticMapping(next) |
| { |
| function uiSourceCodeAdded(uiSourceCode) { } |
| |
| function dumpFileSystemUISourceCodesMappings() |
| { |
| var uiSourceCodes = InspectorTest.testWorkspace.project(fileSystemProjectId).uiSourceCodes(); |
| InspectorTest.addResult("UISourceCode uri to url mappings:"); |
| for (var i = 0; i < uiSourceCodes.length; ++i) |
| InspectorTest.addResult(" " + uiSourceCodes[i].uri() + " -> " + uiSourceCodes[i].url); |
| } |
| |
| var fileSystemPath = "/var/www"; |
| var fileSystemProjectId = WebInspector.FileSystemProjectDelegate.projectId(fileSystemPath); |
| var files = {"/html/foo.js": "<foo content>", "/bar.js": "<bar content>"}; |
| |
| createObjects(); |
| InspectorTest.testFileMapping.setMappingEntries([]); |
| InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded, 4); |
| InspectorTest.addResult("Adding file system."); |
| manager.addMockFileSystem(fileSystemPath, files); |
| InspectorTest.addResult("Adding network resource."); |
| InspectorTest.addMockUISourceCodeToWorkspace("http://localhost/html/foo.js", WebInspector.resourceTypes.Script, "<foo content>"); |
| InspectorTest.addMockUISourceCodeToWorkspace("http://localhost/bar.js", WebInspector.resourceTypes.Script, "<foo content>"); |
| dumpFileSystemUISourceCodesMappings(); |
| var uiSourceCode = InspectorTest.testWorkspace.uiSourceCode(fileSystemProjectId, ["html", "foo.js"]); |
| var networkUISourceCode = InspectorTest.testWorkspace.uiSourceCode("http://localhost", ["html", "foo.js"]); |
| InspectorTest.override(WebInspector, "suggestReload", function() { }); |
| InspectorTest.addResult("Adding mapping between network and file system resources."); |
| InspectorTest.testWorkspace.addMapping(networkUISourceCode, uiSourceCode, manager.fileSystemWorkspaceProvider); |
| manager.removeMockFileSystem(fileSystemPath); |
| |
| InspectorTest.addResult("Emulate reloading inspector."); |
| createObjects(); |
| InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded, 2); |
| manager.addMockFileSystem(fileSystemPath, files); |
| dumpFileSystemUISourceCodesMappings(); |
| InspectorTest.override(WebInspector, "suggestReload", function() { }); |
| InspectorTest.addResult("Removing mapping between network and file system resources."); |
| uiSourceCode = InspectorTest.testWorkspace.uiSourceCode(fileSystemProjectId, ["html", "foo.js"]); |
| InspectorTest.testWorkspace.removeMapping(uiSourceCode); |
| manager.removeMockFileSystem(fileSystemPath); |
| |
| InspectorTest.addResult("Emulate reloading inspector."); |
| createObjects(); |
| InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded, 2); |
| manager.addMockFileSystem(fileSystemPath, files); |
| dumpFileSystemUISourceCodesMappings(); |
| manager.removeMockFileSystem("/var/www"); |
| |
| InspectorTest.testFileMapping.setMappingEntries([]); |
| next(); |
| }, |
| |
| function testScriptFileOnReloadWithDirtyFile(next) |
| { |
| var originalFileContent = "<foo content>"; |
| var scriptURL = "http://localhost/html/foo.js"; |
| var scriptContent = originalFileContent + "\n //@ sourceURL=" + scriptURL + " \n "; |
| function uiSourceCodeAdded(uiSourceCode) { } |
| |
| function unloadScript() |
| { |
| resourceScriptMapping._debuggerReset(); |
| defaultScriptMapping._debuggerReset(); |
| } |
| |
| function loadScript() |
| { |
| script = InspectorTest.createScriptMock(scriptURL, 0, 0, false, scriptContent); |
| InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded, 1); |
| defaultScriptMapping.addScript(script); |
| resourceScriptMapping.addScript(script); |
| } |
| |
| var fileSystemPath = "/var/www"; |
| var fileSystemProjectId = WebInspector.FileSystemProjectDelegate.projectId(fileSystemPath); |
| var files = {"/html/foo.js": originalFileContent, "/bar.js": "<bar content>"}; |
| createObjects(); |
| var entry1 = new WebInspector.FileMapping.Entry("http://localhost/", "/var/www/"); |
| InspectorTest.testFileMapping.setMappingEntries([entry1]); |
| InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded, 2); |
| InspectorTest.addResult("Adding file system."); |
| manager.addMockFileSystem(fileSystemPath, files); |
| |
| loadScript(); |
| |
| var uiSourceCode = InspectorTest.testWorkspace.uiSourceCode(fileSystemProjectId, ["html", "foo.js"]); |
| InspectorTest.showUISourceCode(uiSourceCode, didShowScriptSource); |
| |
| function dumpUISourceCodeAndScriptContents() |
| { |
| InspectorTest.addResult("Dumping uiSourceCode and script content:"); |
| InspectorTest.addResult(" uiSourceCode: " + uiSourceCode.workingCopy()); |
| InspectorTest.addResult(" script: " + scriptContent); |
| } |
| |
| function didShowScriptSource(sourceFrame) |
| { |
| dumpUISourceCodeAndScriptContents(); |
| InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM()); |
| InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFrame._muted); |
| |
| InspectorTest.addResult("Editing uiSourceCode:"); |
| uiSourceCode.setWorkingCopy("<foo content edited>"); |
| InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM()); |
| InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFrame._muted); |
| |
| function setScriptSourceOverrideFailure(scriptId, newContent, callback) |
| { |
| callback("error"); |
| } |
| InspectorTest.override(WebInspector.debuggerModel, "setScriptSource", setScriptSourceOverrideFailure); |
| |
| InspectorTest.addResult("Committing uiSourceCode with live edit failure:"); |
| uiSourceCode.commitWorkingCopy(function() { }); |
| dumpUISourceCodeAndScriptContents(); |
| InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM()); |
| InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFrame._muted); |
| |
| InspectorTest.addResult("Reloading with saved but diverged uiSourceCode:"); |
| unloadScript(); |
| InspectorTest.assertTrue(!uiSourceCode.scriptFile(), "UISourceCode should not have script file after unloading scripts."); |
| InspectorTest.assertTrue(!sourceFrame._muted, "Saved but diverged source frame should not be muted"); |
| |
| InspectorTest.addResult("Loading script."); |
| loadScript(); |
| dumpUISourceCodeAndScriptContents(); |
| InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM()); |
| InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFrame._muted); |
| |
| InspectorTest.addResult("Editing uiSourceCode again:"); |
| uiSourceCode.setWorkingCopy("<foo content edited again>"); |
| InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM()); |
| InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFrame._muted); |
| |
| function setScriptSourceOverrideSuccess(scriptId, newContent, callback) |
| { |
| scriptContent = newContent; |
| callback(); |
| } |
| InspectorTest.override(WebInspector.debuggerModel, "setScriptSource", setScriptSourceOverrideSuccess); |
| |
| InspectorTest.addResult("Committing uiSourceCode again (with live edit success now):"); |
| uiSourceCode.commitWorkingCopy(function() { }); |
| dumpUISourceCodeAndScriptContents(); |
| InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM()); |
| InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFrame._muted); |
| |
| InspectorTest.addResult("Reloading page:"); |
| unloadScript(); |
| InspectorTest.assertTrue(!uiSourceCode.scriptFile(), "UISourceCode should not have script file after unloading scripts."); |
| InspectorTest.assertTrue(!sourceFrame._muted, "Saved and merged source frame should not be muted"); |
| InspectorTest.addResult("Loading script."); |
| loadScript(); |
| InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM()); |
| InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFrame._muted); |
| |
| InspectorTest.addResult("Editing uiSourceCode again and reloading while it is dirty:"); |
| uiSourceCode.setWorkingCopy("<foo content edited and dirty>"); |
| unloadScript(); |
| InspectorTest.assertTrue(!uiSourceCode.scriptFile(), "UISourceCode should not have script file after unloading scripts."); |
| InspectorTest.assertTrue(sourceFrame._muted, "Dirty source frame should be muted"); |
| InspectorTest.addResult("Loading script."); |
| loadScript(); |
| InspectorTest.addResult(" - hasDivergedFromVM: " + !!uiSourceCode.scriptFile().hasDivergedFromVM()); |
| InspectorTest.addResult(" - sourceFrame._muted: " + !!sourceFrame._muted); |
| |
| unloadScript(); |
| loadScript; |
| |
| next(); |
| } |
| } |
| ]); |
| }; |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests file system project mappings.</p> |
| </body> |
| </html> |