|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests the public evaluation API from the debugger controller. |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
|
9 |
|
10 function test() { |
|
11 Task.spawn(function() { |
|
12 let [tab, debuggee, panel] = yield initDebugger(TAB_URL); |
|
13 let win = panel.panelWin; |
|
14 let frames = win.DebuggerController.StackFrames; |
|
15 let framesView = win.DebuggerView.StackFrames; |
|
16 let sources = win.DebuggerController.SourceScripts; |
|
17 let sourcesView = win.DebuggerView.Sources; |
|
18 let editorView = win.DebuggerView.editor; |
|
19 let events = win.EVENTS; |
|
20 |
|
21 function checkView(selectedFrame, selectedSource, caretLine, editorText) { |
|
22 is(win.gThreadClient.state, "paused", |
|
23 "Should only be getting stack frames while paused."); |
|
24 is(framesView.itemCount, 4, |
|
25 "Should have four frames."); |
|
26 is(framesView.selectedDepth, selectedFrame, |
|
27 "The correct frame is selected in the widget."); |
|
28 is(sourcesView.selectedIndex, selectedSource, |
|
29 "The correct source is selected in the widget."); |
|
30 ok(isCaretPos(panel, caretLine), |
|
31 "Editor caret location is correct."); |
|
32 is(editorView.getText().search(editorText[0]), editorText[1], |
|
33 "The correct source is not displayed."); |
|
34 } |
|
35 |
|
36 // Cache the sources text to avoid having to wait for their retrieval. |
|
37 yield promise.all(sourcesView.attachments.map(e => sources.getText(e.source))); |
|
38 is(sources._cache.size, 2, "There should be two cached sources in the cache."); |
|
39 |
|
40 // Allow this generator function to yield first. |
|
41 executeSoon(() => debuggee.firstCall()); |
|
42 yield waitForSourceAndCaretAndScopes(panel, "-02.js", 1); |
|
43 checkView(0, 1, 1, [/secondCall/, 118]); |
|
44 |
|
45 // Change the selected frame and eval inside it. |
|
46 let updatedFrame = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); |
|
47 framesView.selectedDepth = 3; // oldest frame |
|
48 yield updatedFrame; |
|
49 checkView(3, 0, 5, [/firstCall/, 118]); |
|
50 |
|
51 let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); |
|
52 try { |
|
53 yield frames.evaluate("foo"); |
|
54 } catch (result) { |
|
55 is(result.return.type, "object", "The evaluation thrown type is correct."); |
|
56 is(result.return.class, "Error", "The evaluation thrown class is correct."); |
|
57 ok(!result.return, "The evaluation hasn't returned."); |
|
58 } |
|
59 |
|
60 yield updatedView; |
|
61 checkView(3, 0, 5, [/firstCall/, 118]); |
|
62 ok(true, "Evaluating while in a user-selected frame works properly."); |
|
63 |
|
64 yield resumeDebuggerThenCloseAndFinish(panel); |
|
65 }); |
|
66 } |