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 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 // Test that the '%c' modifier works with the console API. See bug 823097.
8 function test() {
9 let hud;
11 const TEST_URI = "data:text/html;charset=utf8,<p>test for " +
12 "console.log('%ccustom styles', 'color:red')";
14 const checks = [{
15 // check the basics work
16 style: "color:red;font-size:1.3em",
17 props: { color: true, fontSize: true },
18 sameStyleExpected: true,
19 }, {
20 // check that the url() is not allowed
21 style: "color:blue;background-image:url('http://example.com/test')",
22 props: { color: true, fontSize: false, background: false,
23 backgroundImage: false },
24 sameStyleExpected: false,
25 }, {
26 // check that some properties are not allowed
27 style: "color:pink;position:absolute;top:10px",
28 props: { color: true, position: false, top: false },
29 sameStyleExpected: false,
30 }];
32 Task.spawn(runner).then(finishTest);
34 function* runner() {
35 const {tab} = yield loadTab(TEST_URI);
36 hud = yield openConsole(tab);
38 for (let check of checks) {
39 yield checkStyle(check);
40 }
42 yield closeConsole(tab);
43 }
45 function* checkStyle(check) {
46 hud.jsterm.clearOutput();
48 info("checkStyle " + check.style);
49 hud.jsterm.execute("console.log('%cfoobar', \"" + check.style + "\")");
51 let [result] = yield waitForMessages({
52 webconsole: hud,
53 messages: [{
54 text: "foobar",
55 category: CATEGORY_WEBDEV,
56 }],
57 });
59 let msg = [...result.matched][0];
60 ok(msg, "message element");
62 let span = msg.querySelector(".message-body span[style]");
63 ok(span, "span element");
65 info("span textContent is: " + span.textContent);
66 isnot(span.textContent.indexOf("foobar"), -1, "span textContent check");
68 let outputStyle = span.getAttribute("style").replace(/\s+|;+$/g, "");
69 if (check.sameStyleExpected) {
70 is(outputStyle, check.style, "span style is correct");
71 } else {
72 isnot(outputStyle, check.style, "span style is not the same");
73 }
75 for (let prop of Object.keys(check.props)) {
76 is(!!span.style[prop], check.props[prop], "property check for " + prop);
77 }
78 }
79 }