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, when changing the value of a property in the variables michael@0: // view. 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, michael@0: gStackframes, gVariablesView; 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: michael@0: executeSoon(() => { michael@0: info("openDebugger"); michael@0: openDebugger().then(debuggerOpened); michael@0: }); 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: executeSoon(() => { 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: function onFramesAdded() michael@0: { michael@0: info("onFramesAdded"); michael@0: michael@0: executeSoon(() => michael@0: openConsole(null, () => michael@0: gJSTerm.execute("fooObj", onExecuteFooObj) michael@0: ) michael@0: ); michael@0: } michael@0: michael@0: michael@0: function onExecuteFooObj(msg) michael@0: { michael@0: ok(msg, "output message found"); michael@0: ok(msg.textContent.contains('{ testProp2: "testValue2" }'), "message text check"); michael@0: michael@0: let anchor = msg.querySelector("a"); michael@0: ok(anchor, "object link found"); michael@0: michael@0: gJSTerm.once("variablesview-fetched", onFooObjFetch); michael@0: michael@0: executeSoon(() => EventUtils.synthesizeMouse(anchor, 2, 2, {}, michael@0: gWebConsole.iframeWindow)); michael@0: } michael@0: michael@0: function onFooObjFetch(aEvent, aVar) michael@0: { michael@0: gVariablesView = aVar._variablesView; michael@0: ok(gVariablesView, "variables view object"); michael@0: michael@0: findVariableViewProperties(aVar, [ michael@0: { name: "testProp2", value: "testValue2" }, michael@0: { name: "testProp", value: "testValue", dontMatch: true }, michael@0: ], { webconsole: gWebConsole }).then(onTestPropFound); michael@0: } michael@0: michael@0: function onTestPropFound(aResults) michael@0: { michael@0: let prop = aResults[0].matchedProp; michael@0: ok(prop, "matched the |testProp2| property in the variables view"); michael@0: michael@0: // Check that property value updates work and that jsterm functions can be michael@0: // used. michael@0: updateVariablesViewProperty({ michael@0: property: prop, michael@0: field: "value", michael@0: string: "document.title + foo2 + $('p')", michael@0: webconsole: gWebConsole, michael@0: callback: onFooObjFetchAfterUpdate, michael@0: }); michael@0: } michael@0: michael@0: function onFooObjFetchAfterUpdate(aEvent, aVar) michael@0: { michael@0: info("onFooObjFetchAfterUpdate"); michael@0: let para = content.wrappedJSObject.document.querySelector("p"); michael@0: let expectedValue = content.document.title + "foo2SecondCall" + para; michael@0: michael@0: findVariableViewProperties(aVar, [ michael@0: { name: "testProp2", value: expectedValue }, michael@0: ], { webconsole: gWebConsole }).then(onUpdatedTestPropFound); michael@0: } michael@0: michael@0: function onUpdatedTestPropFound(aResults) michael@0: { michael@0: let prop = aResults[0].matchedProp; michael@0: ok(prop, "matched the updated |testProp2| property value"); michael@0: michael@0: // Check that testProp2 was updated. michael@0: executeSoon(() => gJSTerm.execute("fooObj.testProp2", onExecuteFooObjTestProp2)); michael@0: } michael@0: michael@0: function onExecuteFooObjTestProp2() michael@0: { michael@0: let para = content.wrappedJSObject.document.querySelector("p"); michael@0: let expected = content.document.title + "foo2SecondCall" + para; michael@0: michael@0: isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, michael@0: "fooObj.testProp2 is correct"); michael@0: michael@0: gWebConsole = gJSTerm = gDebuggerWin = gThread = gDebuggerController = michael@0: gStackframes = gVariablesView = null; michael@0: executeSoon(finishTest); michael@0: }