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