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 /* vim:set ts=2 sw=2 sts=2 et: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
8 let jsterm, testDriver;
10 function test() {
11 addTab(TEST_URI);
12 browser.addEventListener("load", function onLoad() {
13 browser.removeEventListener("load", onLoad, true);
14 openConsole(null, function(hud) {
15 testDriver = testJSTerm(hud);
16 testDriver.next();
17 });
18 }, true);
19 }
21 function nextTest() {
22 testDriver.next();
23 }
25 function checkResult(msg, desc) {
26 waitForMessages({
27 webconsole: jsterm.hud.owner,
28 messages: [{
29 name: desc,
30 category: CATEGORY_OUTPUT,
31 }],
32 }).then(([result]) => {
33 let node = [...result.matched][0].querySelector(".message-body");
34 if (typeof msg == "string") {
35 is(node.textContent.trim(), msg,
36 "correct message shown for " + desc);
37 }
38 else if (typeof msg == "function") {
39 ok(msg(node), "correct message shown for " + desc);
40 }
42 nextTest();
43 });
44 }
46 function testJSTerm(hud)
47 {
48 jsterm = hud.jsterm;
49 const HELP_URL = "https://developer.mozilla.org/docs/Tools/Web_Console/Helpers";
51 jsterm.clearOutput();
52 jsterm.execute("$('#header').getAttribute('id')");
53 checkResult('"header"', "$() worked");
54 yield undefined;
56 jsterm.clearOutput();
57 jsterm.execute("$$('h1').length");
58 checkResult("1", "$$() worked");
59 yield undefined;
61 jsterm.clearOutput();
62 jsterm.execute("$x('.//*', document.body)[0] == $$('h1')[0]");
63 checkResult("true", "$x() worked");
64 yield undefined;
66 // no jsterm.clearOutput() here as we clear the output using the clear() fn.
67 jsterm.execute("clear()");
69 waitForSuccess({
70 name: "clear() worked",
71 validatorFn: function()
72 {
73 return jsterm.outputNode.childNodes.length == 0;
74 },
75 successFn: nextTest,
76 failureFn: nextTest,
77 });
79 yield undefined;
81 jsterm.clearOutput();
82 jsterm.execute("keys({b:1})[0] == 'b'");
83 checkResult("true", "keys() worked", 1);
84 yield undefined;
86 jsterm.clearOutput();
87 jsterm.execute("values({b:1})[0] == 1");
88 checkResult("true", "values() worked", 1);
89 yield undefined;
91 jsterm.clearOutput();
93 let openedLinks = 0;
94 let onExecuteCalls = 0;
95 let oldOpenLink = hud.openLink;
96 hud.openLink = (url) => {
97 if (url == HELP_URL) {
98 openedLinks++;
99 }
100 };
102 function onExecute() {
103 onExecuteCalls++;
104 if (onExecuteCalls == 3) {
105 nextTest();
106 }
107 }
109 jsterm.execute("help()", onExecute);
110 jsterm.execute("help", onExecute);
111 jsterm.execute("?", onExecute);
112 yield undefined;
114 let output = jsterm.outputNode.querySelector(".message[category='output']");
115 ok(!output, "no output for help() calls");
116 is(openedLinks, 3, "correct number of pages opened by the help calls");
117 hud.openLink = oldOpenLink;
119 jsterm.clearOutput();
120 jsterm.execute("pprint({b:2, a:1})");
121 checkResult("\" b: 2\n a: 1\"", "pprint()");
122 yield undefined;
124 // check instanceof correctness, bug 599940
125 jsterm.clearOutput();
126 jsterm.execute("[] instanceof Array");
127 checkResult("true", "[] instanceof Array == true");
128 yield undefined;
130 jsterm.clearOutput();
131 jsterm.execute("({}) instanceof Object");
132 checkResult("true", "({}) instanceof Object == true");
133 yield undefined;
135 // check for occurrences of Object XRayWrapper, bug 604430
136 jsterm.clearOutput();
137 jsterm.execute("document");
138 checkResult(function(node) {
139 return node.textContent.search(/\[object xraywrapper/i) == -1;
140 }, "document - no XrayWrapper");
141 yield undefined;
143 // check that pprint(window) and keys(window) don't throw, bug 608358
144 jsterm.clearOutput();
145 jsterm.execute("pprint(window)");
146 checkResult(null, "pprint(window)");
147 yield undefined;
149 jsterm.clearOutput();
150 jsterm.execute("keys(window)");
151 checkResult(null, "keys(window)");
152 yield undefined;
154 // bug 614561
155 jsterm.clearOutput();
156 jsterm.execute("pprint('hi')");
157 checkResult("\" 0: \"h\"\n 1: \"i\"\"", "pprint('hi')");
158 yield undefined;
160 // check that pprint(function) shows function source, bug 618344
161 jsterm.clearOutput();
162 jsterm.execute("pprint(print)");
163 checkResult(function(node) {
164 return node.textContent.indexOf("aOwner.helperResult") > -1;
165 }, "pprint(function) shows source");
166 yield undefined;
168 // check that an evaluated null produces "null", bug 650780
169 jsterm.clearOutput();
170 jsterm.execute("null");
171 checkResult("null", "null is null");
172 yield undefined;
174 jsterm.clearOutput();
175 jsterm.execute("undefined");
176 checkResult("undefined", "undefined is printed");
177 yield undefined;
179 jsterm = testDriver = null;
180 executeSoon(finishTest);
181 yield undefined;
182 }