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.inspectorView.showPanel("sources");
22 var liveEditSupport = WebInspector.debuggerWorkspaceBinding.liveEditSupport(WebInspector.targetManager.targets()[0]);
24 function pathToFileName(path)
26 return path.substring(path.lastIndexOf("/") + 1);
29 function dumpBreakpointStorageAndLocations()
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);
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());
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());
60 function addBreakpointSniffer(lineNumber, disabled)
62 var prefix = this.main ? "" : "Original";
63 InspectorTest.addResult(" " + prefix + "TextEditor.addBreakpoint(lineNumber = " + lineNumber + ", disabled = " + disabled + ")");
66 function removeBreakpointSniffer(lineNumber)
68 var prefix = this.main ? "" : "Original";
69 InspectorTest.addResult(" " + prefix + "TextEditor.removeBreakpoint(lineNumber = " + lineNumber + ")");
72 WebInspector.breakpointManager._storage._breakpoints = {};
74 InspectorTest.runDebuggerTestSuite([
75 function testEditUndo(next)
77 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
79 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
81 function didShowScriptSource(sourceFrame)
83 javaScriptSourceFrame = sourceFrame;
84 uiSourceCode = sourceFrame._uiSourceCode;
85 javaScriptSourceFrame._textEditor.main = true;
87 InspectorTest.addSniffer(javaScriptSourceFrame._textEditor.__proto__, "addBreakpoint", addBreakpointSniffer, true);
88 InspectorTest.addSniffer(javaScriptSourceFrame._textEditor.__proto__, "removeBreakpoint", removeBreakpointSniffer, true);
90 InspectorTest.addResult("Setting breakpoint:");
91 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
92 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
95 function breakpointResolved(callback, breakpointId, locations)
97 var location = locations[0];
98 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
100 dumpBreakpointStorageAndLocations();
101 InspectorTest.addResult("Editing source:");
102 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//");
104 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
105 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
108 function didShowOriginalUISourceCode(sourceFrame)
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.");
114 dumpBreakpointStorageAndLocations();
115 InspectorTest.addResult("Undoing source editing:");
116 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
117 InspectorTest.undoSourceEditing(javaScriptSourceFrame);
120 function breakpointResolvedAgain()
122 dumpBreakpointStorageAndLocations();
123 InspectorTest.addResult("Finally removing breakpoint:");
124 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
126 dumpBreakpointStorageAndLocations();
131 function testEditCommit(next)
133 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
135 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
137 function didShowScriptSource(sourceFrame)
139 javaScriptSourceFrame = sourceFrame;
140 uiSourceCode = sourceFrame._uiSourceCode;
142 InspectorTest.addResult("Setting breakpoint:");
143 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
144 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
147 function breakpointResolved(callback, breakpointId, locations)
149 var location = locations[0];
150 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
152 dumpBreakpointStorageAndLocations();
153 InspectorTest.addResult("Editing source:");
154 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//");
156 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
157 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
160 function didShowOriginalUISourceCode(sourceFrame)
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.");
166 dumpBreakpointStorageAndLocations();
167 InspectorTest.addResult("Committing edited source:");
168 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
169 InspectorTest.commitSource(javaScriptSourceFrame);
172 function breakpointResolvedAgain()
174 dumpBreakpointStorageAndLocations();
175 InspectorTest.addResult("Finally removing breakpoint:");
176 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
178 dumpBreakpointStorageAndLocations();
183 function testEditCommitFailEditCommit(next)
185 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
187 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
189 function didShowScriptSource(sourceFrame)
191 javaScriptSourceFrame = sourceFrame;
192 uiSourceCode = sourceFrame._uiSourceCode;
194 InspectorTest.addResult("Setting breakpoint:");
195 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
196 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
199 function breakpointResolved(callback, breakpointId, locations)
201 var location = locations[0];
202 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
204 dumpBreakpointStorageAndLocations();
205 InspectorTest.addResult("Editing source:");
206 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}");
208 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
209 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
212 function didShowOriginalUISourceCode(sourceFrame)
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.");
218 dumpBreakpointStorageAndLocations();
219 InspectorTest.addResult("Committing edited source:");
220 InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", commitFailed);
221 InspectorTest.commitSource(javaScriptSourceFrame);
224 function commitFailed(error)
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, "//}", "}//");
231 dumpBreakpointStorageAndLocations();
232 InspectorTest.addResult("Committing edited source again:");
233 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
234 InspectorTest.commitSource(javaScriptSourceFrame);
237 function breakpointResolvedAgain()
239 dumpBreakpointStorageAndLocations();
240 InspectorTest.addResult("Finally removing breakpoint:");
241 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
243 dumpBreakpointStorageAndLocations();
248 function testEditCommitFailUndoCommit(next)
250 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
252 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
254 function didShowScriptSource(sourceFrame)
256 javaScriptSourceFrame = sourceFrame;
257 uiSourceCode = sourceFrame._uiSourceCode;
259 InspectorTest.addResult("Setting breakpoint:");
260 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
261 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
264 function breakpointResolved(callback, breakpointId, locations)
266 var location = locations[0];
267 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
269 dumpBreakpointStorageAndLocations();
270 InspectorTest.addResult("Editing source:");
271 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}");
273 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
274 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
277 function didShowOriginalUISourceCode(sourceFrame)
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.");
283 dumpBreakpointStorageAndLocations();
284 InspectorTest.addResult("Committing edited source:");
285 InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", commitFailed);
286 InspectorTest.commitSource(javaScriptSourceFrame);
289 function commitFailed(error)
291 InspectorTest.assertTrue(!!error, "Commit should have failed.");
292 dumpBreakpointStorageAndLocations();
293 InspectorTest.addResult("Undoing source editing:");
294 InspectorTest.undoSourceEditing(javaScriptSourceFrame);
296 dumpBreakpointStorageAndLocations();
297 InspectorTest.addResult("Committing edited source again:");
298 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
299 InspectorTest.commitSource(javaScriptSourceFrame);
302 function breakpointResolvedAgain()
304 dumpBreakpointStorageAndLocations();
305 InspectorTest.addResult("Finally removing breakpoint:");
306 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
308 dumpBreakpointStorageAndLocations();
313 function testEditAnonymousUndo(next)
315 var javaScriptSourceFrame, uiSourceCode, script, liveEditSourceFrame, liveEditUISourceCode;
317 function testFunction()
321 InspectorTest.evaluateInPage(String(testFunction), InspectorTest.runTestFunctionAndWaitUntilPaused.bind(InspectorTest, paused));
324 InspectorTest.resumeExecution(resumed);
329 InspectorTest.addResult("Showing script source:");
330 InspectorTest.showUISourceCode(panel.visibleView._uiSourceCode, didShowScriptSource);
333 function didShowScriptSource(sourceFrame)
335 javaScriptSourceFrame = sourceFrame;
336 uiSourceCode = sourceFrame._uiSourceCode;
338 InspectorTest.addResult("Setting breakpoint:");
339 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
340 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
343 function breakpointResolved(callback, breakpointId, locations)
345 var location = locations[0];
346 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
348 dumpBreakpointStorageAndLocations();
349 liveEditUISourceCode = liveEditSupport.uiSourceCodeForLiveEdit(uiSourceCode);
350 InspectorTest.showUISourceCode(liveEditUISourceCode, didShowLiveEditScriptSource.bind(null, location));
353 function didShowLiveEditScriptSource(location, sourceFrame)
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();
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);
371 function didShowOriginalUISourceCode(sourceFrame)
373 InspectorTest.addResult("Finally removing breakpoint:");
374 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
375 dumpBreakpointStorageAndLocations();
380 function testEditDynamicAnonymousUndo(next)
382 var javaScriptSourceFrame, uiSourceCode, script, liveEditSourceFrame, liveEditUISourceCode;
384 InspectorTest.evaluateInPage("loadDynamicAnonymousScript()", InspectorTest.runTestFunctionAndWaitUntilPaused.bind(InspectorTest, paused));
387 InspectorTest.resumeExecution(resumed);
392 InspectorTest.addResult("Showing script source:");
393 InspectorTest.showUISourceCode(panel.visibleView._uiSourceCode, didShowScriptSource);
396 function didShowScriptSource(sourceFrame)
398 javaScriptSourceFrame = sourceFrame;
399 uiSourceCode = sourceFrame._uiSourceCode;
401 InspectorTest.addResult("Setting breakpoint:");
402 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
403 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
406 function breakpointResolved(callback, breakpointId, locations)
408 var location = locations[0];
409 script = WebInspector.debuggerModel.scriptForId(location.scriptId);
411 dumpBreakpointStorageAndLocations();
412 liveEditUISourceCode = liveEditSupport.uiSourceCodeForLiveEdit(uiSourceCode);
413 InspectorTest.showUISourceCode(liveEditUISourceCode, didShowLiveEditScriptSource.bind(null, location));
416 function didShowLiveEditScriptSource(location, sourceFrame)
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();
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);
434 function didShowOriginalUISourceCode(sourceFrame)
436 InspectorTest.addResult("Finally removing breakpoint:");
437 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
438 dumpBreakpointStorageAndLocations();
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>