| <html> |
| <head> |
| <script src="../../http/tests/inspector/inspector-test.js"></script> |
| <script src="../../http/tests/inspector/debugger-test.js"></script> |
| <script src="../../http/tests/inspector/live-edit-test.js"></script> |
| <script src="resources/edit-me-breakpoints.js"></script> |
| <script> |
| function loadDynamicAnonymousScript() |
| { |
| function testFunction() |
| { |
| debugger; |
| } |
| var scriptElement = document.createElement("script"); |
| scriptElement.textContent = String(testFunction); |
| docuemnt.head.appendChild(scriptElement); |
| } |
| |
| function test() |
| { |
| var panel = WebInspector.showPanel("scripts"); |
| |
| function pathToFileName(path) |
| { |
| return path.substring(path.lastIndexOf("/") + 1); |
| } |
| |
| function dumpBreakpointStorageAndLocations() |
| { |
| var breakpointManager = WebInspector.breakpointManager; |
| var breakpoints = breakpointManager._storage._setting.get(); |
| InspectorTest.addResult(" Dumping breakpoint storage"); |
| for (var i = 0; i < breakpoints.length; ++i) |
| InspectorTest.addResult(" " + pathToFileName(breakpoints[i].sourceFileId) + ":" + breakpoints[i].lineNumber + ", enabled:" + breakpoints[i].enabled); |
| |
| var breakpointManager = WebInspector.breakpointManager; |
| locations = breakpointManager.allBreakpointLocations(); |
| InspectorTest.addResult(" Dumping breakpoint locations"); |
| for (var i = 0; i < locations.length; ++i) { |
| var uiLocation = locations[i].uiLocation; |
| var uiSourceCode = uiLocation.uiSourceCode; |
| var originURL = uiSourceCode.originURL(); |
| var lineNumber = uiLocation.lineNumber; |
| var project = uiSourceCode.project(); |
| InspectorTest.addResult(" url: " + pathToFileName(originURL) + ", lineNumber: " + lineNumber + ", project type: " + project.type() + ", project id: " + project.id()); |
| } |
| |
| breakpoints = breakpointManager.allBreakpoints(); |
| InspectorTest.addResult(" Dumping breakpoints"); |
| for (var i = 0; i < breakpoints.length; ++i) { |
| var breakpoint = breakpoints[i]; |
| var primaryUILocation = breakpoint.primaryUILocation(); |
| var uiSourceCode = primaryUILocation.uiSourceCode; |
| var originURL = uiSourceCode.originURL(); |
| var lineNumber = primaryUILocation.lineNumber; |
| var project = uiSourceCode.project(); |
| InspectorTest.addResult(" url: " + pathToFileName(originURL) + ", lineNumber: " + lineNumber + ", project type: " + project.type() + ", project id: " + project.id()); |
| } |
| } |
| |
| function addBreakpointSniffer(lineNumber, disabled) |
| { |
| var prefix = this.main ? "" : "Original"; |
| InspectorTest.addResult(" " + prefix + "TextEditor.addBreakpoint(lineNumber = " + lineNumber + ", disabled = " + disabled + ")"); |
| } |
| |
| function removeBreakpointSniffer(lineNumber) |
| { |
| var prefix = this.main ? "" : "Original"; |
| InspectorTest.addResult(" " + prefix + "TextEditor.removeBreakpoint(lineNumber = " + lineNumber + ")"); |
| } |
| |
| WebInspector.breakpointManager._storage._breakpoints = {}; |
| InspectorTest.addSniffer(WebInspector.DefaultTextEditor.prototype, "addBreakpoint", addBreakpointSniffer, true); |
| InspectorTest.addSniffer(WebInspector.DefaultTextEditor.prototype, "removeBreakpoint", removeBreakpointSniffer, true); |
| |
| InspectorTest.runDebuggerTestSuite([ |
| function testEditUndo(next) |
| { |
| var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode; |
| |
| InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource); |
| |
| function didShowScriptSource(sourceFrame) |
| { |
| javaScriptSourceFrame = sourceFrame; |
| uiSourceCode = sourceFrame._uiSourceCode; |
| javaScriptSourceFrame._textEditor.main = true; |
| |
| InspectorTest.addResult("Setting breakpoint:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved); |
| InspectorTest.setBreakpoint(sourceFrame, 2, "", true); |
| } |
| |
| function breakpointResolved(location) |
| { |
| script = WebInspector.debuggerModel.scriptForId(location.scriptId); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Editing source:"); |
| InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//"); |
| |
| originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode; |
| InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode); |
| } |
| |
| function didShowOriginalUISourceCode(sourceFrame) |
| { |
| originalJavaScriptSourceFrame = sourceFrame; |
| InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ."); |
| InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ."); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Undoing source editing:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolvedAgain); |
| InspectorTest.undoSourceEditing(javaScriptSourceFrame); |
| } |
| |
| function breakpointResolvedAgain() |
| { |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Finally removing breakpoint:"); |
| InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2); |
| |
| dumpBreakpointStorageAndLocations(); |
| next(); |
| } |
| }, |
| |
| function testEditCommit(next) |
| { |
| var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode; |
| |
| InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource); |
| |
| function didShowScriptSource(sourceFrame) |
| { |
| javaScriptSourceFrame = sourceFrame; |
| uiSourceCode = sourceFrame._uiSourceCode; |
| |
| InspectorTest.addResult("Setting breakpoint:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved); |
| InspectorTest.setBreakpoint(sourceFrame, 2, "", true); |
| } |
| |
| function breakpointResolved(location) |
| { |
| script = WebInspector.debuggerModel.scriptForId(location.scriptId); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Editing source:"); |
| InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "}//"); |
| |
| originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode; |
| InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode); |
| } |
| |
| function didShowOriginalUISourceCode(sourceFrame) |
| { |
| originalJavaScriptSourceFrame = sourceFrame; |
| InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ."); |
| InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ."); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Committing edited source:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolvedAgain); |
| InspectorTest.commitSource(javaScriptSourceFrame); |
| } |
| |
| function breakpointResolvedAgain() |
| { |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Finally removing breakpoint:"); |
| InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2); |
| |
| dumpBreakpointStorageAndLocations(); |
| next(); |
| } |
| }, |
| |
| function testEditCommitFailEditCommit(next) |
| { |
| var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode; |
| |
| InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource); |
| |
| function didShowScriptSource(sourceFrame) |
| { |
| javaScriptSourceFrame = sourceFrame; |
| uiSourceCode = sourceFrame._uiSourceCode; |
| |
| InspectorTest.addResult("Setting breakpoint:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved); |
| InspectorTest.setBreakpoint(sourceFrame, 2, "", true); |
| } |
| |
| function breakpointResolved(location) |
| { |
| script = WebInspector.debuggerModel.scriptForId(location.scriptId); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Editing source:"); |
| InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}"); |
| |
| originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode; |
| InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode); |
| } |
| |
| function didShowOriginalUISourceCode(sourceFrame) |
| { |
| originalJavaScriptSourceFrame = sourceFrame; |
| InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ."); |
| InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ."); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Committing edited source:"); |
| InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", commitFailed); |
| InspectorTest.commitSource(javaScriptSourceFrame); |
| } |
| |
| function commitFailed(error) |
| { |
| InspectorTest.assertTrue(!!error, "Commit should have failed."); |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Editing source again so that live edit could succeed:"); |
| InspectorTest.replaceInSource(javaScriptSourceFrame, "//}", "}//"); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Committing edited source again:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolvedAgain); |
| InspectorTest.commitSource(javaScriptSourceFrame); |
| } |
| |
| function breakpointResolvedAgain() |
| { |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Finally removing breakpoint:"); |
| InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2); |
| |
| dumpBreakpointStorageAndLocations(); |
| next(); |
| } |
| }, |
| |
| function testEditCommitFailUndoCommit(next) |
| { |
| var javaScriptSourceFrame, uiSourceCode, script, originalJavaScriptSourceFrame, originalUISourceCode; |
| |
| InspectorTest.showScriptSource("edit-me-breakpoints.js", didShowScriptSource); |
| |
| function didShowScriptSource(sourceFrame) |
| { |
| javaScriptSourceFrame = sourceFrame; |
| uiSourceCode = sourceFrame._uiSourceCode; |
| |
| InspectorTest.addResult("Setting breakpoint:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved); |
| InspectorTest.setBreakpoint(sourceFrame, 2, "", true); |
| } |
| |
| function breakpointResolved(location) |
| { |
| script = WebInspector.debuggerModel.scriptForId(location.scriptId); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Editing source:"); |
| InspectorTest.replaceInSource(javaScriptSourceFrame, "}", "//}"); |
| |
| originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode; |
| InspectorTest.showUISourceCode(originalUISourceCode, didShowOriginalUISourceCode); |
| } |
| |
| function didShowOriginalUISourceCode(sourceFrame) |
| { |
| originalJavaScriptSourceFrame = sourceFrame; |
| InspectorTest.assertTrue(originalJavaScriptSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ."); |
| InspectorTest.assertTrue(originalUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ."); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Committing edited source:"); |
| InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", commitFailed); |
| InspectorTest.commitSource(javaScriptSourceFrame); |
| } |
| |
| function commitFailed(error) |
| { |
| InspectorTest.assertTrue(!!error, "Commit should have failed."); |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Undoing source editing:"); |
| InspectorTest.undoSourceEditing(javaScriptSourceFrame); |
| |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Committing edited source again:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolvedAgain); |
| InspectorTest.commitSource(javaScriptSourceFrame); |
| } |
| |
| function breakpointResolvedAgain() |
| { |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.addResult("Finally removing breakpoint:"); |
| InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2); |
| |
| dumpBreakpointStorageAndLocations(); |
| next(); |
| } |
| }, |
| |
| function testEditAnonymousUndo(next) |
| { |
| var javaScriptSourceFrame, uiSourceCode, script, liveEditSourceFrame, liveEditUISourceCode; |
| |
| function testFunction() |
| { |
| debugger; |
| } |
| InspectorTest.evaluateInPage(String(testFunction), InspectorTest.runTestFunctionAndWaitUntilPaused.bind(InspectorTest, paused)); |
| function paused() |
| { |
| InspectorTest.resumeExecution(resumed); |
| } |
| |
| function resumed() |
| { |
| InspectorTest.addResult("Showing script source:"); |
| InspectorTest.showUISourceCode(panel.visibleView._uiSourceCode, didShowScriptSource); |
| } |
| |
| function didShowScriptSource(sourceFrame) |
| { |
| javaScriptSourceFrame = sourceFrame; |
| uiSourceCode = sourceFrame._uiSourceCode; |
| |
| InspectorTest.addResult("Setting breakpoint:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved); |
| InspectorTest.setBreakpoint(sourceFrame, 2, "", true); |
| } |
| |
| function breakpointResolved(location) |
| { |
| script = WebInspector.debuggerModel.scriptForId(location.scriptId); |
| |
| dumpBreakpointStorageAndLocations(); |
| liveEditUISourceCode = WebInspector.liveEditSupport.uiSourceCodeForLiveEdit(uiSourceCode); |
| InspectorTest.showUISourceCode(liveEditUISourceCode, didShowLiveEditScriptSource); |
| } |
| |
| function didShowLiveEditScriptSource(sourceFrame) |
| { |
| liveEditSourceFrame = sourceFrame; |
| InspectorTest.assertTrue(liveEditSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ."); |
| InspectorTest.assertTrue(liveEditUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ."); |
| InspectorTest.addResult("Editing source:"); |
| liveEditSourceFrame._textEditor.main = true; |
| InspectorTest.replaceInSource(liveEditSourceFrame, "}", "}//"); |
| dumpBreakpointStorageAndLocations(); |
| |
| var originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode; |
| InspectorTest.assertTrue(originalUISourceCode === uiSourceCode, "Mapped and original uiSourceCodes should be the same."); |
| InspectorTest.addResult("Undoing source editing:"); |
| InspectorTest.undoSourceEditing(liveEditSourceFrame); |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.showUISourceCode(uiSourceCode, didShowOriginalUISourceCode); |
| } |
| |
| function didShowOriginalUISourceCode(sourceFrame) |
| { |
| InspectorTest.addResult("Finally removing breakpoint:"); |
| InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2); |
| dumpBreakpointStorageAndLocations(); |
| next(); |
| } |
| }, |
| |
| function testEditDynamicAnonymousUndo(next) |
| { |
| var javaScriptSourceFrame, uiSourceCode, script, liveEditSourceFrame, liveEditUISourceCode; |
| |
| InspectorTest.evaluateInPage("loadDynamicAnonymousScript()", InspectorTest.runTestFunctionAndWaitUntilPaused.bind(InspectorTest, paused)); |
| function paused() |
| { |
| InspectorTest.resumeExecution(resumed); |
| } |
| |
| function resumed() |
| { |
| InspectorTest.addResult("Showing script source:"); |
| InspectorTest.showUISourceCode(panel.visibleView._uiSourceCode, didShowScriptSource); |
| } |
| |
| function didShowScriptSource(sourceFrame) |
| { |
| javaScriptSourceFrame = sourceFrame; |
| uiSourceCode = sourceFrame._uiSourceCode; |
| |
| InspectorTest.addResult("Setting breakpoint:"); |
| InspectorTest.addSniffer(WebInspector.BreakpointManager.Breakpoint.prototype, "_addResolvedLocation", breakpointResolved); |
| InspectorTest.setBreakpoint(sourceFrame, 2, "", true); |
| } |
| |
| function breakpointResolved(location) |
| { |
| script = WebInspector.debuggerModel.scriptForId(location.scriptId); |
| |
| dumpBreakpointStorageAndLocations(); |
| liveEditUISourceCode = WebInspector.liveEditSupport.uiSourceCodeForLiveEdit(uiSourceCode); |
| InspectorTest.showUISourceCode(liveEditUISourceCode, didShowLiveEditScriptSource); |
| } |
| |
| function didShowLiveEditScriptSource(sourceFrame) |
| { |
| liveEditSourceFrame = sourceFrame; |
| InspectorTest.assertTrue(liveEditSourceFrame !== javaScriptSourceFrame, "Edited and original javaScriptSourceFrames should differ."); |
| InspectorTest.assertTrue(liveEditUISourceCode !== uiSourceCode, "Edited and original uiSourceCodes should differ."); |
| liveEditSourceFrame._textEditor.main = true; |
| InspectorTest.addResult("Editing source:"); |
| InspectorTest.replaceInSource(liveEditSourceFrame, "}", "}//"); |
| dumpBreakpointStorageAndLocations(); |
| |
| var originalUISourceCode = script.rawLocationToUILocation(location.lineNumber).uiSourceCode; |
| InspectorTest.assertTrue(originalUISourceCode === uiSourceCode, "Mapped and original uiSourceCodes should be the same."); |
| InspectorTest.addResult("Undoing source editing:"); |
| InspectorTest.undoSourceEditing(liveEditSourceFrame); |
| dumpBreakpointStorageAndLocations(); |
| InspectorTest.showUISourceCode(uiSourceCode, didShowOriginalUISourceCode); |
| } |
| |
| function didShowOriginalUISourceCode(sourceFrame) |
| { |
| InspectorTest.addResult("Finally removing breakpoint:"); |
| InspectorTest.removeBreakpoint(javaScriptSourceFrame, 2); |
| dumpBreakpointStorageAndLocations(); |
| next(); |
| } |
| }, |
| ]); |
| }; |
| |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests breakpoints are correctly dimmed and restored in JavaScriptSourceFrame during live edit.</p> |
| <a href="https://bugs.webkit.org/show_bug.cgi?id=99598">Bug 99598</a> |
| </body> |
| </html> |