Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / sources / debugger / live-edit-breakpoints.html
blob7cdebda40f0bc03f352a98b7f84cdc93e72b8087
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()
10 function testFunction()
12 debugger;
14 var scriptElement = document.createElement("script");
15 scriptElement.textContent = String(testFunction);
16 docuemnt.head.appendChild(scriptElement);
19 function test()
21 var panel = WebInspector.panels.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.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
91 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
94 function breakpointResolved(callback, breakpointId, locations)
96 var location = locations[0];
97 script = InspectorTest.debuggerModel.scriptForId(location.scriptId);
99 dumpBreakpointStorageAndLocations();
100 InspectorTest.addResult("Editing source:");
101 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//");
103 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
104 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
107 function didShowOriginalUISourceCode(sourceFrame)
109 originalJavaScriptSourceFrame = sourceFrame;
110 InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
111 InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
113 dumpBreakpointStorageAndLocations();
114 InspectorTest.addResult("Undoing source editing:");
115 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
116 InspectorTest.undoSourceEditing(javaScriptSourceFrame);
119 function breakpointResolvedAgain()
121 dumpBreakpointStorageAndLocations();
122 InspectorTest.addResult("Finally removing breakpoint:");
123 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
125 dumpBreakpointStorageAndLocations();
126 next();
130 function testEditCommit(next)
132 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
134 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
136 function didShowScriptSource(sourceFrame)
138 javaScriptSourceFrame = sourceFrame;
139 uiSourceCode = sourceFrame._uiSourceCode;
141 InspectorTest.addResult("Setting breakpoint:");
142 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
143 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
146 function breakpointResolved(callback, breakpointId, locations)
148 var location = locations[0];
149 script = InspectorTest.debuggerModel.scriptForId(location.scriptId);
151 dumpBreakpointStorageAndLocations();
152 InspectorTest.addResult("Editing source:");
153 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//");
155 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
156 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
159 function didShowOriginalUISourceCode(sourceFrame)
161 originalJavaScriptSourceFrame = sourceFrame;
162 InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
163 InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
165 dumpBreakpointStorageAndLocations();
166 InspectorTest.addResult("Committing edited source:");
167 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
168 InspectorTest.commitSource(javaScriptSourceFrame);
171 function breakpointResolvedAgain()
173 dumpBreakpointStorageAndLocations();
174 InspectorTest.addResult("Finally removing breakpoint:");
175 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
177 dumpBreakpointStorageAndLocations();
178 next();
182 function testEditCommitFailEditCommit(next)
184 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
186 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
188 function didShowScriptSource(sourceFrame)
190 javaScriptSourceFrame = sourceFrame;
191 uiSourceCode = sourceFrame._uiSourceCode;
193 InspectorTest.addResult("Setting breakpoint:");
194 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
195 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
198 function breakpointResolved(callback, breakpointId, locations)
200 var location = locations[0];
201 script = InspectorTest.debuggerModel.scriptForId(location.scriptId);
203 dumpBreakpointStorageAndLocations();
204 InspectorTest.addResult("Editing source:");
205 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}");
207 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
208 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
211 function didShowOriginalUISourceCode(sourceFrame)
213 originalJavaScriptSourceFrame = sourceFrame;
214 InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
215 InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
217 dumpBreakpointStorageAndLocations();
218 InspectorTest.addResult("Committing edited source:");
219 InspectorTest.addSniffer(InspectorTest.debuggerModel, "_didEditScriptSource", commitFailed);
220 InspectorTest.commitSource(javaScriptSourceFrame);
223 function commitFailed(error)
225 InspectorTest.assertTrue(!!error, "Commit should have failed.");
226 dumpBreakpointStorageAndLocations();
227 InspectorTest.addResult("Editing source again so that live edit could succeed:");
228 InspectorTest.replaceInSource(javaScriptSourceFrame, "//}", "}//");
230 dumpBreakpointStorageAndLocations();
231 InspectorTest.addResult("Committing edited source again:");
232 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
233 InspectorTest.commitSource(javaScriptSourceFrame);
236 function breakpointResolvedAgain()
238 dumpBreakpointStorageAndLocations();
239 InspectorTest.addResult("Finally removing breakpoint:");
240 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
242 dumpBreakpointStorageAndLocations();
243 next();
247 function testEditCommitFailUndoCommit(next)
249 var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode;
251 InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource);
253 function didShowScriptSource(sourceFrame)
255 javaScriptSourceFrame = sourceFrame;
256 uiSourceCode = sourceFrame._uiSourceCode;
258 InspectorTest.addResult("Setting breakpoint:");
259 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolved);
260 InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
263 function breakpointResolved(callback, breakpointId, locations)
265 var location = locations[0];
266 script = InspectorTest.debuggerModel.scriptForId(location.scriptId);
268 dumpBreakpointStorageAndLocations();
269 InspectorTest.addResult("Editing source:");
270 InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}");
272 originalUISourceCode = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location).uiSourceCode;
273 InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode);
276 function didShowOriginalUISourceCode(sourceFrame)
278 originalJavaScriptSourceFrame = sourceFrame;
279 InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ.");
280 InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ.");
282 dumpBreakpointStorageAndLocations();
283 InspectorTest.addResult("Committing edited source:");
284 InspectorTest.addSniffer(InspectorTest.debuggerModel, "_didEditScriptSource", commitFailed);
285 InspectorTest.commitSource(javaScriptSourceFrame);
288 function commitFailed(error)
290 InspectorTest.assertTrue(!!error, "Commit should have failed.");
291 dumpBreakpointStorageAndLocations();
292 InspectorTest.addResult("Undoing source editing:");
293 InspectorTest.undoSourceEditing(javaScriptSourceFrame);
295 dumpBreakpointStorageAndLocations();
296 InspectorTest.addResult("Committing edited source again:");
297 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didSetBreakpointInDebugger", breakpointResolvedAgain);
298 InspectorTest.commitSource(javaScriptSourceFrame);
301 function breakpointResolvedAgain()
303 dumpBreakpointStorageAndLocations();
304 InspectorTest.addResult("Finally removing breakpoint:");
305 InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2);
307 dumpBreakpointStorageAndLocations();
308 next();
314 </script>
315 </head>
316 <body onload="runTest()">
317 <p>Tests breakpoints are correctly dimmed and restored in JavaScriptSourceFrame during live edit.</p>
318 <a href="https://bugs.webkit.org/show_bug.cgi?id=99598">Bug 99598</a>
319 </body>
320 </html>