| <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/isolated-filesystem-test.js"></script> |
| <script> |
| function test() |
| { |
| function fileSystemUISourceCodes() |
| { |
| var uiSourceCodes = []; |
| var fileSystemProjects = Workspace.workspace.projectsForType(Workspace.projectTypes.FileSystem); |
| for (var project of fileSystemProjects) |
| uiSourceCodes = uiSourceCodes.concat(project.uiSourceCodes()); |
| return uiSourceCodes; |
| } |
| |
| function dumpUISourceCode(uiSourceCode, callback) |
| { |
| InspectorTest.addResult("UISourceCode: " + uiSourceCode.url().replace(/.*LayoutTests/, "LayoutTests")); |
| if (uiSourceCode.contentType() === Common.resourceTypes.Script || uiSourceCode.contentType() === Common.resourceTypes.Document) |
| InspectorTest.addResult("UISourceCode is content script: " + (uiSourceCode.project().type() === Workspace.projectTypes.ContentScripts)); |
| uiSourceCode.requestContent().then(didRequestContent); |
| |
| function didRequestContent(content, contentEncoded) |
| { |
| InspectorTest.addResult("Highlighter type: " + Bindings.NetworkProject.uiSourceCodeMimeType(uiSourceCode)); |
| InspectorTest.addResult("UISourceCode content: " + content); |
| callback(); |
| } |
| } |
| |
| function dumpUISourceCodes(uiSourceCodes, next) |
| { |
| innerDumpUISourceCodes(uiSourceCodes, 0, next); |
| |
| function innerDumpUISourceCodes(uiSourceCodes, startIndex, next) |
| { |
| InspectorTest.addResult(""); |
| if (startIndex === uiSourceCodes.length) { |
| next(); |
| return; |
| } |
| |
| dumpUISourceCode(uiSourceCodes[startIndex], innerDumpUISourceCodes.bind(this, uiSourceCodes, startIndex + 1, next)); |
| } |
| } |
| |
| function dumpUISourceCodeLocations(uiSourceCodes, lineNumber) |
| { |
| InspectorTest.addResult("Dumping uiSourceCode location link texts:"); |
| for (var i = 0; i < uiSourceCodes.length; ++i) { |
| var uiSourceCode = uiSourceCodes[i]; |
| var uiLocation = uiSourceCode.uiLocation(lineNumber); |
| InspectorTest.addResult(" - " + uiLocation.linkText()); |
| } |
| } |
| |
| function dumpWorkspaceUISourceCodes() |
| { |
| InspectorTest.addResult("Dumping uiSourceCodes origin URLs:"); |
| var uiSourceCodes = fileSystemUISourceCodes(); |
| for (var i = 0; i < uiSourceCodes.length; ++i) |
| InspectorTest.addResult(" - " + uiSourceCodes[i].url()); |
| } |
| |
| function createFileSystem(name, callback) |
| { |
| var fs = new InspectorTest.TestFileSystem(name); |
| fs.root.mkdir("html").addFile("foo.js", ""); |
| fs.root.mkdir(".git").addFile("foogit.js", ""); |
| fs.root.addFile("bar.js", ""); |
| fs.root.mkdir("html2").addFile("foo.js", ""); |
| fs.reportCreated(callback.bind(null, fs)); |
| } |
| |
| InspectorTest.runTestSuite([ |
| function testFileSystems(next) |
| { |
| InspectorTest.addResult("Adding first file system."); |
| var fs1 = new InspectorTest.TestFileSystem("file:///var/www"); |
| fs1.addFileMapping("http://localhost/", "/localhost/"); |
| var fs2 = new InspectorTest.TestFileSystem("file:///foo/bar"); |
| fs2.addFileMapping("http://www.example.com/", "/"); |
| InspectorTest.addResult("Adding second file system."); |
| |
| InspectorTest.addResult("Adding files to file systems."); |
| |
| var localhostDir = fs1.root.mkdir("localhost"); |
| localhostDir.addFile("foo.js", "<foo content>"); |
| fs1.root.addFile("bar.js", "<bark content>"); |
| |
| fs2.root.addFile("baz.js", "<bazzz content>"); |
| fs1.reportCreated(function() {}); |
| fs2.reportCreated(function() {}); |
| |
| Workspace.workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, onUISourceCode); |
| |
| var count = 3; |
| function onUISourceCode() |
| { |
| if (--count) |
| return; |
| Workspace.workspace.removeEventListener(Workspace.Workspace.Events.UISourceCodeAdded, onUISourceCode); |
| onUISourceCodesLoaded(); |
| } |
| |
| var uiSourceCodes; |
| |
| function onUISourceCodesLoaded() |
| { |
| uiSourceCodes = fileSystemUISourceCodes(); |
| dumpUISourceCodes(uiSourceCodes, uiSourceCodesDumped); |
| } |
| |
| function uiSourceCodesDumped() |
| { |
| dumpUISourceCodeLocations(uiSourceCodes, 5); |
| Workspace.workspace.addEventListener(Workspace.Workspace.Events.WorkingCopyCommitted, contentCommitted, this); |
| uiSourceCodes[0].addRevision("<Modified UISourceCode content>"); |
| } |
| |
| function contentCommitted() |
| { |
| InspectorTest.addResult("After revision added:"); |
| dumpUISourceCode(uiSourceCodes[0], finalize); |
| } |
| |
| function finalize() |
| { |
| fs1.reportRemoved(); |
| fs2.reportRemoved(); |
| next(); |
| } |
| }, |
| |
| function testDefaultExcludes(next) |
| { |
| createFileSystem("file:///var/www", dumpExcludes); |
| |
| function dumpExcludes(fs) |
| { |
| InspectorTest.addResult(""); |
| InspectorTest.addResult("-- Default excludes --"); |
| dumpWorkspaceUISourceCodes(); |
| fs.reportRemoved(); |
| next(); |
| } |
| }, |
| |
| function testExcludesSettings(next) |
| { |
| Common.settings.createLocalSetting("workspaceExcludedFolders", {}).set({"file:///var/www2":["/html/"]}); |
| createFileSystem("file:///var/www2", dumpExcludes); |
| |
| function dumpExcludes(fs) |
| { |
| InspectorTest.addResult(""); |
| InspectorTest.addResult("-- Excluded /html/ --"); |
| dumpWorkspaceUISourceCodes(); |
| fs.reportRemoved(); |
| next(); |
| } |
| }, |
| |
| function testExcludesViaDelegate(next) |
| { |
| createFileSystem("file:///var/www3", dumpExcludes); |
| |
| function dumpExcludes(fs) |
| { |
| fileSystemUISourceCodes()[0].project().excludeFolder("file:///var/www3/html2/"); |
| InspectorTest.addResult(""); |
| InspectorTest.addResult("-- Excluded /html2/ --"); |
| dumpWorkspaceUISourceCodes(); |
| fs.reportRemoved(); |
| next(); |
| } |
| }, |
| |
| function testFileAddedExternally(next) |
| { |
| var fs = new InspectorTest.TestFileSystem("file:///var/www4"); |
| var dir = fs.root.mkdir("html"); |
| dir.addFile("foo.js", ""); |
| fs.reportCreated(dumpFileSystem); |
| |
| function dumpFileSystem() |
| { |
| InspectorTest.addResult("-- Original tree --"); |
| dumpWorkspaceUISourceCodes(); |
| |
| dir.addFile("bar.js", ""); |
| InspectorFrontendHost.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.FileSystemFilesChangedAddedRemoved, { |
| changed: [], |
| added:["/var/www4/html/bar.js"], |
| removed: [] |
| }); |
| |
| InspectorTest.addResult("-- File added externally --"); |
| dumpWorkspaceUISourceCodes(); |
| fs.reportRemoved(); |
| next(); |
| } |
| }, |
| |
| function testGitFolders(next) |
| { |
| var fs = new InspectorTest.TestFileSystem("file:///var/www3"); |
| var project1 = fs.root.mkdir("project_1"); |
| project1.mkdir(".git").addFile("foo.git"); |
| var project2 = fs.root.mkdir("project_2"); |
| project2.mkdir(".git").addFile("bar.git"); |
| var project3 = fs.root.mkdir("project_3"); |
| project3.mkdir(".svn").addFile("baz.svn"); |
| var project4 = fs.root.mkdir("project_4"); |
| project4.addFile("index.html"); |
| fs.reportCreated(dumpGitFolders); |
| |
| function dumpGitFolders() |
| { |
| var isolatedFileSystem = Workspace.isolatedFileSystemManager.fileSystem("file:///var/www3"); |
| var folders = isolatedFileSystem.initialGitFolders(); |
| folders.sort(); |
| for (var gitFolder of folders) |
| InspectorTest.addResult(gitFolder); |
| fs.reportRemoved(); |
| next(); |
| } |
| }, |
| |
| function testUISourceCodeMetadata(next) |
| { |
| var fs = new InspectorTest.TestFileSystem("file:///var/www3"); |
| var file = fs.root.mkdir("test").addFile("hello.js", "123456"); |
| fs.reportCreated(function() { }); |
| InspectorTest.waitForScriptSource("hello.js", onUISourceCode); |
| var uiSourceCode; |
| |
| function onUISourceCode(sourceCode) |
| { |
| uiSourceCode = sourceCode; |
| uiSourceCode.requestMetadata().then(onInitialMetadata); |
| } |
| |
| function onInitialMetadata(metadata) |
| { |
| dumpMetadata("Initial metadata", metadata); |
| file.setContent("changed content"); |
| uiSourceCode.requestMetadata().then(onChangedMetadata); |
| } |
| |
| function onChangedMetadata(metadata) |
| { |
| dumpMetadata("Changed metadata", metadata); |
| fs.reportRemoved(); |
| next(); |
| } |
| |
| function dumpMetadata(label, metadata) |
| { |
| InspectorTest.addResult(label); |
| InspectorTest.addResult(" content size: " + metadata.contentSize); |
| InspectorTest.addResult(" modification time: " + metadata.modificationTime.toISOString()); |
| } |
| }, |
| |
| function testFileRename(next) |
| { |
| var fs = new InspectorTest.TestFileSystem("file:///var/www3"); |
| var file = fs.root.mkdir("test").addFile("hello.js", "123456"); |
| fs.reportCreated(function() { }); |
| InspectorTest.waitForScriptSource("hello.js", onUISourceCode); |
| var uiSourceCode; |
| var originalURL; |
| function onUISourceCode(sourceCode) |
| { |
| uiSourceCode = sourceCode; |
| originalURL = uiSourceCode.url(); |
| InspectorTest.addResult('URL before rename: ' + originalURL); |
| uiSourceCode.rename('goodbye.js').then(renamed); |
| } |
| |
| function renamed() |
| { |
| InspectorTest.addResult('URL after rename: ' + uiSourceCode.url()); |
| if (uiSourceCode.project().workspace().uiSourceCodeForURL(originalURL)) |
| InspectorTest.addResult('ERROR: Still found original URL in workspace.'); |
| if (!uiSourceCode.project().workspace().uiSourceCodeForURL(uiSourceCode.url())) |
| InspectorTest.addResult('ERROR: Could not find new URL in workspace.'); |
| next(); |
| } |
| } |
| ]); |
| }; |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests file system project.</p> |
| </body> |
| </html> |