|
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(frameDepth, 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, frameDepth, |
|
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 // Eval while not paused. |
|
41 try { |
|
42 yield frames.evaluate("foo"); |
|
43 } catch (error) { |
|
44 is(error.message, "No stack frame available.", |
|
45 "Evaluating shouldn't work while the debuggee isn't paused."); |
|
46 } |
|
47 |
|
48 // Allow this generator function to yield first. |
|
49 executeSoon(() => debuggee.firstCall()); |
|
50 yield waitForSourceAndCaretAndScopes(panel, "-02.js", 1); |
|
51 checkView(0, 1, 1, [/secondCall/, 118]); |
|
52 |
|
53 // Eval in the topmost frame, while paused. |
|
54 let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); |
|
55 let result = yield frames.evaluate("foo"); |
|
56 ok(!result.throw, "The evaluation hasn't thrown."); |
|
57 is(result.return.type, "object", "The evaluation return type is correct."); |
|
58 is(result.return.class, "Function", "The evaluation return class is correct."); |
|
59 |
|
60 yield updatedView; |
|
61 checkView(0, 1, 1, [/secondCall/, 118]); |
|
62 ok(true, "Evaluating in the topmost frame works properly."); |
|
63 |
|
64 // Eval in a different frame, while paused. |
|
65 let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES); |
|
66 try { |
|
67 yield frames.evaluate("foo", { depth: 3 }); // oldest frame |
|
68 } catch (result) { |
|
69 is(result.return.type, "object", "The evaluation thrown type is correct."); |
|
70 is(result.return.class, "Error", "The evaluation thrown class is correct."); |
|
71 ok(!result.return, "The evaluation hasn't returned."); |
|
72 } |
|
73 |
|
74 yield updatedView; |
|
75 checkView(0, 1, 1, [/secondCall/, 118]); |
|
76 ok(true, "Evaluating in a custom frame works properly."); |
|
77 |
|
78 // Eval in a non-existent frame, while paused. |
|
79 waitForDebuggerEvents(panel, events.FETCHED_SCOPES).then(() => { |
|
80 ok(false, "Shouldn't have updated the view when trying to evaluate " + |
|
81 "an expression in a non-existent stack frame."); |
|
82 }); |
|
83 try { |
|
84 yield frames.evaluate("foo", { depth: 4 }); // non-existent frame |
|
85 } catch (error) { |
|
86 is(error.message, "No stack frame available.", |
|
87 "Evaluating shouldn't work if the specified frame doesn't exist."); |
|
88 } |
|
89 |
|
90 yield resumeDebuggerThenCloseAndFinish(panel); |
|
91 }); |
|
92 } |