1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_eval_in_debugger_stackframe.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +// Test that makes sure web console eval happens in the user-selected stackframe 1.10 +// from the js debugger. 1.11 + 1.12 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html"; 1.13 + 1.14 +let gWebConsole, gJSTerm, gDebuggerWin, gThread, gDebuggerController, gStackframes; 1.15 + 1.16 +function test() 1.17 +{ 1.18 + addTab(TEST_URI); 1.19 + browser.addEventListener("load", function onLoad() { 1.20 + browser.removeEventListener("load", onLoad, true); 1.21 + openConsole(null, consoleOpened); 1.22 + }, true); 1.23 +} 1.24 + 1.25 +function consoleOpened(hud) 1.26 +{ 1.27 + gWebConsole = hud; 1.28 + gJSTerm = hud.jsterm; 1.29 + gJSTerm.execute("foo", onExecuteFoo); 1.30 +} 1.31 + 1.32 +function onExecuteFoo() 1.33 +{ 1.34 + isnot(gWebConsole.outputNode.textContent.indexOf("globalFooBug783499"), -1, 1.35 + "|foo| value is correct"); 1.36 + 1.37 + gJSTerm.clearOutput(); 1.38 + 1.39 + // Test for Bug 690529 - Web Console and Scratchpad should evaluate 1.40 + // expressions in the scope of the content window, not in a sandbox. 1.41 + executeSoon(() => gJSTerm.execute("foo2 = 'newFoo'; window.foo2", onNewFoo2)); 1.42 +} 1.43 + 1.44 +function onNewFoo2(msg) 1.45 +{ 1.46 + is(gWebConsole.outputNode.textContent.indexOf("undefined"), -1, 1.47 + "|undefined| is not displayed after adding |foo2|"); 1.48 + 1.49 + ok(msg, "output result found"); 1.50 + 1.51 + isnot(msg.textContent.indexOf("newFoo"), -1, 1.52 + "'newFoo' is displayed after adding |foo2|"); 1.53 + 1.54 + gJSTerm.clearOutput(); 1.55 + 1.56 + info("openDebugger"); 1.57 + executeSoon(() => openDebugger().then(debuggerOpened)); 1.58 +} 1.59 + 1.60 +function debuggerOpened(aResult) 1.61 +{ 1.62 + gDebuggerWin = aResult.panelWin; 1.63 + gDebuggerController = gDebuggerWin.DebuggerController; 1.64 + gThread = gDebuggerController.activeThread; 1.65 + gStackframes = gDebuggerController.StackFrames; 1.66 + 1.67 + info("openConsole"); 1.68 + executeSoon(() => 1.69 + openConsole(null, () => 1.70 + gJSTerm.execute("foo + foo2", onExecuteFooAndFoo2) 1.71 + ) 1.72 + ); 1.73 +} 1.74 + 1.75 +function onExecuteFooAndFoo2() 1.76 +{ 1.77 + let expected = "globalFooBug783499newFoo"; 1.78 + isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, 1.79 + "|foo + foo2| is displayed after starting the debugger"); 1.80 + 1.81 + executeSoon(() => { 1.82 + gJSTerm.clearOutput(); 1.83 + 1.84 + info("openDebugger"); 1.85 + openDebugger().then(() => { 1.86 + gThread.addOneTimeListener("framesadded", onFramesAdded); 1.87 + 1.88 + info("firstCall()"); 1.89 + content.wrappedJSObject.firstCall(); 1.90 + }); 1.91 + }); 1.92 +} 1.93 + 1.94 +function onFramesAdded() 1.95 +{ 1.96 + info("onFramesAdded, openConsole() now"); 1.97 + executeSoon(() => 1.98 + openConsole(null, () => 1.99 + gJSTerm.execute("foo + foo2", onExecuteFooAndFoo2InSecondCall) 1.100 + ) 1.101 + ); 1.102 +} 1.103 + 1.104 +function onExecuteFooAndFoo2InSecondCall() 1.105 +{ 1.106 + let expected = "globalFooBug783499foo2SecondCall"; 1.107 + isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, 1.108 + "|foo + foo2| from |secondCall()|"); 1.109 + 1.110 + executeSoon(() => { 1.111 + gJSTerm.clearOutput(); 1.112 + 1.113 + info("openDebugger and selectFrame(1)"); 1.114 + 1.115 + openDebugger().then(() => { 1.116 + gStackframes.selectFrame(1); 1.117 + 1.118 + info("openConsole"); 1.119 + executeSoon(() => 1.120 + openConsole(null, () => 1.121 + gJSTerm.execute("foo + foo2 + foo3", onExecuteFoo23InFirstCall) 1.122 + ) 1.123 + ); 1.124 + }); 1.125 + }); 1.126 +} 1.127 + 1.128 +function onExecuteFoo23InFirstCall() 1.129 +{ 1.130 + let expected = "fooFirstCallnewFoofoo3FirstCall"; 1.131 + isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, 1.132 + "|foo + foo2 + foo3| from |firstCall()|"); 1.133 + 1.134 + executeSoon(() => 1.135 + gJSTerm.execute("foo = 'abba'; foo3 = 'bug783499'; foo + foo3", 1.136 + onExecuteFooAndFoo3ChangesInFirstCall)); 1.137 +} 1.138 + 1.139 +function onExecuteFooAndFoo3ChangesInFirstCall() 1.140 +{ 1.141 + let expected = "abbabug783499"; 1.142 + isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, 1.143 + "|foo + foo3| updated in |firstCall()|"); 1.144 + 1.145 + is(content.wrappedJSObject.foo, "globalFooBug783499", "|foo| in content window"); 1.146 + is(content.wrappedJSObject.foo2, "newFoo", "|foo2| in content window"); 1.147 + ok(!content.wrappedJSObject.foo3, "|foo3| was not added to the content window"); 1.148 + 1.149 + gWebConsole = gJSTerm = gDebuggerWin = gThread = gDebuggerController = 1.150 + gStackframes = null; 1.151 + executeSoon(finishTest); 1.152 +}