| <html> |
| <head> |
| <script src="../../http/tests/inspector/inspector-test.js"></script> |
| |
| <script> |
| |
| function test() |
| { |
| var uiSourceCodes = {}; |
| |
| var defaultMapping = { |
| rawLocationToUILocation: function(rawLocation) |
| { |
| return new WebInspector.UILocation(uiSourceCodes[rawLocation.scriptId], rawLocation.lineNumber, 0); |
| }, |
| |
| uiLocationToRawLocation: function(uiSourceCode, lineNumber) |
| { |
| return new WebInspector.DebuggerModel.Location(uiSourceCode.url, lineNumber, 0); |
| } |
| }; |
| |
| var shiftingMapping = { |
| rawLocationToUILocation: function(rawLocation) |
| { |
| return new WebInspector.UILocation(uiSourceCodes[rawLocation.scriptId], rawLocation.lineNumber + 10, 0); |
| }, |
| |
| uiLocationToRawLocation: function(uiSourceCode, lineNumber) |
| { |
| return new WebInspector.DebuggerModel.Location(uiSourceCode.url, lineNumber - 10, 0); |
| } |
| }; |
| |
| function DebuggerModelMock(sourceMapping) |
| { |
| this._scripts = {}; |
| this._sourceMapping = sourceMapping; |
| this._breakpoints = {}; |
| } |
| |
| DebuggerModelMock.prototype = { |
| _addScript: function(scriptId, url) |
| { |
| this._scripts[scriptId] = new WebInspector.Script(scriptId, url); |
| this._scripts[scriptId].setSourceMapping(this._sourceMapping); |
| }, |
| |
| setBreakpointByScriptLocation: function(location, condition, callback) |
| { |
| var breakpointId = location.scriptId + ":" + location.lineNumber; |
| if (this._breakpoints[breakpointId]) { |
| callback(null); |
| return; |
| } |
| |
| this._breakpoints[breakpointId] = true; |
| InspectorTest.addResult(" debuggerModel.setBreakpoint(" + [location.scriptId, location.lineNumber, condition].join(":") + ")"); |
| if (!callback) |
| return; |
| if (location.lineNumber >= 2000) { |
| callback(breakpointId, []); |
| return; |
| } |
| if (location.lineNumber >= 1000) { |
| var shiftedLocation = {scriptId: location.scriptId, lineNumber: location.lineNumber + 10, columnNumber: location.columnNumber }; |
| callback(breakpointId, [shiftedLocation]); |
| return; |
| } |
| callback(breakpointId, [location]); |
| }, |
| |
| removeBreakpoint: function(breakpointId, callback) |
| { |
| InspectorTest.addResult(" debuggerModel.removeBreakpoint(" + breakpointId + ")"); |
| delete this._breakpoints[breakpointId]; |
| if (callback) |
| callback(); |
| }, |
| |
| setBreakpointsActive: function() { }, |
| |
| createLiveLocation: function(rawLocation, updateDelegate) |
| { |
| return this._scripts[rawLocation.scriptId].createLiveLocation(rawLocation, updateDelegate); |
| }, |
| |
| scriptForId: function(scriptId) |
| { |
| return this._scripts[scriptId]; |
| }, |
| |
| reset: function() |
| { |
| InspectorTest.addResult(" Resetting debugger."); |
| this._scripts = {}; |
| }, |
| |
| setSourceMapping: function(sourceMapping) |
| { |
| for (var scriptId in this._scripts) |
| this._scripts[scriptId].setSourceMapping(sourceMapping); |
| } |
| } |
| DebuggerModelMock.prototype.__proto__ = WebInspector.Object.prototype; |
| |
| function WorkspaceMock() |
| { |
| } |
| |
| var temporaryUISourceCodes = {}; |
| WorkspaceMock.prototype = { |
| _addUISourceCode: function(url) |
| { |
| var uiSourceCode = new WebInspector.JavaScriptSource(url, null, false); |
| uiSourceCode.setSourceMapping(defaultMapping); |
| uiSourceCodes[url] = uiSourceCode; |
| this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCode); |
| return uiSourceCode; |
| }, |
| |
| _addTemporaryUISourceCode: function(url) |
| { |
| var uiSourceCode = new WebInspector.JavaScriptSource(url, null, null, false); |
| uiSourceCode.qq = 345; |
| uiSourceCode.setSourceMapping(defaultMapping); |
| uiSourceCodes[url] = uiSourceCode; |
| temporaryUISourceCodes[url] = uiSourceCode; |
| this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeAdded, uiSourceCode); |
| return uiSourceCode; |
| }, |
| |
| _removeTemporaryUISourceCode: function(url) |
| { |
| this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeRemoved, temporaryUISourceCodes[url]); |
| delete temporaryUISourceCodes[url]; |
| delete uiSourceCodes[url]; |
| }, |
| |
| uiSourceCodes: function() |
| { |
| return Object.values(uiSourceCodes); |
| }, |
| |
| reset: function() |
| { |
| InspectorTest.addResult(" Resetting workspace."); |
| this.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectWillReset); |
| } |
| } |
| WorkspaceMock.prototype.__proto__ = WebInspector.Object.prototype; |
| |
| var dummySetting = { |
| get: function() { return []; }, |
| set: function(breakpoints) { } |
| }; |
| |
| function breakpointAdded(event) |
| { |
| var breakpoint = event.data.breakpoint; |
| var uiLocation = event.data.uiLocation; |
| InspectorTest.addResult(" breakpointAdded(" + [uiLocation.uiSourceCode.url, uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled()].join(", ") + ")"); |
| } |
| |
| function breakpointRemoved(event) |
| { |
| var uiLocation = event.data.uiLocation; |
| InspectorTest.addResult(" breakpointRemoved(" + [uiLocation.uiSourceCode.url, uiLocation.lineNumber].join(", ") + ")"); |
| } |
| |
| InspectorTest.addSniffer(WebInspector.Script.prototype, "createLiveLocation", function(rawLocation) |
| { |
| InspectorTest.addResult(" Location created: " + rawLocation.scriptId + ":" + rawLocation.lineNumber); |
| }, true); |
| InspectorTest.addSniffer(WebInspector.Script.Location.prototype, "dispose", function() |
| { |
| InspectorTest.addResult(" Location disposed: " + this._rawLocation.scriptId + ":" + this._rawLocation.lineNumber); |
| }, true); |
| |
| function addUISourceCode(breakpointManager, url) |
| { |
| breakpointManager._debuggerModel._addScript(url, url); |
| InspectorTest.addResult(" Adding UISourceCode: " + url + ")"); |
| return breakpointManager._workspace._addUISourceCode(url); |
| } |
| |
| function addTemporaryUISourceCode(breakpointManager, url) |
| { |
| breakpointManager._debuggerModel._addScript(url, url); |
| InspectorTest.addResult(" Adding temporary UISourceCode: " + url + ")"); |
| return breakpointManager._workspace._addTemporaryUISourceCode(url); |
| } |
| |
| function removeTemporaryUISourceCode(breakpointManager, url) |
| { |
| InspectorTest.addResult(" Removing temporary UISourceCode: " + url + ")"); |
| breakpointManager._workspace._removeTemporaryUISourceCode(url); |
| } |
| |
| function createBreakpoint(uiSourceCodeId, lineNumber, condition, enabled) |
| { |
| return { sourceFileId: uiSourceCodeId, lineNumber: lineNumber, condition: condition, enabled: enabled }; |
| } |
| |
| var serializedBreakpoints = []; |
| serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true)); |
| serializedBreakpoints.push(createBreakpoint("a.js", 20, "", false)); |
| serializedBreakpoints.push(createBreakpoint("b.js", 3, "", true)); |
| |
| function createBreakpointManager(persistentBreakpoints, sourceMapping) |
| { |
| persistentBreakpoints = persistentBreakpoints || []; |
| var setting = { |
| get: function() { return persistentBreakpoints; }, |
| set: function(breakpoints) { persistentBreakpoints = breakpoints; } |
| }; |
| |
| var sourceMapping = sourceMapping || defaultMapping; |
| var debuggerModel = new DebuggerModelMock(sourceMapping); |
| var workspaceMock = new WorkspaceMock(); |
| var breakpointManager = new WebInspector.BreakpointManager(setting, debuggerModel, workspaceMock); |
| breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointAdded, breakpointAdded); |
| breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointRemoved, breakpointRemoved); |
| InspectorTest.addResult(" Created breakpoints manager"); |
| dumpBreakpointStorage(breakpointManager); |
| return breakpointManager; |
| } |
| |
| function setBreakpoint(breakpointManager, uiSourceCode, lineNumber, condition, enabled) |
| { |
| InspectorTest.addResult(" Setting breakpoint at " + uiSourceCode.url + ":" + lineNumber + " enabled:" + enabled + " condition:" + condition); |
| return breakpointManager.setBreakpoint(uiSourceCode, lineNumber, condition, enabled); |
| } |
| |
| function removeBreakpoint(breakpointManager, uiSourceCode, lineNumber) |
| { |
| InspectorTest.addResult(" Removing breakpoint at " + uiSourceCode.url + ":" + lineNumber); |
| breakpointManager.findBreakpoint(uiSourceCode, lineNumber).remove(); |
| } |
| |
| function dumpBreakpointStorage(breakpointManager) |
| { |
| var breakpoints = breakpointManager._storage._setting.get(); |
| InspectorTest.addResult(" Dumping Storage"); |
| for (var i = 0; i < breakpoints.length; ++i) |
| InspectorTest.addResult(" " + breakpoints[i].sourceFileId + ":" + breakpoints[i].lineNumber + " enabled:" + breakpoints[i].enabled + " condition:" + breakpoints[i].condition); |
| } |
| |
| function resetBreakpointManager(breakpointManager, next) |
| { |
| dumpBreakpointStorage(breakpointManager); |
| InspectorTest.addResult(" Resetting breakpoint manager"); |
| breakpointManager.reset(); |
| uiSourceCodes = {}; |
| next(); |
| } |
| |
| InspectorTest.runTestSuite([ |
| function testSetBreakpoint(next) |
| { |
| var breakpointManager = createBreakpointManager(); |
| var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); |
| setBreakpoint(breakpointManager, uiSourceCode, 30, "", true); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testSetDisabledBreakpoint(next) |
| { |
| var breakpointManager = createBreakpointManager(); |
| var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); |
| var breakpoint = setBreakpoint(breakpointManager, uiSourceCode, 30, "", false); |
| dumpBreakpointStorage(breakpointManager); |
| InspectorTest.addResult(" Enabling breakpoint"); |
| breakpoint.setEnabled(true); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testSetConditionalBreakpoint(next) |
| { |
| var breakpointManager = createBreakpointManager(); |
| var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); |
| var breakpoint = setBreakpoint(breakpointManager, uiSourceCode, 30, "condition", true); |
| dumpBreakpointStorage(breakpointManager); |
| InspectorTest.addResult(" Updating condition"); |
| breakpoint.setCondition(""); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testRestoreBreakpoints(next) |
| { |
| var breakpointManager = createBreakpointManager(serializedBreakpoints); |
| addUISourceCode(breakpointManager, "a.js"); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testRestoreBreakpointsTwice(next) |
| { |
| var breakpointManager = createBreakpointManager(serializedBreakpoints); |
| addUISourceCode(breakpointManager, "a.js"); |
| addUISourceCode(breakpointManager, "a.js"); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testRestoreBreakpointsAfterTemporaryUISourceCodeRemoved(next) |
| { |
| var breakpointManager = createBreakpointManager(serializedBreakpoints); |
| addTemporaryUISourceCode(breakpointManager, "a.js"); |
| addUISourceCode(breakpointManager, "a.js"); |
| removeTemporaryUISourceCode(breakpointManager, "a.js"); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testRemoveBreakpoints(next) |
| { |
| var breakpointManager = createBreakpointManager(serializedBreakpoints); |
| var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); |
| setBreakpoint(breakpointManager, uiSourceCode, 30, "", true); |
| |
| removeBreakpoint(breakpointManager, uiSourceCode, 30); |
| removeBreakpoint(breakpointManager, uiSourceCode, 10); |
| removeBreakpoint(breakpointManager, uiSourceCode, 20); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testSetBreakpointThatShifts(next) |
| { |
| var breakpointManager = createBreakpointManager(); |
| var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); |
| setBreakpoint(breakpointManager, uiSourceCode, 1015, "", true); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testSetBreakpointThatShiftsTwice(next) |
| { |
| var breakpointManager = createBreakpointManager(); |
| var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); |
| setBreakpoint(breakpointManager, uiSourceCode, 1015, "", true); |
| setBreakpoint(breakpointManager, uiSourceCode, 1015, "", true); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testSetBreakpointOutsideScript(next) |
| { |
| var breakpointManager = createBreakpointManager([]); |
| var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); |
| breakpointManager.setBreakpoint(uiSourceCode, 2500, "", true); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testNavigation(next) |
| { |
| var breakpointManager = createBreakpointManager(serializedBreakpoints); |
| var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js"); |
| |
| InspectorTest.addResult("\n Navigating to B."); |
| breakpointManager._debuggerModel.reset(); |
| breakpointManager._workspace.reset(); |
| var uiSourceCodeB = addUISourceCode(breakpointManager, "b.js"); |
| |
| InspectorTest.addResult("\n Navigating back to A."); |
| breakpointManager._debuggerModel.reset(); |
| breakpointManager._workspace.reset(); |
| InspectorTest.addResult(" Resolving provisional breakpoint."); |
| var eventData = { breakpointId: "a.js:10", location: { scriptId: "a.js", lineNumber: 11, columnNumber: 5 }}; |
| breakpointManager._debuggerModel.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointResolved, eventData); |
| addUISourceCode(breakpointManager, "a.js"); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testSourceMapping(next) |
| { |
| // Source mapping will shift everthing 10 lines ahead so that breakpoint 1 clashed with breakpoint 2. |
| var serializedBreakpoints = []; |
| serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true)); |
| serializedBreakpoints.push(createBreakpoint("a.js", 20, "", true)); |
| |
| var breakpointManager = createBreakpointManager(serializedBreakpoints); |
| var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js"); |
| InspectorTest.addResult("\n Toggling source mapping."); |
| breakpointManager._sourceMapping = shiftingMapping; |
| breakpointManager._debuggerModel.setSourceMapping(shiftingMapping); |
| InspectorTest.addResult("\n Toggling source mapping back."); |
| breakpointManager._sourceMapping = defaultMapping; |
| breakpointManager._debuggerModel.setSourceMapping(defaultMapping); |
| resetBreakpointManager(breakpointManager, next); |
| }, |
| |
| function testProvisionalBreakpointsResolve(next) |
| { |
| var serializedBreakpoints = []; |
| serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true)); |
| |
| var breakpointManager = createBreakpointManager(serializedBreakpoints); |
| var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); |
| breakpointManager._debuggerModel.reset(); |
| breakpointManager._workspace.reset(); |
| InspectorTest.addResult(" Resolving provisional breakpoint."); |
| var eventData = { breakpointId: "a.js:10", location: { scriptId: "a.js", lineNumber: 11, columnNumber: 5 }}; |
| breakpointManager._debuggerModel.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointResolved, eventData); |
| resetBreakpointManager(breakpointManager, next); |
| } |
| ]); |
| }; |
| |
| </script> |
| |
| </head> |
| |
| <body onload="runTest()"> |
| <p>Tests BreakpointManager class.</p> |
| |
| </body> |
| </html> |