3 <script src=
"../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../http/tests/inspector/workspace-test.js"></script>
8 var uiSourceCodes
= {};
9 var projectDelegates
= {};
10 var projectDelegates
= {};
11 function createUISourceCode(projectId
, path
)
13 var projectDelegate
= projectDelegates
[projectId
];
14 if (!projectDelegates
[projectId
]) {
15 projectDelegate
= new MockProjectDelegate(projectId
);
16 workspace
.addProject(projectId
, projectDelegate
);
17 projectDelegates
[projectId
] = projectDelegate
;
20 var parentPath
= path
.substring(0, path
.lastIndexOf("/"));
21 var name
= path
.substring(path
.lastIndexOf("/") + 1);
22 var fileDescriptor
= new WebInspector
.FileDescriptor(parentPath
, name
, path
, path
, WebInspector
.resourceTypes
.Script
);
23 projectDelegate
.dispatchEventToListeners(WebInspector
.ProjectDelegate
.Events
.FileAdded
, fileDescriptor
);
26 function MockProjectDelegate(projectId
)
28 WebInspector
.Object
.call(this);
29 this._projectId
= projectId
.startsWith("1:") ? projectId
.substring(2) : projectId
;
31 MockProjectDelegate
.prototype = {
32 url: function() { return this._projectId
; },
33 displayName: function() {},
34 type: function() { return WebInspector
.projectTypes
.Network
; },
35 __proto__
: WebInspector
.Object
.prototype
38 var fileSystemMapping
= new WebInspector
.FileSystemMapping();
39 var fileSystemPath
= "/var/www";
40 var projectId
= WebInspector
.FileSystemWorkspaceBinding
.projectId(fileSystemPath
);
41 fileSystemMapping
.addFileSystem("/var/www");
42 fileSystemMapping
.addFileMapping("/var/www", "http://localhost/", "/localhost/");
43 var workspace
= new WebInspector
.Workspace(fileSystemMapping
);
44 var networkMapping
= new WebInspector
.NetworkMapping(workspace
, fileSystemMapping
);
46 function dumpHasMappingForURL(url
)
48 var result
= networkMapping
.hasMappingForURL(url
)
50 InspectorTest
.addResult(" url " + url
+ " is mapped.");
52 InspectorTest
.addResult(" url " + url
+ " is not mapped.");
55 function dumpUISourceCodeForURL(url
)
57 var uiSourceCode
= networkMapping
.uiSourceCodeForURLForAnyTarget(url
);
58 InspectorTest
.addResult(" url " + url
+ " is mapped to " + (uiSourceCode
? uiSourceCode
.uri() : null));
61 function dumpURLForPath(fileSystemPath
, filePath
)
63 var url
= networkMapping
.urlForPath(fileSystemPath
, filePath
)
64 InspectorTest
.addResult(" path " + fileSystemPath
+ " / " + filePath
+ " is mapped to " + (url
? url
: null));
67 createUISourceCode(projectId
, "localhost/index.html");
69 createUISourceCode("1:http://www.example.com", "index.html");
70 createUISourceCode("1:http://localhost", "index.html");
71 createUISourceCode("1:http://localhost", "foo/index.html");
72 createUISourceCode("1:https://localhost", "index.html");
74 dumpHasMappingForURL("http://www.example.com/index.html");
75 dumpHasMappingForURL("http://localhost/index.html");
76 dumpHasMappingForURL("http://localhost/foo/index.html");
77 dumpHasMappingForURL("https://localhost/index.html");
78 InspectorTest
.addResult("");
80 dumpUISourceCodeForURL("http://www.example.com/index.html");
81 dumpUISourceCodeForURL("http://localhost/index.html");
82 dumpUISourceCodeForURL("http://localhost/foo/index.html");
83 dumpUISourceCodeForURL("https://localhost/index.html");
84 InspectorTest
.addResult("");
86 dumpURLForPath("/home/example.com", "foo/index.html");
87 dumpURLForPath("/home/example.com", "index.html");
88 dumpURLForPath("/var/www", "localhost/index.html");
89 dumpURLForPath("/var/www", "localhost/foo/index.html");
90 dumpURLForPath("/home/foo", "index.html");
92 InspectorTest
.completeTest();
96 <body onload=
"runTest()">
97 <p>Tests workspace mappings
</p>