Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / sources / debugger / live-edit-breakpoints.html
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/live-edit-test.js"></script>
6 <script src="resources/edit-me-breakpoints.js"></script>
7 <script>
8 function loadDynamicAnonymousScript()
9 {
10     function testFunction()
11     {
12         debugger;
13     }
14     var scriptElement = document.createElement("script");
15     scriptElement.textContent = String(testFunction);
16     docuemnt.head.appendChild(scriptElement);
17 }
18
19 function test()
20 {
21     var panel = WebInspector.inspectorView.showPanel("sources");
22     var liveEditSupport = WebInspector.debuggerWorkspaceBinding.liveEditSupport(WebInspector.targetManager.targets()[0]);
23
24     function pathToFileName(path)
25     {
26         return path.substring(path.lastIndexOf("/") + 1);
27     }
28
29     function dumpBreakpointStorageAndLocations()
30     {
31         var breakpointManager = WebInspector.breakpointManager;
32         var breakpoints = breakpointManager._storage._setting.get();
33         InspectorTest.addResult("    Dumping breakpoint storage");
34         for (var i = 0; i < breakpoints.length; ++i)
35             InspectorTest.addResult("        " + pathToFileName(breakpoints[i].sourceFileId) + ":" + breakpoints[i].lineNumber + ", enabled:" + breakpoints[i].enabled);
36
37         locations = breakpointManager.allBreakpointLocations();
38         InspectorTest.addResult("    Dumping breakpoint locations");
39         for (var i = 0; i < locations.length; ++i) {
40             var uiLocation = locations[i].uiLocation;
41             var uiSourceCode = uiLocation.uiSourceCode;
42             var originURL = uiSourceCode.originURL();
43             var lineNumber = uiLocation.lineNumber;
44             var project = uiSourceCode.project();
45             InspectorTest.addResult("        url: " + pathToFileName(originURL) + ", lineNumber: " + lineNumber + ", project type: " + project.type() + ", project id: " + project.id());
46         }
47
48         breakpoints = breakpointManager.allBreakpoints();
49         InspectorTest.addResult("    Dumping breakpoints");
50         for (var i = 0; i < breakpoints.length; ++i) {
51             var breakpoint = breakpoints[i];
52             var uiSourceCode = breakpointManager._workspace.uiSourceCode(breakpoint.projectId(), breakpoint.path());
53             var lineNumber = breakpoint.lineNumber();
54             var originURL = uiSourceCode.originURL();
55             var project = uiSourceCode.project();
56             InspectorTest.addResult("        url: " + pathToFileName(originURL) + ", lineNumber: " + lineNumber + ", project type: " + project.type() + ", project id: " + project.id());
57         }
58     }
59
60     function addBreakpointSniffer(lineNumber, disabled)
61     {
62         var prefix = this.main ? "" : "Original";
63         InspectorTest.addResult("    " + prefix + "TextEditor.addBreakpoint(lineNumber = " + lineNumber + ", disabled = " + disabled + ")");
64     }
65
66     function removeBreakpointSniffer(lineNumber)
67     {
68         var prefix = this.main ? "" : "Original";
69         InspectorTest.addResult("    " + prefix + "TextEditor.removeBreakpoint(lineNumber = " + lineNumber + ")");
70     }
71
72     WebInspector.breakpointManager._storage._breakpoints = {};
73
74     InspectorTest.runDebuggerTestSuite([
75         function testEditUndo(next)
76         {
77             var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
78
79             InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
80
81             function didShowScriptSource(sourceFrame)
82             {
83                 javaScriptSourceFrame = sourceFrame;
84                 uiSourceCode = sourceFrame._uiSourceCode;
85                 javaScriptSourceFrame._textEditor.main = true;
86
87                 InspectorTest.addSniffer(javaScriptSourceFrame._textEditor.__proto__, "addBreakpoint", addBreakpointSniffer, true);
88                 InspectorTest.addSniffer(javaScriptSourceFrame._textEditor.__proto__, "removeBreakpoint", removeBreakpointSniffer, true);
89                 
90                 InspectorTest.addResult("Setting breakpoint:");
91                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
92                 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
93             }
94
95             function breakpointResolved(callback, breakpointId, locations)
96             {
97                 var location = locations[0];
98                 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
99
100                 dumpBreakpointStorageAndLocations();
101                 InspectorTest.addResult("Editing source:");
102                 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//");
103
104                 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
105                 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
106             }
107
108             function didShowOriginalUISourceCode(sourceFrame)
109             {
110                 originalJavaScriptSourceFrame = sourceFrame;
111                 InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
112                 InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
113
114                 dumpBreakpointStorageAndLocations();
115                 InspectorTest.addResult("Undoing source editing:");
116                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
117                 InspectorTest.undoSourceEditing(javaScriptSourceFrame);
118             }
119
120             function breakpointResolvedAgain()
121             {
122                 dumpBreakpointStorageAndLocations();
123                 InspectorTest.addResult("Finally removing breakpoint:");
124                 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
125
126                 dumpBreakpointStorageAndLocations();
127                 next();
128             }
129         },
130
131         function testEditCommit(next)
132         {
133             var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
134
135             InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
136
137             function didShowScriptSource(sourceFrame)
138             {
139                 javaScriptSourceFrame = sourceFrame;
140                 uiSourceCode = sourceFrame._uiSourceCode;
141                 
142                 InspectorTest.addResult("Setting breakpoint:");
143                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
144                 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
145             }
146
147             function breakpointResolved(callback, breakpointId, locations)
148             {
149                 var location = locations[0];
150                 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
151
152                 dumpBreakpointStorageAndLocations();
153                 InspectorTest.addResult("Editing source:");
154                 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//");
155
156                 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
157                 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
158             }
159
160             function didShowOriginalUISourceCode(sourceFrame)
161             {
162                 originalJavaScriptSourceFrame = sourceFrame;
163                 InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
164                 InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
165
166                 dumpBreakpointStorageAndLocations();
167                 InspectorTest.addResult("Committing edited source:");
168                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
169                 InspectorTest.commitSource(javaScriptSourceFrame);
170             }
171
172             function breakpointResolvedAgain()
173             {
174                 dumpBreakpointStorageAndLocations();
175                 InspectorTest.addResult("Finally removing breakpoint:");
176                 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
177
178                 dumpBreakpointStorageAndLocations();
179                 next();
180             }
181         },
182
183         function testEditCommitFailEditCommit(next)
184         {
185             var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
186
187             InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
188
189             function didShowScriptSource(sourceFrame)
190             {
191                 javaScriptSourceFrame = sourceFrame;
192                 uiSourceCode = sourceFrame._uiSourceCode;
193                 
194                 InspectorTest.addResult("Setting breakpoint:");
195                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
196                 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
197             }
198
199             function breakpointResolved(callback, breakpointId, locations)
200             {
201                 var location = locations[0];
202                 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
203
204                 dumpBreakpointStorageAndLocations();
205                 InspectorTest.addResult("Editing source:");
206                 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}");
207
208                 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
209                 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
210             }
211
212             function didShowOriginalUISourceCode(sourceFrame)
213             {
214                 originalJavaScriptSourceFrame = sourceFrame;
215                 InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
216                 InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
217
218                 dumpBreakpointStorageAndLocations();
219                 InspectorTest.addResult("Committing edited source:");
220                 InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", commitFailed);
221                 InspectorTest.commitSource(javaScriptSourceFrame);
222             }
223
224             function commitFailed(error)
225             {
226                 InspectorTest.assertTrue(!!error, "Commit should have failed.");
227                 dumpBreakpointStorageAndLocations();
228                 InspectorTest.addResult("Editing source again so that live edit could succeed:");
229                 InspectorTest.replaceInSource(javaScriptSourceFrame, "//}", "}//");
230
231                 dumpBreakpointStorageAndLocations();
232                 InspectorTest.addResult("Committing edited source again:");
233                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
234                 InspectorTest.commitSource(javaScriptSourceFrame);
235             }
236
237             function breakpointResolvedAgain()
238             {
239                 dumpBreakpointStorageAndLocations();
240                 InspectorTest.addResult("Finally removing breakpoint:");
241                 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
242
243                 dumpBreakpointStorageAndLocations();
244                 next();
245             }
246         },
247
248         function testEditCommitFailUndoCommit(next)
249         {
250             var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
251
252             InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
253
254             function didShowScriptSource(sourceFrame)
255             {
256                 javaScriptSourceFrame = sourceFrame;
257                 uiSourceCode = sourceFrame._uiSourceCode;
258                 
259                 InspectorTest.addResult("Setting breakpoint:");
260                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
261                 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
262             }
263
264             function breakpointResolved(callback, breakpointId, locations)
265             {
266                 var location = locations[0];
267                 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
268
269                 dumpBreakpointStorageAndLocations();
270                 InspectorTest.addResult("Editing source:");
271                 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}");
272
273                 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
274                 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
275             }
276
277             function didShowOriginalUISourceCode(sourceFrame)
278             {
279                 originalJavaScriptSourceFrame = sourceFrame;
280                 InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
281                 InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
282
283                 dumpBreakpointStorageAndLocations();
284                 InspectorTest.addResult("Committing edited source:");
285                 InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", commitFailed);
286                 InspectorTest.commitSource(javaScriptSourceFrame);
287             }
288
289             function commitFailed(error)
290             {
291                 InspectorTest.assertTrue(!!error, "Commit should have failed.");
292                 dumpBreakpointStorageAndLocations();
293                 InspectorTest.addResult("Undoing source editing:");
294                 InspectorTest.undoSourceEditing(javaScriptSourceFrame);
295
296                 dumpBreakpointStorageAndLocations();
297                 InspectorTest.addResult("Committing edited source again:");
298                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
299                 InspectorTest.commitSource(javaScriptSourceFrame);
300             }
301
302             function breakpointResolvedAgain()
303             {
304                 dumpBreakpointStorageAndLocations();
305                 InspectorTest.addResult("Finally removing breakpoint:");
306                 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
307
308                 dumpBreakpointStorageAndLocations();
309                 next();
310             }
311         },
312
313         function testEditAnonymousUndo(next)
314         {
315             var javaScriptSourceFrame, uiSourceCode, script, liveEditSourceFrame, liveEditUISourceCode;
316             
317             function testFunction()
318             {
319                 debugger;
320             }
321             InspectorTest.evaluateInPage(String(testFunction), InspectorTest.runTestFunctionAndWaitUntilPaused.bind(InspectorTest, paused));
322             function paused()
323             {
324                 InspectorTest.resumeExecution(resumed);
325             }
326
327             function resumed()
328             {
329                 InspectorTest.addResult("Showing script source:");
330                 InspectorTest.showUISourceCode(panel.visibleView._uiSourceCode, didShowScriptSource);
331             }
332
333             function didShowScriptSource(sourceFrame)
334             {
335                 javaScriptSourceFrame = sourceFrame;
336                 uiSourceCode = sourceFrame._uiSourceCode;
337                 
338                 InspectorTest.addResult("Setting breakpoint:");
339                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
340                 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
341             }
342
343             function breakpointResolved(callback, breakpointId, locations)
344             {
345                 var location = locations[0];
346                 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
347
348                 dumpBreakpointStorageAndLocations();
349                 liveEditUISourceCode = liveEditSupport.uiSourceCodeForLiveEdit(uiSourceCode);
350                 InspectorTest.showUISourceCode(liveEditUISourceCode, didShowLiveEditScriptSource.bind(null, location));
351             }
352
353             function didShowLiveEditScriptSource(location, sourceFrame)
354             {
355                 liveEditSourceFrame = sourceFrame;
356                 InspectorTest.assertTrue(liveEditSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
357                 InspectorTest.assertTrue(liveEditUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
358                 InspectorTest.addResult("Editing source:");
359                 liveEditSourceFrame._textEditor.main = true;
360                 InspectorTest.replaceInSource(liveEditSourceFrame, "}", "}//");
361                 dumpBreakpointStorageAndLocations();
362
363                 var originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
364                 InspectorTest.assertTrue(originalUISourceCode === uiSourceCode, "Mapped and original uiSourceCodes should be the same.");
365                 InspectorTest.addResult("Undoing source editing:");
366                 InspectorTest.undoSourceEditing(liveEditSourceFrame);
367                 dumpBreakpointStorageAndLocations();
368                 InspectorTest.showUISourceCode(uiSourceCode, didShowOriginalUISourceCode);
369             }
370
371             function didShowOriginalUISourceCode(sourceFrame)
372             {
373                 InspectorTest.addResult("Finally removing breakpoint:");
374                 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
375                 dumpBreakpointStorageAndLocations();
376                 next();
377             }
378         },
379
380         function testEditDynamicAnonymousUndo(next)
381         {
382             var javaScriptSourceFrame, uiSourceCode, script, liveEditSourceFrame, liveEditUISourceCode;
383             
384             InspectorTest.evaluateInPage("loadDynamicAnonymousScript()", InspectorTest.runTestFunctionAndWaitUntilPaused.bind(InspectorTest, paused));
385             function paused()
386             {
387                 InspectorTest.resumeExecution(resumed);
388             }
389
390             function resumed()
391             {
392                 InspectorTest.addResult("Showing script source:");
393                 InspectorTest.showUISourceCode(panel.visibleView._uiSourceCode, didShowScriptSource);
394             }
395
396             function didShowScriptSource(sourceFrame)
397             {
398                 javaScriptSourceFrame = sourceFrame;
399                 uiSourceCode = sourceFrame._uiSourceCode;
400                 
401                 InspectorTest.addResult("Setting breakpoint:");
402                 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
403                 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
404             }
405
406             function breakpointResolved(callback, breakpointId, locations)
407             {
408                 var location = locations[0];
409                 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
410
411                 dumpBreakpointStorageAndLocations();
412                 liveEditUISourceCode = liveEditSupport.uiSourceCodeForLiveEdit(uiSourceCode);
413                 InspectorTest.showUISourceCode(liveEditUISourceCode, didShowLiveEditScriptSource.bind(null, location));
414             }
415
416             function didShowLiveEditScriptSource(location, sourceFrame)
417             {
418                 liveEditSourceFrame = sourceFrame;
419                 InspectorTest.assertTrue(liveEditSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
420                 InspectorTest.assertTrue(liveEditUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
421                 liveEditSourceFrame._textEditor.main = true;
422                 InspectorTest.addResult("Editing source:");
423                 InspectorTest.replaceInSource(liveEditSourceFrame, "}", "}//");
424                 dumpBreakpointStorageAndLocations();
425
426                 var originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
427                 InspectorTest.assertTrue(originalUISourceCode === uiSourceCode, "Mapped and original uiSourceCodes should be the same.");
428                 InspectorTest.addResult("Undoing source editing:");
429                 InspectorTest.undoSourceEditing(liveEditSourceFrame);
430                 dumpBreakpointStorageAndLocations();
431                 InspectorTest.showUISourceCode(uiSourceCode, didShowOriginalUISourceCode);
432             }
433
434             function didShowOriginalUISourceCode(sourceFrame)
435             {
436                 InspectorTest.addResult("Finally removing breakpoint:");
437                 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
438                 dumpBreakpointStorageAndLocations();
439                 next();
440             }
441         },
442     ]);
443 };
444
445 </script>
446 </head>
447 <body onload="runTest()">
448 <p>Tests breakpoints are correctly dimmed and restored in JavaScriptSourceFrame during live edit.</p>
449 <a href="https://bugs.webkit.org/show_bug.cgi?id=99598">Bug 99598</a>
450 </body>
451 </html>