Upstream version 11.40.277.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 <script src="../../../http/tests/inspector/workspace-test.js"></script>
5 <script src="breakpoint-manager.js"></script>
6
7 <script>
8
9 function test()
10 {
11     var mockTarget;
12     function resetWorkspace(breakpointManager)
13     {
14         mockTarget.debuggerModel.reset();
15         InspectorTest.addResult("  Resetting workspace.");
16         breakpointManager._debuggerWorkspaceBinding._reset(mockTarget);
17         breakpointManager._debuggerWorkspaceBinding._networkWorkspaceBinding.reset();
18     }
19
20     function createWorkspace()
21     {
22         InspectorTest.createWorkspace(true);
23         mockTarget = InspectorTest.createMockTarget(1);
24         InspectorTest.testTargetManager.addTarget(mockTarget);
25     }
26
27     function createBreakpoint(uiSourceCodeId, lineNumber, condition, enabled)
28     {
29         return { sourceFileId: uiSourceCodeId, lineNumber: lineNumber, condition: condition, enabled: enabled };
30     }
31
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));
36
37     createWorkspace();
38     InspectorTest.setupLiveLocationSniffers();
39
40     var addUISourceCode = function() {
41         var args = [mockTarget].concat(Array.prototype.slice.call(arguments));
42         return InspectorTest.addUISourceCode.apply(null, args);
43     }
44     var createBreakpointManager = function(serializedBreakpoints) {
45         return InspectorTest.createBreakpointManager(InspectorTest.testTargetManager, InspectorTest.testDebuggerWorkspaceBinding, serializedBreakpoints);
46     }
47
48     InspectorTest.runTestSuite([
49         function testSetBreakpoint(next)
50         {
51             var breakpointManager = createBreakpointManager();
52             var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
53             InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true);
54             InspectorTest.finishBreakpointTest(breakpointManager, next);
55         },
56
57         function testSetDisabledBreakpoint(next)
58         {
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);
67         },
68
69         function testSetConditionalBreakpoint(next)
70         {
71             var breakpointManager = createBreakpointManager();
72             var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
73             var breakpoint = InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "condition", true, step2);
74
75             function step2()
76             {
77                 InspectorTest.dumpBreakpointLocations(breakpointManager);
78                 InspectorTest.dumpBreakpointStorage(breakpointManager);
79                 InspectorTest.addResult("  Updating condition");
80                 breakpoint.setCondition("");
81                 InspectorTest.finishBreakpointTest(breakpointManager, next);
82             }
83         },
84
85         function testRestoreBreakpoints(next)
86         {
87             createWorkspace();
88             var breakpointManager = createBreakpointManager(serializedBreakpoints);
89             addUISourceCode(breakpointManager, "a.js");
90             InspectorTest.finishBreakpointTest(breakpointManager, next);
91         },
92
93         function testRestoreBreakpointsTwice(next)
94         {
95             createWorkspace();
96             var breakpointManager = createBreakpointManager(serializedBreakpoints);
97             addUISourceCode(breakpointManager, "a.js");
98             addUISourceCode(breakpointManager, "a.js");
99             InspectorTest.finishBreakpointTest(breakpointManager, next);
100         },
101
102         function testRemoveBreakpoints(next)
103         {
104             createWorkspace();
105             var breakpointManager = createBreakpointManager(serializedBreakpoints);
106             var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
107             window.setBreakpointCallback = step2.bind(this);
108
109             function step2()
110             {
111                 InspectorTest.dumpBreakpointLocations(breakpointManager);
112                 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true, step3);
113             }
114
115             function step3()
116             {
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);
122             }
123         },
124
125         function testSetBreakpointThatShifts(next)
126         {
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);
132         },
133
134         function testSetBreakpointThatShiftsTwice(next)
135         {
136             createWorkspace();
137             var breakpointManager = createBreakpointManager();
138             var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
139             InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 1015, 0, "", true, step2);
140
141             function step2()
142             {
143                 InspectorTest.dumpBreakpointLocations(breakpointManager);
144                 InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 1015, 0, "", true);
145                 InspectorTest.finishBreakpointTest(breakpointManager, next);
146             }
147         },
148
149         function testSetBreakpointOutsideScript(next)
150         {
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);
156        },
157
158         function testNavigation(next)
159         {
160             createWorkspace();
161             var breakpointManager = createBreakpointManager(serializedBreakpoints);
162             var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
163             window.setBreakpointCallback = step2.bind(this);
164
165             function step2()
166             {
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);
172             }
173
174             function step3()
175             {
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, "a.js", 10, 0));
182                 addUISourceCode(breakpointManager, "a.js", false, true);
183                 InspectorTest.finishBreakpointTest(breakpointManager, next);
184             }
185         },
186
187         function testSourceMapping(next)
188         {
189             var shiftingMapping = {
190                 rawLocationToUILocation: function(rawLocation)
191                 {
192                     if (this._disabled)
193                         return null;
194                     return InspectorTest.uiSourceCodes[rawLocation.scriptId].uiLocation(rawLocation.lineNumber + 10, 0);
195                 },
196
197                 uiLocationToRawLocation: function(uiSourceCode, lineNumber)
198                 {
199                     return new WebInspector.DebuggerModel.Location(mockTarget, uiSourceCode.url, lineNumber - 10, 0);
200                 },
201
202                 isIdentity: function()
203                 {
204                     return false;
205                 }
206             };
207
208             // Source mapping will shift everything 10 lines ahead so that breakpoint 1 clashes with breakpoint 2.
209             var serializedBreakpoints = [];
210             serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true));
211             serializedBreakpoints.push(createBreakpoint("a.js", 20, "", true));
212
213             createWorkspace();
214             var breakpointManager = createBreakpointManager(serializedBreakpoints);
215             var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
216             window.setBreakpointCallback = step2.bind(this);
217
218             function step2()
219             {
220                 window.setBreakpointCallback = step3.bind(this);
221             }
222
223             function step3()
224             {
225                 InspectorTest.dumpBreakpointLocations(breakpointManager);
226                 InspectorTest.addResult("\n  Toggling source mapping.");
227                 mockTarget.debuggerModel.pushSourceMapping(shiftingMapping);
228                 InspectorTest.dumpBreakpointLocations(breakpointManager);
229                 InspectorTest.addResult("\n  Toggling source mapping back.");
230                 mockTarget.debuggerModel.disableSourceMapping(shiftingMapping);
231                 InspectorTest.finishBreakpointTest(breakpointManager, next);
232             }
233
234         },
235
236         function testProvisionalBreakpointsResolve(next)
237         {
238             var serializedBreakpoints = [];
239             serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true));
240
241             createWorkspace();
242             var breakpointManager = createBreakpointManager(serializedBreakpoints);
243             var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
244             window.setBreakpointCallback = step2.bind(this);
245
246             function step2()
247             {
248                 InspectorTest.dumpBreakpointLocations(breakpointManager);
249                 resetWorkspace(breakpointManager);
250                 InspectorTest.addResult("  Resolving provisional breakpoint.");
251                 InspectorTest.addScript(mockTarget, breakpointManager, "a.js");
252                 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebInspector.DebuggerModel.Location(mockTarget, "a.js", 11, 0));
253                 var breakpoints = breakpointManager.allBreakpoints();
254                 InspectorTest.assertEquals(1, breakpoints.length, "Exactly one provisional breakpoint should be registered in breakpoint manager.");
255                 InspectorTest.finishBreakpointTest(breakpointManager, next);
256             }
257         },
258
259         function testSourceMappingReload(next)
260         {
261             function createSourceMapping(uiSourceCodeA, uiSourceCodeB)
262             {
263                 var mapping = {
264                     rawLocationToUILocation: function(rawLocation)
265                     {
266                         if (this._disabled)
267                             return null;
268                         return uiSourceCodeB.uiLocation(rawLocation.lineNumber + 10, 0);
269                     },
270
271                     uiLocationToRawLocation: function(uiSourceCode, lineNumber)
272                     {
273                         return new WebInspector.DebuggerModel.Location(mockTarget, uiSourceCodeA.url, lineNumber - 10, 0);
274                     },
275
276                     isIdentity: function()
277                     {
278                         return false;
279                     }
280                 };
281
282                 return mapping;
283             }
284             // Source mapping will shift everything 10 lines ahead.
285             var serializedBreakpoints = [createBreakpoint("b.js", 20, "foo == bar", true)];
286             createWorkspace();
287             var breakpointManager = createBreakpointManager(serializedBreakpoints);
288             InspectorTest.addResult("\n  Adding files:");
289             var uiSourceCodeA = addUISourceCode(breakpointManager, "a.js");
290             var uiSourceCodeB = addUISourceCode(breakpointManager, "b.js", true, true);
291
292             InspectorTest.addResult("\n  Toggling source mapping.");
293             var sourceMapping = createSourceMapping(uiSourceCodeA, uiSourceCodeB);
294             mockTarget.debuggerModel.pushSourceMapping(sourceMapping);
295             breakpointManager._debuggerWorkspaceBinding.setSourceMapping(mockTarget, uiSourceCodeB, sourceMapping);
296             InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, breakpointActionsPerformedBeforeReload.bind(this));
297
298             function breakpointActionsPerformedBeforeReload()
299             {
300                 InspectorTest.dumpBreakpointLocations(breakpointManager);
301                 InspectorTest.addResult("\n  Reloading:");
302                 resetWorkspace(breakpointManager);
303
304                 InspectorTest.addResult("\n  Adding files:");
305                 InspectorTest.addScript(mockTarget, breakpointManager, "a.js");
306                 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebInspector.DebuggerModel.Location(mockTarget, "a.js", 10, 0));
307                 uiSourceCodeA = addUISourceCode(breakpointManager, "a.js", false, true);
308                 uiSourceCodeB = addUISourceCode(breakpointManager, "b.js", true, true);
309
310                 InspectorTest.addResult("\n  Toggling source mapping.");
311                 var sourceMapping = createSourceMapping(uiSourceCodeA, uiSourceCodeB);
312                 mockTarget.debuggerModel.pushSourceMapping(sourceMapping);
313                 breakpointManager._debuggerWorkspaceBinding.setSourceMapping(mockTarget, uiSourceCodeB, sourceMapping);
314                 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, breakpointActionsPerformed.bind(this));
315             }
316
317             function breakpointActionsPerformed()
318             {
319                 InspectorTest.finishBreakpointTest(breakpointManager, next);
320             }
321         },
322
323         function testBreakpointInCollectedReload(next)
324         {
325             createWorkspace();
326             var breakpointManager = createBreakpointManager();
327             InspectorTest.addResult("\n  Adding file without script:");
328             var uiSourceCode = addUISourceCode(breakpointManager, "a.js", true, true);
329
330             InspectorTest.addResult("\n  Setting breakpoint:");
331             InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 10, 0, "", true, step2);
332
333             function step2()
334             {
335                 InspectorTest.dumpBreakpointLocations(breakpointManager);
336                 InspectorTest.addResult("\n  Reloading:");
337                 resetWorkspace(breakpointManager);
338
339                 InspectorTest.addResult("\n  Adding file with script:");
340                 var uiSourceCode = addUISourceCode(breakpointManager, "a.js");
341
342                 InspectorTest.addResult("\n  Emulating breakpoint resolved event:");
343                 mockTarget.debuggerModel._breakpointResolved("a.js:10", new WebInspector.DebuggerModel.Location(mockTarget, "a.js", 10, 0));
344
345                 InspectorTest.addResult("\n  Make sure we don't do any unnecessary breakpoint actions:");
346                 InspectorTest.runAfterPendingBreakpointUpdates(breakpointManager, breakpointActionsPerformed.bind(this));
347
348                 function breakpointActionsPerformed()
349                 {
350                     InspectorTest.finishBreakpointTest(breakpointManager, next);
351                 }
352             }
353         },
354     ]);
355 };
356 </script>
357
358 </head>
359
360 <body onload="runTest()">
361 <p>Tests BreakpointManager class.</p>
362
363 </body>
364 </html>