browser/devtools/webconsole/test/browser_webconsole_console_custom_styles.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial