browser/devtools/webconsole/test/browser_console_variables_view.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:934c5790cf5c
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
5
6 // Check that variables view works as expected in the web console.
7
8 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html";
9
10 let gWebConsole, gJSTerm, gVariablesView;
11
12 function test()
13 {
14 addTab(TEST_URI);
15 browser.addEventListener("load", function onLoad() {
16 browser.removeEventListener("load", onLoad, true);
17 openConsole(null, consoleOpened);
18 }, true);
19 }
20
21 function consoleOpened(hud)
22 {
23 gWebConsole = hud;
24 gJSTerm = hud.jsterm;
25 gJSTerm.execute("fooObj", onExecuteFooObj);
26 }
27
28 function onExecuteFooObj(msg)
29 {
30 ok(msg, "output message found");
31 ok(msg.textContent.contains('{ testProp: "testValue" }'), "message text check");
32
33 let anchor = msg.querySelector("a");
34 ok(anchor, "object link found");
35
36 gJSTerm.once("variablesview-fetched", onFooObjFetch);
37
38 executeSoon(() =>
39 EventUtils.synthesizeMouse(anchor, 2, 2, {}, gWebConsole.iframeWindow)
40 );
41 }
42
43 function onFooObjFetch(aEvent, aVar)
44 {
45 gVariablesView = aVar._variablesView;
46 ok(gVariablesView, "variables view object");
47
48 findVariableViewProperties(aVar, [
49 { name: "testProp", value: "testValue" },
50 ], { webconsole: gWebConsole }).then(onTestPropFound);
51 }
52
53 function onTestPropFound(aResults)
54 {
55 let prop = aResults[0].matchedProp;
56 ok(prop, "matched the |testProp| property in the variables view");
57
58 is(content.wrappedJSObject.fooObj.testProp, aResults[0].value,
59 "|fooObj.testProp| value is correct");
60
61 // Check that property value updates work and that jsterm functions can be
62 // used.
63 updateVariablesViewProperty({
64 property: prop,
65 field: "value",
66 string: "document.title + window.location + $('p')",
67 webconsole: gWebConsole,
68 callback: onFooObjFetchAfterUpdate,
69 });
70 }
71
72 function onFooObjFetchAfterUpdate(aEvent, aVar)
73 {
74 info("onFooObjFetchAfterUpdate");
75 let para = content.wrappedJSObject.document.querySelector("p");
76 let expectedValue = content.document.title + content.location + para;
77
78 findVariableViewProperties(aVar, [
79 { name: "testProp", value: expectedValue },
80 ], { webconsole: gWebConsole }).then(onUpdatedTestPropFound);
81 }
82
83 function onUpdatedTestPropFound(aResults)
84 {
85 let prop = aResults[0].matchedProp;
86 ok(prop, "matched the updated |testProp| property value");
87
88 is(content.wrappedJSObject.fooObj.testProp, aResults[0].value,
89 "|fooObj.testProp| value has been updated");
90
91 // Check that property name updates work.
92 updateVariablesViewProperty({
93 property: prop,
94 field: "name",
95 string: "testUpdatedProp",
96 webconsole: gWebConsole,
97 callback: onFooObjFetchAfterPropRename,
98 });
99 }
100
101 function onFooObjFetchAfterPropRename(aEvent, aVar)
102 {
103 info("onFooObjFetchAfterPropRename");
104
105 let para = content.wrappedJSObject.document.querySelector("p");
106 let expectedValue = content.document.title + content.location + para;
107
108 // Check that the new value is in the variables view.
109 findVariableViewProperties(aVar, [
110 { name: "testUpdatedProp", value: expectedValue },
111 ], { webconsole: gWebConsole }).then(onRenamedTestPropFound);
112 }
113
114 function onRenamedTestPropFound(aResults)
115 {
116 let prop = aResults[0].matchedProp;
117 ok(prop, "matched the renamed |testProp| property");
118
119 ok(!content.wrappedJSObject.fooObj.testProp,
120 "|fooObj.testProp| has been deleted");
121 is(content.wrappedJSObject.fooObj.testUpdatedProp, aResults[0].value,
122 "|fooObj.testUpdatedProp| is correct");
123
124 // Check that property value updates that cause exceptions are reported in
125 // the web console output.
126 updateVariablesViewProperty({
127 property: prop,
128 field: "value",
129 string: "foobarzFailure()",
130 webconsole: gWebConsole,
131 callback: onPropUpdateError,
132 });
133 }
134
135 function onPropUpdateError(aEvent, aVar)
136 {
137 info("onPropUpdateError");
138
139 let para = content.wrappedJSObject.document.querySelector("p");
140 let expectedValue = content.document.title + content.location + para;
141
142 // Make sure the property did not change.
143 findVariableViewProperties(aVar, [
144 { name: "testUpdatedProp", value: expectedValue },
145 ], { webconsole: gWebConsole }).then(onRenamedTestPropFoundAgain);
146 }
147
148 function onRenamedTestPropFoundAgain(aResults)
149 {
150 let prop = aResults[0].matchedProp;
151 ok(prop, "matched the renamed |testProp| property again");
152
153 let outputNode = gWebConsole.outputNode;
154
155 waitForMessages({
156 webconsole: gWebConsole,
157 messages: [{
158 name: "exception in property update reported in the web console output",
159 text: "foobarzFailure",
160 category: CATEGORY_OUTPUT,
161 severity: SEVERITY_ERROR,
162 }],
163 }).then(testPropDelete.bind(null, prop));
164 }
165
166 function testPropDelete(aProp)
167 {
168 gVariablesView.window.focus();
169 aProp.focus();
170
171 executeSoon(() => {
172 EventUtils.synthesizeKey("VK_DELETE", {}, gVariablesView.window);
173 gWebConsole = gJSTerm = gVariablesView = null;
174 });
175
176 waitForSuccess({
177 name: "property deleted",
178 timeout: 60000,
179 validatorFn: () => !("testUpdatedProp" in content.wrappedJSObject.fooObj),
180 successFn: finishTest,
181 failureFn: finishTest,
182 });
183 }

mercurial