browser/devtools/webconsole/test/browser_eval_in_debugger_stackframe.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:b457a68b2334
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
5
6 // Test that makes sure web console eval happens in the user-selected stackframe
7 // from the js debugger.
8
9 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html";
10
11 let gWebConsole, gJSTerm, gDebuggerWin, gThread, gDebuggerController, gStackframes;
12
13 function test()
14 {
15 addTab(TEST_URI);
16 browser.addEventListener("load", function onLoad() {
17 browser.removeEventListener("load", onLoad, true);
18 openConsole(null, consoleOpened);
19 }, true);
20 }
21
22 function consoleOpened(hud)
23 {
24 gWebConsole = hud;
25 gJSTerm = hud.jsterm;
26 gJSTerm.execute("foo", onExecuteFoo);
27 }
28
29 function onExecuteFoo()
30 {
31 isnot(gWebConsole.outputNode.textContent.indexOf("globalFooBug783499"), -1,
32 "|foo| value is correct");
33
34 gJSTerm.clearOutput();
35
36 // Test for Bug 690529 - Web Console and Scratchpad should evaluate
37 // expressions in the scope of the content window, not in a sandbox.
38 executeSoon(() => gJSTerm.execute("foo2 = 'newFoo'; window.foo2", onNewFoo2));
39 }
40
41 function onNewFoo2(msg)
42 {
43 is(gWebConsole.outputNode.textContent.indexOf("undefined"), -1,
44 "|undefined| is not displayed after adding |foo2|");
45
46 ok(msg, "output result found");
47
48 isnot(msg.textContent.indexOf("newFoo"), -1,
49 "'newFoo' is displayed after adding |foo2|");
50
51 gJSTerm.clearOutput();
52
53 info("openDebugger");
54 executeSoon(() => openDebugger().then(debuggerOpened));
55 }
56
57 function debuggerOpened(aResult)
58 {
59 gDebuggerWin = aResult.panelWin;
60 gDebuggerController = gDebuggerWin.DebuggerController;
61 gThread = gDebuggerController.activeThread;
62 gStackframes = gDebuggerController.StackFrames;
63
64 info("openConsole");
65 executeSoon(() =>
66 openConsole(null, () =>
67 gJSTerm.execute("foo + foo2", onExecuteFooAndFoo2)
68 )
69 );
70 }
71
72 function onExecuteFooAndFoo2()
73 {
74 let expected = "globalFooBug783499newFoo";
75 isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1,
76 "|foo + foo2| is displayed after starting the debugger");
77
78 executeSoon(() => {
79 gJSTerm.clearOutput();
80
81 info("openDebugger");
82 openDebugger().then(() => {
83 gThread.addOneTimeListener("framesadded", onFramesAdded);
84
85 info("firstCall()");
86 content.wrappedJSObject.firstCall();
87 });
88 });
89 }
90
91 function onFramesAdded()
92 {
93 info("onFramesAdded, openConsole() now");
94 executeSoon(() =>
95 openConsole(null, () =>
96 gJSTerm.execute("foo + foo2", onExecuteFooAndFoo2InSecondCall)
97 )
98 );
99 }
100
101 function onExecuteFooAndFoo2InSecondCall()
102 {
103 let expected = "globalFooBug783499foo2SecondCall";
104 isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1,
105 "|foo + foo2| from |secondCall()|");
106
107 executeSoon(() => {
108 gJSTerm.clearOutput();
109
110 info("openDebugger and selectFrame(1)");
111
112 openDebugger().then(() => {
113 gStackframes.selectFrame(1);
114
115 info("openConsole");
116 executeSoon(() =>
117 openConsole(null, () =>
118 gJSTerm.execute("foo + foo2 + foo3", onExecuteFoo23InFirstCall)
119 )
120 );
121 });
122 });
123 }
124
125 function onExecuteFoo23InFirstCall()
126 {
127 let expected = "fooFirstCallnewFoofoo3FirstCall";
128 isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1,
129 "|foo + foo2 + foo3| from |firstCall()|");
130
131 executeSoon(() =>
132 gJSTerm.execute("foo = 'abba'; foo3 = 'bug783499'; foo + foo3",
133 onExecuteFooAndFoo3ChangesInFirstCall));
134 }
135
136 function onExecuteFooAndFoo3ChangesInFirstCall()
137 {
138 let expected = "abbabug783499";
139 isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1,
140 "|foo + foo3| updated in |firstCall()|");
141
142 is(content.wrappedJSObject.foo, "globalFooBug783499", "|foo| in content window");
143 is(content.wrappedJSObject.foo2, "newFoo", "|foo2| in content window");
144 ok(!content.wrappedJSObject.foo3, "|foo3| was not added to the content window");
145
146 gWebConsole = gJSTerm = gDebuggerWin = gThread = gDebuggerController =
147 gStackframes = null;
148 executeSoon(finishTest);
149 }

mercurial