OLD | NEW |
---|---|
(Empty) | |
1 var initialize_BreakpointManagerTest = function() { | |
2 | |
3 InspectorTest.uiSourceCodes = {}; | |
4 | |
5 InspectorTest.initializeDefaultMappingOn = function (target) { | |
vsevik
2014/06/09 15:27:11
...OnTarget
sergeyv
2014/06/10 08:56:48
Done.
| |
6 var defaultMapping = { | |
7 rawLocationToUILocation: function(rawLocation) | |
8 { | |
9 return InspectorTest.uiSourceCodes[rawLocation.scriptId].uiLocation( rawLocation.lineNumber, 0); | |
10 }, | |
11 | |
12 uiLocationToRawLocation: function(uiSourceCode, lineNumber) | |
13 { | |
14 if (!InspectorTest.uiSourceCodes[uiSourceCode.url]) | |
15 return null; | |
16 return new WebInspector.DebuggerModel.Location(target, uiSourceCode. url, lineNumber, 0); | |
17 }, | |
18 | |
19 isIdentity: function() | |
20 { | |
21 return true; | |
22 } | |
23 }; | |
24 | |
25 target.defaultMapping = defaultMapping; | |
26 } | |
27 | |
28 InspectorTest.DebuggerModelMock = function (target, sourceMapping) | |
29 { | |
30 target.debuggerModel = this; | |
31 this._target = target; | |
32 this._breakpointResolvedEventTarget = new WebInspector.Object(); | |
33 this._scripts = {}; | |
34 this._sourceMapping = sourceMapping; | |
35 this._breakpoints = {}; | |
36 } | |
37 | |
38 InspectorTest.DebuggerModelMock.prototype = { | |
39 target: function() | |
40 { | |
41 return this._target; | |
42 }, | |
43 | |
44 _addScript: function(scriptId, url) | |
45 { | |
46 this._scripts[scriptId] = new WebInspector.Script(this._target, scriptId , url); | |
47 this._scripts[scriptId].pushSourceMapping(this._sourceMapping); | |
48 }, | |
49 | |
50 _scriptForURL: function(url) | |
51 { | |
52 for (var scriptId in this._scripts) { | |
53 var script = this._scripts[scriptId]; | |
54 if (script.sourceURL === url) | |
55 return script; | |
56 } | |
57 }, | |
58 | |
59 _scheduleSetBeakpointCallback: function(callback, breakpointId, locations) | |
60 { | |
61 setTimeout(innerCallback.bind(this), 0); | |
62 | |
63 function innerCallback() | |
64 { | |
65 if (callback) | |
66 callback(breakpointId, locations); | |
67 if (window.setBreakpointCallback) { | |
68 var savedCallback = window.setBreakpointCallback; | |
69 delete window.setBreakpointCallback; | |
70 savedCallback(); | |
71 } | |
72 } | |
73 }, | |
74 | |
75 setBreakpointByURL: function(url, lineNumber, columnNumber, condition, callb ack) | |
76 { | |
77 InspectorTest.addResult(" debuggerModel.setBreakpoint(" + [url, lineN umber, condition].join(":") + ")"); | |
78 | |
79 var breakpointId = url + ":" + lineNumber; | |
80 if (this._breakpoints[breakpointId]) { | |
81 this._scheduleSetBeakpointCallback(callback, null); | |
82 return; | |
83 } | |
84 this._breakpoints[breakpointId] = true; | |
85 | |
86 var locations = []; | |
87 var script = this._scriptForURL(url); | |
88 if (script) { | |
89 var location = new WebInspector.DebuggerModel.Location(this._target, script.scriptId, lineNumber, 0); | |
90 locations.push(location); | |
91 } | |
92 | |
93 this._scheduleSetBeakpointCallback(callback, breakpointId, locations); | |
94 }, | |
95 | |
96 setBreakpointByScriptLocation: function(location, condition, callback) | |
97 { | |
98 InspectorTest.addResult(" debuggerModel.setBreakpoint(" + [location.s criptId, location.lineNumber, condition].join(":") + ")"); | |
99 | |
100 var breakpointId = location.scriptId + ":" + location.lineNumber; | |
101 if (this._breakpoints[breakpointId]) { | |
102 this._scheduleSetBeakpointCallback(callback, null); | |
103 return; | |
104 } | |
105 this._breakpoints[breakpointId] = true; | |
106 | |
107 if (location.lineNumber >= 2000) { | |
108 this._scheduleSetBeakpointCallback(callback, breakpointId, []); | |
109 return; | |
110 } | |
111 if (location.lineNumber >= 1000) { | |
112 var shiftedLocation = new WebInspector.DebuggerModel.Location(this._ target, location.scriptId, location.lineNumber + 10, location.columnNumber); | |
113 this._scheduleSetBeakpointCallback(callback, breakpointId, [shiftedL ocation]); | |
114 return; | |
115 } | |
116 | |
117 this._scheduleSetBeakpointCallback(callback, breakpointId, [WebInspector .DebuggerModel.Location.fromPayload(this._target, location)]); | |
118 }, | |
119 | |
120 removeBreakpoint: function(breakpointId, callback) | |
121 { | |
122 InspectorTest.addResult(" debuggerModel.removeBreakpoint(" + breakpoi ntId + ")"); | |
123 delete this._breakpoints[breakpointId]; | |
124 if (callback) | |
125 callback(); | |
126 }, | |
127 | |
128 setBreakpointsActive: function() { }, | |
129 | |
130 createLiveLocation: function(rawLocation, updateDelegate) | |
131 { | |
132 return this._scripts[rawLocation.scriptId].createLiveLocation(rawLocatio n, updateDelegate); | |
133 }, | |
134 | |
135 scriptForId: function(scriptId) | |
136 { | |
137 return this._scripts[scriptId]; | |
138 }, | |
139 | |
140 reset: function() | |
141 { | |
142 InspectorTest.addResult(" Resetting debugger."); | |
143 this._scripts = {}; | |
144 }, | |
145 | |
146 pushSourceMapping: function(sourceMapping) | |
147 { | |
148 for (var scriptId in this._scripts) | |
149 this._scripts[scriptId].pushSourceMapping(sourceMapping); | |
150 }, | |
151 | |
152 disableSourceMapping: function(sourceMapping) | |
153 { | |
154 sourceMapping._disabled = true; | |
155 for (var scriptId in this._scripts) | |
156 this._scripts[scriptId].updateLocations(); | |
157 }, | |
158 | |
159 addBreakpointListener: function(breakpointId, listener, thisObject) | |
160 { | |
161 this._breakpointResolvedEventTarget.addEventListener(breakpointId, liste ner, thisObject) | |
162 }, | |
163 | |
164 removeBreakpointListener: function(breakpointId, listener, thisObject) | |
165 { | |
166 this._breakpointResolvedEventTarget.removeEventListener(breakpointId, li stener, thisObject); | |
167 }, | |
168 | |
169 _breakpointResolved: function(breakpointId, location) | |
170 { | |
171 this._breakpointResolvedEventTarget.dispatchEventToListeners(breakpointI d, location); | |
172 } | |
173 } | |
174 InspectorTest.DebuggerModelMock.prototype.__proto__ = WebInspector.Object.protot ype; | |
175 | |
176 InspectorTest.setupLiveLocationSniffers = function() | |
177 { | |
178 InspectorTest.addSniffer(WebInspector.Script.prototype, "createLiveLocation" , function(rawLocation) | |
179 { | |
180 InspectorTest.addResult(" Location created: " + rawLocation.scriptId + ":" + rawLocation.lineNumber); | |
181 }, true); | |
182 InspectorTest.addSniffer(WebInspector.Script.Location.prototype, "dispose", function() | |
183 { | |
184 InspectorTest.addResult(" Location disposed: " + this._rawLocation.sc riptId + ":" + this._rawLocation.lineNumber); | |
185 }, true); | |
186 } | |
187 | |
188 InspectorTest.addUISourceCode = function(target, breakpointManager, url, doNotSe tSourceMapping, doNotAddScript) | |
189 { | |
190 if (!doNotAddScript) | |
191 target.debuggerModel._addScript(url, url); | |
192 InspectorTest.addResult(" Adding UISourceCode: " + url); | |
193 var contentProvider = new WebInspector.StaticContentProvider(WebInspector.re sourceTypes.Script, ""); | |
194 var uiSourceCode = breakpointManager._networkWorkspaceBinding.addFileForURL( url, contentProvider); | |
195 InspectorTest.uiSourceCodes[url] = uiSourceCode; | |
196 if (!doNotSetSourceMapping) | |
197 uiSourceCode.setSourceMappingForTarget(target, target.defaultMapping); | |
198 return uiSourceCode; | |
199 } | |
200 | |
201 InspectorTest.createBreakpointManager = function(targetManager, persistentBreakp oints) | |
202 { | |
203 persistentBreakpoints = persistentBreakpoints || []; | |
204 var setting = { | |
205 get: function() { return persistentBreakpoints; }, | |
206 set: function(breakpoints) { persistentBreakpoints = breakpoints; } | |
207 }; | |
208 | |
209 function breakpointAdded(event) | |
210 { | |
211 var breakpoint = event.data.breakpoint; | |
212 var uiLocation = event.data.uiLocation; | |
213 InspectorTest.addResult(" breakpointAdded(" + [uiLocation.uiSourceCod e.originURL(), uiLocation.lineNumber, uiLocation.columnNumber, breakpoint.condit ion(), breakpoint.enabled()].join(", ") + ")"); | |
214 } | |
215 | |
216 function breakpointRemoved(event) | |
217 { | |
218 var uiLocation = event.data.uiLocation; | |
219 InspectorTest.addResult(" breakpointRemoved(" + [uiLocation.uiSourceC ode.originURL(), uiLocation.lineNumber, uiLocation.columnNumber].join(", ") + ") "); | |
220 } | |
221 var targets = targetManager.targets(); | |
222 for (var i = 0; i < targets.length; ++i) | |
223 new InspectorTest.DebuggerModelMock(targets[i], targets[i].defaultMappin g); | |
224 | |
225 var workspace = new WebInspector.Workspace(); | |
226 var breakpointManager = new WebInspector.BreakpointManager(setting, workspac e, targetManager); | |
227 breakpointManager._networkWorkspaceBinding = new WebInspector.NetworkWorkspa ceBinding(workspace); | |
228 breakpointManager._debuggerProjectDelegate = new WebInspector.DebuggerProjec tDelegate(workspace, "debugger:", WebInspector.projectTypes.Debugger); | |
229 breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.Bre akpointAdded, breakpointAdded); | |
230 breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.Bre akpointRemoved, breakpointRemoved); | |
231 InspectorTest.addResult(" Created breakpoints manager"); | |
232 InspectorTest.dumpBreakpointStorage(breakpointManager); | |
233 return breakpointManager; | |
234 } | |
235 | |
236 InspectorTest.setBreakpoint = function(breakpointManager, uiSourceCode, lineNumb er, columnNumber, condition, enabled, setBreakpointCallback) | |
237 { | |
238 InspectorTest.addResult(" Setting breakpoint at " + uiSourceCode.originURL( ) + ":" + lineNumber + ":" + columnNumber + " enabled:" + enabled + " condition: " + condition); | |
239 if (setBreakpointCallback) | |
240 window.setBreakpointCallback = setBreakpointCallback; | |
241 return breakpointManager.setBreakpoint(uiSourceCode, lineNumber, columnNumbe r, condition, enabled); | |
242 } | |
243 | |
244 InspectorTest.removeBreakpoint = function(breakpointManager, uiSourceCode, lineN umber, columnNumber) | |
245 { | |
246 InspectorTest.addResult(" Removing breakpoint at " + uiSourceCode.originURL () + ":" + lineNumber + ":" + columnNumber); | |
247 breakpointManager.findBreakpoint(uiSourceCode, lineNumber, columnNumber).rem ove(); | |
248 } | |
249 | |
250 InspectorTest.dumpBreakpointStorage = function(breakpointManager) | |
251 { | |
252 var breakpoints = breakpointManager._storage._setting.get(); | |
253 InspectorTest.addResult(" Dumping Storage"); | |
254 for (var i = 0; i < breakpoints.length; ++i) | |
255 InspectorTest.addResult(" " + breakpoints[i].sourceFileId + ":" + bre akpoints[i].lineNumber + " enabled:" + breakpoints[i].enabled + " condition:" + breakpoints[i].condition); | |
256 } | |
257 | |
258 InspectorTest.dumpBreakpointLocations = function(breakpointManager) | |
259 { | |
260 var allBreakpointLocations = breakpointManager.allBreakpointLocations(); | |
261 InspectorTest.addResult(" Dumping Breakpoint Locations"); | |
262 var lastUISourceCode = null; | |
263 var locations = []; | |
264 | |
265 function dumpLocations(uiSourceCode, locations) | |
266 { | |
267 InspectorTest.addResult(" UISourceCode (url='" + uiSourceCode.url + " ', uri='" + uiSourceCode.uri() + "')"); | |
268 for (var i = 0; i < locations.length; ++i) | |
269 InspectorTest.addResult(" Location: (" + locations[i].lineNumbe r + ", " + locations[i].columnNumber + ")"); | |
270 } | |
271 | |
272 for (var i = 0; i < allBreakpointLocations.length; ++i) { | |
273 var uiLocation = allBreakpointLocations[i].uiLocation; | |
274 var uiSourceCode = uiLocation.uiSourceCode; | |
275 if (lastUISourceCode && lastUISourceCode != uiSourceCode) { | |
276 dumpLocations(uiSourceCode, locations); | |
277 locations = []; | |
278 } | |
279 lastUISourceCode = uiSourceCode; | |
280 locations.push(uiLocation); | |
281 } | |
282 if (lastUISourceCode) | |
283 dumpLocations(lastUISourceCode, locations); | |
284 } | |
285 | |
286 InspectorTest.resetBreakpointManager = function(breakpointManager, next) | |
287 { | |
288 InspectorTest.dumpBreakpointStorage(breakpointManager); | |
289 InspectorTest.addResult(" Resetting breakpoint manager"); | |
290 breakpointManager.removeAllBreakpoints(); | |
291 breakpointManager.removeProvisionalBreakpointsForTest(); | |
292 InspectorTest.uiSourceCodes = {}; | |
293 next(); | |
294 } | |
295 | |
296 InspectorTest.resetAndFinish = function(breakpointManager, next) | |
297 { | |
298 function finish() | |
299 { | |
300 InspectorTest.dumpBreakpointLocations(breakpointManager); | |
301 next(); | |
302 } | |
303 | |
304 InspectorTest.dumpBreakpointLocations(breakpointManager); | |
305 InspectorTest.resetBreakpointManager(breakpointManager, finish); | |
306 } | |
307 | |
308 } | |
OLD | NEW |