Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 // Test that makes sure web console eval happens in the user-selected stackframe
7 // from the js debugger, when changing the value of a property in the variables
8 // view.
10 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html";
12 let gWebConsole, gJSTerm, gDebuggerWin, gThread, gDebuggerController,
13 gStackframes, gVariablesView;
15 function test()
16 {
17 addTab(TEST_URI);
18 browser.addEventListener("load", function onLoad() {
19 browser.removeEventListener("load", onLoad, true);
20 openConsole(null, consoleOpened);
21 }, true);
22 }
24 function consoleOpened(hud)
25 {
26 gWebConsole = hud;
27 gJSTerm = hud.jsterm;
29 executeSoon(() => {
30 info("openDebugger");
31 openDebugger().then(debuggerOpened);
32 });
33 }
35 function debuggerOpened(aResult)
36 {
37 gDebuggerWin = aResult.panelWin;
38 gDebuggerController = gDebuggerWin.DebuggerController;
39 gThread = gDebuggerController.activeThread;
40 gStackframes = gDebuggerController.StackFrames;
42 executeSoon(() => {
43 gThread.addOneTimeListener("framesadded", onFramesAdded);
45 info("firstCall()");
46 content.wrappedJSObject.firstCall();
47 });
48 }
50 function onFramesAdded()
51 {
52 info("onFramesAdded");
54 executeSoon(() =>
55 openConsole(null, () =>
56 gJSTerm.execute("fooObj", onExecuteFooObj)
57 )
58 );
59 }
62 function onExecuteFooObj(msg)
63 {
64 ok(msg, "output message found");
65 ok(msg.textContent.contains('{ testProp2: "testValue2" }'), "message text check");
67 let anchor = msg.querySelector("a");
68 ok(anchor, "object link found");
70 gJSTerm.once("variablesview-fetched", onFooObjFetch);
72 executeSoon(() => EventUtils.synthesizeMouse(anchor, 2, 2, {},
73 gWebConsole.iframeWindow));
74 }
76 function onFooObjFetch(aEvent, aVar)
77 {
78 gVariablesView = aVar._variablesView;
79 ok(gVariablesView, "variables view object");
81 findVariableViewProperties(aVar, [
82 { name: "testProp2", value: "testValue2" },
83 { name: "testProp", value: "testValue", dontMatch: true },
84 ], { webconsole: gWebConsole }).then(onTestPropFound);
85 }
87 function onTestPropFound(aResults)
88 {
89 let prop = aResults[0].matchedProp;
90 ok(prop, "matched the |testProp2| property in the variables view");
92 // Check that property value updates work and that jsterm functions can be
93 // used.
94 updateVariablesViewProperty({
95 property: prop,
96 field: "value",
97 string: "document.title + foo2 + $('p')",
98 webconsole: gWebConsole,
99 callback: onFooObjFetchAfterUpdate,
100 });
101 }
103 function onFooObjFetchAfterUpdate(aEvent, aVar)
104 {
105 info("onFooObjFetchAfterUpdate");
106 let para = content.wrappedJSObject.document.querySelector("p");
107 let expectedValue = content.document.title + "foo2SecondCall" + para;
109 findVariableViewProperties(aVar, [
110 { name: "testProp2", value: expectedValue },
111 ], { webconsole: gWebConsole }).then(onUpdatedTestPropFound);
112 }
114 function onUpdatedTestPropFound(aResults)
115 {
116 let prop = aResults[0].matchedProp;
117 ok(prop, "matched the updated |testProp2| property value");
119 // Check that testProp2 was updated.
120 executeSoon(() => gJSTerm.execute("fooObj.testProp2", onExecuteFooObjTestProp2));
121 }
123 function onExecuteFooObjTestProp2()
124 {
125 let para = content.wrappedJSObject.document.querySelector("p");
126 let expected = content.document.title + "foo2SecondCall" + para;
128 isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1,
129 "fooObj.testProp2 is correct");
131 gWebConsole = gJSTerm = gDebuggerWin = gThread = gDebuggerController =
132 gStackframes = gVariablesView = null;
133 executeSoon(finishTest);
134 }