Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: LayoutTests/inspector/sources/debugger/breakpoint-manager.html

Issue 322793003: Devtools: Move out helper methods from breakpoint-manager.html to separate file to reuse them later (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address vsevik's comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | LayoutTests/inspector/sources/debugger/breakpoint-manager.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <html> 1 <html>
2 <head> 2 <head>
3 <script src="../../../http/tests/inspector/inspector-test.js"></script> 3 <script src="../../../http/tests/inspector/inspector-test.js"></script>
4 <script src="breakpoint-manager.js"></script>
4 5
5 <script> 6 <script>
6 7
7 function test() 8 function test()
8 { 9 {
9 var workspace;
10 var uiSourceCodes = {};
11 var mockTarget = {
12
13 id: function()
14 {
15 return 1;
16 }
17 };
18 var targetManager = new WebInspector.TargetManager();
19 targetManager._targets.push(mockTarget);
20
21 var defaultMapping = {
22 rawLocationToUILocation: function(rawLocation)
23 {
24 return uiSourceCodes[rawLocation.scriptId].uiLocation(rawLocation.li neNumber, 0);
25 },
26
27 uiLocationToRawLocation: function(uiSourceCode, lineNumber)
28 {
29 if (!uiSourceCodes[uiSourceCode.url])
30 return null;
31 return new WebInspector.DebuggerModel.Location(mockTarget, uiSourceC ode.url, lineNumber, 0);
32 },
33
34 isIdentity: function()
35 {
36 return true;
37 }
38 };
39
40 var shiftingMapping = {
41 rawLocationToUILocation: function(rawLocation)
42 {
43 if (this._disabled)
44 return null;
45 return uiSourceCodes[rawLocation.scriptId].uiLocation(rawLocation.li neNumber + 10, 0);
46 },
47
48 uiLocationToRawLocation: function(uiSourceCode, lineNumber)
49 {
50 return new WebInspector.DebuggerModel.Location(mockTarget, uiSourceC ode.url, lineNumber - 10, 0);
51 },
52
53 isIdentity: function()
54 {
55 return false;
56 }
57 };
58
59 function createSourceMapping(uiSourceCodeA, uiSourceCodeB)
60 {
61 var mapping = {
62 rawLocationToUILocation: function(rawLocation)
63 {
64 if (this._disabled)
65 return null;
66 return uiSourceCodeB.uiLocation(rawLocation.lineNumber + 10, 0);
67 },
68
69 uiLocationToRawLocation: function(uiSourceCode, lineNumber)
70 {
71 return new WebInspector.DebuggerModel.Location(mockTarget, uiSou rceCodeA.url, lineNumber - 10, 0);
72 },
73
74 isIdentity: function()
75 {
76 return false;
77 }
78 };
79
80 return mapping;
81 }
82
83 function DebuggerModelMock(sourceMapping)
84 {
85 mockTarget.debuggerModel = this;
86 this._breakpointResolvedEventTarget = new WebInspector.Object();
87 this._scripts = {};
88 this._sourceMapping = sourceMapping;
89 this._breakpoints = {};
90 }
91
92 DebuggerModelMock.prototype = {
93 target: function()
94 {
95 return mockTarget;
96 },
97
98 _addScript: function(scriptId, url)
99 {
100 this._scripts[scriptId] = new WebInspector.Script(mockTarget, script Id, url);
101 this._scripts[scriptId].pushSourceMapping(this._sourceMapping);
102 },
103
104 _scriptForURL: function(url)
105 {
106 for (var scriptId in this._scripts) {
107 var script = this._scripts[scriptId];
108 if (script.sourceURL === url)
109 return script;
110 }
111 },
112
113 _scheduleSetBeakpointCallback: function(callback, breakpointId, location s)
114 {
115 setTimeout(innerCallback.bind(this), 0);
116
117 function innerCallback()
118 {
119 if (callback)
120 callback(breakpointId, locations);
121 if (window.setBreakpointCallback) {
122 var savedCallback = window.setBreakpointCallback;
123 delete window.setBreakpointCallback;
124 savedCallback();
125 }
126 }
127 },
128
129 setBreakpointByURL: function(url, lineNumber, columnNumber, condition, c allback)
130 {
131 InspectorTest.addResult(" debuggerModel.setBreakpoint(" + [url, l ineNumber, condition].join(":") + ")");
132
133 var breakpointId = url + ":" + lineNumber;
134 if (this._breakpoints[breakpointId]) {
135 this._scheduleSetBeakpointCallback(callback, null);
136 return;
137 }
138 this._breakpoints[breakpointId] = true;
139
140 var locations = [];
141 var script = this._scriptForURL(url);
142 if (script) {
143 var location = new WebInspector.DebuggerModel.Location(mockTarge t, script.scriptId, lineNumber, 0);
144 locations.push(location);
145 }
146
147 this._scheduleSetBeakpointCallback(callback, breakpointId, locations );
148 },
149
150 setBreakpointByScriptLocation: function(location, condition, callback)
151 {
152 InspectorTest.addResult(" debuggerModel.setBreakpoint(" + [locati on.scriptId, location.lineNumber, condition].join(":") + ")");
153
154 var breakpointId = location.scriptId + ":" + location.lineNumber;
155 if (this._breakpoints[breakpointId]) {
156 this._scheduleSetBeakpointCallback(callback, null);
157 return;
158 }
159 this._breakpoints[breakpointId] = true;
160
161 if (location.lineNumber >= 2000) {
162 this._scheduleSetBeakpointCallback(callback, breakpointId, []);
163 return;
164 }
165 if (location.lineNumber >= 1000) {
166 var shiftedLocation = new WebInspector.DebuggerModel.Location(mo ckTarget, location.scriptId, location.lineNumber + 10, location.columnNumber);
167 this._scheduleSetBeakpointCallback(callback, breakpointId, [shif tedLocation]);
168 return;
169 }
170
171 this._scheduleSetBeakpointCallback(callback, breakpointId, [WebInspe ctor.DebuggerModel.Location.fromPayload(mockTarget, location)]);
172 },
173
174 removeBreakpoint: function(breakpointId, callback)
175 {
176 InspectorTest.addResult(" debuggerModel.removeBreakpoint(" + brea kpointId + ")");
177 delete this._breakpoints[breakpointId];
178 if (callback)
179 callback();
180 },
181
182 setBreakpointsActive: function() { },
183
184 createLiveLocation: function(rawLocation, updateDelegate)
185 {
186 return this._scripts[rawLocation.scriptId].createLiveLocation(rawLoc ation, updateDelegate);
187 },
188
189 scriptForId: function(scriptId)
190 {
191 return this._scripts[scriptId];
192 },
193
194 reset: function()
195 {
196 InspectorTest.addResult(" Resetting debugger.");
197 this._scripts = {};
198 },
199
200 pushSourceMapping: function(sourceMapping)
201 {
202 for (var scriptId in this._scripts)
203 this._scripts[scriptId].pushSourceMapping(sourceMapping);
204 },
205
206 disableSourceMapping: function(sourceMapping)
207 {
208 sourceMapping._disabled = true;
209 for (var scriptId in this._scripts)
210 this._scripts[scriptId].updateLocations();
211 },
212
213 addBreakpointListener: function(breakpointId, listener, thisObject)
214 {
215 this._breakpointResolvedEventTarget.addEventListener(breakpointId, l istener, thisObject)
216 },
217
218 removeBreakpointListener: function(breakpointId, listener, thisObject)
219 {
220 this._breakpointResolvedEventTarget.removeEventListener(breakpointId , listener, thisObject);
221 },
222
223 _breakpointResolved: function(breakpointId, location)
224 {
225 this._breakpointResolvedEventTarget.dispatchEventToListeners(breakpo intId, location);
226 }
227 }
228 DebuggerModelMock.prototype.__proto__ = WebInspector.Object.prototype;
229
230 function resetWorkspace(breakpointManager) 10 function resetWorkspace(breakpointManager)
231 { 11 {
232 InspectorTest.addResult(" Resetting workspace."); 12 InspectorTest.addResult(" Resetting workspace.");
233 breakpointManager._networkWorkspaceBinding.reset(); 13 breakpointManager._networkWorkspaceBinding.reset();
234 breakpointManager._debuggerProjectDelegate.reset(); 14 breakpointManager._debuggerProjectDelegate.reset();
235 } 15 }
236 16
237 function breakpointAdded(event)
238 {
239 var breakpoint = event.data.breakpoint;
240 var uiLocation = event.data.uiLocation;
241 InspectorTest.addResult(" breakpointAdded(" + [uiLocation.uiSourceCod e.originURL(), uiLocation.lineNumber, uiLocation.columnNumber, breakpoint.condit ion(), breakpoint.enabled()].join(", ") + ")");
242 }
243
244 function breakpointRemoved(event)
245 {
246 var uiLocation = event.data.uiLocation;
247 InspectorTest.addResult(" breakpointRemoved(" + [uiLocation.uiSourceC ode.originURL(), uiLocation.lineNumber, uiLocation.columnNumber].join(", ") + ") ");
248 }
249
250 InspectorTest.addSniffer(WebInspector.Script.prototype, "createLiveLocation" , function(rawLocation)
251 {
252 InspectorTest.addResult(" Location created: " + rawLocation.scriptId + ":" + rawLocation.lineNumber);
253 }, true);
254 InspectorTest.addSniffer(WebInspector.Script.Location.prototype, "dispose", function()
255 {
256 InspectorTest.addResult(" Location disposed: " + this._rawLocation.sc riptId + ":" + this._rawLocation.lineNumber);
257 }, true);
258
259 function addUISourceCode(breakpointManager, url, doNotSetSourceMapping, doNo tAddScript)
260 {
261 if (!doNotAddScript)
262 mockTarget.debuggerModel._addScript(url, url);
263 InspectorTest.addResult(" Adding UISourceCode: " + url);
264 var contentProvider = new WebInspector.StaticContentProvider(WebInspecto r.resourceTypes.Script, "");
265 var uiSourceCode = breakpointManager._networkWorkspaceBinding.addFileFor URL(url, contentProvider);
266 uiSourceCodes[url] = uiSourceCode;
267 if (!doNotSetSourceMapping)
268 uiSourceCode.setSourceMappingForTarget(mockTarget, defaultMapping);
269 return uiSourceCode;
270 }
271
272 function addTemporaryUISourceCode(breakpointManager, url) 17 function addTemporaryUISourceCode(breakpointManager, url)
273 { 18 {
274 mockTarget.debuggerModel._addScript(url, url); 19 mockTarget.debuggerModel._addScript(url, url);
275 InspectorTest.addResult(" Adding temporary UISourceCode: " + url); 20 InspectorTest.addResult(" Adding temporary UISourceCode: " + url);
276 var contentProvider = new WebInspector.StaticContentProvider(WebInspecto r.resourceTypes.Script, ""); 21 var contentProvider = new WebInspector.StaticContentProvider(WebInspecto r.resourceTypes.Script, "");
277 var path = breakpointManager._debuggerProjectDelegate.addContentProvider ("", url, url, contentProvider); 22 var path = breakpointManager._debuggerProjectDelegate.addContentProvider ("", url, url, contentProvider);
278 var uiSourceCode = workspace.uiSourceCode("debugger:", path); 23 var uiSourceCode = breakpointManager._workspace.uiSourceCode("debugger:" , path);
279 uiSourceCode.setSourceMappingForTarget(mockTarget, defaultMapping); 24 uiSourceCode.setSourceMappingForTarget(mockTarget, mockTarget.defaultMap ping);
280 uiSourceCodes[url] = uiSourceCode; 25 InspectorTest.uiSourceCodes[url] = uiSourceCode;
281 return uiSourceCode; 26 return uiSourceCode;
282 } 27 }
283 28
284 function createBreakpoint(uiSourceCodeId, lineNumber, condition, enabled) 29 function createBreakpoint(uiSourceCodeId, lineNumber, condition, enabled)
285 { 30 {
286 return { sourceFileId: uiSourceCodeId, lineNumber: lineNumber, condition : condition, enabled: enabled }; 31 return { sourceFileId: uiSourceCodeId, lineNumber: lineNumber, condition : condition, enabled: enabled };
287 } 32 }
288 33
289 var serializedBreakpoints = []; 34 var serializedBreakpoints = [];
290 serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true)) ; 35 serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true)) ;
291 serializedBreakpoints.push(createBreakpoint("a.js", 20, "", false)); 36 serializedBreakpoints.push(createBreakpoint("a.js", 20, "", false));
292 serializedBreakpoints.push(createBreakpoint("b.js", 3, "", true)); 37 serializedBreakpoints.push(createBreakpoint("b.js", 3, "", true));
293 38
294 function createBreakpointManager(persistentBreakpoints, sourceMapping) 39 var mockTarget = {
295 {
296 persistentBreakpoints = persistentBreakpoints || [];
297 var setting = {
298 get: function() { return persistentBreakpoints; },
299 set: function(breakpoints) { persistentBreakpoints = breakpoints; }
300 };
301 40
302 var sourceMapping = sourceMapping || defaultMapping; 41 id: function()
303 var debuggerModel = new DebuggerModelMock(sourceMapping); 42 {
304 workspace = new WebInspector.Workspace(); 43 return 1;
305 var breakpointManager = new WebInspector.BreakpointManager(setting, work space, targetManager); 44 }
306 breakpointManager._networkWorkspaceBinding = new WebInspector.NetworkWor kspaceBinding(workspace); 45 };
307 breakpointManager._debuggerProjectDelegate = new WebInspector.DebuggerPr ojectDelegate(workspace, "debugger:", WebInspector.projectTypes.Debugger); 46 var targetManager = new WebInspector.TargetManager();
308 breakpointManager.addEventListener(WebInspector.BreakpointManager.Events .BreakpointAdded, breakpointAdded); 47 targetManager._targets.push(mockTarget);
309 breakpointManager.addEventListener(WebInspector.BreakpointManager.Events .BreakpointRemoved, breakpointRemoved);
310 InspectorTest.addResult(" Created breakpoints manager");
311 dumpBreakpointStorage(breakpointManager);
312 return breakpointManager;
313 }
314 48
315 function setBreakpoint(breakpointManager, uiSourceCode, lineNumber, columnNu mber, condition, enabled) 49 InspectorTest.setupLiveLocationSniffers();
316 { 50 InspectorTest.initializeDefaultMappingOnTarget(mockTarget);
317 InspectorTest.addResult(" Setting breakpoint at " + uiSourceCode.origin URL() + ":" + lineNumber + ":" + columnNumber + " enabled:" + enabled + " condit ion:" + condition);
318 return breakpointManager.setBreakpoint(uiSourceCode, lineNumber, columnN umber, condition, enabled);
319 }
320 51
321 function removeBreakpoint(breakpointManager, uiSourceCode, lineNumber, colum nNumber) 52 var addUISourceCode = InspectorTest.addUISourceCode.bind(null, mockTarget);
322 { 53 var createBreakpointManager = InspectorTest.createBreakpointManager.bind(nul l, targetManager);
323 InspectorTest.addResult(" Removing breakpoint at " + uiSourceCode.origi nURL() + ":" + lineNumber + ":" + columnNumber);
324 breakpointManager.findBreakpoint(uiSourceCode, lineNumber, columnNumber) .remove();
325 }
326
327 function dumpBreakpointStorage(breakpointManager)
328 {
329 var breakpoints = breakpointManager._storage._setting.get();
330 InspectorTest.addResult(" Dumping Storage");
331 for (var i = 0; i < breakpoints.length; ++i)
332 InspectorTest.addResult(" " + breakpoints[i].sourceFileId + ":" + breakpoints[i].lineNumber + " enabled:" + breakpoints[i].enabled + " condition :" + breakpoints[i].condition);
333 }
334
335 function dumpBreakpointLocations(breakpointManager)
336 {
337 var allBreakpointLocations = breakpointManager.allBreakpointLocations();
338 InspectorTest.addResult(" Dumping Breakpoint Locations");
339 var lastUISourceCode = null;
340 var locations = [];
341
342 function dumpLocations(uiSourceCode, locations)
343 {
344 InspectorTest.addResult(" UISourceCode (url='" + uiSourceCode.url + "', uri='" + uiSourceCode.uri() + "')");
345 for (var i = 0; i < locations.length; ++i)
346 InspectorTest.addResult(" Location: (" + locations[i].lineN umber + ", " + locations[i].columnNumber + ")");
347 }
348
349 for (var i = 0; i < allBreakpointLocations.length; ++i) {
350 var uiLocation = allBreakpointLocations[i].uiLocation;
351 var uiSourceCode = uiLocation.uiSourceCode;
352 if (lastUISourceCode && lastUISourceCode != uiSourceCode) {
353 dumpLocations(uiSourceCode, locations);
354 locations = [];
355 }
356 lastUISourceCode = uiSourceCode;
357 locations.push(uiLocation);
358 }
359 if (lastUISourceCode)
360 dumpLocations(lastUISourceCode, locations);
361 }
362
363 function resetBreakpointManager(breakpointManager, next)
364 {
365 dumpBreakpointStorage(breakpointManager);
366 InspectorTest.addResult(" Resetting breakpoint manager");
367 breakpointManager.removeAllBreakpoints();
368 breakpointManager.removeProvisionalBreakpointsForTest();
369 uiSourceCodes = {};
370 next();
371 }
372 54
373 InspectorTest.runTestSuite([ 55 InspectorTest.runTestSuite([
374 function testSetBreakpoint(next) 56 function testSetBreakpoint(next)
375 { 57 {
376 var breakpointManager = createBreakpointManager(); 58 var breakpointManager = createBreakpointManager();
377 var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); 59 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
378 setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true); 60 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true, InspectorTest.finishBreakpointTest.bind(this, breakpointManager, next) );
379 window.setBreakpointCallback = step2.bind(this);
380
381 function step2()
382 {
383 dumpBreakpointLocations(breakpointManager);
384 resetBreakpointManager(breakpointManager, step3);
385 }
386
387 function step3()
388 {
389 dumpBreakpointLocations(breakpointManager);
390 next();
391 }
392 }, 61 },
393 62
394 function testSetDisabledBreakpoint(next) 63 function testSetDisabledBreakpoint(next)
395 { 64 {
396 var breakpointManager = createBreakpointManager(); 65 var breakpointManager = createBreakpointManager();
397 var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); 66 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
398 var breakpoint = setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", false); 67 var breakpoint = InspectorTest.setBreakpoint(breakpointManager, uiSo urceCode, 30, 0, "", false);
399 dumpBreakpointLocations(breakpointManager); 68 InspectorTest.dumpBreakpointLocations(breakpointManager);
400 dumpBreakpointStorage(breakpointManager); 69 InspectorTest.dumpBreakpointStorage(breakpointManager);
401 InspectorTest.addResult(" Enabling breakpoint"); 70 InspectorTest.addResult(" Enabling breakpoint");
402 breakpoint.setEnabled(true); 71 breakpoint.setEnabled(true);
403 window.setBreakpointCallback = step2.bind(this); 72 window.setBreakpointCallback = InspectorTest.finishBreakpointTest.bi nd(this, breakpointManager, next);
404
405 function step2()
406 {
407 dumpBreakpointLocations(breakpointManager);
408 resetBreakpointManager(breakpointManager, step3);
409 }
410
411 function step3()
412 {
413 dumpBreakpointLocations(breakpointManager);
414 next();
415 }
416 }, 73 },
417 74
418 function testSetConditionalBreakpoint(next) 75 function testSetConditionalBreakpoint(next)
419 { 76 {
420 var breakpointManager = createBreakpointManager(); 77 var breakpointManager = createBreakpointManager();
421 var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); 78 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
422 var breakpoint = setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "condition", true); 79 var breakpoint = InspectorTest.setBreakpoint(breakpointManager, uiSo urceCode, 30, 0, "condition", true, step2);
423 window.setBreakpointCallback = step2.bind(this);
424 80
425 function step2() 81 function step2()
426 { 82 {
427 dumpBreakpointLocations(breakpointManager); 83 InspectorTest.dumpBreakpointLocations(breakpointManager);
428 dumpBreakpointStorage(breakpointManager); 84 InspectorTest.dumpBreakpointStorage(breakpointManager);
429 InspectorTest.addResult(" Updating condition"); 85 InspectorTest.addResult(" Updating condition");
430 breakpoint.setCondition(""); 86 breakpoint.setCondition("");
431 window.setBreakpointCallback = step3.bind(this); 87 window.setBreakpointCallback = InspectorTest.finishBreakpointTes t.bind(this, breakpointManager, next);
432 }
433
434 function step3()
435 {
436 dumpBreakpointLocations(breakpointManager);
437 resetBreakpointManager(breakpointManager, step4);
438 }
439
440 function step4()
441 {
442 dumpBreakpointLocations(breakpointManager);
443 next();
444 } 88 }
445 }, 89 },
446 90
447 function testRestoreBreakpoints(next) 91 function testRestoreBreakpoints(next)
448 { 92 {
449 var breakpointManager = createBreakpointManager(serializedBreakpoint s); 93 var breakpointManager = createBreakpointManager(serializedBreakpoint s);
450 addUISourceCode(breakpointManager, "a.js"); 94 addUISourceCode(breakpointManager, "a.js");
451 window.setBreakpointCallback = step2.bind(this); 95 window.setBreakpointCallback = InspectorTest.finishBreakpointTest.bi nd(this, breakpointManager, next);
452
453 function step2()
454 {
455 dumpBreakpointLocations(breakpointManager);
456 resetBreakpointManager(breakpointManager, step3);
457 }
458
459 function step3()
460 {
461 dumpBreakpointLocations(breakpointManager);
462 next();
463 }
464 }, 96 },
465 97
466 function testRestoreBreakpointsTwice(next) 98 function testRestoreBreakpointsTwice(next)
467 { 99 {
468 var breakpointManager = createBreakpointManager(serializedBreakpoint s); 100 var breakpointManager = createBreakpointManager(serializedBreakpoint s);
469 addUISourceCode(breakpointManager, "a.js"); 101 addUISourceCode(breakpointManager, "a.js");
470 addUISourceCode(breakpointManager, "a.js"); 102 addUISourceCode(breakpointManager, "a.js");
471 window.setBreakpointCallback = step2.bind(this); 103 window.setBreakpointCallback = InspectorTest.finishBreakpointTest.bi nd(this, breakpointManager, next);
472
473 function step2()
474 {
475 dumpBreakpointLocations(breakpointManager);
476 resetBreakpointManager(breakpointManager, step3);
477 }
478
479 function step3()
480 {
481 dumpBreakpointLocations(breakpointManager);
482 next();
483 }
484 }, 104 },
485 105
486 function testRemoveBreakpoints(next) 106 function testRemoveBreakpoints(next)
487 { 107 {
488 var breakpointManager = createBreakpointManager(serializedBreakpoint s); 108 var breakpointManager = createBreakpointManager(serializedBreakpoint s);
489 var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); 109 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
490 window.setBreakpointCallback = step2.bind(this); 110 window.setBreakpointCallback = step2.bind(this);
491 111
492 function step2() 112 function step2()
493 { 113 {
494 dumpBreakpointLocations(breakpointManager); 114 InspectorTest.dumpBreakpointLocations(breakpointManager);
495 setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true); 115 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true, step3);
496 window.setBreakpointCallback = step3.bind(this);
497 } 116 }
498 117
499 function step3() 118 function step3()
500 { 119 {
501 dumpBreakpointLocations(breakpointManager); 120 InspectorTest.dumpBreakpointLocations(breakpointManager);
502 removeBreakpoint(breakpointManager, uiSourceCode, 30, 0); 121 InspectorTest.removeBreakpoint(breakpointManager, uiSourceCode, 30, 0);
503 removeBreakpoint(breakpointManager, uiSourceCode, 10, 0); 122 InspectorTest.removeBreakpoint(breakpointManager, uiSourceCode, 10, 0);
504 removeBreakpoint(breakpointManager, uiSourceCode, 20, 0); 123 InspectorTest.removeBreakpoint(breakpointManager, uiSourceCode, 20, 0);
505 dumpBreakpointLocations(breakpointManager); 124 InspectorTest.finishBreakpointTest(breakpointManager, next);
506 resetBreakpointManager(breakpointManager, step4);
507 }
508
509 function step4()
510 {
511 dumpBreakpointLocations(breakpointManager);
512 next();
513 } 125 }
514 }, 126 },
515 127
516 function testSetBreakpointThatShifts(next) 128 function testSetBreakpointThatShifts(next)
517 { 129 {
518 var breakpointManager = createBreakpointManager(); 130 var breakpointManager = createBreakpointManager();
519 var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); 131 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
520 setBreakpoint(breakpointManager, uiSourceCode, 1015, 0, "", true); 132 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 1015, 0 , "", true, InspectorTest.finishBreakpointTest.bind(this, breakpointManager, nex t));
521 window.setBreakpointCallback = step2.bind(this);
522
523 function step2()
524 {
525 dumpBreakpointLocations(breakpointManager);
526 resetBreakpointManager(breakpointManager, step3);
527 }
528
529 function step3()
530 {
531 dumpBreakpointLocations(breakpointManager);
532 next();
533 }
534 }, 133 },
535 134
536 function testSetBreakpointThatShiftsTwice(next) 135 function testSetBreakpointThatShiftsTwice(next)
537 { 136 {
538 var breakpointManager = createBreakpointManager(); 137 var breakpointManager = createBreakpointManager();
539 var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); 138 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
540 setBreakpoint(breakpointManager, uiSourceCode, 1015, 0, "", true); 139 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 1015, 0 , "", true, step2);
541 window.setBreakpointCallback = step2.bind(this);
542 140
543 function step2() 141 function step2()
544 { 142 {
545 dumpBreakpointLocations(breakpointManager); 143 InspectorTest.dumpBreakpointLocations(breakpointManager);
546 setBreakpoint(breakpointManager, uiSourceCode, 1015, 0, "", true ); 144 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 101 5, 0, "", true, InspectorTest.finishBreakpointTest.bind(this, breakpointManager, next));
547 window.setBreakpointCallback = step3.bind(this);
548 }
549
550 function step3()
551 {
552 dumpBreakpointLocations(breakpointManager);
553 resetBreakpointManager(breakpointManager, step4);
554 }
555
556 function step4()
557 {
558 dumpBreakpointLocations(breakpointManager);
559 next();
560 } 145 }
561 }, 146 },
562 147
563 function testSetBreakpointOutsideScript(next) 148 function testSetBreakpointOutsideScript(next)
564 { 149 {
565 var breakpointManager = createBreakpointManager([]); 150 var breakpointManager = createBreakpointManager();
566 var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); 151 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
567 breakpointManager.setBreakpoint(uiSourceCode, 2500, 0, "", true); 152 breakpointManager.setBreakpoint(uiSourceCode, 2500, 0, "", true);
568 window.setBreakpointCallback = step2.bind(this); 153 window.setBreakpointCallback = InspectorTest.finishBreakpointTest.bi nd(this, breakpointManager, next);
569
570 function step2()
571 {
572 dumpBreakpointLocations(breakpointManager);
573 resetBreakpointManager(breakpointManager, step3);
574 }
575
576 function step3()
577 {
578 dumpBreakpointLocations(breakpointManager);
579 next();
580 }
581 }, 154 },
582 155
583 function testNavigation(next) 156 function testNavigation(next)
584 { 157 {
585 var breakpointManager = createBreakpointManager(serializedBreakpoint s); 158 var breakpointManager = createBreakpointManager(serializedBreakpoint s);
586 var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js"); 159 var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
587 window.setBreakpointCallback = step2.bind(this); 160 window.setBreakpointCallback = step2.bind(this);
588 161
589 function step2() 162 function step2()
590 { 163 {
591 dumpBreakpointLocations(breakpointManager); 164 InspectorTest.dumpBreakpointLocations(breakpointManager);
592 InspectorTest.addResult("\n Navigating to B."); 165 InspectorTest.addResult("\n Navigating to B.");
593 mockTarget.debuggerModel.reset(); 166 mockTarget.debuggerModel.reset();
594 resetWorkspace(breakpointManager); 167 resetWorkspace(breakpointManager);
595 var uiSourceCodeB = addUISourceCode(breakpointManager, "b.js"); 168 var uiSourceCodeB = addUISourceCode(breakpointManager, "b.js");
596 window.setBreakpointCallback = step3.bind(this); 169 window.setBreakpointCallback = step3.bind(this);
597 } 170 }
598 171
599 function step3() 172 function step3()
600 { 173 {
601 dumpBreakpointLocations(breakpointManager); 174 InspectorTest.dumpBreakpointLocations(breakpointManager);
602 InspectorTest.addResult("\n Navigating back to A."); 175 InspectorTest.addResult("\n Navigating back to A.");
603 mockTarget.debuggerModel.reset(); 176 mockTarget.debuggerModel.reset();
604 resetWorkspace(breakpointManager); 177 resetWorkspace(breakpointManager);
605 InspectorTest.addResult(" Resolving provisional breakpoint."); 178 InspectorTest.addResult(" Resolving provisional breakpoint.");
606 addTemporaryUISourceCode(breakpointManager, "a.js"); 179 addTemporaryUISourceCode(breakpointManager, "a.js");
607 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebI nspector.DebuggerModel.Location(mockTarget, "a.js", 11, 5)); 180 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebI nspector.DebuggerModel.Location(mockTarget, "a.js", 11, 5));
608 addUISourceCode(breakpointManager, "a.js"); 181 addUISourceCode(breakpointManager, "a.js");
609 window.setBreakpointCallback = step4.bind(this); 182 window.setBreakpointCallback = InspectorTest.finishBreakpointTes t.bind(this, breakpointManager, next);
610 }
611
612 function step4()
613 {
614 dumpBreakpointLocations(breakpointManager);
615 resetBreakpointManager(breakpointManager, step5);
616 }
617
618 function step5()
619 {
620 dumpBreakpointLocations(breakpointManager);
621 next();
622 } 183 }
623 }, 184 },
624 185
625 function testSourceMapping(next) 186 function testSourceMapping(next)
626 { 187 {
188 var shiftingMapping = {
189 rawLocationToUILocation: function(rawLocation)
190 {
191 if (this._disabled)
192 return null;
193 return InspectorTest.uiSourceCodes[rawLocation.scriptId].uiL ocation(rawLocation.lineNumber + 10, 0);
194 },
195
196 uiLocationToRawLocation: function(uiSourceCode, lineNumber)
197 {
198 return new WebInspector.DebuggerModel.Location(mockTarget, u iSourceCode.url, lineNumber - 10, 0);
199 },
200
201 isIdentity: function()
202 {
203 return false;
204 }
205 };
206
627 // Source mapping will shift everthing 10 lines ahead so that breakp oint 1 clashed with breakpoint 2. 207 // Source mapping will shift everthing 10 lines ahead so that breakp oint 1 clashed with breakpoint 2.
628 var serializedBreakpoints = []; 208 var serializedBreakpoints = [];
629 serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar" , true)); 209 serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar" , true));
630 serializedBreakpoints.push(createBreakpoint("a.js", 20, "", true)); 210 serializedBreakpoints.push(createBreakpoint("a.js", 20, "", true));
631 211
632 var breakpointManager = createBreakpointManager(serializedBreakpoint s); 212 var breakpointManager = createBreakpointManager(serializedBreakpoint s);
633 var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js"); 213 var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
634 window.setBreakpointCallback = step2.bind(this); 214 window.setBreakpointCallback = step2.bind(this);
635 215
636 function step2() 216 function step2()
637 { 217 {
638 window.setBreakpointCallback = step3.bind(this); 218 window.setBreakpointCallback = step3.bind(this);
639 } 219 }
640 220
641 function step3() 221 function step3()
642 { 222 {
643 dumpBreakpointLocations(breakpointManager); 223 InspectorTest.dumpBreakpointLocations(breakpointManager);
644 InspectorTest.addResult("\n Toggling source mapping."); 224 InspectorTest.addResult("\n Toggling source mapping.");
645 mockTarget.debuggerModel.pushSourceMapping(shiftingMapping); 225 mockTarget.debuggerModel.pushSourceMapping(shiftingMapping);
646 dumpBreakpointLocations(breakpointManager); 226 InspectorTest.dumpBreakpointLocations(breakpointManager);
647 InspectorTest.addResult("\n Toggling source mapping back."); 227 InspectorTest.addResult("\n Toggling source mapping back.");
648 mockTarget.debuggerModel.disableSourceMapping(shiftingMapping); 228 mockTarget.debuggerModel.disableSourceMapping(shiftingMapping);
649 dumpBreakpointLocations(breakpointManager); 229 InspectorTest.finishBreakpointTest(breakpointManager, next);
650 resetBreakpointManager(breakpointManager, step4);
651 } 230 }
652 231
653 function step4()
654 {
655 dumpBreakpointLocations(breakpointManager);
656 next();
657 }
658 }, 232 },
659 233
660 function testProvisionalBreakpointsResolve(next) 234 function testProvisionalBreakpointsResolve(next)
661 { 235 {
662 var serializedBreakpoints = []; 236 var serializedBreakpoints = [];
663 serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar" , true)); 237 serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar" , true));
664 238
665 var breakpointManager = createBreakpointManager(serializedBreakpoint s); 239 var breakpointManager = createBreakpointManager(serializedBreakpoint s);
666 var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); 240 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
667 window.setBreakpointCallback = step2.bind(this); 241 window.setBreakpointCallback = step2.bind(this);
668 242
669 function step2() 243 function step2()
670 { 244 {
671 dumpBreakpointLocations(breakpointManager); 245 InspectorTest.dumpBreakpointLocations(breakpointManager);
672 mockTarget.debuggerModel.reset(); 246 mockTarget.debuggerModel.reset();
673 resetWorkspace(breakpointManager); 247 resetWorkspace(breakpointManager);
674 InspectorTest.addResult(" Resolving provisional breakpoint."); 248 InspectorTest.addResult(" Resolving provisional breakpoint.");
675 addTemporaryUISourceCode(breakpointManager, "a.js"); 249 addTemporaryUISourceCode(breakpointManager, "a.js");
676 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebI nspector.DebuggerModel.Location(mockTarget, "a.js", 11, 5)); 250 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebI nspector.DebuggerModel.Location(mockTarget, "a.js", 11, 5));
677 var breakpoints = breakpointManager.allBreakpoints(); 251 var breakpoints = breakpointManager.allBreakpoints();
678 InspectorTest.assertEquals(breakpoints.length, 1, "Exactly one p rovisional breakpoint should be registered in breakpoint manager."); 252 InspectorTest.assertEquals(breakpoints.length, 1, "Exactly one p rovisional breakpoint should be registered in breakpoint manager.");
679 dumpBreakpointLocations(breakpointManager); 253 InspectorTest.finishBreakpointTest(breakpointManager, next);
680 resetBreakpointManager(breakpointManager, step3);
681 }
682
683 function step3()
684 {
685 dumpBreakpointLocations(breakpointManager);
686 next();
687 } 254 }
688 }, 255 },
689 256
690 function testSourceMappingReload(next) 257 function testSourceMappingReload(next)
691 { 258 {
259 function createSourceMapping(uiSourceCodeA, uiSourceCodeB)
260 {
261 var mapping = {
262 rawLocationToUILocation: function(rawLocation)
263 {
264 if (this._disabled)
265 return null;
266 return uiSourceCodeB.uiLocation(rawLocation.lineNumber + 10, 0);
267 },
268
269 uiLocationToRawLocation: function(uiSourceCode, lineNumber)
270 {
271 return new WebInspector.DebuggerModel.Location(mockTarge t, uiSourceCodeA.url, lineNumber - 10, 0);
272 },
273
274 isIdentity: function()
275 {
276 return false;
277 }
278 };
279
280 return mapping;
281 }
692 // Source mapping will shift everthing 10 lines ahead. 282 // Source mapping will shift everthing 10 lines ahead.
693 var serializedBreakpoints = [createBreakpoint("b.js", 20, "foo == ba r", true)]; 283 var serializedBreakpoints = [createBreakpoint("b.js", 20, "foo == ba r", true)];
694 var breakpointManager = createBreakpointManager(serializedBreakpoint s); 284 var breakpointManager = createBreakpointManager(serializedBreakpoint s);
695 InspectorTest.addResult("\n Adding files:"); 285 InspectorTest.addResult("\n Adding files:");
696 var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js"); 286 var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
697 var uiSourceCodeB = addUISourceCode(breakpointManager, "b.js", true, true); 287 var uiSourceCodeB = addUISourceCode(breakpointManager, "b.js", true, true);
698 288
699 InspectorTest.addResult("\n Toggling source mapping."); 289 InspectorTest.addResult("\n Toggling source mapping.");
700 var sourceMapping = createSourceMapping(uiSourceCodeA, uiSourceCodeB ); 290 var sourceMapping = createSourceMapping(uiSourceCodeA, uiSourceCodeB );
701 mockTarget.debuggerModel.pushSourceMapping(sourceMapping); 291 mockTarget.debuggerModel.pushSourceMapping(sourceMapping);
702 window.setBreakpointCallback = provisionalBreakpointSet.bind(this); 292 window.setBreakpointCallback = provisionalBreakpointSet.bind(this);
703 uiSourceCodeB.setSourceMappingForTarget(mockTarget, sourceMapping); 293 uiSourceCodeB.setSourceMappingForTarget(mockTarget, sourceMapping);
704 294
705 function provisionalBreakpointSet() 295 function provisionalBreakpointSet()
706 { 296 {
707 window.setBreakpointCallback = step2.bind(this); 297 window.setBreakpointCallback = step2.bind(this);
708 } 298 }
709 299
710 function step2() 300 function step2()
711 { 301 {
712 dumpBreakpointLocations(breakpointManager); 302 InspectorTest.dumpBreakpointLocations(breakpointManager);
713 InspectorTest.addResult("\n Reloading:"); 303 InspectorTest.addResult("\n Reloading:");
714 mockTarget.debuggerModel.reset(); 304 mockTarget.debuggerModel.reset();
715 resetWorkspace(breakpointManager); 305 resetWorkspace(breakpointManager);
716 306
717 InspectorTest.addResult("\n Adding files:"); 307 InspectorTest.addResult("\n Adding files:");
718 addTemporaryUISourceCode(breakpointManager, "a.js"); 308 addTemporaryUISourceCode(breakpointManager, "a.js");
719 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebI nspector.DebuggerModel.Location(mockTarget, "a.js", 10, 5)); 309 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebI nspector.DebuggerModel.Location(mockTarget, "a.js", 10, 5));
720 uiSourceCodeA = addUISourceCode(breakpointManager, "a.js"); 310 uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
721 uiSourceCodeB = addUISourceCode(breakpointManager, "b.js", true, true); 311 uiSourceCodeB = addUISourceCode(breakpointManager, "b.js", true, true);
722 312
723 InspectorTest.addResult("\n Toggling source mapping."); 313 InspectorTest.addResult("\n Toggling source mapping.");
724 var sourceMapping = createSourceMapping(uiSourceCodeA, uiSourceC odeB); 314 var sourceMapping = createSourceMapping(uiSourceCodeA, uiSourceC odeB);
725 mockTarget.debuggerModel.pushSourceMapping(sourceMapping); 315 mockTarget.debuggerModel.pushSourceMapping(sourceMapping);
726 window.setBreakpointCallback = provisionalBreakpointSetAfterRelo ad.bind(this); 316 window.setBreakpointCallback = provisionalBreakpointSetAfterRelo ad.bind(this);
727 uiSourceCodeB.setSourceMappingForTarget(mockTarget, sourceMappin g); 317 uiSourceCodeB.setSourceMappingForTarget(mockTarget, sourceMappin g);
728 } 318 }
729 319
730 function provisionalBreakpointSetAfterReload() 320 function provisionalBreakpointSetAfterReload()
731 { 321 {
732 window.setBreakpointCallback = step3.bind(this); 322 window.setBreakpointCallback = InspectorTest.finishBreakpointTes t.bind(this, breakpointManager, next);
733 } 323 }
734 324
735 function step3()
736 {
737 dumpBreakpointLocations(breakpointManager);
738 resetBreakpointManager(breakpointManager, step4);
739 }
740
741 function step4()
742 {
743 dumpBreakpointLocations(breakpointManager);
744 next();
745 }
746 }, 325 },
747 326
748 function testBreakpointInCollectedReload(next) 327 function testBreakpointInCollectedReload(next)
749 { 328 {
750 var breakpointManager = createBreakpointManager(); 329 var breakpointManager = createBreakpointManager();
751 InspectorTest.addResult("\n Adding file without script:"); 330 InspectorTest.addResult("\n Adding file without script:");
752 var uiSourceCode = addUISourceCode(breakpointManager, "a.js", true, true); 331 var uiSourceCode = addUISourceCode(breakpointManager, "a.js", true, true);
753 332
754 InspectorTest.addResult("\n Setting breakpoint:"); 333 InspectorTest.addResult("\n Setting breakpoint:");
755 setBreakpoint(breakpointManager, uiSourceCode, 10, 0, "", true); 334 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 10, 0, "", true, step2);
756 window.setBreakpointCallback = step2.bind(this);
757 335
758 function step2() 336 function step2()
759 { 337 {
760 dumpBreakpointLocations(breakpointManager); 338 InspectorTest.dumpBreakpointLocations(breakpointManager);
761 InspectorTest.addResult("\n Reloading:"); 339 InspectorTest.addResult("\n Reloading:");
762 mockTarget.debuggerModel.reset(); 340 mockTarget.debuggerModel.reset();
763 resetWorkspace(breakpointManager); 341 resetWorkspace(breakpointManager);
764 342
765 InspectorTest.addResult("\n Adding file with script:"); 343 InspectorTest.addResult("\n Adding file with script:");
766 var uiSourceCode = addUISourceCode(breakpointManager, "a.js"); 344 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
767 345
768 InspectorTest.addResult("\n Emulating breakpoint resolved event :"); 346 InspectorTest.addResult("\n Emulating breakpoint resolved event :");
769 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebI nspector.DebuggerModel.Location(mockTarget, "a.js", 10, 5)); 347 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebI nspector.DebuggerModel.Location(mockTarget, "a.js", 10, 5));
770 348
771 InspectorTest.addResult("\n Waiting for breakpoint to be set in debugger again:"); 349 InspectorTest.addResult("\n Waiting for breakpoint to be set in debugger again:");
772 window.setBreakpointCallback = step3.bind(this); 350 window.setBreakpointCallback = InspectorTest.finishBreakpointTes t.bind(this, breakpointManager, next);
773 }
774
775 function step3()
776 {
777 dumpBreakpointLocations(breakpointManager);
778 resetBreakpointManager(breakpointManager, step4);
779 }
780
781 function step4()
782 {
783 dumpBreakpointLocations(breakpointManager);
784 next();
785 } 351 }
786 }, 352 },
787 ]); 353 ]);
788 }; 354 };
789 355
790 </script> 356 </script>
791 357
792 </head> 358 </head>
793 359
794 <body onload="runTest()"> 360 <body onload="runTest()">
795 <p>Tests BreakpointManager class.</p> 361 <p>Tests BreakpointManager class.</p>
796 362
797 </body> 363 </body>
798 </html> 364 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/inspector/sources/debugger/breakpoint-manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698