|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 // Test that the '%c' modifier works with the console API. See bug 823097. |
|
7 |
|
8 function test() { |
|
9 let hud; |
|
10 |
|
11 const TEST_URI = "data:text/html;charset=utf8,<p>test for " + |
|
12 "console.log('%ccustom styles', 'color:red')"; |
|
13 |
|
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 }]; |
|
31 |
|
32 Task.spawn(runner).then(finishTest); |
|
33 |
|
34 function* runner() { |
|
35 const {tab} = yield loadTab(TEST_URI); |
|
36 hud = yield openConsole(tab); |
|
37 |
|
38 for (let check of checks) { |
|
39 yield checkStyle(check); |
|
40 } |
|
41 |
|
42 yield closeConsole(tab); |
|
43 } |
|
44 |
|
45 function* checkStyle(check) { |
|
46 hud.jsterm.clearOutput(); |
|
47 |
|
48 info("checkStyle " + check.style); |
|
49 hud.jsterm.execute("console.log('%cfoobar', \"" + check.style + "\")"); |
|
50 |
|
51 let [result] = yield waitForMessages({ |
|
52 webconsole: hud, |
|
53 messages: [{ |
|
54 text: "foobar", |
|
55 category: CATEGORY_WEBDEV, |
|
56 }], |
|
57 }); |
|
58 |
|
59 let msg = [...result.matched][0]; |
|
60 ok(msg, "message element"); |
|
61 |
|
62 let span = msg.querySelector(".message-body span[style]"); |
|
63 ok(span, "span element"); |
|
64 |
|
65 info("span textContent is: " + span.textContent); |
|
66 isnot(span.textContent.indexOf("foobar"), -1, "span textContent check"); |
|
67 |
|
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 } |
|
74 |
|
75 for (let prop of Object.keys(check.props)) { |
|
76 is(!!span.style[prop], check.props[prop], "property check for " + prop); |
|
77 } |
|
78 } |
|
79 } |