| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../../http/tests/inspector/inspector-test.js"></script> | |
| 4 <script src="../../../http/tests/inspector/debugger-test.js"></script> | |
| 5 <script src="../../../http/tests/inspector/workspace-test.js"></script> | |
| 6 <script src="../../../http/tests/inspector/isolated-filesystem-test.js"></script
> | |
| 7 <script src="../../../http/tests/inspector/live-edit-test.js"></script> | |
| 8 <script> | |
| 9 | |
| 10 function test() | |
| 11 { | |
| 12 var target; | |
| 13 var resourceScriptMapping; | |
| 14 var defaultScriptMapping; | |
| 15 var persistence; | |
| 16 var fileSystemProjectId = Persistence.FileSystemWorkspaceBinding.projectId("
file:///var/www"); | |
| 17 | |
| 18 function createWorkspaceWithTarget() | |
| 19 { | |
| 20 target = InspectorTest.createWorkspaceWithTarget(false); | |
| 21 var entry = InspectorTest.testDebuggerWorkspaceBinding._targetToData.get
(target); | |
| 22 resourceScriptMapping = entry._resourceMapping; | |
| 23 defaultScriptMapping = entry._defaultMapping; | |
| 24 if (persistence) | |
| 25 persistence.dispose(); | |
| 26 persistence = new Persistence.Persistence(InspectorTest.testWorkspace, B
indings.breakpointManager, Workspace.fileSystemMapping); | |
| 27 } | |
| 28 | |
| 29 function dumpFileSystemUISourceCodesMappings() | |
| 30 { | |
| 31 var uiSourceCodes = InspectorTest.testWorkspace.project(fileSystemProjec
tId).uiSourceCodes(); | |
| 32 InspectorTest.addResult("UISourceCode uri to url mappings:"); | |
| 33 for (var uiSourceCode of uiSourceCodes) { | |
| 34 var binding = persistence.binding(uiSourceCode); | |
| 35 var url = binding ? binding.network.url() : ""; | |
| 36 InspectorTest.addResult(" " + uiSourceCode.url() + " -> " + url); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 InspectorTest.runTestSuite([ | |
| 41 function testAutomaticMapping(next) | |
| 42 { | |
| 43 createWorkspaceWithTarget(); | |
| 44 | |
| 45 InspectorTest.addResult("Adding file system."); | |
| 46 var fs = new InspectorTest.TestFileSystem("file:///var/www"); | |
| 47 fs.root.mkdir("html").addFile("foo.js", "<foo content>"); | |
| 48 fs.root.addFile("bar.js", "<bar content>"); | |
| 49 fs.reportCreated(fileSystemCreated1); | |
| 50 var networkUISourceCode; | |
| 51 | |
| 52 function fileSystemCreated1() | |
| 53 { | |
| 54 InspectorTest.addResult("Adding network resource."); | |
| 55 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ht
ml/foo.js", Common.resourceTypes.Script, "<foo content>", target); | |
| 56 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ba
r.js", Common.resourceTypes.Script, "<foo content>", target); | |
| 57 dumpFileSystemUISourceCodesMappings(); | |
| 58 | |
| 59 var uiSourceCode = InspectorTest.testWorkspace.uiSourceCode(file
SystemProjectId, "file:///var/www/html/foo.js"); | |
| 60 networkUISourceCode = InspectorTest.testWorkspace.uiSourceCode(B
indings.NetworkProject.projectId(target, target.resourceTreeModel.mainFrame, fal
se), "http://localhost/html/foo.js"); | |
| 61 InspectorTest.addResult("Adding mapping between network and file
system resources."); | |
| 62 | |
| 63 var fileSystemPath = Persistence.FileSystemWorkspaceBinding.file
SystemPath(uiSourceCode.project().id()); | |
| 64 Workspace.fileSystemMapping.addMappingForResource(networkUISourc
eCode.url(), fileSystemPath, uiSourceCode.url()); | |
| 65 var setting = JSON.stringify(Workspace.fileSystemMapping._fileSy
stemMappingSetting.get()); | |
| 66 | |
| 67 InspectorTest.addResult("Emulate reloading inspector."); | |
| 68 fs.reportRemoved(); | |
| 69 createWorkspaceWithTarget(); | |
| 70 Workspace.fileSystemMapping._fileSystemMappingSetting.set(JSON.p
arse(setting)); | |
| 71 Workspace.fileSystemMapping._loadFromSettings(); | |
| 72 fs.reportCreated(fileSystemCreated2); | |
| 73 } | |
| 74 | |
| 75 function fileSystemCreated2() | |
| 76 { | |
| 77 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ht
ml/foo.js", Common.resourceTypes.Script, "<foo content>", target); | |
| 78 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ba
r.js", Common.resourceTypes.Script, "<foo content>", target); | |
| 79 | |
| 80 dumpFileSystemUISourceCodesMappings(); | |
| 81 | |
| 82 InspectorTest.addResult("Removing mapping between network and fi
le system resources."); | |
| 83 var uiSourceCode = InspectorTest.testWorkspace.uiSourceCode(file
SystemProjectId, "file:///var/www/html/foo.js"); | |
| 84 Workspace.fileSystemMapping.removeMappingForURL(uiSourceCode.url
()); | |
| 85 | |
| 86 InspectorTest.addResult("Emulate reloading inspector."); | |
| 87 fs.reportRemoved(); | |
| 88 createWorkspaceWithTarget(); | |
| 89 fs.reportCreated(fileSystemCreated3); | |
| 90 } | |
| 91 | |
| 92 function fileSystemCreated3() | |
| 93 { | |
| 94 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ht
ml/foo.js", Common.resourceTypes.Script, "<foo content>", target); | |
| 95 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/ba
r.js", Common.resourceTypes.Script, "<foo content>", target); | |
| 96 dumpFileSystemUISourceCodesMappings(); | |
| 97 | |
| 98 Workspace.fileSystemMapping.removeMappingForURL(networkUISourceC
ode.url()); | |
| 99 fs.reportRemoved(); | |
| 100 next(); | |
| 101 } | |
| 102 }, | |
| 103 | |
| 104 function testRemoveProject(next) | |
| 105 { | |
| 106 function dumpWorkspaceUISourceCodes() | |
| 107 { | |
| 108 InspectorTest.addResult("Dumping uiSourceCodes origin URLs:"); | |
| 109 var uiSourceCodes = InspectorTest.testWorkspace.uiSourceCodes(); | |
| 110 for (var i = 0; i < uiSourceCodes.length; ++i) | |
| 111 InspectorTest.addResult(" - " + uiSourceCodes[i].url()); | |
| 112 } | |
| 113 | |
| 114 createWorkspaceWithTarget(); | |
| 115 | |
| 116 InspectorTest.addResult("Adding file system."); | |
| 117 var fs = new InspectorTest.TestFileSystem("file:///var/www"); | |
| 118 fs.root.addFile("foo.js", ""); | |
| 119 fs.reportCreated(fileSystemCreated); | |
| 120 | |
| 121 function fileSystemCreated() | |
| 122 { | |
| 123 dumpWorkspaceUISourceCodes(); | |
| 124 InspectorTest.addResult("Removing project:"); | |
| 125 InspectorTest.testWorkspace.addEventListener(Workspace.Workspace
.Events.ProjectRemoved, projectRemoved); | |
| 126 InspectorTest.testTargetManager.removeTarget(target); | |
| 127 target = null; | |
| 128 } | |
| 129 | |
| 130 function projectRemoved() | |
| 131 { | |
| 132 InspectorTest.testWorkspace.removeEventListener(Workspace.Worksp
ace.Events.ProjectRemoved, projectRemoved); | |
| 133 InspectorTest.addResult("Received project removed event."); | |
| 134 fs.reportRemoved(); | |
| 135 setImmediate(next); | |
| 136 } | |
| 137 }, | |
| 138 | |
| 139 function testProjectBasedMapping(next) | |
| 140 { | |
| 141 createWorkspaceWithTarget(); | |
| 142 | |
| 143 InspectorTest.addResult("Adding file system."); | |
| 144 var fs = new InspectorTest.TestFileSystem("file:///var/www"); | |
| 145 fs.root.mkdir("html").addFile("foo.js", "<foo content>"); | |
| 146 fs.root.mkdir("html2").addFile("bar.js", "<bar content>"); | |
| 147 fs.root.addFile(".devtools", JSON.stringify({ mappings: [ { folder:
"/html/", url: "http://localhost/h1/" }, { folder: "/html2/", url: "http://local
host/h2/" } ]})); | |
| 148 fs.reportCreated(fileSystemCreated); | |
| 149 | |
| 150 function fileSystemCreated() | |
| 151 { | |
| 152 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/h1
/foo.js", Common.resourceTypes.Script, "<foo content>", target); | |
| 153 InspectorTest.addMockUISourceCodeViaNetwork("http://localhost/h2
/bar.js", Common.resourceTypes.Script, "<bar content>", target); | |
| 154 dumpFileSystemUISourceCodesMappings(); | |
| 155 fs.reportRemoved(); | |
| 156 next(); | |
| 157 } | |
| 158 } | |
| 159 ]); | |
| 160 }; | |
| 161 </script> | |
| 162 </head> | |
| 163 <body onload="runTest()"> | |
| 164 <p>Tests file system project mappings.</p> | |
| 165 </body> | |
| 166 </html> | |
| OLD | NEW |