michael@0: /* 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: // Test that makes sure web console eval happens in the user-selected stackframe michael@0: // from the js debugger. michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html"; michael@0: michael@0: let gWebConsole, gJSTerm, gDebuggerWin, gThread, gDebuggerController, gStackframes; michael@0: michael@0: function test() michael@0: { michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, consoleOpened); michael@0: }, true); michael@0: } michael@0: michael@0: function consoleOpened(hud) michael@0: { michael@0: gWebConsole = hud; michael@0: gJSTerm = hud.jsterm; michael@0: gJSTerm.execute("foo", onExecuteFoo); michael@0: } michael@0: michael@0: function onExecuteFoo() michael@0: { michael@0: isnot(gWebConsole.outputNode.textContent.indexOf("globalFooBug783499"), -1, michael@0: "|foo| value is correct"); michael@0: michael@0: gJSTerm.clearOutput(); michael@0: michael@0: // Test for Bug 690529 - Web Console and Scratchpad should evaluate michael@0: // expressions in the scope of the content window, not in a sandbox. michael@0: executeSoon(() => gJSTerm.execute("foo2 = 'newFoo'; window.foo2", onNewFoo2)); michael@0: } michael@0: michael@0: function onNewFoo2(msg) michael@0: { michael@0: is(gWebConsole.outputNode.textContent.indexOf("undefined"), -1, michael@0: "|undefined| is not displayed after adding |foo2|"); michael@0: michael@0: ok(msg, "output result found"); michael@0: michael@0: isnot(msg.textContent.indexOf("newFoo"), -1, michael@0: "'newFoo' is displayed after adding |foo2|"); michael@0: michael@0: gJSTerm.clearOutput(); michael@0: michael@0: info("openDebugger"); michael@0: executeSoon(() => openDebugger().then(debuggerOpened)); michael@0: } michael@0: michael@0: function debuggerOpened(aResult) michael@0: { michael@0: gDebuggerWin = aResult.panelWin; michael@0: gDebuggerController = gDebuggerWin.DebuggerController; michael@0: gThread = gDebuggerController.activeThread; michael@0: gStackframes = gDebuggerController.StackFrames; michael@0: michael@0: info("openConsole"); michael@0: executeSoon(() => michael@0: openConsole(null, () => michael@0: gJSTerm.execute("foo + foo2", onExecuteFooAndFoo2) michael@0: ) michael@0: ); michael@0: } michael@0: michael@0: function onExecuteFooAndFoo2() michael@0: { michael@0: let expected = "globalFooBug783499newFoo"; michael@0: isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, michael@0: "|foo + foo2| is displayed after starting the debugger"); michael@0: michael@0: executeSoon(() => { michael@0: gJSTerm.clearOutput(); michael@0: michael@0: info("openDebugger"); michael@0: openDebugger().then(() => { michael@0: gThread.addOneTimeListener("framesadded", onFramesAdded); michael@0: michael@0: info("firstCall()"); michael@0: content.wrappedJSObject.firstCall(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function onFramesAdded() michael@0: { michael@0: info("onFramesAdded, openConsole() now"); michael@0: executeSoon(() => michael@0: openConsole(null, () => michael@0: gJSTerm.execute("foo + foo2", onExecuteFooAndFoo2InSecondCall) michael@0: ) michael@0: ); michael@0: } michael@0: michael@0: function onExecuteFooAndFoo2InSecondCall() michael@0: { michael@0: let expected = "globalFooBug783499foo2SecondCall"; michael@0: isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, michael@0: "|foo + foo2| from |secondCall()|"); michael@0: michael@0: executeSoon(() => { michael@0: gJSTerm.clearOutput(); michael@0: michael@0: info("openDebugger and selectFrame(1)"); michael@0: michael@0: openDebugger().then(() => { michael@0: gStackframes.selectFrame(1); michael@0: michael@0: info("openConsole"); michael@0: executeSoon(() => michael@0: openConsole(null, () => michael@0: gJSTerm.execute("foo + foo2 + foo3", onExecuteFoo23InFirstCall) michael@0: ) michael@0: ); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function onExecuteFoo23InFirstCall() michael@0: { michael@0: let expected = "fooFirstCallnewFoofoo3FirstCall"; michael@0: isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, michael@0: "|foo + foo2 + foo3| from |firstCall()|"); michael@0: michael@0: executeSoon(() => michael@0: gJSTerm.execute("foo = 'abba'; foo3 = 'bug783499'; foo + foo3", michael@0: onExecuteFooAndFoo3ChangesInFirstCall)); michael@0: } michael@0: michael@0: function onExecuteFooAndFoo3ChangesInFirstCall() michael@0: { michael@0: let expected = "abbabug783499"; michael@0: isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, michael@0: "|foo + foo3| updated in |firstCall()|"); michael@0: michael@0: is(content.wrappedJSObject.foo, "globalFooBug783499", "|foo| in content window"); michael@0: is(content.wrappedJSObject.foo2, "newFoo", "|foo2| in content window"); michael@0: ok(!content.wrappedJSObject.foo3, "|foo3| was not added to the content window"); michael@0: michael@0: gWebConsole = gJSTerm = gDebuggerWin = gThread = gDebuggerController = michael@0: gStackframes = null; michael@0: executeSoon(finishTest); michael@0: }