1 var initialize_BreakpointManagerTest = function() {
3 InspectorTest.uiSourceCodes = {};
5 InspectorTest.dumpTargetIds = false;
7 InspectorTest.initializeDefaultMappingOnTarget = function(target)
10 rawLocationToUILocation: function(rawLocation)
12 return InspectorTest.uiSourceCodes[rawLocation.scriptId].uiLocation(rawLocation.lineNumber, 0);
15 uiLocationToRawLocation: function(uiSourceCode, lineNumber)
17 if (!InspectorTest.uiSourceCodes[uiSourceCode.url])
19 return new WebInspector.DebuggerModel.Location(target, uiSourceCode.url, lineNumber, 0);
22 isIdentity: function()
27 target.defaultMapping = defaultMapping;
30 InspectorTest.createMockTarget = function(id)
37 resourceTreeModel: new WebInspector.Object(),
38 addEventListener: function() { },
39 removeEventListener: function() { },
40 dispose: function() { },
41 isDetached: function() { return !!this.detached; }
43 target._modelByConstructor = new Map();
44 InspectorTest.initializeDefaultMappingOnTarget(target);
45 target.debuggerModel = new InspectorTest.DebuggerModelMock(target, target.defaultMapping, InspectorTest.testDebuggerWorkspaceBinding);
46 target.debuggerModel._target = target;
50 InspectorTest.dumpTarget = function(targetAware)
52 return InspectorTest.dumpTargetIds ? "target " + targetAware.target().id() + " " : "";
55 InspectorTest.DebuggerModelMock = function(target, sourceMapping, debuggerWorkspaceBinding)
57 WebInspector.SDKModel.call(this, WebInspector.DebuggerModel, target);
58 this._breakpointResolvedEventTarget = new WebInspector.Object();
60 this._sourceMapping = sourceMapping;
61 this._breakpoints = {};
62 this._debuggerWorkspaceBinding = InspectorTest.testDebuggerWorkspaceBinding;
65 InspectorTest.DebuggerModelMock.prototype = {
71 debuggerEnabled: function()
76 scriptsForSourceURL: function(url)
78 var script = this._scriptForURL(url);
79 return script ? [script] : [];
82 _addScript: function(scriptId, url)
84 var script = new WebInspector.Script(this._target, scriptId, url);
85 this._scripts[scriptId] = script;
86 this._debuggerWorkspaceBinding._targetToData.get(this._target)._parsedScriptSource({data: script});
89 _registerScript: function(script)
91 this._scripts[script.scriptId] = script;
92 this._debuggerWorkspaceBinding._targetToData.get(this._target)._parsedScriptSource({data: script});
95 _scriptForURL: function(url)
97 for (var scriptId in this._scripts) {
98 var script = this._scripts[scriptId];
99 if (script.sourceURL === url)
104 _scheduleSetBeakpointCallback: function(callback, breakpointId, locations)
106 setTimeout(innerCallback.bind(this), 0);
108 function innerCallback()
111 callback(breakpointId, locations);
112 if (window.setBreakpointCallback) {
113 var savedCallback = window.setBreakpointCallback;
114 delete window.setBreakpointCallback;
120 createRawLocation: function(script, line, column)
122 return new WebInspector.DebuggerModel.Location(this.target(), script.scriptId, line, column);
125 setBreakpointByURL: function(url, lineNumber, columnNumber, condition, callback)
127 InspectorTest.addResult(" " + InspectorTest.dumpTarget(this) + "debuggerModel.setBreakpoint(" + [url, lineNumber, condition].join(":") + ")");
129 var breakpointId = url + ":" + lineNumber;
130 if (this._breakpoints[breakpointId]) {
131 this._scheduleSetBeakpointCallback(callback, null);
134 this._breakpoints[breakpointId] = true;
136 if (lineNumber >= 2000) {
137 this._scheduleSetBeakpointCallback(callback, breakpointId, []);
140 if (lineNumber >= 1000) {
141 var shiftedLocation = new WebInspector.DebuggerModel.Location(this._target, url, lineNumber + 10, columnNumber);
142 this._scheduleSetBeakpointCallback(callback, breakpointId, [shiftedLocation]);
147 var script = this._scriptForURL(url);
149 var location = new WebInspector.DebuggerModel.Location(this._target, script.scriptId, lineNumber, 0);
150 locations.push(location);
153 this._scheduleSetBeakpointCallback(callback, breakpointId, locations);
156 removeBreakpoint: function(breakpointId, callback)
158 InspectorTest.addResult(" " + InspectorTest.dumpTarget(this) + "debuggerModel.removeBreakpoint(" + breakpointId + ")");
159 delete this._breakpoints[breakpointId];
161 setTimeout(callback, 0);
164 setBreakpointsActive: function() { },
166 scriptForId: function(scriptId)
168 return this._scripts[scriptId];
173 InspectorTest.addResult(" Resetting debugger.");
175 this._debuggerWorkspaceBinding._reset(this._target);
178 pushSourceMapping: function(sourceMapping)
180 for (var scriptId in this._scripts)
181 this._debuggerWorkspaceBinding.pushSourceMapping(this._scripts[scriptId], sourceMapping);
184 disableSourceMapping: function(sourceMapping)
186 sourceMapping._disabled = true;
187 for (var scriptId in this._scripts)
188 this._debuggerWorkspaceBinding.updateLocations(this._scripts[scriptId]);
191 addBreakpointListener: function(breakpointId, listener, thisObject)
193 this._breakpointResolvedEventTarget.addEventListener(breakpointId, listener, thisObject)
196 removeBreakpointListener: function(breakpointId, listener, thisObject)
198 this._breakpointResolvedEventTarget.removeEventListener(breakpointId, listener, thisObject);
201 _breakpointResolved: function(breakpointId, location)
203 this._breakpointResolvedEventTarget.dispatchEventToListeners(breakpointId, location);
206 __proto__: WebInspector.Object.prototype
209 InspectorTest.setupLiveLocationSniffers = function()
211 InspectorTest.addSniffer(WebInspector.DebuggerWorkspaceBinding.prototype, "createLiveLocation", function(rawLocation)
213 InspectorTest.addResult(" Location created: " + InspectorTest.dumpTarget(rawLocation) + rawLocation.scriptId + ":" + rawLocation.lineNumber);
215 InspectorTest.addSniffer(WebInspector.DebuggerWorkspaceBinding.Location.prototype, "dispose", function()
217 InspectorTest.addResult(" Location disposed: " + InspectorTest.dumpTarget(this._rawLocation) + this._rawLocation.scriptId + ":" + this._rawLocation.lineNumber);
221 InspectorTest.addScript = function(target, breakpointManager, url)
223 target.debuggerModel._addScript(url, url);
224 InspectorTest.addResult(" Adding script: " + url);
225 var uiSourceCodes = breakpointManager._workspace.uiSourceCodesForProjectType(WebInspector.projectTypes.Debugger);
226 for (var i = 0; i < uiSourceCodes.length; ++i) {
227 var uiSourceCode = uiSourceCodes[i];
228 if (uiSourceCode.url === url) {
229 breakpointManager._debuggerWorkspaceBinding.setSourceMapping(target, uiSourceCode, breakpointManager.defaultMapping);
230 InspectorTest.uiSourceCodes[url] = uiSourceCode;
236 InspectorTest.addUISourceCode = function(target, breakpointManager, url, doNotSetSourceMapping, doNotAddScript)
239 InspectorTest.addScript(target, breakpointManager, url);
240 InspectorTest.addResult(" Adding UISourceCode: " + url);
241 var contentProvider = new WebInspector.StaticContentProvider(WebInspector.resourceTypes.Script, "");
242 var binding = breakpointManager._debuggerWorkspaceBinding;
243 var uiSourceCode = binding._networkWorkspaceBinding.addFileForURL(url, contentProvider);
244 InspectorTest.uiSourceCodes[url] = uiSourceCode;
245 if (!doNotSetSourceMapping) {
246 breakpointManager._debuggerWorkspaceBinding.setSourceMapping(target, uiSourceCode, breakpointManager.defaultMapping);
247 breakpointManager._debuggerWorkspaceBinding.updateLocations(target.debuggerModel.scriptForId(url));
252 InspectorTest.createBreakpointManager = function(targetManager, debuggerWorkspaceBinding, persistentBreakpoints)
254 InspectorTest._pendingBreakpointUpdates = 0;
255 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_updateInDebugger", updateInDebugger, true);
256 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.prototype, "_didUpdateInDebugger", didUpdateInDebugger, true);
258 function updateInDebugger()
260 InspectorTest._pendingBreakpointUpdates++;
263 function didUpdateInDebugger()
265 InspectorTest._pendingBreakpointUpdates--;
266 InspectorTest._notifyAfterBreakpointUpdate();
269 persistentBreakpoints = persistentBreakpoints || [];
271 get: function() { return persistentBreakpoints; },
272 set: function(breakpoints) { persistentBreakpoints = breakpoints; }
275 function breakpointAdded(event)
277 var breakpoint = event.data.breakpoint;
278 var uiLocation = event.data.uiLocation;
279 InspectorTest.addResult(" breakpointAdded(" + [uiLocation.uiSourceCode.originURL(), uiLocation.lineNumber, uiLocation.columnNumber, breakpoint.condition(), breakpoint.enabled()].join(", ") + ")");
282 function breakpointRemoved(event)
284 var uiLocation = event.data.uiLocation;
285 InspectorTest.addResult(" breakpointRemoved(" + [uiLocation.uiSourceCode.originURL(), uiLocation.lineNumber, uiLocation.columnNumber].join(", ") + ")");
287 var targets = targetManager.targets();
288 var mappingForManager;
289 for (var i = 0; i < targets.length; ++i) {
290 InspectorTest.initializeDefaultMappingOnTarget(targets[i]);
291 if (!mappingForManager)
292 mappingForManager = targets[i].defaultMapping;
293 var model = new InspectorTest.DebuggerModelMock(targets[i], targets[i].defaultMapping, debuggerWorkspaceBinding);
294 targets[i].debuggerModel = model;
297 var breakpointManager = new WebInspector.BreakpointManager(setting, debuggerWorkspaceBinding._workspace, targetManager, debuggerWorkspaceBinding);
298 breakpointManager.defaultMapping = mappingForManager;
299 breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointAdded, breakpointAdded);
300 breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointRemoved, breakpointRemoved);
301 InspectorTest.addResult(" Created breakpoints manager");
302 InspectorTest.dumpBreakpointStorage(breakpointManager);
303 return breakpointManager;
306 InspectorTest.setBreakpoint = function(breakpointManager, uiSourceCode, lineNumber, columnNumber, condition, enabled, setBreakpointCallback)
308 InspectorTest.addResult(" Setting breakpoint at " + uiSourceCode.originURL() + ":" + lineNumber + ":" + columnNumber + " enabled:" + enabled + " condition:" + condition);
309 if (setBreakpointCallback)
310 window.setBreakpointCallback = setBreakpointCallback;
311 return breakpointManager.setBreakpoint(uiSourceCode, lineNumber, columnNumber, condition, enabled);
314 InspectorTest.removeBreakpoint = function(breakpointManager, uiSourceCode, lineNumber, columnNumber)
316 InspectorTest.addResult(" Removing breakpoint at " + uiSourceCode.originURL() + ":" + lineNumber + ":" + columnNumber);
317 breakpointManager.findBreakpoint(uiSourceCode, lineNumber, columnNumber).remove();
320 InspectorTest.dumpBreakpointStorage = function(breakpointManager)
322 var breakpoints = breakpointManager._storage._setting.get();
323 InspectorTest.addResult(" Dumping Storage");
324 for (var i = 0; i < breakpoints.length; ++i)
325 InspectorTest.addResult(" " + breakpoints[i].sourceFileId + ":" + breakpoints[i].lineNumber + " enabled:" + breakpoints[i].enabled + " condition:" + breakpoints[i].condition);
328 InspectorTest.dumpBreakpointLocations = function(breakpointManager)
330 var allBreakpointLocations = breakpointManager.allBreakpointLocations();
331 InspectorTest.addResult(" Dumping Breakpoint Locations");
332 var lastUISourceCode = null;
335 function dumpLocations(uiSourceCode, locations)
337 locations.sort(function(a, b) {
338 return a.lineNumber - b.lineNumber;
340 InspectorTest.addResult(" UISourceCode (url='" + uiSourceCode.url + "', uri='" + uiSourceCode.uri() + "')");
341 for (var i = 0; i < locations.length; ++i)
342 InspectorTest.addResult(" Location: (" + locations[i].lineNumber + ", " + locations[i].columnNumber + ")");
345 for (var i = 0; i < allBreakpointLocations.length; ++i) {
346 var uiLocation = allBreakpointLocations[i].uiLocation;
347 var uiSourceCode = uiLocation.uiSourceCode;
348 if (lastUISourceCode && lastUISourceCode != uiSourceCode) {
349 dumpLocations(uiSourceCode, locations);
352 lastUISourceCode = uiSourceCode;
353 locations.push(uiLocation);
355 if (lastUISourceCode)
356 dumpLocations(lastUISourceCode, locations);
359 InspectorTest.resetBreakpointManager = function(breakpointManager, next)
361 InspectorTest.addResult(" Resetting breakpoint manager");
362 breakpointManager.removeAllBreakpoints();
363 breakpointManager.removeProvisionalBreakpointsForTest();
364 InspectorTest.uiSourceCodes = {};
368 InspectorTest.runAfterPendingBreakpointUpdates = function(breakpointManager, callback)
370 InspectorTest._pendingBreakpointUpdatesCallback = callback;
371 InspectorTest._notifyAfterBreakpointUpdate();
374 InspectorTest._notifyAfterBreakpointUpdate = function()
376 if (!InspectorTest._pendingBreakpointUpdates && InspectorTest._pendingBreakpointUpdatesCallback) {
377 var callback = InspectorTest._pendingBreakpointUpdatesCallback;
378 delete InspectorTest._pendingBreakpointUpdatesCallback;
383 InspectorTest.finishBreakpointTest = function(breakpointManager, next)
385 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, dump);
389 InspectorTest.dumpBreakpointLocations(breakpointManager);
390 InspectorTest.dumpBreakpointStorage(breakpointManager);
391 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, reset);
396 InspectorTest.resetBreakpointManager(breakpointManager, didReset);
401 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, finish);
406 InspectorTest.dumpBreakpointLocations(breakpointManager);