Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: LayoutTests/inspector/sources/debugger/script-snippet-model.html

Issue 1153923005: DevTools: shard inspector/debugger tests for faster execution. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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>
6 function startWorker()
7 {
8 var workerScript = "postMessage('Done.');";
9 var blob = new Blob([workerScript], { type: "text/javascript" });
10 var worker = new Worker(URL.createObjectURL(blob));
11 }
12
13 function test()
14 {
15 function evaluateSnippetAndDumpEvaluationDetails(uiSourceCode, context, call back)
16 {
17 InspectorTest.addSniffer(WebInspector.ScriptSnippetModel.prototype, "_pr intRunScriptResult", dumpResult);
18 WebInspector.scriptSnippetModel.evaluateScriptSnippet(context, uiSourceC ode);
19 var target = context.target();
20 var mapping = WebInspector.scriptSnippetModel._mappingForTarget.get(targ et);
21 var evaluationSourceURL = mapping._evaluationSourceURL(uiSourceCode);
22 var snippetId = WebInspector.scriptSnippetModel._snippetIdForUISourceCod e.get(uiSourceCode);
23 InspectorTest.addResult("Last evaluation source url for snippet: " + eva luationSourceURL);
24 InspectorTest.assertEquals(snippetId, WebInspector.scriptSnippetModel._s nippetIdForSourceURL(evaluationSourceURL), "Snippet can not be identified by its evaluation sourceURL.");
25
26
27 function dumpResult(target, result, wasThrown)
28 {
29 InspectorTest.addResult("Snippet execution result: " + result.descri ption);
30 callback();
31 }
32 }
33
34 function resetSnippetsSettings()
35 {
36 WebInspector.scriptSnippetModel._snippetStorage._lastSnippetIdentifierSe tting.set(0);
37 WebInspector.scriptSnippetModel._snippetStorage._snippetsSetting.set([]) ;
38 WebInspector.scriptSnippetModel._lastSnippetEvaluationIndexSetting.set(0 );
39 WebInspector.scriptSnippetModel = new WebInspector.ScriptSnippetModel(We bInspector.workspace);
40 }
41
42 var workspace = WebInspector.workspace;
43 InspectorTest.runDebuggerTestSuite([
44 function testCreateEditRenameRemove(next)
45 {
46 var uiSourceCode1;
47
48 function filterSnippet(uiSourceCode)
49 {
50 return uiSourceCode.project().type() === WebInspector.projectTyp es.Snippets;
51 }
52
53 function uiSourceCodeAdded(event)
54 {
55 var uiSourceCode = event.data;
56 InspectorTest.addResult("UISourceCodeAdded: " + uiSourceCode.nam e());
57 }
58
59 function uiSourceCodeRemoved(event)
60 {
61 var uiSourceCode = event.data;
62 InspectorTest.addResult("UISourceCodeRemoved: " + uiSourceCode.n ame());
63 }
64
65 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCod eAdded, uiSourceCodeAdded);
66 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCod eRemoved, uiSourceCodeRemoved);
67
68 function renameSnippetAndCheckWorkspace(uiSourceCode, snippetName)
69 {
70 InspectorTest.addResult("Renaming snippet to '" + snippetName + "' ...");
71 uiSourceCode.rename(snippetName, renameCallback);
72
73 function renameCallback(success)
74 {
75 if (success)
76 InspectorTest.addResult("Snippet renamed successfully.") ;
77 else
78 InspectorTest.addResult("Snippet was not renamed.");
79 }
80 InspectorTest.addResult("UISourceCode name is '" + uiSourceCode. name() + "' now.");
81 InspectorTest.addResult("Number of uiSourceCodes in workspace: " + workspace.uiSourceCodes().filter(filterSnippet).length);
82 var storageSnippetsCount = WebInspector.scriptSnippetModel._snip petStorage.snippets().length;
83 InspectorTest.addResult("Number of snippets in the storage: " + storageSnippetsCount);
84 }
85
86 function contentCallback(content)
87 {
88 InspectorTest.addResult("Snippet content: " + content);
89 }
90
91 resetSnippetsSettings();
92
93 WebInspector.scriptSnippetModel.project().createFile("", null, "", s tep2.bind(this));
94
95 function step2(path)
96 {
97 uiSourceCode1 = WebInspector.scriptSnippetModel.project().uiSour ceCode(path);
98
99 uiSourceCode1.requestContent(contentCallback);
100 uiSourceCode1.addRevision("<snippet content>");
101 InspectorTest.addResult("Snippet content set.");
102 delete uiSourceCode1._content;
103 delete uiSourceCode1._contentLoaded;
104 uiSourceCode1.requestContent(contentCallback);
105 InspectorTest.addResult("Snippet1 created.");
106
107 WebInspector.scriptSnippetModel.project().createFile("", null, " ", step3.bind(this));
108 }
109
110 function step3(path)
111 {
112 var uiSourceCode2 = WebInspector.scriptSnippetModel.project().ui SourceCode(path);
113 InspectorTest.addResult("Snippet2 created.");
114 renameSnippetAndCheckWorkspace(uiSourceCode1, "foo");
115 renameSnippetAndCheckWorkspace(uiSourceCode1, " ");
116 renameSnippetAndCheckWorkspace(uiSourceCode1, " bar ");
117 renameSnippetAndCheckWorkspace(uiSourceCode1, "foo");
118 renameSnippetAndCheckWorkspace(uiSourceCode2, "bar");
119 renameSnippetAndCheckWorkspace(uiSourceCode2, "foo");
120 delete uiSourceCode1._content;
121 delete uiSourceCode1._contentLoaded;
122 uiSourceCode1.requestContent(contentCallback);
123
124 WebInspector.scriptSnippetModel.project().deleteFile(uiSourceCod e1.path());
125 WebInspector.scriptSnippetModel.project().deleteFile(uiSourceCod e2.path());
126
127 WebInspector.scriptSnippetModel.project().createFile("", null, " ", step4.bind(this));
128 }
129
130 function step4(path)
131 {
132 var uiSourceCode3 = WebInspector.scriptSnippetModel.project().ui SourceCode(path);
133 InspectorTest.addResult("Snippet3 created.");
134 WebInspector.scriptSnippetModel.project().deleteFile(uiSourceCod e3.path());
135 InspectorTest.addResult("Snippet3 deleted.");
136
137 InspectorTest.addResult("Number of uiSourceCodes in workspace: " + workspace.uiSourceCodes().filter(filterSnippet).length);
138 var storageSnippetsCount = WebInspector.scriptSnippetModel._snip petStorage.snippets().length;
139 InspectorTest.addResult("Number of snippets in the storage: " + storageSnippetsCount);
140
141 workspace.removeEventListener(WebInspector.Workspace.Events.UISo urceCodeAdded, uiSourceCodeAdded);
142 workspace.removeEventListener(WebInspector.Workspace.Events.UISo urceCodeRemoved, uiSourceCodeRemoved);
143
144 next();
145 }
146 },
147
148 function testEvaluate(next)
149 {
150 var uiSourceCode1;
151 var uiSourceCode2;
152 var context = WebInspector.context.flavor(WebInspector.ExecutionCont ext);
153
154 resetSnippetsSettings();
155 var snippetScriptMapping = WebInspector.scriptSnippetModel.snippetSc riptMapping(WebInspector.targetManager.targets()[0]);
156
157 WebInspector.scriptSnippetModel.project().createFile("", null, "", s tep2.bind(this));
158
159 function step2(path)
160 {
161 uiSourceCode1 = WebInspector.scriptSnippetModel.project().uiSour ceCode(path);
162 uiSourceCode1.rename("Snippet1", function() { });
163 var content = "";
164 content += "// This snippet does nothing.\n";
165 content += "var i = 2+2;\n";
166 uiSourceCode1.setWorkingCopy(content);
167 WebInspector.scriptSnippetModel.project().createFile("", null, " ", step3.bind(this));
168 }
169
170 function step3(path)
171 {
172 uiSourceCode2 = WebInspector.scriptSnippetModel.project().uiSour ceCode(path);
173 uiSourceCode2.rename("Snippet2", function() { });
174 content = "";
175 content += "// This snippet creates a function that does nothing and returns it.\n";
176 content += "function doesNothing() {\n";
177 content += " var i = 2+2;\n";
178 content += "};\n";
179 content += "doesNothing;\n";
180 uiSourceCode2.setWorkingCopy(content);
181 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode1, context, step4);
182 }
183
184 function step4()
185 {
186 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode2, context, step5);
187 }
188
189 function step5()
190 {
191 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode1, context, next);
192 }
193 },
194
195 function testEvaluateEditReload(next)
196 {
197 function evaluateSnippetAndReloadPage(uiSourceCode, callback)
198 {
199 InspectorTest.addSniffer(WebInspector.ScriptSnippetModel.prototy pe, "_printRunScriptResult", snippetFinished);
200 WebInspector.scriptSnippetModel.evaluateScriptSnippet(WebInspect or.context.flavor(WebInspector.ExecutionContext), uiSourceCode);
201
202 function snippetFinished(result, wasThrown)
203 {
204 var script = snippetScriptMapping._scriptForUISourceCode.get (uiSourceCode);
205 InspectorTest.addResult("Snippet execution result: " + resul t.description);
206
207 InspectorTest.reloadPage(callback)
208 }
209 }
210
211 resetSnippetsSettings();
212 var snippetScriptMapping = WebInspector.scriptSnippetModel.snippetSc riptMapping(WebInspector.targetManager.targets()[0]);
213
214 WebInspector.scriptSnippetModel.project().createFile("", null, "", s tep3.bind(this));
215
216 function step3(path)
217 {
218 var uiSourceCode1 = WebInspector.scriptSnippetModel.project().ui SourceCode(path);
219 uiSourceCode1.rename("Snippet1", function() { });
220 var content = "";
221 content += "// This snippet does nothing.\n";
222 content += "var i = 2+2;\n";
223 uiSourceCode1.setWorkingCopy(content);
224
225 evaluateSnippetAndReloadPage(uiSourceCode1, next);
226 }
227 },
228
229 function testEvaluateInWorker(next)
230 {
231 var context;
232
233 InspectorTest.addSniffer(WebInspector.RuntimeModel.prototype, "_exec utionContextCreated", contextCreated);
234 InspectorTest.evaluateInPage("startWorker()");
235
236 function contextCreated()
237 {
238 // Take the only execution context from the worker's RuntimeMode l.
239 context = this.executionContexts()[0];
240
241 resetSnippetsSettings();
242 WebInspector.scriptSnippetModel.project().createFile("", null, " ", step2.bind(this));
243 }
244
245 function step2(path)
246 {
247 var uiSourceCode = WebInspector.scriptSnippetModel.project().uiS ourceCode(path);
248 uiSourceCode.rename("Snippet1", function() { });
249 var content = "2+2;\n";
250 uiSourceCode.setWorkingCopy(content);
251 evaluateSnippetAndDumpEvaluationDetails(uiSourceCode, context, n ext);
252 }
253 },
254 ]);
255 };
256 </script>
257 </head>
258 <body onload="runTest()">
259 <p>Tests script snippet model.</p>
260 </body>
261 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698