1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_console_variables_view_while_debugging.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 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, when changing the value of a property in the variables 1.11 +// view. 1.12 + 1.13 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html"; 1.14 + 1.15 +let gWebConsole, gJSTerm, gDebuggerWin, gThread, gDebuggerController, 1.16 + gStackframes, gVariablesView; 1.17 + 1.18 +function test() 1.19 +{ 1.20 + addTab(TEST_URI); 1.21 + browser.addEventListener("load", function onLoad() { 1.22 + browser.removeEventListener("load", onLoad, true); 1.23 + openConsole(null, consoleOpened); 1.24 + }, true); 1.25 +} 1.26 + 1.27 +function consoleOpened(hud) 1.28 +{ 1.29 + gWebConsole = hud; 1.30 + gJSTerm = hud.jsterm; 1.31 + 1.32 + executeSoon(() => { 1.33 + info("openDebugger"); 1.34 + openDebugger().then(debuggerOpened); 1.35 + }); 1.36 +} 1.37 + 1.38 +function debuggerOpened(aResult) 1.39 +{ 1.40 + gDebuggerWin = aResult.panelWin; 1.41 + gDebuggerController = gDebuggerWin.DebuggerController; 1.42 + gThread = gDebuggerController.activeThread; 1.43 + gStackframes = gDebuggerController.StackFrames; 1.44 + 1.45 + executeSoon(() => { 1.46 + gThread.addOneTimeListener("framesadded", onFramesAdded); 1.47 + 1.48 + info("firstCall()"); 1.49 + content.wrappedJSObject.firstCall(); 1.50 + }); 1.51 +} 1.52 + 1.53 +function onFramesAdded() 1.54 +{ 1.55 + info("onFramesAdded"); 1.56 + 1.57 + executeSoon(() => 1.58 + openConsole(null, () => 1.59 + gJSTerm.execute("fooObj", onExecuteFooObj) 1.60 + ) 1.61 + ); 1.62 +} 1.63 + 1.64 + 1.65 +function onExecuteFooObj(msg) 1.66 +{ 1.67 + ok(msg, "output message found"); 1.68 + ok(msg.textContent.contains('{ testProp2: "testValue2" }'), "message text check"); 1.69 + 1.70 + let anchor = msg.querySelector("a"); 1.71 + ok(anchor, "object link found"); 1.72 + 1.73 + gJSTerm.once("variablesview-fetched", onFooObjFetch); 1.74 + 1.75 + executeSoon(() => EventUtils.synthesizeMouse(anchor, 2, 2, {}, 1.76 + gWebConsole.iframeWindow)); 1.77 +} 1.78 + 1.79 +function onFooObjFetch(aEvent, aVar) 1.80 +{ 1.81 + gVariablesView = aVar._variablesView; 1.82 + ok(gVariablesView, "variables view object"); 1.83 + 1.84 + findVariableViewProperties(aVar, [ 1.85 + { name: "testProp2", value: "testValue2" }, 1.86 + { name: "testProp", value: "testValue", dontMatch: true }, 1.87 + ], { webconsole: gWebConsole }).then(onTestPropFound); 1.88 +} 1.89 + 1.90 +function onTestPropFound(aResults) 1.91 +{ 1.92 + let prop = aResults[0].matchedProp; 1.93 + ok(prop, "matched the |testProp2| property in the variables view"); 1.94 + 1.95 + // Check that property value updates work and that jsterm functions can be 1.96 + // used. 1.97 + updateVariablesViewProperty({ 1.98 + property: prop, 1.99 + field: "value", 1.100 + string: "document.title + foo2 + $('p')", 1.101 + webconsole: gWebConsole, 1.102 + callback: onFooObjFetchAfterUpdate, 1.103 + }); 1.104 +} 1.105 + 1.106 +function onFooObjFetchAfterUpdate(aEvent, aVar) 1.107 +{ 1.108 + info("onFooObjFetchAfterUpdate"); 1.109 + let para = content.wrappedJSObject.document.querySelector("p"); 1.110 + let expectedValue = content.document.title + "foo2SecondCall" + para; 1.111 + 1.112 + findVariableViewProperties(aVar, [ 1.113 + { name: "testProp2", value: expectedValue }, 1.114 + ], { webconsole: gWebConsole }).then(onUpdatedTestPropFound); 1.115 +} 1.116 + 1.117 +function onUpdatedTestPropFound(aResults) 1.118 +{ 1.119 + let prop = aResults[0].matchedProp; 1.120 + ok(prop, "matched the updated |testProp2| property value"); 1.121 + 1.122 + // Check that testProp2 was updated. 1.123 + executeSoon(() => gJSTerm.execute("fooObj.testProp2", onExecuteFooObjTestProp2)); 1.124 +} 1.125 + 1.126 +function onExecuteFooObjTestProp2() 1.127 +{ 1.128 + let para = content.wrappedJSObject.document.querySelector("p"); 1.129 + let expected = content.document.title + "foo2SecondCall" + para; 1.130 + 1.131 + isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, 1.132 + "fooObj.testProp2 is correct"); 1.133 + 1.134 + gWebConsole = gJSTerm = gDebuggerWin = gThread = gDebuggerController = 1.135 + gStackframes = gVariablesView = null; 1.136 + executeSoon(finishTest); 1.137 +}