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 var networkURL
= InspectorTest
.testNetworkMapping
.networkURL(uiSourceCode
);
18 if (!InspectorTest
.uiSourceCodes
[networkURL
])
20 return new WebInspector
.DebuggerModel
.Location(target
.debuggerModel
, networkURL
, lineNumber
, 0);
23 isIdentity: function()
28 target
.defaultMapping
= defaultMapping
;
31 InspectorTest
.dumpTarget = function(targetAware
)
33 return InspectorTest
.dumpTargetIds
? "target " + targetAware
.target().id() + " " : "";
36 InspectorTest
.DebuggerModelMock = function(target
)
38 WebInspector
.SDKModel
.call(this, WebInspector
.DebuggerModel
, target
);
39 this._breakpointResolvedEventTarget
= new WebInspector
.Object();
41 this._breakpoints
= {};
42 this._debuggerWorkspaceBinding
= InspectorTest
.testDebuggerWorkspaceBinding
;
45 InspectorTest
.DebuggerModelMock
.prototype = {
51 debuggerEnabled: function()
56 scriptsForSourceURL: function(url
)
58 var script
= this._scriptForURL(url
);
59 return script
? [script
] : [];
62 _addScript: function(scriptId
, url
)
64 var script
= new WebInspector
.Script(this, scriptId
, url
);
65 this._scripts
[scriptId
] = script
;
66 this._debuggerWorkspaceBinding
._targetToData
.get(this._target
)._parsedScriptSource({data
: script
});
69 _registerScript: function(script
)
71 this._scripts
[script
.scriptId
] = script
;
72 this._debuggerWorkspaceBinding
._targetToData
.get(this._target
)._parsedScriptSource({data
: script
});
75 _scriptForURL: function(url
)
77 for (var scriptId
in this._scripts
) {
78 var script
= this._scripts
[scriptId
];
79 if (script
.sourceURL
=== url
)
84 _scheduleSetBeakpointCallback: function(callback
, breakpointId
, locations
)
86 setTimeout(innerCallback
.bind(this), 0);
88 function innerCallback()
91 callback(breakpointId
, locations
);
92 if (window
.setBreakpointCallback
) {
93 var savedCallback
= window
.setBreakpointCallback
;
94 delete window
.setBreakpointCallback
;
100 createRawLocation: function(script
, line
, column
)
102 return new WebInspector
.DebuggerModel
.Location(this, script
.scriptId
, line
, column
);
105 setBreakpointByURL: function(url
, lineNumber
, columnNumber
, condition
, callback
)
107 InspectorTest
.addResult(" " + InspectorTest
.dumpTarget(this) + "debuggerModel.setBreakpoint(" + [url
, lineNumber
, condition
].join(":") + ")");
109 var breakpointId
= url
+ ":" + lineNumber
;
110 if (this._breakpoints
[breakpointId
]) {
111 this._scheduleSetBeakpointCallback(callback
, null);
114 this._breakpoints
[breakpointId
] = true;
116 if (lineNumber
>= 2000) {
117 this._scheduleSetBeakpointCallback(callback
, breakpointId
, []);
120 if (lineNumber
>= 1000) {
121 var shiftedLocation
= new WebInspector
.DebuggerModel
.Location(this, url
, lineNumber
+ 10, columnNumber
);
122 this._scheduleSetBeakpointCallback(callback
, breakpointId
, [shiftedLocation
]);
127 var script
= this._scriptForURL(url
);
129 var location
= new WebInspector
.DebuggerModel
.Location(this, script
.scriptId
, lineNumber
, 0);
130 locations
.push(location
);
133 this._scheduleSetBeakpointCallback(callback
, breakpointId
, locations
);
136 removeBreakpoint: function(breakpointId
, callback
)
138 InspectorTest
.addResult(" " + InspectorTest
.dumpTarget(this) + "debuggerModel.removeBreakpoint(" + breakpointId
+ ")");
139 delete this._breakpoints
[breakpointId
];
141 setTimeout(callback
, 0);
144 setBreakpointsActive: function() { },
146 scriptForId: function(scriptId
)
148 return this._scripts
[scriptId
];
153 InspectorTest
.addResult(" Resetting debugger.");
155 this._debuggerWorkspaceBinding
._reset(this._target
);
158 pushSourceMapping: function(sourceMapping
)
160 for (var scriptId
in this._scripts
)
161 this._debuggerWorkspaceBinding
.pushSourceMapping(this._scripts
[scriptId
], sourceMapping
);
164 disableSourceMapping: function(sourceMapping
)
166 sourceMapping
._disabled
= true;
167 for (var scriptId
in this._scripts
)
168 this._debuggerWorkspaceBinding
.updateLocations(this._scripts
[scriptId
]);
171 addBreakpointListener: function(breakpointId
, listener
, thisObject
)
173 this._breakpointResolvedEventTarget
.addEventListener(breakpointId
, listener
, thisObject
)
176 removeBreakpointListener: function(breakpointId
, listener
, thisObject
)
178 this._breakpointResolvedEventTarget
.removeEventListener(breakpointId
, listener
, thisObject
);
181 _breakpointResolved: function(breakpointId
, location
)
183 this._breakpointResolvedEventTarget
.dispatchEventToListeners(breakpointId
, location
);
186 __proto__
: WebInspector
.Object
.prototype
189 InspectorTest
.setupLiveLocationSniffers = function()
191 InspectorTest
.addSniffer(WebInspector
.DebuggerWorkspaceBinding
.prototype, "createLiveLocation", function(rawLocation
)
193 InspectorTest
.addResult(" Location created: " + InspectorTest
.dumpTarget(rawLocation
) + rawLocation
.scriptId
+ ":" + rawLocation
.lineNumber
);
195 InspectorTest
.addSniffer(WebInspector
.DebuggerWorkspaceBinding
.Location
.prototype, "dispose", function()
197 InspectorTest
.addResult(" Location disposed: " + InspectorTest
.dumpTarget(this._rawLocation
) + this._rawLocation
.scriptId
+ ":" + this._rawLocation
.lineNumber
);
201 InspectorTest
.addScript = function(target
, breakpointManager
, url
)
203 target
.debuggerModel
._addScript(url
, url
);
204 InspectorTest
.addResult(" Adding script: " + url
);
205 var uiSourceCodes
= breakpointManager
._workspace
.uiSourceCodesForProjectType(WebInspector
.projectTypes
.Debugger
);
206 for (var i
= 0; i
< uiSourceCodes
.length
; ++i
) {
207 var uiSourceCode
= uiSourceCodes
[i
];
208 var networkURL
= InspectorTest
.testNetworkMapping
.networkURL(uiSourceCode
);
209 if (networkURL
=== url
) {
210 breakpointManager
._debuggerWorkspaceBinding
.setSourceMapping(target
, uiSourceCode
, breakpointManager
.defaultMapping
);
211 InspectorTest
.uiSourceCodes
[url
] = uiSourceCode
;
217 InspectorTest
.addUISourceCode = function(target
, breakpointManager
, url
, doNotSetSourceMapping
, doNotAddScript
)
220 InspectorTest
.addScript(target
, breakpointManager
, url
);
221 InspectorTest
.addResult(" Adding UISourceCode: " + url
);
222 var contentProvider
= new WebInspector
.StaticContentProvider(WebInspector
.resourceTypes
.Script
, "");
223 var binding
= breakpointManager
._debuggerWorkspaceBinding
;
224 var uiSourceCode
= InspectorTest
.testNetworkProject
.addFileForURL(url
, contentProvider
);
225 InspectorTest
.uiSourceCodes
[url
] = uiSourceCode
;
226 if (!doNotSetSourceMapping
) {
227 breakpointManager
._debuggerWorkspaceBinding
.setSourceMapping(target
, uiSourceCode
, breakpointManager
.defaultMapping
);
228 breakpointManager
._debuggerWorkspaceBinding
.updateLocations(target
.debuggerModel
.scriptForId(url
));
233 InspectorTest
.createBreakpointManager = function(targetManager
, debuggerWorkspaceBinding
, persistentBreakpoints
)
235 InspectorTest
._pendingBreakpointUpdates
= 0;
236 InspectorTest
.addSniffer(WebInspector
.BreakpointManager
.TargetBreakpoint
.prototype, "_updateInDebugger", updateInDebugger
, true);
237 InspectorTest
.addSniffer(WebInspector
.BreakpointManager
.TargetBreakpoint
.prototype, "_didUpdateInDebugger", didUpdateInDebugger
, true);
239 function updateInDebugger()
241 InspectorTest
._pendingBreakpointUpdates
++;
244 function didUpdateInDebugger()
246 InspectorTest
._pendingBreakpointUpdates
--;
247 InspectorTest
._notifyAfterBreakpointUpdate();
250 persistentBreakpoints
= persistentBreakpoints
|| [];
252 get: function() { return persistentBreakpoints
; },
253 set: function(breakpoints
) { persistentBreakpoints
= breakpoints
; }
256 function breakpointAdded(event
)
258 var breakpoint
= event
.data
.breakpoint
;
259 var uiLocation
= event
.data
.uiLocation
;
260 InspectorTest
.addResult(" breakpointAdded(" + [uiLocation
.uiSourceCode
.originURL(), uiLocation
.lineNumber
, uiLocation
.columnNumber
, breakpoint
.condition(), breakpoint
.enabled()].join(", ") + ")");
263 function breakpointRemoved(event
)
265 var uiLocation
= event
.data
.uiLocation
;
266 InspectorTest
.addResult(" breakpointRemoved(" + [uiLocation
.uiSourceCode
.originURL(), uiLocation
.lineNumber
, uiLocation
.columnNumber
].join(", ") + ")");
268 var targets
= targetManager
.targets();
269 var mappingForManager
;
270 for (var i
= 0; i
< targets
.length
; ++i
) {
271 InspectorTest
.initializeDefaultMappingOnTarget(targets
[i
]);
272 if (!mappingForManager
)
273 mappingForManager
= targets
[i
].defaultMapping
;
274 var model
= new InspectorTest
.DebuggerModelMock(targets
[i
], targets
[i
].defaultMapping
, debuggerWorkspaceBinding
);
275 targets
[i
].debuggerModel
= model
;
278 var breakpointManager
= new WebInspector
.BreakpointManager(setting
, debuggerWorkspaceBinding
._workspace
, debuggerWorkspaceBinding
._networkMapping
, targetManager
, debuggerWorkspaceBinding
);
279 breakpointManager
.defaultMapping
= mappingForManager
;
280 breakpointManager
.addEventListener(WebInspector
.BreakpointManager
.Events
.BreakpointAdded
, breakpointAdded
);
281 breakpointManager
.addEventListener(WebInspector
.BreakpointManager
.Events
.BreakpointRemoved
, breakpointRemoved
);
282 InspectorTest
.addResult(" Created breakpoints manager");
283 InspectorTest
.dumpBreakpointStorage(breakpointManager
);
284 return breakpointManager
;
287 InspectorTest
.setBreakpoint = function(breakpointManager
, uiSourceCode
, lineNumber
, columnNumber
, condition
, enabled
, setBreakpointCallback
)
289 InspectorTest
.addResult(" Setting breakpoint at " + uiSourceCode
.originURL() + ":" + lineNumber
+ ":" + columnNumber
+ " enabled:" + enabled
+ " condition:" + condition
);
290 if (setBreakpointCallback
)
291 window
.setBreakpointCallback
= setBreakpointCallback
;
292 return breakpointManager
.setBreakpoint(uiSourceCode
, lineNumber
, columnNumber
, condition
, enabled
);
295 InspectorTest
.removeBreakpoint = function(breakpointManager
, uiSourceCode
, lineNumber
, columnNumber
)
297 InspectorTest
.addResult(" Removing breakpoint at " + uiSourceCode
.originURL() + ":" + lineNumber
+ ":" + columnNumber
);
298 breakpointManager
.findBreakpoint(uiSourceCode
, lineNumber
, columnNumber
).remove();
301 InspectorTest
.dumpBreakpointStorage = function(breakpointManager
)
303 var breakpoints
= breakpointManager
._storage
._setting
.get();
304 InspectorTest
.addResult(" Dumping Storage");
305 for (var i
= 0; i
< breakpoints
.length
; ++i
)
306 InspectorTest
.addResult(" " + breakpoints
[i
].sourceFileId
+ ":" + breakpoints
[i
].lineNumber
+ " enabled:" + breakpoints
[i
].enabled
+ " condition:" + breakpoints
[i
].condition
);
309 InspectorTest
.dumpBreakpointLocations = function(breakpointManager
)
311 var allBreakpointLocations
= breakpointManager
.allBreakpointLocations();
312 InspectorTest
.addResult(" Dumping Breakpoint Locations");
313 var lastUISourceCode
= null;
316 function dumpLocations(uiSourceCode
, locations
)
318 locations
.sort(function(a
, b
) {
319 return a
.lineNumber
- b
.lineNumber
;
321 var networkURL
= InspectorTest
.testNetworkMapping
.networkURL(uiSourceCode
);
322 InspectorTest
.addResult(" UISourceCode (url='" + networkURL
+ "', uri='" + uiSourceCode
.uri() + "')");
323 for (var i
= 0; i
< locations
.length
; ++i
)
324 InspectorTest
.addResult(" Location: (" + locations
[i
].lineNumber
+ ", " + locations
[i
].columnNumber
+ ")");
327 for (var i
= 0; i
< allBreakpointLocations
.length
; ++i
) {
328 var uiLocation
= allBreakpointLocations
[i
].uiLocation
;
329 var uiSourceCode
= uiLocation
.uiSourceCode
;
330 if (lastUISourceCode
&& lastUISourceCode
!= uiSourceCode
) {
331 dumpLocations(uiSourceCode
, locations
);
334 lastUISourceCode
= uiSourceCode
;
335 locations
.push(uiLocation
);
337 if (lastUISourceCode
)
338 dumpLocations(lastUISourceCode
, locations
);
341 InspectorTest
.resetBreakpointManager = function(breakpointManager
, next
)
343 InspectorTest
.addResult(" Resetting breakpoint manager");
344 breakpointManager
.removeAllBreakpoints();
345 breakpointManager
.removeProvisionalBreakpointsForTest();
346 InspectorTest
.uiSourceCodes
= {};
350 InspectorTest
.runAfterPendingBreakpointUpdates = function(breakpointManager
, callback
)
352 InspectorTest
._pendingBreakpointUpdatesCallback
= callback
;
353 InspectorTest
._notifyAfterBreakpointUpdate();
356 InspectorTest
._notifyAfterBreakpointUpdate = function()
358 if (!InspectorTest
._pendingBreakpointUpdates
&& InspectorTest
._pendingBreakpointUpdatesCallback
) {
359 var callback
= InspectorTest
._pendingBreakpointUpdatesCallback
;
360 delete InspectorTest
._pendingBreakpointUpdatesCallback
;
365 InspectorTest
.finishBreakpointTest = function(breakpointManager
, next
)
367 InspectorTest
.runAfterPendingBreakpointUpdates(breakpointManager
, dump
);
371 InspectorTest
.dumpBreakpointLocations(breakpointManager
);
372 InspectorTest
.dumpBreakpointStorage(breakpointManager
);
373 InspectorTest
.runAfterPendingBreakpointUpdates(breakpointManager
, reset
);
378 InspectorTest
.resetBreakpointManager(breakpointManager
, didReset
);
383 InspectorTest
.runAfterPendingBreakpointUpdates(breakpointManager
, finish
);
388 InspectorTest
.dumpBreakpointLocations(breakpointManager
);