| OLD | NEW |
| (Empty) |
| 1 var initialize_BreakpointManagerTest = function() { | |
| 2 | |
| 3 InspectorTest.uiSourceCodes = {}; | |
| 4 | |
| 5 InspectorTest.dumpTargetIds = false; | |
| 6 | |
| 7 InspectorTest.initializeDefaultMappingOnTarget = function(target) | |
| 8 { | |
| 9 var defaultMapping = { | |
| 10 rawLocationToUILocation: function(rawLocation) | |
| 11 { | |
| 12 return InspectorTest.uiSourceCodes[rawLocation.scriptId].uiLocation(
rawLocation.lineNumber, 0); | |
| 13 }, | |
| 14 | |
| 15 uiLocationToRawLocation: function(uiSourceCode, lineNumber) | |
| 16 { | |
| 17 var networkURL = InspectorTest.testNetworkMapping.networkURL(uiSourc
eCode); | |
| 18 if (!InspectorTest.uiSourceCodes[networkURL]) | |
| 19 return null; | |
| 20 return new WebInspector.DebuggerModel.Location(target.debuggerModel,
networkURL, lineNumber, 0); | |
| 21 }, | |
| 22 | |
| 23 isIdentity: function() | |
| 24 { | |
| 25 return true; | |
| 26 } | |
| 27 }; | |
| 28 target.defaultMapping = defaultMapping; | |
| 29 } | |
| 30 | |
| 31 InspectorTest.dumpTarget = function(targetAware) | |
| 32 { | |
| 33 return InspectorTest.dumpTargetIds ? "target " + targetAware.target().id()
+ " " : ""; | |
| 34 } | |
| 35 | |
| 36 InspectorTest.DebuggerModelMock = function(target) | |
| 37 { | |
| 38 WebInspector.SDKModel.call(this, WebInspector.DebuggerModel, target); | |
| 39 this._breakpointResolvedEventTarget = new WebInspector.Object(); | |
| 40 this._scripts = {}; | |
| 41 this._breakpoints = {}; | |
| 42 this._debuggerWorkspaceBinding = InspectorTest.testDebuggerWorkspaceBinding; | |
| 43 } | |
| 44 | |
| 45 InspectorTest.DebuggerModelMock.prototype = { | |
| 46 target: function() | |
| 47 { | |
| 48 return this._target; | |
| 49 }, | |
| 50 | |
| 51 debuggerEnabled: function() | |
| 52 { | |
| 53 return true; | |
| 54 }, | |
| 55 | |
| 56 scriptsForSourceURL: function(url) | |
| 57 { | |
| 58 var script = this._scriptForURL(url); | |
| 59 return script ? [script] : []; | |
| 60 }, | |
| 61 | |
| 62 _addScript: function(scriptId, url) | |
| 63 { | |
| 64 var script = new WebInspector.Script(this, scriptId, url); | |
| 65 this._scripts[scriptId] = script; | |
| 66 this._debuggerWorkspaceBinding._targetToData.get(this._target)._parsedSc
riptSource({data: script}); | |
| 67 }, | |
| 68 | |
| 69 _registerScript: function(script) | |
| 70 { | |
| 71 this._scripts[script.scriptId] = script; | |
| 72 this._debuggerWorkspaceBinding._targetToData.get(this._target)._parsedSc
riptSource({data: script}); | |
| 73 }, | |
| 74 | |
| 75 _scriptForURL: function(url) | |
| 76 { | |
| 77 for (var scriptId in this._scripts) { | |
| 78 var script = this._scripts[scriptId]; | |
| 79 if (script.sourceURL === url) | |
| 80 return script; | |
| 81 } | |
| 82 }, | |
| 83 | |
| 84 _scheduleSetBeakpointCallback: function(callback, breakpointId, locations) | |
| 85 { | |
| 86 setTimeout(innerCallback.bind(this), 0); | |
| 87 | |
| 88 function innerCallback() | |
| 89 { | |
| 90 if (callback) | |
| 91 callback(breakpointId, locations); | |
| 92 if (window.setBreakpointCallback) { | |
| 93 var savedCallback = window.setBreakpointCallback; | |
| 94 delete window.setBreakpointCallback; | |
| 95 savedCallback(); | |
| 96 } | |
| 97 } | |
| 98 }, | |
| 99 | |
| 100 createRawLocation: function(script, line, column) | |
| 101 { | |
| 102 return new WebInspector.DebuggerModel.Location(this, script.scriptId, li
ne, column); | |
| 103 }, | |
| 104 | |
| 105 setBreakpointByURL: function(url, lineNumber, columnNumber, condition, callb
ack) | |
| 106 { | |
| 107 InspectorTest.addResult(" " + InspectorTest.dumpTarget(this) + "debug
gerModel.setBreakpoint(" + [url, lineNumber, condition].join(":") + ")"); | |
| 108 | |
| 109 var breakpointId = url + ":" + lineNumber; | |
| 110 if (this._breakpoints[breakpointId]) { | |
| 111 this._scheduleSetBeakpointCallback(callback, null); | |
| 112 return; | |
| 113 } | |
| 114 this._breakpoints[breakpointId] = true; | |
| 115 | |
| 116 if (lineNumber >= 2000) { | |
| 117 this._scheduleSetBeakpointCallback(callback, breakpointId, []); | |
| 118 return; | |
| 119 } | |
| 120 if (lineNumber >= 1000) { | |
| 121 var shiftedLocation = new WebInspector.DebuggerModel.Location(this,
url, lineNumber + 10, columnNumber); | |
| 122 this._scheduleSetBeakpointCallback(callback, breakpointId, [shiftedL
ocation]); | |
| 123 return; | |
| 124 } | |
| 125 | |
| 126 var locations = []; | |
| 127 var script = this._scriptForURL(url); | |
| 128 if (script) { | |
| 129 var location = new WebInspector.DebuggerModel.Location(this, script.
scriptId, lineNumber, 0); | |
| 130 locations.push(location); | |
| 131 } | |
| 132 | |
| 133 this._scheduleSetBeakpointCallback(callback, breakpointId, locations); | |
| 134 }, | |
| 135 | |
| 136 removeBreakpoint: function(breakpointId, callback) | |
| 137 { | |
| 138 InspectorTest.addResult(" " + InspectorTest.dumpTarget(this) + "debug
gerModel.removeBreakpoint(" + breakpointId + ")"); | |
| 139 delete this._breakpoints[breakpointId]; | |
| 140 if (callback) | |
| 141 setTimeout(callback, 0); | |
| 142 }, | |
| 143 | |
| 144 setBreakpointsActive: function() { }, | |
| 145 | |
| 146 scriptForId: function(scriptId) | |
| 147 { | |
| 148 return this._scripts[scriptId]; | |
| 149 }, | |
| 150 | |
| 151 reset: function() | |
| 152 { | |
| 153 InspectorTest.addResult(" Resetting debugger."); | |
| 154 this._scripts = {}; | |
| 155 this._debuggerWorkspaceBinding._reset(this._target); | |
| 156 }, | |
| 157 | |
| 158 pushSourceMapping: function(sourceMapping) | |
| 159 { | |
| 160 for (var scriptId in this._scripts) | |
| 161 this._debuggerWorkspaceBinding.pushSourceMapping(this._scripts[scrip
tId], sourceMapping); | |
| 162 }, | |
| 163 | |
| 164 disableSourceMapping: function(sourceMapping) | |
| 165 { | |
| 166 sourceMapping._disabled = true; | |
| 167 for (var scriptId in this._scripts) | |
| 168 this._debuggerWorkspaceBinding.updateLocations(this._scripts[scriptI
d]); | |
| 169 }, | |
| 170 | |
| 171 addBreakpointListener: function(breakpointId, listener, thisObject) | |
| 172 { | |
| 173 this._breakpointResolvedEventTarget.addEventListener(breakpointId, liste
ner, thisObject) | |
| 174 }, | |
| 175 | |
| 176 removeBreakpointListener: function(breakpointId, listener, thisObject) | |
| 177 { | |
| 178 this._breakpointResolvedEventTarget.removeEventListener(breakpointId, li
stener, thisObject); | |
| 179 }, | |
| 180 | |
| 181 _breakpointResolved: function(breakpointId, location) | |
| 182 { | |
| 183 this._breakpointResolvedEventTarget.dispatchEventToListeners(breakpointI
d, location); | |
| 184 }, | |
| 185 | |
| 186 __proto__: WebInspector.Object.prototype | |
| 187 } | |
| 188 | |
| 189 InspectorTest.setupLiveLocationSniffers = function() | |
| 190 { | |
| 191 InspectorTest.addSniffer(WebInspector.DebuggerWorkspaceBinding.prototype, "c
reateLiveLocation", function(rawLocation) | |
| 192 { | |
| 193 InspectorTest.addResult(" Location created: " + InspectorTest.dumpTar
get(rawLocation) + rawLocation.scriptId + ":" + rawLocation.lineNumber); | |
| 194 }, true); | |
| 195 InspectorTest.addSniffer(WebInspector.DebuggerWorkspaceBinding.Location.prot
otype, "dispose", function() | |
| 196 { | |
| 197 InspectorTest.addResult(" Location disposed: " + InspectorTest.dumpTa
rget(this._rawLocation) + this._rawLocation.scriptId + ":" + this._rawLocation.l
ineNumber); | |
| 198 }, true); | |
| 199 } | |
| 200 | |
| 201 InspectorTest.addScript = function(target, breakpointManager, url) | |
| 202 { | |
| 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(uiSourceCod
e); | |
| 209 if (networkURL === url) { | |
| 210 breakpointManager._debuggerWorkspaceBinding.setSourceMapping(target,
uiSourceCode, breakpointManager.defaultMapping); | |
| 211 InspectorTest.uiSourceCodes[url] = uiSourceCode; | |
| 212 return uiSourceCode; | |
| 213 } | |
| 214 } | |
| 215 } | |
| 216 | |
| 217 InspectorTest.addUISourceCode = function(target, breakpointManager, url, doNotSe
tSourceMapping, doNotAddScript) | |
| 218 { | |
| 219 if (!doNotAddScript) | |
| 220 InspectorTest.addScript(target, breakpointManager, url); | |
| 221 InspectorTest.addResult(" Adding UISourceCode: " + url); | |
| 222 var contentProvider = new WebInspector.StaticContentProvider(WebInspector.re
sourceTypes.Script, ""); | |
| 223 var binding = breakpointManager._debuggerWorkspaceBinding; | |
| 224 var uiSourceCode = InspectorTest.testNetworkProject.addFileForURL(url, conte
ntProvider); | |
| 225 InspectorTest.uiSourceCodes[url] = uiSourceCode; | |
| 226 if (!doNotSetSourceMapping) { | |
| 227 breakpointManager._debuggerWorkspaceBinding.setSourceMapping(target, uiS
ourceCode, breakpointManager.defaultMapping); | |
| 228 breakpointManager._debuggerWorkspaceBinding.updateLocations(target.debug
gerModel.scriptForId(url)); | |
| 229 } | |
| 230 return uiSourceCode; | |
| 231 } | |
| 232 | |
| 233 InspectorTest.createBreakpointManager = function(targetManager, debuggerWorkspac
eBinding, persistentBreakpoints) | |
| 234 { | |
| 235 InspectorTest._pendingBreakpointUpdates = 0; | |
| 236 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.pro
totype, "_updateInDebugger", updateInDebugger, true); | |
| 237 InspectorTest.addSniffer(WebInspector.BreakpointManager.TargetBreakpoint.pro
totype, "_didUpdateInDebugger", didUpdateInDebugger, true); | |
| 238 | |
| 239 function updateInDebugger() | |
| 240 { | |
| 241 InspectorTest._pendingBreakpointUpdates++; | |
| 242 } | |
| 243 | |
| 244 function didUpdateInDebugger() | |
| 245 { | |
| 246 InspectorTest._pendingBreakpointUpdates--; | |
| 247 InspectorTest._notifyAfterBreakpointUpdate(); | |
| 248 } | |
| 249 | |
| 250 persistentBreakpoints = persistentBreakpoints || []; | |
| 251 var setting = { | |
| 252 get: function() { return persistentBreakpoints; }, | |
| 253 set: function(breakpoints) { persistentBreakpoints = breakpoints; } | |
| 254 }; | |
| 255 | |
| 256 function breakpointAdded(event) | |
| 257 { | |
| 258 var breakpoint = event.data.breakpoint; | |
| 259 var uiLocation = event.data.uiLocation; | |
| 260 InspectorTest.addResult(" breakpointAdded(" + [uiLocation.uiSourceCod
e.originURL(), uiLocation.lineNumber, uiLocation.columnNumber, breakpoint.condit
ion(), breakpoint.enabled()].join(", ") + ")"); | |
| 261 } | |
| 262 | |
| 263 function breakpointRemoved(event) | |
| 264 { | |
| 265 var uiLocation = event.data.uiLocation; | |
| 266 InspectorTest.addResult(" breakpointRemoved(" + [uiLocation.uiSourceC
ode.originURL(), uiLocation.lineNumber, uiLocation.columnNumber].join(", ") + ")
"); | |
| 267 } | |
| 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].d
efaultMapping, debuggerWorkspaceBinding); | |
| 275 targets[i].debuggerModel = model; | |
| 276 } | |
| 277 | |
| 278 var breakpointManager = new WebInspector.BreakpointManager(setting, debugger
WorkspaceBinding._workspace, debuggerWorkspaceBinding._networkMapping, targetMan
ager, debuggerWorkspaceBinding); | |
| 279 breakpointManager.defaultMapping = mappingForManager; | |
| 280 breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.Bre
akpointAdded, breakpointAdded); | |
| 281 breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.Bre
akpointRemoved, breakpointRemoved); | |
| 282 InspectorTest.addResult(" Created breakpoints manager"); | |
| 283 InspectorTest.dumpBreakpointStorage(breakpointManager); | |
| 284 return breakpointManager; | |
| 285 } | |
| 286 | |
| 287 InspectorTest.setBreakpoint = function(breakpointManager, uiSourceCode, lineNumb
er, columnNumber, condition, enabled, setBreakpointCallback) | |
| 288 { | |
| 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, columnNumbe
r, condition, enabled); | |
| 293 } | |
| 294 | |
| 295 InspectorTest.removeBreakpoint = function(breakpointManager, uiSourceCode, lineN
umber, columnNumber) | |
| 296 { | |
| 297 InspectorTest.addResult(" Removing breakpoint at " + uiSourceCode.originURL
() + ":" + lineNumber + ":" + columnNumber); | |
| 298 breakpointManager.findBreakpoint(uiSourceCode, lineNumber, columnNumber).rem
ove(); | |
| 299 } | |
| 300 | |
| 301 InspectorTest.dumpBreakpointStorage = function(breakpointManager) | |
| 302 { | |
| 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 + ":" + bre
akpoints[i].lineNumber + " enabled:" + breakpoints[i].enabled + " condition:" +
breakpoints[i].condition); | |
| 307 } | |
| 308 | |
| 309 InspectorTest.dumpBreakpointLocations = function(breakpointManager) | |
| 310 { | |
| 311 var allBreakpointLocations = breakpointManager.allBreakpointLocations(); | |
| 312 InspectorTest.addResult(" Dumping Breakpoint Locations"); | |
| 313 var lastUISourceCode = null; | |
| 314 var locations = []; | |
| 315 | |
| 316 function dumpLocations(uiSourceCode, locations) | |
| 317 { | |
| 318 locations.sort(function(a, b) { | |
| 319 return a.lineNumber - b.lineNumber; | |
| 320 }); | |
| 321 var networkURL = InspectorTest.testNetworkMapping.networkURL(uiSourceCod
e); | |
| 322 InspectorTest.addResult(" UISourceCode (url='" + networkURL + "', uri
='" + uiSourceCode.uri() + "')"); | |
| 323 for (var i = 0; i < locations.length; ++i) | |
| 324 InspectorTest.addResult(" Location: (" + locations[i].lineNumbe
r + ", " + locations[i].columnNumber + ")"); | |
| 325 } | |
| 326 | |
| 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); | |
| 332 locations = []; | |
| 333 } | |
| 334 lastUISourceCode = uiSourceCode; | |
| 335 locations.push(uiLocation); | |
| 336 } | |
| 337 if (lastUISourceCode) | |
| 338 dumpLocations(lastUISourceCode, locations); | |
| 339 } | |
| 340 | |
| 341 InspectorTest.resetBreakpointManager = function(breakpointManager, next) | |
| 342 { | |
| 343 InspectorTest.addResult(" Resetting breakpoint manager"); | |
| 344 breakpointManager.removeAllBreakpoints(); | |
| 345 breakpointManager.removeProvisionalBreakpointsForTest(); | |
| 346 InspectorTest.uiSourceCodes = {}; | |
| 347 next(); | |
| 348 } | |
| 349 | |
| 350 InspectorTest.runAfterPendingBreakpointUpdates = function(breakpointManager, cal
lback) | |
| 351 { | |
| 352 InspectorTest._pendingBreakpointUpdatesCallback = callback; | |
| 353 InspectorTest._notifyAfterBreakpointUpdate(); | |
| 354 } | |
| 355 | |
| 356 InspectorTest._notifyAfterBreakpointUpdate = function() | |
| 357 { | |
| 358 if (!InspectorTest._pendingBreakpointUpdates && InspectorTest._pendingBreakp
ointUpdatesCallback) { | |
| 359 var callback = InspectorTest._pendingBreakpointUpdatesCallback; | |
| 360 delete InspectorTest._pendingBreakpointUpdatesCallback; | |
| 361 callback(); | |
| 362 } | |
| 363 } | |
| 364 | |
| 365 InspectorTest.finishBreakpointTest = function(breakpointManager, next) | |
| 366 { | |
| 367 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, dump); | |
| 368 | |
| 369 function dump() | |
| 370 { | |
| 371 InspectorTest.dumpBreakpointLocations(breakpointManager); | |
| 372 InspectorTest.dumpBreakpointStorage(breakpointManager); | |
| 373 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, reset)
; | |
| 374 } | |
| 375 | |
| 376 function reset() | |
| 377 { | |
| 378 InspectorTest.resetBreakpointManager(breakpointManager, didReset); | |
| 379 } | |
| 380 | |
| 381 function didReset() | |
| 382 { | |
| 383 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, finish
); | |
| 384 } | |
| 385 | |
| 386 function finish() | |
| 387 { | |
| 388 InspectorTest.dumpBreakpointLocations(breakpointManager); | |
| 389 next(); | |
| 390 } | |
| 391 } | |
| 392 | |
| 393 } | |
| OLD | NEW |