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(selectedFrame, 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, selectedFrame, 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: // 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: // Change the selected frame and eval inside it. michael@0: let updatedFrame = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); michael@0: framesView.selectedDepth = 3; // oldest frame michael@0: yield updatedFrame; michael@0: checkView(3, 0, 5, [/firstCall/, 118]); michael@0: michael@0: let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); michael@0: try { michael@0: yield frames.evaluate("foo"); 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(3, 0, 5, [/firstCall/, 118]); michael@0: ok(true, "Evaluating while in a user-selected frame works properly."); michael@0: michael@0: yield resumeDebuggerThenCloseAndFinish(panel); michael@0: }); michael@0: }