| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="../../../http/tests/inspector/debugger-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> | 5 <script> |
| 6 function loadIframe() |
| 7 { |
| 8 var iframe = document.createElement("iframe"); |
| 9 iframe.setAttribute("src", "resources/multiple-scripts.html"); |
| 10 document.body.appendChild(iframe); |
| 11 } |
| 12 |
| 7 function test() | 13 function test() |
| 8 { | 14 { |
| 9 var defaultScriptMapping; | 15 var url = InspectorTest.mainTarget.inspectedURL().replace("resource-script-m
apping.html", "resources/multiple-scripts.html"); |
| 10 var target = InspectorTest.debuggerModel.target(); | 16 var scripts = []; |
| 17 var count = 3; |
| 11 | 18 |
| 12 function createResourceScriptMapping() | 19 InspectorTest.addResult("Waiting for scripts"); |
| 20 InspectorTest.debuggerModel.addEventListener(SDK.DebuggerModel.Events.Parsed
ScriptSource, onScriptParsed); |
| 21 InspectorTest.evaluateInPage("loadIframe()"); |
| 22 |
| 23 function onScriptParsed(event) |
| 13 { | 24 { |
| 14 InspectorTest.createWorkspace(); | 25 var script = event.data; |
| 15 InspectorTest.testTargetManager.addTarget(target); | 26 if (script.sourceURL !== url) |
| 16 defaultScriptMapping = InspectorTest.testDebuggerWorkspaceBinding._targe
tToData.get(target)._defaultMapping; | 27 return; |
| 17 var resourceScriptMapping = new Bindings.ResourceScriptMapping(Inspector
Test.debuggerModel, InspectorTest.testWorkspace, InspectorTest.testDebuggerWorks
paceBinding); | 28 InspectorTest.addResult("Script arrived"); |
| 18 return resourceScriptMapping; | 29 scripts.push(script); |
| 30 if (!--count) { |
| 31 InspectorTest.debuggerModel.removeEventListener(SDK.DebuggerModel.Ev
ents.ParsedScriptSource, onScriptParsed); |
| 32 InspectorTest.addResult("Waiting for UISourceCode"); |
| 33 InspectorTest.waitForUISourceCode(onUISourceCode, url); |
| 34 } |
| 19 } | 35 } |
| 20 | 36 |
| 21 function uiLocation(script, lineNumber, columnNumber) | 37 function onUISourceCode(uiSourceCode) |
| 22 { | 38 { |
| 23 var location = script.debuggerModel.createRawLocation(script, lineNumber
, columnNumber); | 39 InspectorTest.addResult("UISourceCode arrived"); |
| 24 return InspectorTest.testDebuggerWorkspaceBinding.rawLocationToUILocatio
n(location); | 40 scripts.sort((s1, s2) => { return s1.lineOffset - s2.lineOffset; }); |
| 41 for (var script of scripts) { |
| 42 InspectorTest.addResult(`Checking script at (${script.lineOffset}, $
{script.columnOffset})`); |
| 43 var line = script.lineOffset; |
| 44 var column = script.columnOffset + 2; |
| 45 var rawLocation = InspectorTest.debuggerModel.createRawLocation(scri
pt, line, column); |
| 46 var uiLocation = Bindings.debuggerWorkspaceBinding.rawLocationToUILo
cation(rawLocation); |
| 47 InspectorTest.checkUILocation(uiSourceCode, line, column, uiLocation
); |
| 48 var reverseLocation = Bindings.debuggerWorkspaceBinding.uiLocationTo
RawLocation(InspectorTest.mainTarget, uiSourceCode, line, column); |
| 49 InspectorTest.checkRawLocation(script, line, column, reverseLocation
); |
| 50 } |
| 51 InspectorTest.completeTest(); |
| 25 } | 52 } |
| 26 | |
| 27 function resetModels() | |
| 28 { | |
| 29 InspectorTest.debuggerModel._reset(); | |
| 30 } | |
| 31 | |
| 32 InspectorTest.runTestSuite([ | |
| 33 function testScriptWithPendingResource(next) | |
| 34 { | |
| 35 var script; | |
| 36 resetModels(); | |
| 37 var resourceScriptMapping = createResourceScriptMapping(); | |
| 38 var url = "foo.js"; | |
| 39 step1(); | |
| 40 | |
| 41 function step1() | |
| 42 { | |
| 43 InspectorTest.addResult("Adding script for pending request."); | |
| 44 script = InspectorTest.createScriptMock(url, 0, 0, true, "<conte
nt script source>"); | |
| 45 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUIS
ourceCodeAdded); | |
| 46 defaultScriptMapping.addScript(script); | |
| 47 resourceScriptMapping.addScript(script); | |
| 48 | |
| 49 var originalUISourceCode; | |
| 50 uiLocation(script, 0, 5); | |
| 51 | |
| 52 function originalUISourceCodeAdded(uiSourceCode) | |
| 53 { | |
| 54 originalUISourceCode = uiSourceCode; | |
| 55 } | |
| 56 | |
| 57 InspectorTest.checkUILocation(originalUISourceCode, 0, 5, uiLoca
tion(script, 0, 5)); | |
| 58 InspectorTest.checkRawLocation(script, 10, 0, InspectorTest.test
DebuggerWorkspaceBinding.uiLocationToRawLocation(target, originalUISourceCode, 1
0, 0)); | |
| 59 InspectorTest.dumpUISourceCode(originalUISourceCode, step2); | |
| 60 } | |
| 61 | |
| 62 function step2() | |
| 63 { | |
| 64 InspectorTest.addResult("Adding uiSourceCode for finished resour
ce."); | |
| 65 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCod
eAdded); | |
| 66 InspectorTest.addMockUISourceCodeToWorkspace(url, Common.resourc
eTypes.Script, "<content script resource content>"); | |
| 67 | |
| 68 function uiSourceCodeAdded(uiSourceCode) | |
| 69 { | |
| 70 InspectorTest.checkUILocation(uiSourceCode, 0, 5, uiLocation
(script, 0, 5)); | |
| 71 InspectorTest.checkRawLocation(script, 10, 0, InspectorTest.
testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode, 10, 0
)); | |
| 72 InspectorTest.dumpUISourceCode(uiSourceCode, next); | |
| 73 } | |
| 74 } | |
| 75 }, | |
| 76 | |
| 77 function testScriptWithFinishedResource(next) | |
| 78 { | |
| 79 var script; | |
| 80 resetModels(); | |
| 81 var mockUISourceCode; | |
| 82 var resourceScriptMapping = createResourceScriptMapping(); | |
| 83 var url = "foo.js"; | |
| 84 step1(); | |
| 85 | |
| 86 function step1() | |
| 87 { | |
| 88 InspectorTest.addResult("Adding uiSourceCode for finished resour
ce."); | |
| 89 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCod
eForResourceAdded); | |
| 90 InspectorTest.addMockUISourceCodeToWorkspace(url, Common.resourc
eTypes.Script, "<script resource content>"); | |
| 91 } | |
| 92 | |
| 93 function uiSourceCodeForResourceAdded(uiSourceCode) | |
| 94 { | |
| 95 mockUISourceCode = uiSourceCode; | |
| 96 InspectorTest.dumpUISourceCode(uiSourceCode, step2); | |
| 97 } | |
| 98 | |
| 99 function step2() | |
| 100 { | |
| 101 InspectorTest.addResult("Adding script for finished request."); | |
| 102 script = InspectorTest.createScriptMock(url, 0, 0, false, "<scri
pt source>"); | |
| 103 resourceScriptMapping.addScript(script); | |
| 104 InspectorTest.checkUILocation(mockUISourceCode, 0, 5, uiLocation
(script, 0, 5)); | |
| 105 InspectorTest.checkRawLocation(script, 10, 0, InspectorTest.test
DebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 10, 0
)); | |
| 106 InspectorTest.dumpUISourceCode(mockUISourceCode, next); | |
| 107 } | |
| 108 }, | |
| 109 | |
| 110 function testHTMLWithPendingResource(next) | |
| 111 { | |
| 112 var script1; | |
| 113 var script2; | |
| 114 resetModels(); | |
| 115 var resourceScriptMapping = createResourceScriptMapping(); | |
| 116 var originalUISourceCode1; | |
| 117 var originalUISourceCode2; | |
| 118 var url = "index.html"; | |
| 119 step1(); | |
| 120 | |
| 121 function step1() | |
| 122 { | |
| 123 InspectorTest.addResult("Adding first script for pending request
."); | |
| 124 script1 = InspectorTest.createScriptMock(url, 0, 10, false, "<sc
ript source 1>"); | |
| 125 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUIS
ourceCodeAdded); | |
| 126 defaultScriptMapping.addScript(script1); | |
| 127 resourceScriptMapping.addScript(script1); | |
| 128 | |
| 129 uiLocation(script1, 0, 5); | |
| 130 | |
| 131 function originalUISourceCodeAdded(uiSourceCode) | |
| 132 { | |
| 133 originalUISourceCode1 = uiSourceCode; | |
| 134 } | |
| 135 | |
| 136 InspectorTest.checkUILocation(originalUISourceCode1, 0, 5, uiLoc
ation(script1, 0, 5)); | |
| 137 InspectorTest.checkRawLocation(script1, 10, 0, InspectorTest.tes
tDebuggerWorkspaceBinding.uiLocationToRawLocation(target, originalUISourceCode1,
10, 0)); | |
| 138 InspectorTest.dumpUISourceCode(originalUISourceCode1, step2); | |
| 139 } | |
| 140 | |
| 141 function step2() | |
| 142 { | |
| 143 InspectorTest.addResult("Adding second script for pending reques
t."); | |
| 144 script2 = InspectorTest.createScriptMock(url, 0, 45, false, "<sc
ript source 2>"); | |
| 145 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUIS
ourceCodeAdded); | |
| 146 defaultScriptMapping.addScript(script2); | |
| 147 resourceScriptMapping.addScript(script2); | |
| 148 | |
| 149 function originalUISourceCodeAdded(uiSourceCode) | |
| 150 { | |
| 151 originalUISourceCode2 = uiSourceCode; | |
| 152 } | |
| 153 InspectorTest.checkUILocation(originalUISourceCode2, 0, 45, uiLo
cation(script2, 0, 45)); | |
| 154 InspectorTest.checkRawLocation(script1, 10, 0, InspectorTest.tes
tDebuggerWorkspaceBinding.uiLocationToRawLocation(target, originalUISourceCode1,
10, 0)); | |
| 155 InspectorTest.dumpUISourceCode(originalUISourceCode2, step3); | |
| 156 } | |
| 157 | |
| 158 function step3() | |
| 159 { | |
| 160 InspectorTest.addResult("Adding uiSourceCode for finished resour
ce."); | |
| 161 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCod
eAdded); | |
| 162 InspectorTest.addMockUISourceCodeToWorkspace(url, Common.resourc
eTypes.Document, "<resource content>"); | |
| 163 | |
| 164 function uiSourceCodeAdded(uiSourceCode) | |
| 165 { | |
| 166 InspectorTest.checkUILocation(uiSourceCode, 0, 5, uiLocation
(script1, 0, 5)); | |
| 167 InspectorTest.checkRawLocation(script1, 10, 0, InspectorTest
.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode, 10,
0)); | |
| 168 InspectorTest.dumpUISourceCode(uiSourceCode, next); | |
| 169 } | |
| 170 } | |
| 171 }, | |
| 172 | |
| 173 function testHTMLWithFinishedResource(next) | |
| 174 { | |
| 175 var script1; | |
| 176 var script2; | |
| 177 resetModels(); | |
| 178 var mockUISourceCode; | |
| 179 var resourceScriptMapping = createResourceScriptMapping(); | |
| 180 var url = "index.html"; | |
| 181 step1(); | |
| 182 | |
| 183 function step1() | |
| 184 { | |
| 185 InspectorTest.addResult("Adding uiSourceCode for finished resour
ce."); | |
| 186 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCod
eForResourceAdded); | |
| 187 InspectorTest.addMockUISourceCodeToWorkspace(url, Common.resourc
eTypes.Document, "<resource content>"); | |
| 188 } | |
| 189 | |
| 190 function uiSourceCodeForResourceAdded(uiSourceCode) | |
| 191 { | |
| 192 mockUISourceCode = uiSourceCode; | |
| 193 InspectorTest.dumpUISourceCode(uiSourceCode, step2); | |
| 194 } | |
| 195 | |
| 196 function step2() | |
| 197 { | |
| 198 InspectorTest.addResult("Adding first script for finished reques
t."); | |
| 199 script1 = InspectorTest.createScriptMock(url, 1, 10, false, "<sc
ript source 1>"); | |
| 200 resourceScriptMapping.addScript(script1); | |
| 201 InspectorTest.checkUILocation(mockUISourceCode, 1, 20, uiLocatio
n(script1, 1, 20)); | |
| 202 InspectorTest.checkRawLocation(script1, 1, 0, InspectorTest.test
DebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 1, 0)
); | |
| 203 InspectorTest.checkRawLocation(script1, 6, 0, InspectorTest.test
DebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 6, 0)
); | |
| 204 InspectorTest.dumpUISourceCode(mockUISourceCode, step3); | |
| 205 } | |
| 206 | |
| 207 function step3() | |
| 208 { | |
| 209 InspectorTest.addResult("Adding second script for finished reque
st."); | |
| 210 script2 = InspectorTest.createScriptMock(url, 5, 45, false, "<sc
ript\nsource\n2>"); | |
| 211 resourceScriptMapping.addScript(script2); | |
| 212 InspectorTest.checkUILocation(mockUISourceCode, 1, 20, uiLocatio
n(script1, 1, 20)); | |
| 213 InspectorTest.checkRawLocation(script1, 1, 0, InspectorTest.test
DebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 1, 0)
); | |
| 214 InspectorTest.checkRawLocation(script2, 6, 0, InspectorTest.test
DebuggerWorkspaceBinding.uiLocationToRawLocation(target, mockUISourceCode, 6, 0)
); | |
| 215 InspectorTest.dumpUISourceCode(mockUISourceCode, next); | |
| 216 } | |
| 217 } | |
| 218 ]); | |
| 219 }; | 53 }; |
| 220 </script> | 54 </script> |
| 221 </head> | 55 </head> |
| 222 <body onload="runTest()"> | 56 <body onload="runTest()"> |
| 223 <p>Tests ResourceScriptMapping class.</p> | 57 <p>Tests ResourceScriptMapping class.</p> |
| 224 </body> | 58 </body> |
| 225 </html> | 59 </html> |
| OLD | NEW |