1 var initialize_DebuggerTest = function() {
3 InspectorTest.startDebuggerTest = function(callback, quiet)
5 if (quiet !== undefined)
6 InspectorTest._quiet = quiet;
7 WebInspector.inspectorView.showPanel("sources");
9 if (WebInspector.debuggerModel.debuggerEnabled())
12 InspectorTest.addSniffer(WebInspector.debuggerModel, "_debuggerWasEnabled", startTest);
13 WebInspector.debuggerModel.enableDebugger();
18 InspectorTest.addResult("Debugger was enabled.");
19 InspectorTest.addSniffer(WebInspector.debuggerModel, "_pausedScript", InspectorTest._pausedScript, true);
20 InspectorTest.addSniffer(WebInspector.debuggerModel, "_resumedScript", InspectorTest._resumedScript, true);
21 InspectorTest.safeWrap(callback)();
25 InspectorTest.finishDebuggerTest = function(callback)
27 var sourcesPanel = WebInspector.panels.sources;
29 WebInspector.debuggerModel.setBreakpointsActive(true);
30 InspectorTest.resumeExecution(disableDebugger);
32 function disableDebugger()
34 if (!WebInspector.debuggerModel.debuggerEnabled())
37 InspectorTest.addSniffer(WebInspector.debuggerModel, "_debuggerWasDisabled", debuggerDisabled);
38 WebInspector.debuggerModel.disableDebugger();
42 function debuggerDisabled()
44 InspectorTest.addResult("Debugger was disabled.");
49 InspectorTest.completeDebuggerTest = function()
51 InspectorTest.finishDebuggerTest(InspectorTest.completeTest.bind(InspectorTest));
54 InspectorTest.runDebuggerTestSuite = function(testSuite)
56 var testSuiteTests = testSuite.slice();
60 if (!testSuiteTests.length) {
61 InspectorTest.completeDebuggerTest();
65 var nextTest = testSuiteTests.shift();
66 InspectorTest.addResult("");
67 InspectorTest.addResult("Running: " + /function\s([^(]*)/.exec(nextTest)[1]);
68 InspectorTest.safeWrap(nextTest)(runner, runner);
71 InspectorTest.startDebuggerTest(runner);
74 InspectorTest.runTestFunction = function()
76 InspectorTest.evaluateInConsole("setTimeout(testFunction, 0)");
77 InspectorTest.addResult("Set timer for test function.");
80 InspectorTest.runTestFunctionAndWaitUntilPaused = function(callback)
82 InspectorTest.runTestFunction();
83 InspectorTest.waitUntilPaused(callback);
86 InspectorTest.runAsyncCallStacksTest = function(totalDebuggerStatements, maxAsyncCallStackDepth)
88 InspectorTest.setQuiet(true);
89 InspectorTest.startDebuggerTest(step1);
93 DebuggerAgent.setAsyncCallStackDepth(maxAsyncCallStackDepth, step2);
98 InspectorTest.runTestFunctionAndWaitUntilPaused(didPause);
102 var callStacksOutput = [];
103 function didPause(callFrames, reason, breakpointIds, asyncStackTrace)
106 callStacksOutput.push(InspectorTest.captureStackTraceIntoString(callFrames, asyncStackTrace) + "\n");
107 if (step < totalDebuggerStatements) {
108 InspectorTest.resumeExecution(InspectorTest.waitUntilPaused.bind(InspectorTest, didPause));
110 InspectorTest.addResult("Captured call stacks in no particular order:");
111 callStacksOutput.sort();
112 InspectorTest.addResults(callStacksOutput);
113 InspectorTest.completeDebuggerTest();
118 InspectorTest.waitUntilPausedNextTime = function(callback)
120 InspectorTest._waitUntilPausedCallback = InspectorTest.safeWrap(callback);
123 InspectorTest.waitUntilPaused = function(callback)
125 callback = InspectorTest.safeWrap(callback);
127 if (InspectorTest._pausedScriptArguments)
128 callback.apply(callback, InspectorTest._pausedScriptArguments);
130 InspectorTest._waitUntilPausedCallback = callback;
133 InspectorTest.waitUntilResumedNextTime = function(callback)
135 InspectorTest._waitUntilResumedCallback = InspectorTest.safeWrap(callback);
138 InspectorTest.waitUntilResumed = function(callback)
140 callback = InspectorTest.safeWrap(callback);
142 if (!InspectorTest._pausedScriptArguments)
145 InspectorTest._waitUntilResumedCallback = callback;
148 InspectorTest.resumeExecution = function(callback)
150 if (WebInspector.panels.sources.paused)
151 WebInspector.panels.sources.togglePause();
152 InspectorTest.waitUntilResumed(callback);
155 InspectorTest.captureStackTrace = function(callFrames, asyncStackTrace, options)
157 InspectorTest.addResult(InspectorTest.captureStackTraceIntoString(callFrames, asyncStackTrace, options));
160 InspectorTest.captureStackTraceIntoString = function(callFrames, asyncStackTrace, options)
163 options = options || {};
165 function printCallFrames(callFrames)
167 for (var i = 0; i < callFrames.length; i++) {
168 var frame = callFrames[i];
169 var script = WebInspector.debuggerModel.scriptForId(frame.location().scriptId);
173 url = WebInspector.displayNameForURL(script.sourceURL);
174 lineNumber = frame.location().lineNumber + 1;
176 url = "(internal script)";
177 lineNumber = "(line number)";
179 var s = " " + i + ") " + frame.functionName + " (" + url + (options.dropLineNumbers ? "" : ":" + lineNumber) + ")";
181 if (options.printReturnValue && frame.returnValue())
182 results.push(" <return>: " + frame.returnValue().description);
186 results.push("Call stack:");
187 printCallFrames(callFrames);
189 while (asyncStackTrace) {
190 results.push(" [" + (asyncStackTrace.description || "Async Call") + "]");
191 printCallFrames(WebInspector.DebuggerModel.CallFrame.fromPayloadArray(WebInspector.targetManager.activeTarget(), asyncStackTrace.callFrames));
192 if (asyncStackTrace.callFrames.peekLast().functionName === "testFunction")
194 asyncStackTrace = asyncStackTrace.asyncStackTrace;
196 return results.join("\n");
199 InspectorTest.dumpSourceFrameContents = function(sourceFrame)
201 InspectorTest.addResult("==Source frame contents start==");
202 var textEditor = sourceFrame._textEditor;
203 for (var i = 0; i < textEditor.linesCount; ++i)
204 InspectorTest.addResult(textEditor.line(i));
205 InspectorTest.addResult("==Source frame contents end==");
208 InspectorTest._pausedScript = function(callFrames, reason, auxData, breakpointIds, asyncStackTrace)
210 if (!InspectorTest._quiet)
211 InspectorTest.addResult("Script execution paused.");
212 InspectorTest._pausedScriptArguments = [WebInspector.DebuggerModel.CallFrame.fromPayloadArray(WebInspector.targetManager.activeTarget(), callFrames), reason, breakpointIds, asyncStackTrace];
213 if (InspectorTest._waitUntilPausedCallback) {
214 var callback = InspectorTest._waitUntilPausedCallback;
215 delete InspectorTest._waitUntilPausedCallback;
216 callback.apply(callback, InspectorTest._pausedScriptArguments);
220 InspectorTest._resumedScript = function()
222 if (!InspectorTest._quiet)
223 InspectorTest.addResult("Script execution resumed.");
224 delete InspectorTest._pausedScriptArguments;
225 if (InspectorTest._waitUntilResumedCallback) {
226 var callback = InspectorTest._waitUntilResumedCallback;
227 delete InspectorTest._waitUntilResumedCallback;
232 InspectorTest.showUISourceCode = function(uiSourceCode, callback)
234 var panel = WebInspector.inspectorView.showPanel("sources");
235 panel.showUISourceCode(uiSourceCode);
236 var sourceFrame = panel.visibleView;
237 if (sourceFrame.loaded)
238 callback(sourceFrame);
240 InspectorTest.addSniffer(sourceFrame, "onTextEditorContentLoaded", callback && callback.bind(null, sourceFrame));
243 InspectorTest.showScriptSource = function(scriptName, callback)
245 InspectorTest.waitForScriptSource(scriptName, function(uiSourceCode) { InspectorTest.showUISourceCode(uiSourceCode, callback); });
248 InspectorTest.waitForScriptSource = function(scriptName, callback)
250 var panel = WebInspector.inspectorView.showPanel("sources");
251 var uiSourceCodes = panel._workspace.uiSourceCodes();
252 for (var i = 0; i < uiSourceCodes.length; ++i) {
253 if (uiSourceCodes[i].name() === scriptName) {
254 callback(uiSourceCodes[i]);
259 InspectorTest.addSniffer(WebInspector.SourcesView.prototype, "_addUISourceCode", InspectorTest.waitForScriptSource.bind(InspectorTest, scriptName, callback));
262 InspectorTest.dumpNavigatorView = function(navigatorView, id, prefix)
264 InspectorTest.addResult(prefix + "Dumping ScriptsNavigator " + id + " tab:");
265 dumpNavigatorTreeOutline(prefix, navigatorView._scriptsTree);
267 function dumpNavigatorTreeElement(prefix, treeElement)
269 InspectorTest.addResult(prefix + treeElement.titleText);
270 for (var i = 0; i < treeElement.children.length; ++i)
271 dumpNavigatorTreeElement(prefix + " ", treeElement.children[i]);
274 function dumpNavigatorTreeOutline(prefix, treeOutline)
276 for (var i = 0; i < treeOutline.children.length; ++i)
277 dumpNavigatorTreeElement(prefix + " ", treeOutline.children[i]);
281 InspectorTest.setBreakpoint = function(sourceFrame, lineNumber, condition, enabled)
283 if (!sourceFrame._muted)
284 sourceFrame._setBreakpoint(lineNumber, 0, condition, enabled);
287 InspectorTest.removeBreakpoint = function(sourceFrame, lineNumber)
289 sourceFrame._breakpointManager.findBreakpointOnLine(sourceFrame._uiSourceCode, lineNumber).remove();
292 InspectorTest.dumpBreakpointSidebarPane = function(title)
294 var paneElement = WebInspector.panels.sources.sidebarPanes.jsBreakpoints.listElement;
295 InspectorTest.addResult("Breakpoint sidebar pane " + (title || ""));
296 InspectorTest.addResult(InspectorTest.textContentWithLineBreaks(paneElement));
299 InspectorTest.expandProperties = function(properties, callback)
302 function expandNextPath()
304 if (index === properties.length) {
305 InspectorTest.safeWrap(callback)();
308 var parentTreeElement = properties[index++];
309 var path = properties[index++];
310 InspectorTest._expandProperty(parentTreeElement, path, 0, expandNextPath);
312 InspectorTest.runAfterPendingDispatches(expandNextPath);
315 InspectorTest._expandProperty = function(parentTreeElement, path, pathIndex, callback)
317 if (pathIndex === path.length) {
318 InspectorTest.addResult("Expanded property: " + path.join("."));
322 var name = path[pathIndex++];
323 var propertyTreeElement = InspectorTest._findChildPropertyTreeElement(parentTreeElement, name);
324 if (!propertyTreeElement) {
325 InspectorTest.addResult("Failed to expand property: " + path.slice(0, pathIndex).join("."));
326 InspectorTest.completeDebuggerTest();
329 propertyTreeElement.expand();
330 InspectorTest.runAfterPendingDispatches(InspectorTest._expandProperty.bind(InspectorTest, propertyTreeElement, path, pathIndex, callback));
333 InspectorTest._findChildPropertyTreeElement = function(parent, childName)
335 var children = parent.children;
336 for (var i = 0; i < children.length; i++) {
337 var treeElement = children[i];
338 var property = treeElement.property;
339 if (property.name === childName)
344 InspectorTest.setQuiet = function(quiet)
346 InspectorTest._quiet = quiet;
349 InspectorTest.queryScripts = function(filter)
352 for (var scriptId in WebInspector.debuggerModel._scripts) {
353 var script = WebInspector.debuggerModel._scripts[scriptId];
354 if (!filter || filter(script))
355 scripts.push(script);
360 InspectorTest.createScriptMock = function(url, startLine, startColumn, isContentScript, source)
362 var scriptId = ++InspectorTest._lastScriptId;
363 var lineCount = source.lineEndings().length;
364 var endLine = startLine + lineCount - 1;
365 var endColumn = lineCount === 1 ? startColumn + source.length : source.length - source.lineEndings()[lineCount - 2];
366 var hasSourceURL = !!source.match(/\/\/#\ssourceURL=\s*(\S*?)\s*$/m) || !!source.match(/\/\/@\ssourceURL=\s*(\S*?)\s*$/m);
367 var script = new WebInspector.Script(WebInspector.targetManager.activeTarget(), scriptId, url, startLine, startColumn, endLine, endColumn, isContentScript, null, hasSourceURL);
368 script.requestContent = function(callback)
370 var trimmedSource = WebInspector.Script._trimSourceURLComment(source);
371 callback(trimmedSource, false, "text/javascript");
373 WebInspector.debuggerModel._registerScript(script);
377 InspectorTest._lastScriptId = 0;
379 InspectorTest.checkRawLocation = function(script, lineNumber, columnNumber, location)
381 InspectorTest.assertEquals(script.scriptId, location.scriptId, "Incorrect scriptId");
382 InspectorTest.assertEquals(lineNumber, location.lineNumber, "Incorrect lineNumber");
383 InspectorTest.assertEquals(columnNumber, location.columnNumber, "Incorrect columnNumber");
386 InspectorTest.checkUILocation = function(uiSourceCode, lineNumber, columnNumber, location)
388 InspectorTest.assertEquals(uiSourceCode, location.uiSourceCode, "Incorrect uiSourceCode, expected '" + (uiSourceCode ? uiSourceCode.originURL() : null) + "'," +
389 " but got '" + (location.uiSourceCode ? location.uiSourceCode.originURL() : null) + "'");
390 InspectorTest.assertEquals(lineNumber, location.lineNumber, "Incorrect lineNumber, expected '" + lineNumber + "', but got '" + location.lineNumber + "'");
391 InspectorTest.assertEquals(columnNumber, location.columnNumber, "Incorrect columnNumber, expected '" + columnNumber + "', but got '" + location.columnNumber + "'");
394 InspectorTest.scriptFormatter = function()
396 var editorActions = WebInspector.moduleManager.instances(WebInspector.SourcesView.EditorAction);
397 for (var i = 0; i < editorActions.length; ++i) {
398 if (editorActions[i] instanceof WebInspector.ScriptFormatterEditorAction)
399 return editorActions[i];