| 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 test() | 6 function test() |
| 7 { | 7 { |
| 8 function resetSnippetsSettings() | 8 function resetSnippetsSettings() |
| 9 { | 9 { |
| 10 WebInspector.scriptSnippetModel._snippetStorage.reset(); | 10 WebInspector.scriptSnippetModel._snippetStorage._lastSnippetIdentifierSe
tting.set(0); |
| 11 WebInspector.scriptSnippetModel._snippetStorage._snippetsSetting.set([])
; |
| 11 WebInspector.scriptSnippetModel._lastSnippetEvaluationIndexSetting.set(0
); | 12 WebInspector.scriptSnippetModel._lastSnippetEvaluationIndexSetting.set(0
); |
| 12 WebInspector.scriptSnippetModel.reset(); | 13 WebInspector.scriptSnippetModel = new WebInspector.ScriptSnippetModel(We
bInspector.workspace); |
| 13 } | 14 } |
| 14 | 15 |
| 15 var workspace = WebInspector.workspace; | 16 var workspace = WebInspector.workspace; |
| 16 var snippetsProject = WebInspector.scriptSnippetModel.project(); | |
| 17 var snippetScriptMapping = WebInspector.scriptSnippetModel.snippetScriptMapp
ing(WebInspector.targetManager.targets()[0]); | |
| 18 InspectorTest.runDebuggerTestSuite([ | 17 InspectorTest.runDebuggerTestSuite([ |
| 19 function testCreateEditRenameRemove(next) | 18 function testCreateEditRenameRemove(next) |
| 20 { | 19 { |
| 21 var uiSourceCode1; | 20 var uiSourceCode1; |
| 22 | 21 |
| 23 function filterSnippet(uiSourceCode) | 22 function filterSnippet(uiSourceCode) |
| 24 { | 23 { |
| 25 return uiSourceCode.project().type() === WebInspector.projectTyp
es.Snippets; | 24 return uiSourceCode.project().type() === WebInspector.projectTyp
es.Snippets; |
| 26 } | 25 } |
| 27 | 26 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 58 InspectorTest.addResult("Number of snippets in the storage: " +
storageSnippetsCount); | 57 InspectorTest.addResult("Number of snippets in the storage: " +
storageSnippetsCount); |
| 59 } | 58 } |
| 60 | 59 |
| 61 function contentCallback(content) | 60 function contentCallback(content) |
| 62 { | 61 { |
| 63 InspectorTest.addResult("Snippet content: " + content); | 62 InspectorTest.addResult("Snippet content: " + content); |
| 64 } | 63 } |
| 65 | 64 |
| 66 resetSnippetsSettings(); | 65 resetSnippetsSettings(); |
| 67 | 66 |
| 68 snippetsProject.createFile("", null, "", step2.bind(this)); | 67 WebInspector.scriptSnippetModel.project().createFile("", null, "", s
tep2.bind(this)); |
| 69 | 68 |
| 70 function step2(path) | 69 function step2(path) |
| 71 { | 70 { |
| 72 uiSourceCode1 = snippetsProject.uiSourceCode(path); | 71 uiSourceCode1 = WebInspector.scriptSnippetModel.project().uiSour
ceCode(path); |
| 73 | 72 |
| 74 uiSourceCode1.requestContent(contentCallback); | 73 uiSourceCode1.requestContent(contentCallback); |
| 75 uiSourceCode1.addRevision("<snippet content>"); | 74 uiSourceCode1.addRevision("<snippet content>"); |
| 76 InspectorTest.addResult("Snippet content set."); | 75 InspectorTest.addResult("Snippet content set."); |
| 77 delete uiSourceCode1._content; | 76 delete uiSourceCode1._content; |
| 78 delete uiSourceCode1._contentLoaded; | 77 delete uiSourceCode1._contentLoaded; |
| 79 uiSourceCode1.requestContent(contentCallback); | 78 uiSourceCode1.requestContent(contentCallback); |
| 80 InspectorTest.addResult("Snippet1 created."); | 79 InspectorTest.addResult("Snippet1 created."); |
| 81 | 80 |
| 82 snippetsProject.createFile("", null, "", step3.bind(this)); | 81 WebInspector.scriptSnippetModel.project().createFile("", null, "
", step3.bind(this)); |
| 83 } | 82 } |
| 84 | 83 |
| 85 function step3(path) | 84 function step3(path) |
| 86 { | 85 { |
| 87 var uiSourceCode2 = snippetsProject.uiSourceCode(path); | 86 var uiSourceCode2 = WebInspector.scriptSnippetModel.project().ui
SourceCode(path); |
| 88 InspectorTest.addResult("Snippet2 created."); | 87 InspectorTest.addResult("Snippet2 created."); |
| 89 renameSnippetAndCheckWorkspace(uiSourceCode1, "foo"); | 88 renameSnippetAndCheckWorkspace(uiSourceCode1, "foo"); |
| 90 renameSnippetAndCheckWorkspace(uiSourceCode1, " "); | 89 renameSnippetAndCheckWorkspace(uiSourceCode1, " "); |
| 91 renameSnippetAndCheckWorkspace(uiSourceCode1, " bar "); | 90 renameSnippetAndCheckWorkspace(uiSourceCode1, " bar "); |
| 92 renameSnippetAndCheckWorkspace(uiSourceCode1, "foo"); | 91 renameSnippetAndCheckWorkspace(uiSourceCode1, "foo"); |
| 93 renameSnippetAndCheckWorkspace(uiSourceCode2, "bar"); | 92 renameSnippetAndCheckWorkspace(uiSourceCode2, "bar"); |
| 94 renameSnippetAndCheckWorkspace(uiSourceCode2, "foo"); | 93 renameSnippetAndCheckWorkspace(uiSourceCode2, "foo"); |
| 95 delete uiSourceCode1._content; | 94 delete uiSourceCode1._content; |
| 96 delete uiSourceCode1._contentLoaded; | 95 delete uiSourceCode1._contentLoaded; |
| 97 uiSourceCode1.requestContent(contentCallback); | 96 uiSourceCode1.requestContent(contentCallback); |
| 98 | 97 |
| 99 snippetsProject.deleteFile(uiSourceCode1.path()); | 98 WebInspector.scriptSnippetModel.project().deleteFile(uiSourceCod
e1.path()); |
| 100 snippetsProject.deleteFile(uiSourceCode2.path()); | 99 WebInspector.scriptSnippetModel.project().deleteFile(uiSourceCod
e2.path()); |
| 101 | 100 |
| 102 snippetsProject.createFile("", null, "", step4.bind(this)); | 101 WebInspector.scriptSnippetModel.project().createFile("", null, "
", step4.bind(this)); |
| 103 } | 102 } |
| 104 | 103 |
| 105 function step4(path) | 104 function step4(path) |
| 106 { | 105 { |
| 107 var uiSourceCode3 = snippetsProject.uiSourceCode(path); | 106 var uiSourceCode3 = WebInspector.scriptSnippetModel.project().ui
SourceCode(path); |
| 108 InspectorTest.addResult("Snippet3 created."); | 107 InspectorTest.addResult("Snippet3 created."); |
| 109 snippetsProject.deleteFile(uiSourceCode3.path()); | 108 WebInspector.scriptSnippetModel.project().deleteFile(uiSourceCod
e3.path()); |
| 110 InspectorTest.addResult("Snippet3 deleted."); | 109 InspectorTest.addResult("Snippet3 deleted."); |
| 111 | 110 |
| 112 InspectorTest.addResult("Number of uiSourceCodes in workspace: "
+ workspace.uiSourceCodes().filter(filterSnippet).length); | 111 InspectorTest.addResult("Number of uiSourceCodes in workspace: "
+ workspace.uiSourceCodes().filter(filterSnippet).length); |
| 113 var storageSnippetsCount = WebInspector.scriptSnippetModel._snip
petStorage.snippets().length; | 112 var storageSnippetsCount = WebInspector.scriptSnippetModel._snip
petStorage.snippets().length; |
| 114 InspectorTest.addResult("Number of snippets in the storage: " +
storageSnippetsCount); | 113 InspectorTest.addResult("Number of snippets in the storage: " +
storageSnippetsCount); |
| 115 | 114 |
| 116 workspace.removeEventListener(WebInspector.Workspace.Events.UISo
urceCodeAdded, uiSourceCodeAdded); | 115 workspace.removeEventListener(WebInspector.Workspace.Events.UISo
urceCodeAdded, uiSourceCodeAdded); |
| 117 workspace.removeEventListener(WebInspector.Workspace.Events.UISo
urceCodeRemoved, uiSourceCodeRemoved); | 116 workspace.removeEventListener(WebInspector.Workspace.Events.UISo
urceCodeRemoved, uiSourceCodeRemoved); |
| 118 | 117 |
| 119 next(); | 118 next(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 141 } | 140 } |
| 142 | 141 |
| 143 function dumpResult(target, result, wasThrown) | 142 function dumpResult(target, result, wasThrown) |
| 144 { | 143 { |
| 145 InspectorTest.addResult("Snippet execution result: " + resul
t.description); | 144 InspectorTest.addResult("Snippet execution result: " + resul
t.description); |
| 146 callback(); | 145 callback(); |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 | 148 |
| 150 resetSnippetsSettings(); | 149 resetSnippetsSettings(); |
| 150 var snippetScriptMapping = WebInspector.scriptSnippetModel.snippetSc
riptMapping(WebInspector.targetManager.targets()[0]); |
| 151 | 151 |
| 152 snippetsProject.createFile("", null, "", step2.bind(this)); | 152 WebInspector.scriptSnippetModel.project().createFile("", null, "", s
tep2.bind(this)); |
| 153 | 153 |
| 154 function step2(path) | 154 function step2(path) |
| 155 { | 155 { |
| 156 uiSourceCode1 = snippetsProject.uiSourceCode(path); | 156 uiSourceCode1 = WebInspector.scriptSnippetModel.project().uiSour
ceCode(path); |
| 157 uiSourceCode1.rename("Snippet1", function() { }); | 157 uiSourceCode1.rename("Snippet1", function() { }); |
| 158 var content = ""; | 158 var content = ""; |
| 159 content += "// This snippet does nothing.\n"; | 159 content += "// This snippet does nothing.\n"; |
| 160 content += "var i = 2+2;\n"; | 160 content += "var i = 2+2;\n"; |
| 161 uiSourceCode1.setWorkingCopy(content); | 161 uiSourceCode1.setWorkingCopy(content); |
| 162 snippetsProject.createFile("", null, "", step3.bind(this)); | 162 WebInspector.scriptSnippetModel.project().createFile("", null, "
", step3.bind(this)); |
| 163 } | 163 } |
| 164 | 164 |
| 165 function step3(path) | 165 function step3(path) |
| 166 { | 166 { |
| 167 uiSourceCode2 = snippetsProject.uiSourceCode(path); | 167 uiSourceCode2 = WebInspector.scriptSnippetModel.project().uiSour
ceCode(path); |
| 168 uiSourceCode2.rename("Snippet2", function() { }); | 168 uiSourceCode2.rename("Snippet2", function() { }); |
| 169 content = ""; | 169 content = ""; |
| 170 content += "// This snippet creates a function that does nothing
and returns it.\n"; | 170 content += "// This snippet creates a function that does nothing
and returns it.\n"; |
| 171 content += "function doesNothing() {\n"; | 171 content += "function doesNothing() {\n"; |
| 172 content += " var i = 2+2;\n"; | 172 content += " var i = 2+2;\n"; |
| 173 content += "};\n"; | 173 content += "};\n"; |
| 174 content += "doesNothing;\n"; | 174 content += "doesNothing;\n"; |
| 175 uiSourceCode2.setWorkingCopy(content); | 175 uiSourceCode2.setWorkingCopy(content); |
| 176 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode1, step4); | 176 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode1, step4); |
| 177 } | 177 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 199 function snippetFinished(result, wasThrown) | 199 function snippetFinished(result, wasThrown) |
| 200 { | 200 { |
| 201 var script = snippetScriptMapping._scriptForUISourceCode.get
(uiSourceCode); | 201 var script = snippetScriptMapping._scriptForUISourceCode.get
(uiSourceCode); |
| 202 InspectorTest.addResult("Snippet execution result: " + resul
t.description); | 202 InspectorTest.addResult("Snippet execution result: " + resul
t.description); |
| 203 | 203 |
| 204 InspectorTest.reloadPage(callback) | 204 InspectorTest.reloadPage(callback) |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 resetSnippetsSettings(); | 208 resetSnippetsSettings(); |
| 209 var snippetScriptMapping = WebInspector.scriptSnippetModel.snippetSc
riptMapping(WebInspector.targetManager.targets()[0]); |
| 209 | 210 |
| 210 snippetsProject.createFile("", null, "", step3.bind(this)); | 211 WebInspector.scriptSnippetModel.project().createFile("", null, "", s
tep3.bind(this)); |
| 211 | 212 |
| 212 function step3(path) | 213 function step3(path) |
| 213 { | 214 { |
| 214 var uiSourceCode1 = snippetsProject.uiSourceCode(path); | 215 var uiSourceCode1 = WebInspector.scriptSnippetModel.project().ui
SourceCode(path); |
| 215 uiSourceCode1.rename("Snippet1", function() { }); | 216 uiSourceCode1.rename("Snippet1", function() { }); |
| 216 var content = ""; | 217 var content = ""; |
| 217 content += "// This snippet does nothing.\n"; | 218 content += "// This snippet does nothing.\n"; |
| 218 content += "var i = 2+2;\n"; | 219 content += "var i = 2+2;\n"; |
| 219 uiSourceCode1.setWorkingCopy(content); | 220 uiSourceCode1.setWorkingCopy(content); |
| 220 | 221 |
| 221 evaluateSnippetAndReloadPage(uiSourceCode1, next); | 222 evaluateSnippetAndReloadPage(uiSourceCode1, next); |
| 222 } | 223 } |
| 223 } | 224 } |
| 224 ]); | 225 ]); |
| 225 }; | 226 }; |
| 226 </script> | 227 </script> |
| 227 </head> | 228 </head> |
| 228 <body onload="runTest()"> | 229 <body onload="runTest()"> |
| 229 <p>Tests script snippet model.</p> | 230 <p>Tests script snippet model.</p> |
| 230 </body> | 231 </body> |
| 231 </html> | 232 </html> |
| OLD | NEW |