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 // Check that variables view works as expected in the web console.
8 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html";
10 let gWebConsole, gJSTerm, gVariablesView;
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 }
21 function consoleOpened(hud)
22 {
23 gWebConsole = hud;
24 gJSTerm = hud.jsterm;
25 gJSTerm.execute("fooObj", onExecuteFooObj);
26 }
28 function onExecuteFooObj(msg)
29 {
30 ok(msg, "output message found");
31 ok(msg.textContent.contains('{ testProp: "testValue" }'), "message text check");
33 let anchor = msg.querySelector("a");
34 ok(anchor, "object link found");
36 gJSTerm.once("variablesview-fetched", onFooObjFetch);
38 executeSoon(() =>
39 EventUtils.synthesizeMouse(anchor, 2, 2, {}, gWebConsole.iframeWindow)
40 );
41 }
43 function onFooObjFetch(aEvent, aVar)
44 {
45 gVariablesView = aVar._variablesView;
46 ok(gVariablesView, "variables view object");
48 findVariableViewProperties(aVar, [
49 { name: "testProp", value: "testValue" },
50 ], { webconsole: gWebConsole }).then(onTestPropFound);
51 }
53 function onTestPropFound(aResults)
54 {
55 let prop = aResults[0].matchedProp;
56 ok(prop, "matched the |testProp| property in the variables view");
58 is(content.wrappedJSObject.fooObj.testProp, aResults[0].value,
59 "|fooObj.testProp| value is correct");
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 }
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;
78 findVariableViewProperties(aVar, [
79 { name: "testProp", value: expectedValue },
80 ], { webconsole: gWebConsole }).then(onUpdatedTestPropFound);
81 }
83 function onUpdatedTestPropFound(aResults)
84 {
85 let prop = aResults[0].matchedProp;
86 ok(prop, "matched the updated |testProp| property value");
88 is(content.wrappedJSObject.fooObj.testProp, aResults[0].value,
89 "|fooObj.testProp| value has been updated");
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 }
101 function onFooObjFetchAfterPropRename(aEvent, aVar)
102 {
103 info("onFooObjFetchAfterPropRename");
105 let para = content.wrappedJSObject.document.querySelector("p");
106 let expectedValue = content.document.title + content.location + para;
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 }
114 function onRenamedTestPropFound(aResults)
115 {
116 let prop = aResults[0].matchedProp;
117 ok(prop, "matched the renamed |testProp| property");
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");
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 }
135 function onPropUpdateError(aEvent, aVar)
136 {
137 info("onPropUpdateError");
139 let para = content.wrappedJSObject.document.querySelector("p");
140 let expectedValue = content.document.title + content.location + para;
142 // Make sure the property did not change.
143 findVariableViewProperties(aVar, [
144 { name: "testUpdatedProp", value: expectedValue },
145 ], { webconsole: gWebConsole }).then(onRenamedTestPropFoundAgain);
146 }
148 function onRenamedTestPropFoundAgain(aResults)
149 {
150 let prop = aResults[0].matchedProp;
151 ok(prop, "matched the renamed |testProp| property again");
153 let outputNode = gWebConsole.outputNode;
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 }
166 function testPropDelete(aProp)
167 {
168 gVariablesView.window.focus();
169 aProp.focus();
171 executeSoon(() => {
172 EventUtils.synthesizeKey("VK_DELETE", {}, gVariablesView.window);
173 gWebConsole = gJSTerm = gVariablesView = null;
174 });
176 waitForSuccess({
177 name: "property deleted",
178 timeout: 60000,
179 validatorFn: () => !("testUpdatedProp" in content.wrappedJSObject.fooObj),
180 successFn: finishTest,
181 failureFn: finishTest,
182 });
183 }