Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / sources / debugger-breakpoints / breakpoint-manager.html
blob890f71adf69d73a315297f87257849d4321a2e2a
1 <html>
2 <head>
3 <script src="../../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../../http/tests/inspector/workspace-test.js"></script>
5 <script src="breakpoint-manager.js"></script>
7 <script>
9 function test()
11 var mockTarget;
13 function createWorkspace()
15 InspectorTest.createWorkspace(true);
16 mockTarget = InspectorTest.createMockTarget(1, InspectorTest.DebuggerModelMock);
19 function resetWorkspace(breakpointManager)
21 mockTarget.debuggerModel.reset();
22 InspectorTest.addResult(" Resetting workspace.");
23 breakpointManager._debuggerWorkspaceBinding._reset(mockTarget);
24 InspectorTest.testNetworkProject._reset();
27 function createBreakpoint(uiSourceCodeId, lineNumber, condition, enabled)
29 return { sourceFileId: uiSourceCodeId, lineNumber: lineNumber, condition: condition, enabled: enabled };
32 var serializedBreakpoints = [];
33 serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true));
34 serializedBreakpoints.push(createBreakpoint("a.js", 20, "", false));
35 serializedBreakpoints.push(createBreakpoint("b.js", 3, "", true));
37 createWorkspace();
38 InspectorTest.setupLiveLocationSniffers();
40 var addUISourceCode = function() {
41 var args = [mockTarget].concat(Array.prototype.slice.call(arguments));
42 return InspectorTest.addUISourceCode.apply(null, args);
44 var createBreakpointManager = function(serializedBreakpoints) {
45 return InspectorTest.createBreakpointManager(InspectorTest.testTargetManager, InspectorTest.testDebuggerWorkspaceBinding, serializedBreakpoints);
48 InspectorTest.runTestSuite([
49 function testSetBreakpoint(next)
51 var breakpointManager = createBreakpointManager();
52 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
53 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true);
54 InspectorTest.finishBreakpointTest(breakpointManager, next);
57 function testSetDisabledBreakpoint(next)
59 var breakpointManager = createBreakpointManager();
60 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
61 var breakpoint = InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", false);
62 InspectorTest.dumpBreakpointLocations(breakpointManager);
63 InspectorTest.dumpBreakpointStorage(breakpointManager);
64 InspectorTest.addResult(" Enabling breakpoint");
65 breakpoint.setEnabled(true);
66 InspectorTest.finishBreakpointTest(breakpointManager, next);
69 function testSetConditionalBreakpoint(next)
71 var breakpointManager = createBreakpointManager();
72 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
73 var breakpoint = InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "condition", true, step2);
75 function step2()
77 InspectorTest.dumpBreakpointLocations(breakpointManager);
78 InspectorTest.dumpBreakpointStorage(breakpointManager);
79 InspectorTest.addResult(" Updating condition");
80 breakpoint.setCondition("");
81 InspectorTest.finishBreakpointTest(breakpointManager, next);
85 function testRestoreBreakpoints(next)
87 createWorkspace();
88 var breakpointManager = createBreakpointManager(serializedBreakpoints);
89 addUISourceCode(breakpointManager, "a.js");
90 InspectorTest.finishBreakpointTest(breakpointManager, next);
93 function testRestoreBreakpointsTwice(next)
95 createWorkspace();
96 var breakpointManager = createBreakpointManager(serializedBreakpoints);
97 addUISourceCode(breakpointManager, "a.js");
98 addUISourceCode(breakpointManager, "a.js");
99 InspectorTest.finishBreakpointTest(breakpointManager, next);
102 function testRemoveBreakpoints(next)
104 createWorkspace();
105 var breakpointManager = createBreakpointManager(serializedBreakpoints);
106 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
107 window.setBreakpointCallback = step2.bind(this);
109 function step2()
111 InspectorTest.dumpBreakpointLocations(breakpointManager);
112 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true, step3);
115 function step3()
117 InspectorTest.dumpBreakpointLocations(breakpointManager);
118 InspectorTest.removeBreakpoint(breakpointManager, uiSourceCode, 30, 0);
119 InspectorTest.removeBreakpoint(breakpointManager, uiSourceCode, 10, 0);
120 InspectorTest.removeBreakpoint(breakpointManager, uiSourceCode, 20, 0);
121 InspectorTest.finishBreakpointTest(breakpointManager, next);
125 function testSetBreakpointThatShifts(next)
127 createWorkspace();
128 var breakpointManager = createBreakpointManager();
129 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
130 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 1015, 0, "", true);
131 InspectorTest.finishBreakpointTest(breakpointManager, next);
134 function testSetBreakpointThatShiftsTwice(next)
136 createWorkspace();
137 var breakpointManager = createBreakpointManager();
138 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
139 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 1015, 0, "", true, step2);
141 function step2()
143 InspectorTest.dumpBreakpointLocations(breakpointManager);
144 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 1015, 0, "", true);
145 InspectorTest.finishBreakpointTest(breakpointManager, next);
149 function testSetBreakpointOutsideScript(next)
151 createWorkspace();
152 var breakpointManager = createBreakpointManager();
153 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
154 breakpointManager.setBreakpoint(uiSourceCode, 2500, 0, "", true);
155 InspectorTest.finishBreakpointTest(breakpointManager, next);
158 function testNavigation(next)
160 createWorkspace();
161 var breakpointManager = createBreakpointManager(serializedBreakpoints);
162 var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
163 window.setBreakpointCallback = step2.bind(this);
165 function step2()
167 InspectorTest.dumpBreakpointLocations(breakpointManager);
168 InspectorTest.addResult("\n Navigating to B.");
169 resetWorkspace(breakpointManager);
170 var uiSourceCodeB = addUISourceCode(breakpointManager, "b.js");
171 window.setBreakpointCallback = step3.bind(this);
174 function step3()
176 InspectorTest.dumpBreakpointLocations(breakpointManager);
177 InspectorTest.addResult("\n Navigating back to A.");
178 resetWorkspace(breakpointManager);
179 InspectorTest.addResult(" Resolving provisional breakpoint.");
180 InspectorTest.addScript(mockTarget, breakpointManager, "a.js");
181 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebInspector.DebuggerModel.Location(mockTarget.debuggerModel, "a.js", 10, 0));
182 addUISourceCode(breakpointManager, "a.js", false, true);
183 InspectorTest.finishBreakpointTest(breakpointManager, next);
187 function testSourceMapping(next)
189 var shiftingMapping = {
190 rawLocationToUILocation: function(rawLocation)
192 if (this._disabled)
193 return null;
194 return InspectorTest.uiSourceCodes[rawLocation.scriptId].uiLocation(rawLocation.lineNumber + 10, 0);
197 uiLocationToRawLocation: function(uiSourceCode, lineNumber)
199 var networkURL = InspectorTest.testNetworkMapping.networkURL(uiSourceCode);
200 return new WebInspector.DebuggerModel.Location(mockTarget.debuggerModel, networkURL, lineNumber - 10, 0);
203 isIdentity: function()
205 return false;
209 // Source mapping will shift everything 10 lines ahead so that breakpoint 1 clashes with breakpoint 2.
210 var serializedBreakpoints = [];
211 serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true));
212 serializedBreakpoints.push(createBreakpoint("a.js", 20, "", true));
214 createWorkspace();
215 var breakpointManager = createBreakpointManager(serializedBreakpoints);
216 var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
217 window.setBreakpointCallback = step2.bind(this);
219 function step2()
221 window.setBreakpointCallback = step3.bind(this);
224 function step3()
226 InspectorTest.dumpBreakpointLocations(breakpointManager);
227 InspectorTest.addResult("\n Toggling source mapping.");
228 mockTarget.debuggerModel.pushSourceMapping(shiftingMapping);
229 InspectorTest.dumpBreakpointLocations(breakpointManager);
230 InspectorTest.addResult("\n Toggling source mapping back.");
231 mockTarget.debuggerModel.disableSourceMapping(shiftingMapping);
232 InspectorTest.finishBreakpointTest(breakpointManager, next);
237 function testProvisionalBreakpointsResolve(next)
239 var serializedBreakpoints = [];
240 serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true));
242 createWorkspace();
243 var breakpointManager = createBreakpointManager(serializedBreakpoints);
244 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
245 window.setBreakpointCallback = step2.bind(this);
247 function step2()
249 InspectorTest.dumpBreakpointLocations(breakpointManager);
250 resetWorkspace(breakpointManager);
251 InspectorTest.addResult(" Resolving provisional breakpoint.");
252 InspectorTest.addScript(mockTarget, breakpointManager, "a.js");
253 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebInspector.DebuggerModel.Location(mockTarget.debuggerModel, "a.js", 11, 0));
254 var breakpoints = breakpointManager.allBreakpoints();
255 InspectorTest.assertEquals(1, breakpoints.length, "Exactly one provisional breakpoint should be registered in breakpoint manager.");
256 InspectorTest.finishBreakpointTest(breakpointManager, next);
260 function testSourceMappingReload(next)
262 function createSourceMapping(uiSourceCodeA, uiSourceCodeB)
264 var mapping = {
265 rawLocationToUILocation: function(rawLocation)
267 if (this._disabled)
268 return null;
269 return uiSourceCodeB.uiLocation(rawLocation.lineNumber + 10, 0);
272 uiLocationToRawLocation: function(uiSourceCode, lineNumber)
274 var networkURL = InspectorTest.testNetworkMapping.networkURL(uiSourceCodeA);
275 return new WebInspector.DebuggerModel.Location(mockTarget.debuggerModel, networkURL, lineNumber - 10, 0);
278 isIdentity: function()
280 return false;
284 return mapping;
286 // Source mapping will shift everything 10 lines ahead.
287 var serializedBreakpoints = [createBreakpoint("b.js", 20, "foo == bar", true)];
288 createWorkspace();
289 var breakpointManager = createBreakpointManager(serializedBreakpoints);
290 InspectorTest.addResult("\n Adding files:");
291 var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
292 var uiSourceCodeB = addUISourceCode(breakpointManager, "b.js", true, true);
294 InspectorTest.addResult("\n Toggling source mapping.");
295 var sourceMapping = createSourceMapping(uiSourceCodeA, uiSourceCodeB);
296 mockTarget.debuggerModel.pushSourceMapping(sourceMapping);
297 breakpointManager._debuggerWorkspaceBinding.setSourceMapping(mockTarget, uiSourceCodeB, sourceMapping);
298 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, breakpointActionsPerformedBeforeReload.bind(this));
300 function breakpointActionsPerformedBeforeReload()
302 InspectorTest.dumpBreakpointLocations(breakpointManager);
303 InspectorTest.addResult("\n Reloading:");
304 resetWorkspace(breakpointManager);
306 InspectorTest.addResult("\n Adding files:");
307 InspectorTest.addScript(mockTarget, breakpointManager, "a.js");
308 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebInspector.DebuggerModel.Location(mockTarget.debuggerModel, "a.js", 10, 0));
309 uiSourceCodeA = addUISourceCode(breakpointManager, "a.js", false, true);
310 uiSourceCodeB = addUISourceCode(breakpointManager, "b.js", true, true);
312 InspectorTest.addResult("\n Toggling source mapping.");
313 var sourceMapping = createSourceMapping(uiSourceCodeA, uiSourceCodeB);
314 mockTarget.debuggerModel.pushSourceMapping(sourceMapping);
315 breakpointManager._debuggerWorkspaceBinding.setSourceMapping(mockTarget, uiSourceCodeB, sourceMapping);
316 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, breakpointActionsPerformed.bind(this));
319 function breakpointActionsPerformed()
321 InspectorTest.finishBreakpointTest(breakpointManager, next);
325 function testBreakpointInCollectedReload(next)
327 createWorkspace();
328 var breakpointManager = createBreakpointManager();
329 InspectorTest.addResult("\n Adding file without script:");
330 var uiSourceCode = addUISourceCode(breakpointManager, "a.js", true, true);
332 InspectorTest.addResult("\n Setting breakpoint:");
333 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 10, 0, "", true, step2);
335 function step2()
337 InspectorTest.dumpBreakpointLocations(breakpointManager);
338 InspectorTest.addResult("\n Reloading:");
339 resetWorkspace(breakpointManager);
341 InspectorTest.addResult("\n Adding file with script:");
342 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
344 InspectorTest.addResult("\n Emulating breakpoint resolved event:");
345 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebInspector.DebuggerModel.Location(mockTarget.debuggerModel, "a.js", 10, 0));
347 InspectorTest.addResult("\n Make sure we don't do any unnecessary breakpoint actions:");
348 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, breakpointActionsPerformed.bind(this));
350 function breakpointActionsPerformed()
352 InspectorTest.finishBreakpointTest(breakpointManager, next);
358 </script>
360 </head>
362 <body onload="runTest()">
363 <p>Tests BreakpointManager class.</p>
365 </body>
366 </html>