blob: 7e6f981559066d3ba98193d4b1ddd69777332915 [file] [log] [blame]
<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 projectDelegates = {};
function createUISourceCode(projectId, path)
{
var projectDelegate = projectDelegates[projectId];
if (!projectDelegates[projectId]) {
projectDelegate = new MockProjectDelegate(projectId);
workspace.addProject(projectDelegate);
projectDelegates[projectId] = projectDelegate;
}
projectDelegate.addUISourceCode(path);
}
function MockProjectDelegate(id)
{
this._id = id;
}
MockProjectDelegate.prototype = {
id: function() {
return this._id;
},
addUISourceCode: function(path) {
var fileDescriptor = new WebInspector.FileDescriptor(path.split("/"), path, path, WebInspector.resourceTypes.Script, true, false);
this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileAdded, fileDescriptor);
},
__proto__: WebInspector.Object.prototype
};
var fileMapping = new WebInspector.FileMapping();
var mappingEntries = [];
mappingEntries.push(new WebInspector.FileMapping.Entry("http://localhost/", "/var/www/localhost/"));
mappingEntries.push(new WebInspector.FileMapping.Entry("http://www.example.com/", "/home/example.com/"));
mappingEntries.push(new WebInspector.FileMapping.Entry("http://www.foo.com/", "/bar/"));
fileMapping.setMappingEntries(mappingEntries);
var fileSystemMapping = new WebInspector.FileSystemMappingImpl();
var fileSystemPath = "/var/www";
var projectId = WebInspector.FileSystemProjectDelegate.projectId(fileSystemPath);
fileSystemMapping.addFileSystemMapping("/var/www");
var workspace = new WebInspector.Workspace(fileMapping, fileSystemMapping);
function dumpHasMappingForURL(url)
{
var result = workspace.hasMappingForURL(url)
if (result)
InspectorTest.addResult(" url " + url + " is mapped.");
else
InspectorTest.addResult(" url " + url + " is not mapped.");
}
function dumpUISourceCodeForURL(url)
{
var uiSourceCode = workspace.uiSourceCodeForURL(url)
InspectorTest.addResult(" url " + url + " is mapped to " + (uiSourceCode ? uiSourceCode.uri() : null));
}
function dumpURLForPath(path)
{
var url = workspace.urlForPath(path)
InspectorTest.addResult(" path " + path + " is mapped to " + (url ? url : null));
}
createUISourceCode(projectId, "localhost/index.html");
createUISourceCode("http://www.example.com", "index.html");
createUISourceCode("http://localhost", "index.html");
createUISourceCode("http://localhost", "foo/index.html");
createUISourceCode("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>