browser/devtools/webconsole/test/browser_console_variables_view_while_debugging.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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, when changing the value of a property in the variables
michael@0 8 // view.
michael@0 9
michael@0 10 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html";
michael@0 11
michael@0 12 let gWebConsole, gJSTerm, gDebuggerWin, gThread, gDebuggerController,
michael@0 13 gStackframes, gVariablesView;
michael@0 14
michael@0 15 function test()
michael@0 16 {
michael@0 17 addTab(TEST_URI);
michael@0 18 browser.addEventListener("load", function onLoad() {
michael@0 19 browser.removeEventListener("load", onLoad, true);
michael@0 20 openConsole(null, consoleOpened);
michael@0 21 }, true);
michael@0 22 }
michael@0 23
michael@0 24 function consoleOpened(hud)
michael@0 25 {
michael@0 26 gWebConsole = hud;
michael@0 27 gJSTerm = hud.jsterm;
michael@0 28
michael@0 29 executeSoon(() => {
michael@0 30 info("openDebugger");
michael@0 31 openDebugger().then(debuggerOpened);
michael@0 32 });
michael@0 33 }
michael@0 34
michael@0 35 function debuggerOpened(aResult)
michael@0 36 {
michael@0 37 gDebuggerWin = aResult.panelWin;
michael@0 38 gDebuggerController = gDebuggerWin.DebuggerController;
michael@0 39 gThread = gDebuggerController.activeThread;
michael@0 40 gStackframes = gDebuggerController.StackFrames;
michael@0 41
michael@0 42 executeSoon(() => {
michael@0 43 gThread.addOneTimeListener("framesadded", onFramesAdded);
michael@0 44
michael@0 45 info("firstCall()");
michael@0 46 content.wrappedJSObject.firstCall();
michael@0 47 });
michael@0 48 }
michael@0 49
michael@0 50 function onFramesAdded()
michael@0 51 {
michael@0 52 info("onFramesAdded");
michael@0 53
michael@0 54 executeSoon(() =>
michael@0 55 openConsole(null, () =>
michael@0 56 gJSTerm.execute("fooObj", onExecuteFooObj)
michael@0 57 )
michael@0 58 );
michael@0 59 }
michael@0 60
michael@0 61
michael@0 62 function onExecuteFooObj(msg)
michael@0 63 {
michael@0 64 ok(msg, "output message found");
michael@0 65 ok(msg.textContent.contains('{ testProp2: "testValue2" }'), "message text check");
michael@0 66
michael@0 67 let anchor = msg.querySelector("a");
michael@0 68 ok(anchor, "object link found");
michael@0 69
michael@0 70 gJSTerm.once("variablesview-fetched", onFooObjFetch);
michael@0 71
michael@0 72 executeSoon(() => EventUtils.synthesizeMouse(anchor, 2, 2, {},
michael@0 73 gWebConsole.iframeWindow));
michael@0 74 }
michael@0 75
michael@0 76 function onFooObjFetch(aEvent, aVar)
michael@0 77 {
michael@0 78 gVariablesView = aVar._variablesView;
michael@0 79 ok(gVariablesView, "variables view object");
michael@0 80
michael@0 81 findVariableViewProperties(aVar, [
michael@0 82 { name: "testProp2", value: "testValue2" },
michael@0 83 { name: "testProp", value: "testValue", dontMatch: true },
michael@0 84 ], { webconsole: gWebConsole }).then(onTestPropFound);
michael@0 85 }
michael@0 86
michael@0 87 function onTestPropFound(aResults)
michael@0 88 {
michael@0 89 let prop = aResults[0].matchedProp;
michael@0 90 ok(prop, "matched the |testProp2| property in the variables view");
michael@0 91
michael@0 92 // Check that property value updates work and that jsterm functions can be
michael@0 93 // used.
michael@0 94 updateVariablesViewProperty({
michael@0 95 property: prop,
michael@0 96 field: "value",
michael@0 97 string: "document.title + foo2 + $('p')",
michael@0 98 webconsole: gWebConsole,
michael@0 99 callback: onFooObjFetchAfterUpdate,
michael@0 100 });
michael@0 101 }
michael@0 102
michael@0 103 function onFooObjFetchAfterUpdate(aEvent, aVar)
michael@0 104 {
michael@0 105 info("onFooObjFetchAfterUpdate");
michael@0 106 let para = content.wrappedJSObject.document.querySelector("p");
michael@0 107 let expectedValue = content.document.title + "foo2SecondCall" + para;
michael@0 108
michael@0 109 findVariableViewProperties(aVar, [
michael@0 110 { name: "testProp2", value: expectedValue },
michael@0 111 ], { webconsole: gWebConsole }).then(onUpdatedTestPropFound);
michael@0 112 }
michael@0 113
michael@0 114 function onUpdatedTestPropFound(aResults)
michael@0 115 {
michael@0 116 let prop = aResults[0].matchedProp;
michael@0 117 ok(prop, "matched the updated |testProp2| property value");
michael@0 118
michael@0 119 // Check that testProp2 was updated.
michael@0 120 executeSoon(() => gJSTerm.execute("fooObj.testProp2", onExecuteFooObjTestProp2));
michael@0 121 }
michael@0 122
michael@0 123 function onExecuteFooObjTestProp2()
michael@0 124 {
michael@0 125 let para = content.wrappedJSObject.document.querySelector("p");
michael@0 126 let expected = content.document.title + "foo2SecondCall" + para;
michael@0 127
michael@0 128 isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1,
michael@0 129 "fooObj.testProp2 is correct");
michael@0 130
michael@0 131 gWebConsole = gJSTerm = gDebuggerWin = gThread = gDebuggerController =
michael@0 132 gStackframes = gVariablesView = null;
michael@0 133 executeSoon(finishTest);
michael@0 134 }

mercurial