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