|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
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. |
|
9 |
|
10 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html"; |
|
11 |
|
12 let gWebConsole, gJSTerm, gDebuggerWin, gThread, gDebuggerController, |
|
13 gStackframes, gVariablesView; |
|
14 |
|
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 } |
|
23 |
|
24 function consoleOpened(hud) |
|
25 { |
|
26 gWebConsole = hud; |
|
27 gJSTerm = hud.jsterm; |
|
28 |
|
29 executeSoon(() => { |
|
30 info("openDebugger"); |
|
31 openDebugger().then(debuggerOpened); |
|
32 }); |
|
33 } |
|
34 |
|
35 function debuggerOpened(aResult) |
|
36 { |
|
37 gDebuggerWin = aResult.panelWin; |
|
38 gDebuggerController = gDebuggerWin.DebuggerController; |
|
39 gThread = gDebuggerController.activeThread; |
|
40 gStackframes = gDebuggerController.StackFrames; |
|
41 |
|
42 executeSoon(() => { |
|
43 gThread.addOneTimeListener("framesadded", onFramesAdded); |
|
44 |
|
45 info("firstCall()"); |
|
46 content.wrappedJSObject.firstCall(); |
|
47 }); |
|
48 } |
|
49 |
|
50 function onFramesAdded() |
|
51 { |
|
52 info("onFramesAdded"); |
|
53 |
|
54 executeSoon(() => |
|
55 openConsole(null, () => |
|
56 gJSTerm.execute("fooObj", onExecuteFooObj) |
|
57 ) |
|
58 ); |
|
59 } |
|
60 |
|
61 |
|
62 function onExecuteFooObj(msg) |
|
63 { |
|
64 ok(msg, "output message found"); |
|
65 ok(msg.textContent.contains('{ testProp2: "testValue2" }'), "message text check"); |
|
66 |
|
67 let anchor = msg.querySelector("a"); |
|
68 ok(anchor, "object link found"); |
|
69 |
|
70 gJSTerm.once("variablesview-fetched", onFooObjFetch); |
|
71 |
|
72 executeSoon(() => EventUtils.synthesizeMouse(anchor, 2, 2, {}, |
|
73 gWebConsole.iframeWindow)); |
|
74 } |
|
75 |
|
76 function onFooObjFetch(aEvent, aVar) |
|
77 { |
|
78 gVariablesView = aVar._variablesView; |
|
79 ok(gVariablesView, "variables view object"); |
|
80 |
|
81 findVariableViewProperties(aVar, [ |
|
82 { name: "testProp2", value: "testValue2" }, |
|
83 { name: "testProp", value: "testValue", dontMatch: true }, |
|
84 ], { webconsole: gWebConsole }).then(onTestPropFound); |
|
85 } |
|
86 |
|
87 function onTestPropFound(aResults) |
|
88 { |
|
89 let prop = aResults[0].matchedProp; |
|
90 ok(prop, "matched the |testProp2| property in the variables view"); |
|
91 |
|
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 } |
|
102 |
|
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; |
|
108 |
|
109 findVariableViewProperties(aVar, [ |
|
110 { name: "testProp2", value: expectedValue }, |
|
111 ], { webconsole: gWebConsole }).then(onUpdatedTestPropFound); |
|
112 } |
|
113 |
|
114 function onUpdatedTestPropFound(aResults) |
|
115 { |
|
116 let prop = aResults[0].matchedProp; |
|
117 ok(prop, "matched the updated |testProp2| property value"); |
|
118 |
|
119 // Check that testProp2 was updated. |
|
120 executeSoon(() => gJSTerm.execute("fooObj.testProp2", onExecuteFooObjTestProp2)); |
|
121 } |
|
122 |
|
123 function onExecuteFooObjTestProp2() |
|
124 { |
|
125 let para = content.wrappedJSObject.document.querySelector("p"); |
|
126 let expected = content.document.title + "foo2SecondCall" + para; |
|
127 |
|
128 isnot(gWebConsole.outputNode.textContent.indexOf(expected), -1, |
|
129 "fooObj.testProp2 is correct"); |
|
130 |
|
131 gWebConsole = gJSTerm = gDebuggerWin = gThread = gDebuggerController = |
|
132 gStackframes = gVariablesView = null; |
|
133 executeSoon(finishTest); |
|
134 } |