| <html> |
| <head> |
| <script src="../http/tests/inspector/inspector-test.js"></script> |
| <script src="../http/tests/inspector/workspace-test.js"></script> |
| <script> |
| function test() |
| { |
| var uiSourceCodes = {}; |
| var projects = {}; |
| var workspace = new WebInspector.Workspace(); |
| |
| function createUISourceCode(projectId, path) |
| { |
| var project = projects[projectId]; |
| if (!projects[projectId]) { |
| if (projectId.startsWith("1:")) |
| projectId = projectId.substring(2); |
| project = new WebInspector.ProjectStore(workspace, projectId, WebInspector.projectTypes.Network, projectId, ""); |
| workspace.addProject(project); |
| projects[projectId] = project; |
| } |
| var parentPath = path.substring(0, path.lastIndexOf("/")); |
| var name = path.substring(path.lastIndexOf("/") + 1); |
| project.addUISourceCode(parentPath, name, path, WebInspector.resourceTypes.Script); |
| } |
| |
| var fileSystemMapping = new WebInspector.FileSystemMapping(); |
| var fileSystemPath = "/var/www"; |
| var projectId = WebInspector.FileSystemWorkspaceBinding.projectId(fileSystemPath); |
| fileSystemMapping.addFileSystem("/var/www"); |
| fileSystemMapping.addFileMapping("/var/www", "http://localhost/", "/localhost/"); |
| var fileSystemWorkspaceBinding = new WebInspector.FileSystemWorkspaceBinding(WebInspector.isolatedFileSystemManager, workspace); |
| var networkMapping = new WebInspector.NetworkMapping(WebInspector.targetManager, workspace, fileSystemWorkspaceBinding, fileSystemMapping); |
| |
| function dumpHasMappingForURL(url) |
| { |
| var result = networkMapping.hasMappingForURL(url) |
| if (result) |
| InspectorTest.addResult(" url " + url + " is mapped."); |
| else |
| InspectorTest.addResult(" url " + url + " is not mapped."); |
| } |
| |
| function dumpUISourceCodeForURL(url) |
| { |
| var uiSourceCode = networkMapping.uiSourceCodeForURLForAnyTarget(url); |
| InspectorTest.addResult(" url " + url + " is mapped to " + (uiSourceCode ? uiSourceCode.uri() : null)); |
| } |
| |
| function dumpURLForPath(fileSystemPath, filePath) |
| { |
| var url = networkMapping.urlForPath(fileSystemPath, filePath) |
| InspectorTest.addResult(" path " + fileSystemPath + " / " + filePath + " is mapped to " + (url ? url : null)); |
| } |
| |
| createUISourceCode(projectId, "localhost/index.html"); |
| |
| createUISourceCode("1:http://www.example.com", "index.html"); |
| createUISourceCode("1:http://localhost", "index.html"); |
| createUISourceCode("1:http://localhost", "foo/index.html"); |
| createUISourceCode("1:https://localhost", "index.html"); |
| |
| dumpHasMappingForURL("http://www.example.com/index.html"); |
| dumpHasMappingForURL("http://localhost/index.html"); |
| dumpHasMappingForURL("http://localhost/foo/index.html"); |
| dumpHasMappingForURL("https://localhost/index.html"); |
| InspectorTest.addResult(""); |
| |
| dumpUISourceCodeForURL("http://www.example.com/index.html"); |
| dumpUISourceCodeForURL("http://localhost/index.html"); |
| dumpUISourceCodeForURL("http://localhost/foo/index.html"); |
| dumpUISourceCodeForURL("https://localhost/index.html"); |
| InspectorTest.addResult(""); |
| |
| dumpURLForPath("/home/example.com", "foo/index.html"); |
| dumpURLForPath("/home/example.com", "index.html"); |
| dumpURLForPath("/var/www", "localhost/index.html"); |
| dumpURLForPath("/var/www", "localhost/foo/index.html"); |
| dumpURLForPath("/home/foo", "index.html"); |
| |
| InspectorTest.completeTest(); |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests workspace mappings</p> |
| </body> |
| </html> |