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