1 var initialize_DebuggerTest = function() {
3 InspectorTest.startDebuggerTest = function(callback, quiet)
5 console.assert(WebInspector.debuggerModel.debuggerEnabled(), "Debugger has to be enabled");
6 if (quiet !== undefined)
7 InspectorTest._quiet = quiet;
8 WebInspector.inspectorView.showPanel("sources");
10 InspectorTest.addSniffer(WebInspector.debuggerModel, "_pausedScript", InspectorTest._pausedScript, true);
11 InspectorTest.addSniffer(WebInspector.debuggerModel, "_resumedScript", InspectorTest._resumedScript, true);
12 InspectorTest.safeWrap(callback)();
15 InspectorTest.completeDebuggerTest = function()
17 WebInspector.breakpointManager.setBreakpointsActive(true);
18 InspectorTest.resumeExecution(InspectorTest.completeTest.bind(InspectorTest));
21 InspectorTest.runDebuggerTestSuite = function(testSuite)
23 var testSuiteTests = testSuite.slice();
27 if (!testSuiteTests.length) {
28 InspectorTest.completeDebuggerTest();
32 var nextTest = testSuiteTests.shift();
33 InspectorTest.addResult("");
34 InspectorTest.addResult("Running: " + /function\s([^(]*)/.exec(nextTest)[1]);
35 InspectorTest.safeWrap(nextTest)(runner, runner);
38 InspectorTest.startDebuggerTest(runner);
41 InspectorTest.runTestFunction = function()
43 InspectorTest.evaluateInConsole("setTimeout(testFunction, 0)");
44 InspectorTest.addResult("Set timer for test function.");
47 InspectorTest.runTestFunctionAndWaitUntilPaused = function(callback)
49 InspectorTest.runTestFunction();
50 InspectorTest.waitUntilPaused(callback);
53 InspectorTest.runAsyncCallStacksTest = function(totalDebuggerStatements, maxAsyncCallStackDepth)
55 InspectorTest.setQuiet(true);
56 InspectorTest.startDebuggerTest(step1);
60 DebuggerAgent.setAsyncCallStackDepth(maxAsyncCallStackDepth, step2);
65 InspectorTest.runTestFunctionAndWaitUntilPaused(didPause);
69 var callStacksOutput = [];
70 function didPause(callFrames, reason, breakpointIds, asyncStackTrace)
73 callStacksOutput.push(InspectorTest.captureStackTraceIntoString(callFrames, asyncStackTrace) + "\n");
74 if (step < totalDebuggerStatements) {
75 InspectorTest.resumeExecution(InspectorTest.waitUntilPaused.bind(InspectorTest, didPause));
77 InspectorTest.addResult("Captured call stacks in no particular order:");
78 callStacksOutput.sort();
79 InspectorTest.addResults(callStacksOutput);
80 InspectorTest.completeDebuggerTest();
85 InspectorTest.waitUntilPausedNextTime = function(callback)
87 InspectorTest._waitUntilPausedCallback = InspectorTest.safeWrap(callback);
90 InspectorTest.waitUntilPaused = function(callback)
92 callback = InspectorTest.safeWrap(callback);
94 if (InspectorTest._pausedScriptArguments)
95 callback.apply(callback, InspectorTest._pausedScriptArguments);
97 InspectorTest._waitUntilPausedCallback = callback;
100 InspectorTest.waitUntilResumedNextTime = function(callback)
102 InspectorTest._waitUntilResumedCallback = InspectorTest.safeWrap(callback);
105 InspectorTest.waitUntilResumed = function(callback)
107 callback = InspectorTest.safeWrap(callback);
109 if (!InspectorTest._pausedScriptArguments)
112 InspectorTest._waitUntilResumedCallback = callback;
115 InspectorTest.resumeExecution = function(callback)
117 if (WebInspector.panels.sources.paused())
118 WebInspector.panels.sources.togglePause();
119 InspectorTest.waitUntilResumed(callback);
122 InspectorTest.waitUntilPausedAndDumpStackAndResume = function(callback, options)
124 InspectorTest.waitUntilPaused(paused);
125 InspectorTest.addSniffer(WebInspector.CallStackSidebarPane.prototype, "setStatus", setStatus);
131 function setStatus(status)
133 if (typeof status === "string")
136 caption = status.textContent;
141 function paused(frames, reason, breakpointIds, async)
144 asyncStackTrace = async;
145 if (typeof caption === "string")
151 InspectorTest.captureStackTrace(callFrames, asyncStackTrace, options);
152 InspectorTest.addResult(caption);
153 InspectorTest.runAfterPendingDispatches(step2);
158 InspectorTest.resumeExecution(InspectorTest.safeWrap(callback));
162 InspectorTest.waitUntilPausedAndPerformSteppingActions = function(actions, callback)
164 callback = InspectorTest.safeWrap(callback);
165 InspectorTest.waitUntilPaused(didPause);
167 function didPause(callFrames, reason, breakpointIds, asyncStackTrace)
169 var action = actions.shift();
170 if (action === "Print") {
171 InspectorTest.captureStackTrace(callFrames, asyncStackTrace);
172 InspectorTest.addResult("");
173 while (action === "Print")
174 action = actions.shift();
182 InspectorTest.addResult("Executing " + action + "...");
186 WebInspector.panels.sources._stepIntoButton.element.click();
189 WebInspector.panels.sources._stepOverButton.element.click();
192 WebInspector.panels.sources._stepOutButton.element.click();
195 WebInspector.panels.sources.togglePause();
198 InspectorTest.addResult("FAIL: Unknown action: " + action);
203 InspectorTest.waitUntilResumed(InspectorTest.waitUntilPaused.bind(InspectorTest, didPause));
207 InspectorTest.captureStackTrace = function(callFrames, asyncStackTrace, options)
209 InspectorTest.addResult(InspectorTest.captureStackTraceIntoString(callFrames, asyncStackTrace, options));
212 InspectorTest.captureStackTraceIntoString = function(callFrames, asyncStackTrace, options)
215 options = options || {};
217 function printCallFrames(callFrames)
220 for (var i = 0; i < callFrames.length; i++) {
221 var frame = callFrames[i];
222 var script = WebInspector.debuggerModel.scriptForId(frame.location().scriptId);
223 var isFramework = WebInspector.BlackboxSupport.isBlackboxedURL(script.sourceURL);
224 if (options.dropFrameworkCallFrames && isFramework)
229 url = WebInspector.displayNameForURL(script.sourceURL);
230 lineNumber = frame.location().lineNumber + 1;
232 url = "(internal script)";
233 lineNumber = "(line number)";
235 var s = (isFramework ? " * " : " ") + (printed++) + ") " + frame.functionName + " (" + url + (options.dropLineNumbers ? "" : ":" + lineNumber) + ")";
237 if (options.printReturnValue && frame.returnValue())
238 results.push(" <return>: " + frame.returnValue().description);
243 results.push("Call stack:");
244 printCallFrames(callFrames);
246 while (asyncStackTrace) {
247 results.push(" [" + (asyncStackTrace.description || "Async Call") + "]");
248 var printed = printCallFrames(WebInspector.DebuggerModel.CallFrame.fromPayloadArray(WebInspector.targetManager.mainTarget(), asyncStackTrace.callFrames));
251 if (asyncStackTrace.callFrames.peekLast().functionName === "testFunction")
253 asyncStackTrace = asyncStackTrace.asyncStackTrace;
255 return results.join("\n");
258 InspectorTest.dumpSourceFrameContents = function(sourceFrame)
260 InspectorTest.addResult("==Source frame contents start==");
261 var textEditor = sourceFrame._textEditor;
262 for (var i = 0; i < textEditor.linesCount; ++i)
263 InspectorTest.addResult(textEditor.line(i));
264 InspectorTest.addResult("==Source frame contents end==");
267 InspectorTest._pausedScript = function(callFrames, reason, auxData, breakpointIds, asyncStackTrace)
269 if (!InspectorTest._quiet)
270 InspectorTest.addResult("Script execution paused.");
271 InspectorTest._pausedScriptArguments = [WebInspector.DebuggerModel.CallFrame.fromPayloadArray(WebInspector.targetManager.mainTarget(), callFrames), reason, breakpointIds, asyncStackTrace, auxData];
272 if (InspectorTest._waitUntilPausedCallback) {
273 var callback = InspectorTest._waitUntilPausedCallback;
274 delete InspectorTest._waitUntilPausedCallback;
275 callback.apply(callback, InspectorTest._pausedScriptArguments);
279 InspectorTest._resumedScript = function()
281 if (!InspectorTest._quiet)
282 InspectorTest.addResult("Script execution resumed.");
283 delete InspectorTest._pausedScriptArguments;
284 if (InspectorTest._waitUntilResumedCallback) {
285 var callback = InspectorTest._waitUntilResumedCallback;
286 delete InspectorTest._waitUntilResumedCallback;
291 InspectorTest.showUISourceCode = function(uiSourceCode, callback)
293 var panel = WebInspector.inspectorView.showPanel("sources");
294 panel.showUISourceCode(uiSourceCode);
295 var sourceFrame = panel.visibleView;
296 if (sourceFrame.loaded)
297 callback(sourceFrame);
299 InspectorTest.addSniffer(sourceFrame, "onTextEditorContentLoaded", callback && callback.bind(null, sourceFrame));
302 InspectorTest.showScriptSource = function(scriptName, callback)
304 InspectorTest.waitForScriptSource(scriptName, function(uiSourceCode) { InspectorTest.showUISourceCode(uiSourceCode, callback); });
307 InspectorTest.waitForScriptSource = function(scriptName, callback)
309 var panel = WebInspector.inspectorView.showPanel("sources");
310 var uiSourceCodes = panel._workspace.uiSourceCodes();
311 for (var i = 0; i < uiSourceCodes.length; ++i) {
312 if (uiSourceCodes[i].name() === scriptName) {
313 callback(uiSourceCodes[i]);
318 InspectorTest.addSniffer(WebInspector.SourcesView.prototype, "_addUISourceCode", InspectorTest.waitForScriptSource.bind(InspectorTest, scriptName, callback));
321 InspectorTest.dumpNavigatorView = function(navigatorView, id, prefix)
323 InspectorTest.addResult(prefix + "Dumping ScriptsNavigator " + id + " tab:");
324 dumpNavigatorTreeOutline(prefix, navigatorView._scriptsTree);
326 function dumpNavigatorTreeElement(prefix, treeElement)
328 InspectorTest.addResult(prefix + treeElement.titleText);
329 for (var i = 0; i < treeElement.children.length; ++i)
330 dumpNavigatorTreeElement(prefix + " ", treeElement.children[i]);
333 function dumpNavigatorTreeOutline(prefix, treeOutline)
335 for (var i = 0; i < treeOutline.children.length; ++i)
336 dumpNavigatorTreeElement(prefix + " ", treeOutline.children[i]);
340 InspectorTest.setBreakpoint = function(sourceFrame, lineNumber, condition, enabled)
342 if (!sourceFrame._muted)
343 sourceFrame._setBreakpoint(lineNumber, 0, condition, enabled);
346 InspectorTest.removeBreakpoint = function(sourceFrame, lineNumber)
348 sourceFrame._breakpointManager.findBreakpointOnLine(sourceFrame._uiSourceCode, lineNumber).remove();
351 InspectorTest.dumpBreakpointSidebarPane = function(title)
353 var paneElement = WebInspector.panels.sources.sidebarPanes.jsBreakpoints.listElement;
354 InspectorTest.addResult("Breakpoint sidebar pane " + (title || ""));
355 InspectorTest.addResult(InspectorTest.textContentWithLineBreaks(paneElement));
358 InspectorTest.expandProperties = function(properties, callback)
361 function expandNextPath()
363 if (index === properties.length) {
364 InspectorTest.safeWrap(callback)();
367 var parentTreeElement = properties[index++];
368 var path = properties[index++];
369 InspectorTest._expandProperty(parentTreeElement, path, 0, expandNextPath);
371 InspectorTest.runAfterPendingDispatches(expandNextPath);
374 InspectorTest._expandProperty = function(parentTreeElement, path, pathIndex, callback)
376 if (pathIndex === path.length) {
377 InspectorTest.addResult("Expanded property: " + path.join("."));
381 var name = path[pathIndex++];
382 var propertyTreeElement = InspectorTest._findChildPropertyTreeElement(parentTreeElement, name);
383 if (!propertyTreeElement) {
384 InspectorTest.addResult("Failed to expand property: " + path.slice(0, pathIndex).join("."));
385 InspectorTest.completeDebuggerTest();
388 propertyTreeElement.expand();
389 InspectorTest.runAfterPendingDispatches(InspectorTest._expandProperty.bind(InspectorTest, propertyTreeElement, path, pathIndex, callback));
392 InspectorTest._findChildPropertyTreeElement = function(parent, childName)
394 var children = parent.children;
395 for (var i = 0; i < children.length; i++) {
396 var treeElement = children[i];
397 var property = treeElement.property;
398 if (property.name === childName)
403 InspectorTest.setQuiet = function(quiet)
405 InspectorTest._quiet = quiet;
408 InspectorTest.queryScripts = function(filter)
411 for (var scriptId in WebInspector.debuggerModel._scripts) {
412 var script = WebInspector.debuggerModel._scripts[scriptId];
413 if (!filter || filter(script))
414 scripts.push(script);
419 InspectorTest.createScriptMock = function(url, startLine, startColumn, isContentScript, source, target, preRegisterCallback)
421 target = target || WebInspector.targetManager.mainTarget();
422 var scriptId = ++InspectorTest._lastScriptId;
423 var lineCount = source.lineEndings().length;
424 var endLine = startLine + lineCount - 1;
425 var endColumn = lineCount === 1 ? startColumn + source.length : source.length - source.lineEndings()[lineCount - 2];
426 var hasSourceURL = !!source.match(/\/\/#\ssourceURL=\s*(\S*?)\s*$/m) || !!source.match(/\/\/@\ssourceURL=\s*(\S*?)\s*$/m);
427 var script = new WebInspector.Script(target, scriptId, url, startLine, startColumn, endLine, endColumn, isContentScript, null, hasSourceURL);
428 script.requestContent = function(callback)
430 var trimmedSource = WebInspector.Script._trimSourceURLComment(source);
431 callback(trimmedSource, false, "text/javascript");
433 if (preRegisterCallback)
434 preRegisterCallback(script);
435 target.debuggerModel._registerScript(script);
439 InspectorTest._lastScriptId = 0;
441 InspectorTest.checkRawLocation = function(script, lineNumber, columnNumber, location)
443 InspectorTest.assertEquals(script.scriptId, location.scriptId, "Incorrect scriptId");
444 InspectorTest.assertEquals(lineNumber, location.lineNumber, "Incorrect lineNumber");
445 InspectorTest.assertEquals(columnNumber, location.columnNumber, "Incorrect columnNumber");
448 InspectorTest.checkUILocation = function(uiSourceCode, lineNumber, columnNumber, location)
450 InspectorTest.assertEquals(uiSourceCode, location.uiSourceCode, "Incorrect uiSourceCode, expected '" + (uiSourceCode ? uiSourceCode.originURL() : null) + "'," +
451 " but got '" + (location.uiSourceCode ? location.uiSourceCode.originURL() : null) + "'");
452 InspectorTest.assertEquals(lineNumber, location.lineNumber, "Incorrect lineNumber, expected '" + lineNumber + "', but got '" + location.lineNumber + "'");
453 InspectorTest.assertEquals(columnNumber, location.columnNumber, "Incorrect columnNumber, expected '" + columnNumber + "', but got '" + location.columnNumber + "'");
456 InspectorTest.scriptFormatter = function()
458 var editorActions = self.runtime.instances(WebInspector.SourcesView.EditorAction);
459 for (var i = 0; i < editorActions.length; ++i) {
460 if (editorActions[i] instanceof WebInspector.ScriptFormatterEditorAction)
461 return editorActions[i];