michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: // Test that the '%c' modifier works with the console API. See bug 823097. michael@0: michael@0: function test() { michael@0: let hud; michael@0: michael@0: const TEST_URI = "data:text/html;charset=utf8,

test for " + michael@0: "console.log('%ccustom styles', 'color:red')"; michael@0: michael@0: const checks = [{ michael@0: // check the basics work michael@0: style: "color:red;font-size:1.3em", michael@0: props: { color: true, fontSize: true }, michael@0: sameStyleExpected: true, michael@0: }, { michael@0: // check that the url() is not allowed michael@0: style: "color:blue;background-image:url('http://example.com/test')", michael@0: props: { color: true, fontSize: false, background: false, michael@0: backgroundImage: false }, michael@0: sameStyleExpected: false, michael@0: }, { michael@0: // check that some properties are not allowed michael@0: style: "color:pink;position:absolute;top:10px", michael@0: props: { color: true, position: false, top: false }, michael@0: sameStyleExpected: false, michael@0: }]; michael@0: michael@0: Task.spawn(runner).then(finishTest); michael@0: michael@0: function* runner() { michael@0: const {tab} = yield loadTab(TEST_URI); michael@0: hud = yield openConsole(tab); michael@0: michael@0: for (let check of checks) { michael@0: yield checkStyle(check); michael@0: } michael@0: michael@0: yield closeConsole(tab); michael@0: } michael@0: michael@0: function* checkStyle(check) { michael@0: hud.jsterm.clearOutput(); michael@0: michael@0: info("checkStyle " + check.style); michael@0: hud.jsterm.execute("console.log('%cfoobar', \"" + check.style + "\")"); michael@0: michael@0: let [result] = yield waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "foobar", michael@0: category: CATEGORY_WEBDEV, michael@0: }], michael@0: }); michael@0: michael@0: let msg = [...result.matched][0]; michael@0: ok(msg, "message element"); michael@0: michael@0: let span = msg.querySelector(".message-body span[style]"); michael@0: ok(span, "span element"); michael@0: michael@0: info("span textContent is: " + span.textContent); michael@0: isnot(span.textContent.indexOf("foobar"), -1, "span textContent check"); michael@0: michael@0: let outputStyle = span.getAttribute("style").replace(/\s+|;+$/g, ""); michael@0: if (check.sameStyleExpected) { michael@0: is(outputStyle, check.style, "span style is correct"); michael@0: } else { michael@0: isnot(outputStyle, check.style, "span style is not the same"); michael@0: } michael@0: michael@0: for (let prop of Object.keys(check.props)) { michael@0: is(!!span.style[prop], check.props[prop], "property check for " + prop); michael@0: } michael@0: } michael@0: }