michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests the public evaluation API from the debugger controller. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; michael@0: michael@0: function test() { michael@0: Task.spawn(function() { michael@0: let [tab, debuggee, panel] = yield initDebugger(TAB_URL); michael@0: let win = panel.panelWin; michael@0: let frames = win.DebuggerController.StackFrames; michael@0: let framesView = win.DebuggerView.StackFrames; michael@0: let sources = win.DebuggerController.SourceScripts; michael@0: let sourcesView = win.DebuggerView.Sources; michael@0: let editorView = win.DebuggerView.editor; michael@0: let events = win.EVENTS; michael@0: michael@0: function checkView(frameDepth, selectedSource, caretLine, editorText) { michael@0: is(win.gThreadClient.state, "paused", michael@0: "Should only be getting stack frames while paused."); michael@0: is(framesView.itemCount, 4, michael@0: "Should have four frames."); michael@0: is(framesView.selectedDepth, frameDepth, michael@0: "The correct frame is selected in the widget."); michael@0: is(sourcesView.selectedIndex, selectedSource, michael@0: "The correct source is selected in the widget."); michael@0: ok(isCaretPos(panel, caretLine), michael@0: "Editor caret location is correct."); michael@0: is(editorView.getText().search(editorText[0]), editorText[1], michael@0: "The correct source is not displayed."); michael@0: } michael@0: michael@0: // Cache the sources text to avoid having to wait for their retrieval. michael@0: yield promise.all(sourcesView.attachments.map(e => sources.getText(e.source))); michael@0: is(sources._cache.size, 2, "There should be two cached sources in the cache."); michael@0: michael@0: // Eval while not paused. michael@0: try { michael@0: yield frames.evaluate("foo"); michael@0: } catch (error) { michael@0: is(error.message, "No stack frame available.", michael@0: "Evaluating shouldn't work while the debuggee isn't paused."); michael@0: } michael@0: michael@0: // Allow this generator function to yield first. michael@0: executeSoon(() => debuggee.firstCall()); michael@0: yield waitForSourceAndCaretAndScopes(panel, "-02.js", 1); michael@0: checkView(0, 1, 1, [/secondCall/, 118]); michael@0: michael@0: // Eval in the topmost frame, while paused. michael@0: let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); michael@0: let result = yield frames.evaluate("foo"); michael@0: ok(!result.throw, "The evaluation hasn't thrown."); michael@0: is(result.return.type, "object", "The evaluation return type is correct."); michael@0: is(result.return.class, "Function", "The evaluation return class is correct."); michael@0: michael@0: yield updatedView; michael@0: checkView(0, 1, 1, [/secondCall/, 118]); michael@0: ok(true, "Evaluating in the topmost frame works properly."); michael@0: michael@0: // Eval in a different frame, while paused. michael@0: let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); michael@0: try { michael@0: yield frames.evaluate("foo", { depth: 3 }); // oldest frame michael@0: } catch (result) { michael@0: is(result.return.type, "object", "The evaluation thrown type is correct."); michael@0: is(result.return.class, "Error", "The evaluation thrown class is correct."); michael@0: ok(!result.return, "The evaluation hasn't returned."); michael@0: } michael@0: michael@0: yield updatedView; michael@0: checkView(0, 1, 1, [/secondCall/, 118]); michael@0: ok(true, "Evaluating in a custom frame works properly."); michael@0: michael@0: // Eval in a non-existent frame, while paused. michael@0: waitForDebuggerEvents(panel, events.FETCHED_SCOPES).then(() => { michael@0: ok(false, "Shouldn't have updated the view when trying to evaluate " + michael@0: "an expression in a non-existent stack frame."); michael@0: }); michael@0: try { michael@0: yield frames.evaluate("foo", { depth: 4 }); // non-existent frame michael@0: } catch (error) { michael@0: is(error.message, "No stack frame available.", michael@0: "Evaluating shouldn't work if the specified frame doesn't exist."); michael@0: } michael@0: michael@0: yield resumeDebuggerThenCloseAndFinish(panel); michael@0: }); michael@0: }