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>
8 function loadDynamicAnonymousScript()
10 function testFunction()
14 var scriptElement = document.createElement("script");
15 scriptElement.textContent = String(testFunction);
16 docuemnt.head.appendChild(scriptElement);
21 var panel = WebInspector.showPanel("sources");
23 function pathToFileName(path)
25 return path.substring(path.lastIndexOf("/") + 1);
28 function dumpBreakpointStorageAndLocations()
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);
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());
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());
59 function addBreakpointSniffer(lineNumber, disabled)
61 var prefix = this.main ? "" : "Original";
62 InspectorTest.addResult(" " + prefix + "TextEditor.addBreakpoint(lineNumber = " + lineNumber + ", disabled = " + disabled + ")");
65 function removeBreakpointSniffer(lineNumber)
67 var prefix = this.main ? "" : "Original";
68 InspectorTest.addResult(" " + prefix + "TextEditor.removeBreakpoint(lineNumber = " + lineNumber + ")");
71 WebInspector.breakpointManager._storage._breakpoints = {};
73 InspectorTest.runDebuggerTestSuite([
74 function testEditUndo(next)
76 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
78 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
80 function didShowScriptSource(sourceFrame)
82 javaScriptSourceFrame = sourceFrame;
83 uiSourceCode = sourceFrame._uiSourceCode;
84 javaScriptSourceFrame._textEditor.main = true;
86 InspectorTest.addSniffer(javaScriptSourceFrame._textEditor.__proto__, "addBreakpoint", addBreakpointSniffer, true);
87 InspectorTest.addSniffer(javaScriptSourceFrame._textEditor.__proto__, "removeBreakpoint", removeBreakpointSniffer, true);
89 InspectorTest.addResult("Setting breakpoint:");
90 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved);
91 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
94 function breakpointResolved(location)
96 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
98 dumpBreakpointStorageAndLocations();
99 InspectorTest.addResult("Editing source:");
100 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//");
102 originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode;
103 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
106 function didShowOriginalUISourceCode(sourceFrame)
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.");
112 dumpBreakpointStorageAndLocations();
113 InspectorTest.addResult("Undoing source editing:");
114 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolvedAgain);
115 InspectorTest.undoSourceEditing(javaScriptSourceFrame);
118 function breakpointResolvedAgain()
120 dumpBreakpointStorageAndLocations();
121 InspectorTest.addResult("Finally removing breakpoint:");
122 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
124 dumpBreakpointStorageAndLocations();
129 function testEditCommit(next)
131 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
133 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
135 function didShowScriptSource(sourceFrame)
137 javaScriptSourceFrame = sourceFrame;
138 uiSourceCode = sourceFrame._uiSourceCode;
140 InspectorTest.addResult("Setting breakpoint:");
141 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved);
142 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
145 function breakpointResolved(location)
147 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
149 dumpBreakpointStorageAndLocations();
150 InspectorTest.addResult("Editing source:");
151 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//");
153 originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode;
154 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
157 function didShowOriginalUISourceCode(sourceFrame)
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.");
163 dumpBreakpointStorageAndLocations();
164 InspectorTest.addResult("Committing edited source:");
165 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolvedAgain);
166 InspectorTest.commitSource(javaScriptSourceFrame);
169 function breakpointResolvedAgain()
171 dumpBreakpointStorageAndLocations();
172 InspectorTest.addResult("Finally removing breakpoint:");
173 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
175 dumpBreakpointStorageAndLocations();
180 function testEditCommitFailEditCommit(next)
182 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
184 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
186 function didShowScriptSource(sourceFrame)
188 javaScriptSourceFrame = sourceFrame;
189 uiSourceCode = sourceFrame._uiSourceCode;
191 InspectorTest.addResult("Setting breakpoint:");
192 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved);
193 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
196 function breakpointResolved(location)
198 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
200 dumpBreakpointStorageAndLocations();
201 InspectorTest.addResult("Editing source:");
202 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}");
204 originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode;
205 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
208 function didShowOriginalUISourceCode(sourceFrame)
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.");
214 dumpBreakpointStorageAndLocations();
215 InspectorTest.addResult("Committing edited source:");
216 InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", commitFailed);
217 InspectorTest.commitSource(javaScriptSourceFrame);
220 function commitFailed(error)
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, "//}", "}//");
227 dumpBreakpointStorageAndLocations();
228 InspectorTest.addResult("Committing edited source again:");
229 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolvedAgain);
230 InspectorTest.commitSource(javaScriptSourceFrame);
233 function breakpointResolvedAgain()
235 dumpBreakpointStorageAndLocations();
236 InspectorTest.addResult("Finally removing breakpoint:");
237 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
239 dumpBreakpointStorageAndLocations();
244 function testEditCommitFailUndoCommit(next)
246 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
248 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
250 function didShowScriptSource(sourceFrame)
252 javaScriptSourceFrame = sourceFrame;
253 uiSourceCode = sourceFrame._uiSourceCode;
255 InspectorTest.addResult("Setting breakpoint:");
256 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved);
257 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
260 function breakpointResolved(location)
262 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
264 dumpBreakpointStorageAndLocations();
265 InspectorTest.addResult("Editing source:");
266 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}");
268 originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode;
269 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
272 function didShowOriginalUISourceCode(sourceFrame)
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.");
278 dumpBreakpointStorageAndLocations();
279 InspectorTest.addResult("Committing edited source:");
280 InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", commitFailed);
281 InspectorTest.commitSource(javaScriptSourceFrame);
284 function commitFailed(error)
286 InspectorTest.assertTrue(!!error, "Commit should have failed.");
287 dumpBreakpointStorageAndLocations();
288 InspectorTest.addResult("Undoing source editing:");
289 InspectorTest.undoSourceEditing(javaScriptSourceFrame);
291 dumpBreakpointStorageAndLocations();
292 InspectorTest.addResult("Committing edited source again:");
293 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolvedAgain);
294 InspectorTest.commitSource(javaScriptSourceFrame);
297 function breakpointResolvedAgain()
299 dumpBreakpointStorageAndLocations();
300 InspectorTest.addResult("Finally removing breakpoint:");
301 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
303 dumpBreakpointStorageAndLocations();
308 function testEditAnonymousUndo(next)
310 var javaScriptSourceFrame, uiSourceCode, script, liveEditSourceFrame, liveEditUISourceCode;
312 function testFunction()
316 InspectorTest.evaluateInPage(String(testFunction), InspectorTest.runTestFunctionAndWaitUntilPaused.bind(InspectorTest, paused));
319 InspectorTest.resumeExecution(resumed);
324 InspectorTest.addResult("Showing script source:");
325 InspectorTest.showUISourceCode(panel.visibleView._uiSourceCode, didShowScriptSource);
328 function didShowScriptSource(sourceFrame)
330 javaScriptSourceFrame = sourceFrame;
331 uiSourceCode = sourceFrame._uiSourceCode;
333 InspectorTest.addResult("Setting breakpoint:");
334 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved);
335 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
338 function breakpointResolved(location)
340 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
342 dumpBreakpointStorageAndLocations();
343 liveEditUISourceCode = WebInspector.liveEditSupport.uiSourceCodeForLiveEdit(uiSourceCode);
344 InspectorTest.showUISourceCode(liveEditUISourceCode, didShowLiveEditScriptSource);
347 function didShowLiveEditScriptSource(sourceFrame)
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();
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);
365 function didShowOriginalUISourceCode(sourceFrame)
367 InspectorTest.addResult("Finally removing breakpoint:");
368 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
369 dumpBreakpointStorageAndLocations();
374 function testEditDynamicAnonymousUndo(next)
376 var javaScriptSourceFrame, uiSourceCode, script, liveEditSourceFrame, liveEditUISourceCode;
378 InspectorTest.evaluateInPage("loadDynamicAnonymousScript()", InspectorTest.runTestFunctionAndWaitUntilPaused.bind(InspectorTest, paused));
381 InspectorTest.resumeExecution(resumed);
386 InspectorTest.addResult("Showing script source:");
387 InspectorTest.showUISourceCode(panel.visibleView._uiSourceCode, didShowScriptSource);
390 function didShowScriptSource(sourceFrame)
392 javaScriptSourceFrame = sourceFrame;
393 uiSourceCode = sourceFrame._uiSourceCode;
395 InspectorTest.addResult("Setting breakpoint:");
396 InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved);
397 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
400 function breakpointResolved(location)
402 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
404 dumpBreakpointStorageAndLocations();
405 liveEditUISourceCode = WebInspector.liveEditSupport.uiSourceCodeForLiveEdit(uiSourceCode);
406 InspectorTest.showUISourceCode(liveEditUISourceCode, didShowLiveEditScriptSource);
409 function didShowLiveEditScriptSource(sourceFrame)
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();
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);
427 function didShowOriginalUISourceCode(sourceFrame)
429 InspectorTest.addResult("Finally removing breakpoint:");
430 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
431 dumpBreakpointStorageAndLocations();
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>