| 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> | 5 <script> |
| 6 function startWorker() | 6 function startWorker() |
| 7 { | 7 { |
| 8 var workerScript = "postMessage('Done.');"; | 8 var workerScript = "postMessage('Done.');"; |
| 9 var blob = new Blob([workerScript], { type: "text/javascript" }); | 9 var blob = new Blob([workerScript], { type: "text/javascript" }); |
| 10 var worker = new Worker(URL.createObjectURL(blob)); | 10 var worker = new Worker(URL.createObjectURL(blob)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 function uiSourceCodeRemoved(event) | 60 function uiSourceCodeRemoved(event) |
| 61 { | 61 { |
| 62 var uiSourceCode = event.data; | 62 var uiSourceCode = event.data; |
| 63 InspectorTest.addResult("UISourceCodeRemoved: " + uiSourceCode.n
ame()); | 63 InspectorTest.addResult("UISourceCodeRemoved: " + uiSourceCode.n
ame()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAd
ded, uiSourceCodeAdded); | 66 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAd
ded, uiSourceCodeAdded); |
| 67 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeRe
moved, uiSourceCodeRemoved); | 67 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeRe
moved, uiSourceCodeRemoved); |
| 68 | 68 |
| 69 function renameSnippetAndCheckWorkspace(uiSourceCode, snippetName) | 69 async function renameSnippetAndCheckWorkspace(uiSourceCode, snippetN
ame) |
| 70 { | 70 { |
| 71 InspectorTest.addResult("Renaming snippet to '" + snippetName +
"' ..."); | 71 InspectorTest.addResult("Renaming snippet to '" + snippetName +
"' ..."); |
| 72 uiSourceCode.rename(snippetName, renameCallback); | 72 await uiSourceCode.rename(snippetName).then(success => renameCal
lback(success)); |
| 73 | 73 |
| 74 function renameCallback(success) | 74 function renameCallback(success) |
| 75 { | 75 { |
| 76 if (success) | 76 if (success) |
| 77 InspectorTest.addResult("Snippet renamed successfully.")
; | 77 InspectorTest.addResult("Snippet renamed successfully.")
; |
| 78 else | 78 else |
| 79 InspectorTest.addResult("Snippet was not renamed."); | 79 InspectorTest.addResult("Snippet was not renamed."); |
| 80 } | 80 } |
| 81 InspectorTest.addResult("UISourceCode name is '" + uiSourceCode.
name() + "' now."); | 81 InspectorTest.addResult("UISourceCode name is '" + uiSourceCode.
name() + "' now."); |
| 82 InspectorTest.addResult("Number of uiSourceCodes in workspace: "
+ workspace.uiSourceCodes().filter(filterSnippet).length); | 82 InspectorTest.addResult("Number of uiSourceCodes in workspace: "
+ workspace.uiSourceCodes().filter(filterSnippet).length); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 111 .then(contentDumped2) | 111 .then(contentDumped2) |
| 112 } | 112 } |
| 113 | 113 |
| 114 function contentDumped2() | 114 function contentDumped2() |
| 115 { | 115 { |
| 116 InspectorTest.addResult("Snippet1 created."); | 116 InspectorTest.addResult("Snippet1 created."); |
| 117 Snippets.scriptSnippetModel.project().createFile("", null, "
", step3.bind(this)); | 117 Snippets.scriptSnippetModel.project().createFile("", null, "
", step3.bind(this)); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 function step3(uiSourceCode) | 121 async function step3(uiSourceCode) |
| 122 { | 122 { |
| 123 var uiSourceCode2 = uiSourceCode; | 123 var uiSourceCode2 = uiSourceCode; |
| 124 InspectorTest.addResult("Snippet2 created."); | 124 InspectorTest.addResult("Snippet2 created."); |
| 125 renameSnippetAndCheckWorkspace(uiSourceCode1, "foo"); | 125 await renameSnippetAndCheckWorkspace(uiSourceCode1, "foo"); |
| 126 renameSnippetAndCheckWorkspace(uiSourceCode1, " "); | 126 await renameSnippetAndCheckWorkspace(uiSourceCode1, " "); |
| 127 renameSnippetAndCheckWorkspace(uiSourceCode1, " bar "); | 127 await renameSnippetAndCheckWorkspace(uiSourceCode1, " bar "); |
| 128 renameSnippetAndCheckWorkspace(uiSourceCode1, "foo"); | 128 await renameSnippetAndCheckWorkspace(uiSourceCode1, "foo"); |
| 129 renameSnippetAndCheckWorkspace(uiSourceCode2, "bar"); | 129 await renameSnippetAndCheckWorkspace(uiSourceCode2, "bar"); |
| 130 renameSnippetAndCheckWorkspace(uiSourceCode2, "foo"); | 130 await renameSnippetAndCheckWorkspace(uiSourceCode2, "foo"); |
| 131 uiSourceCode1._requestContentPromise = null; | 131 uiSourceCode1._requestContentPromise = null; |
| 132 uiSourceCode1.contentLoaded = false; | 132 uiSourceCode1.contentLoaded = false; |
| 133 uiSourceCode1.requestContent() | 133 uiSourceCode1.requestContent() |
| 134 .then(contentCallback) | 134 .then(contentCallback) |
| 135 .then(onContentDumped); | 135 .then(onContentDumped); |
| 136 | 136 |
| 137 function onContentDumped() | 137 function onContentDumped() |
| 138 { | 138 { |
| 139 Snippets.scriptSnippetModel.project().deleteFile(uiSourceCod
e1); | 139 Snippets.scriptSnippetModel.project().deleteFile(uiSourceCod
e1); |
| 140 Snippets.scriptSnippetModel.project().deleteFile(uiSourceCod
e2); | 140 Snippets.scriptSnippetModel.project().deleteFile(uiSourceCod
e2); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 168 var context = UI.context.flavor(SDK.ExecutionContext); | 168 var context = UI.context.flavor(SDK.ExecutionContext); |
| 169 | 169 |
| 170 resetSnippetsSettings(); | 170 resetSnippetsSettings(); |
| 171 var snippetScriptMapping = Snippets.scriptSnippetModel.snippetScript
Mapping(SDK.targetManager.models(SDK.DebuggerModel)[0]); | 171 var snippetScriptMapping = Snippets.scriptSnippetModel.snippetScript
Mapping(SDK.targetManager.models(SDK.DebuggerModel)[0]); |
| 172 | 172 |
| 173 Snippets.scriptSnippetModel.project().createFile("", null, "", step2
.bind(this)); | 173 Snippets.scriptSnippetModel.project().createFile("", null, "", step2
.bind(this)); |
| 174 | 174 |
| 175 function step2(uiSourceCode) | 175 function step2(uiSourceCode) |
| 176 { | 176 { |
| 177 uiSourceCode1 = uiSourceCode; | 177 uiSourceCode1 = uiSourceCode; |
| 178 uiSourceCode1.rename("Snippet1", function() { }); | 178 uiSourceCode1.rename("Snippet1"); |
| 179 var content = ""; | 179 var content = ""; |
| 180 content += "// This snippet does nothing.\n"; | 180 content += "// This snippet does nothing.\n"; |
| 181 content += "var i = 2+2;\n"; | 181 content += "var i = 2+2;\n"; |
| 182 uiSourceCode1.setWorkingCopy(content); | 182 uiSourceCode1.setWorkingCopy(content); |
| 183 Snippets.scriptSnippetModel.project().createFile("", null, "", s
tep3.bind(this)); | 183 Snippets.scriptSnippetModel.project().createFile("", null, "", s
tep3.bind(this)); |
| 184 } | 184 } |
| 185 | 185 |
| 186 function step3(uiSourceCode) | 186 function step3(uiSourceCode) |
| 187 { | 187 { |
| 188 uiSourceCode2 = uiSourceCode; | 188 uiSourceCode2 = uiSourceCode; |
| 189 uiSourceCode2.rename("Snippet2", function() { }); | 189 uiSourceCode2.rename("Snippet2"); |
| 190 content = ""; | 190 content = ""; |
| 191 content += "// This snippet creates a function that does nothing
and returns it.\n"; | 191 content += "// This snippet creates a function that does nothing
and returns it.\n"; |
| 192 content += "function doesNothing() {\n"; | 192 content += "function doesNothing() {\n"; |
| 193 content += " var i = 2+2;\n"; | 193 content += " var i = 2+2;\n"; |
| 194 content += "};\n"; | 194 content += "};\n"; |
| 195 content += "doesNothing;\n"; | 195 content += "doesNothing;\n"; |
| 196 uiSourceCode2.setWorkingCopy(content); | 196 uiSourceCode2.setWorkingCopy(content); |
| 197 Snippets.scriptSnippetModel.project().createFile("", null, "", s
tep4.bind(this)); | 197 Snippets.scriptSnippetModel.project().createFile("", null, "", s
tep4.bind(this)); |
| 198 } | 198 } |
| 199 | 199 |
| 200 function step4(uiSourceCode) | 200 function step4(uiSourceCode) |
| 201 { | 201 { |
| 202 uiSourceCode3 = uiSourceCode; | 202 uiSourceCode3 = uiSourceCode; |
| 203 uiSourceCode3.rename("Snippet3", function() { }); | 203 uiSourceCode3.rename("Snippet3"); |
| 204 content = ""; | 204 content = ""; |
| 205 content += "// This snippet uses Command Line API.\n"; | 205 content += "// This snippet uses Command Line API.\n"; |
| 206 content += "$$(\"p\").length"; | 206 content += "$$(\"p\").length"; |
| 207 uiSourceCode3.setWorkingCopy(content); | 207 uiSourceCode3.setWorkingCopy(content); |
| 208 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode1, context,
step5); | 208 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode1, context,
step5); |
| 209 } | 209 } |
| 210 | 210 |
| 211 function step5() | 211 function step5() |
| 212 { | 212 { |
| 213 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode2, context,
step6); | 213 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode2, context,
step6); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 241 } | 241 } |
| 242 | 242 |
| 243 resetSnippetsSettings(); | 243 resetSnippetsSettings(); |
| 244 var snippetScriptMapping = Snippets.scriptSnippetModel.snippetScript
Mapping(SDK.targetManager.models(SDK.DebuggerModel)[0]); | 244 var snippetScriptMapping = Snippets.scriptSnippetModel.snippetScript
Mapping(SDK.targetManager.models(SDK.DebuggerModel)[0]); |
| 245 | 245 |
| 246 Snippets.scriptSnippetModel.project().createFile("", null, "", step3
.bind(this)); | 246 Snippets.scriptSnippetModel.project().createFile("", null, "", step3
.bind(this)); |
| 247 | 247 |
| 248 function step3(uiSourceCode) | 248 function step3(uiSourceCode) |
| 249 { | 249 { |
| 250 var uiSourceCode1 = uiSourceCode; | 250 var uiSourceCode1 = uiSourceCode; |
| 251 uiSourceCode1.rename("Snippet1", function() { }); | 251 uiSourceCode1.rename("Snippet1"); |
| 252 var content = ""; | 252 var content = ""; |
| 253 content += "// This snippet does nothing.\n"; | 253 content += "// This snippet does nothing.\n"; |
| 254 content += "var i = 2+2;\n"; | 254 content += "var i = 2+2;\n"; |
| 255 uiSourceCode1.setWorkingCopy(content); | 255 uiSourceCode1.setWorkingCopy(content); |
| 256 | 256 |
| 257 evaluateSnippetAndReloadPage(uiSourceCode1, next); | 257 evaluateSnippetAndReloadPage(uiSourceCode1, next); |
| 258 } | 258 } |
| 259 }, | 259 }, |
| 260 | 260 |
| 261 function testEvaluateInWorker(next) | 261 function testEvaluateInWorker(next) |
| 262 { | 262 { |
| 263 var context; | 263 var context; |
| 264 | 264 |
| 265 InspectorTest.addSniffer(SDK.RuntimeModel.prototype, "_executionCont
extCreated", contextCreated); | 265 InspectorTest.addSniffer(SDK.RuntimeModel.prototype, "_executionCont
extCreated", contextCreated); |
| 266 InspectorTest.evaluateInPage("startWorker()"); | 266 InspectorTest.evaluateInPage("startWorker()"); |
| 267 | 267 |
| 268 function contextCreated() | 268 function contextCreated() |
| 269 { | 269 { |
| 270 // Take the only execution context from the worker's RuntimeMode
l. | 270 // Take the only execution context from the worker's RuntimeMode
l. |
| 271 context = this.executionContexts()[0]; | 271 context = this.executionContexts()[0]; |
| 272 | 272 |
| 273 resetSnippetsSettings(); | 273 resetSnippetsSettings(); |
| 274 Snippets.scriptSnippetModel.project().createFile("", null, "", s
tep2.bind(this)); | 274 Snippets.scriptSnippetModel.project().createFile("", null, "", s
tep2.bind(this)); |
| 275 } | 275 } |
| 276 | 276 |
| 277 function step2(uiSourceCode) | 277 function step2(uiSourceCode) |
| 278 { | 278 { |
| 279 uiSourceCode.rename("Snippet1", function() { }); | 279 uiSourceCode.rename("Snippet1"); |
| 280 var content = "2+2;\n"; | 280 var content = "2+2;\n"; |
| 281 uiSourceCode.setWorkingCopy(content); | 281 uiSourceCode.setWorkingCopy(content); |
| 282 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode, context, n
ext); | 282 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode, context, n
ext); |
| 283 } | 283 } |
| 284 }, | 284 }, |
| 285 | 285 |
| 286 function testDangerousNames(next) | 286 function testDangerousNames(next) |
| 287 { | 287 { |
| 288 resetSnippetsSettings(); | 288 resetSnippetsSettings(); |
| 289 | 289 |
| 290 Snippets.scriptSnippetModel.project().createFile("", null, "", step2
.bind(this)); | 290 Snippets.scriptSnippetModel.project().createFile("", null, "", step2
.bind(this)); |
| 291 | 291 |
| 292 function step2(uiSourceCode) | 292 function step2(uiSourceCode) |
| 293 { | 293 { |
| 294 uiSourceCode.rename("toString", function() { }); | 294 uiSourceCode.rename("toString"); |
| 295 InspectorTest.showUISourceCode(uiSourceCode,step3.bind(this)); | 295 InspectorTest.showUISourceCode(uiSourceCode,step3.bind(this)); |
| 296 } | 296 } |
| 297 | 297 |
| 298 function step3() | 298 function step3() |
| 299 { | 299 { |
| 300 Snippets.scriptSnippetModel.project().createFile("", null, "", s
tep4.bind(this)); | 300 Snippets.scriptSnippetModel.project().createFile("", null, "", s
tep4.bind(this)); |
| 301 } | 301 } |
| 302 | 302 |
| 303 function step4(uiSourceCode) | 303 function step4(uiSourceCode) |
| 304 { | 304 { |
| 305 uiSourceCode.rename("myfile.toString", function() { }); | 305 uiSourceCode.rename("myfile.toString"); |
| 306 InspectorTest.showUISourceCode(uiSourceCode,next); | 306 InspectorTest.showUISourceCode(uiSourceCode,next); |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 ]); | 309 ]); |
| 310 }; | 310 }; |
| 311 </script> | 311 </script> |
| 312 </head> | 312 </head> |
| 313 <body onload="runTest()"> | 313 <body onload="runTest()"> |
| 314 <p>Tests script snippet model.</p> | 314 <p>Tests script snippet model.</p> |
| 315 </body> | 315 </body> |
| 316 </html> | 316 </html> |
| OLD | NEW |