1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_console_custom_styles.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +"use strict"; 1.8 + 1.9 +// Test that the '%c' modifier works with the console API. See bug 823097. 1.10 + 1.11 +function test() { 1.12 + let hud; 1.13 + 1.14 + const TEST_URI = "data:text/html;charset=utf8,<p>test for " + 1.15 + "console.log('%ccustom styles', 'color:red')"; 1.16 + 1.17 + const checks = [{ 1.18 + // check the basics work 1.19 + style: "color:red;font-size:1.3em", 1.20 + props: { color: true, fontSize: true }, 1.21 + sameStyleExpected: true, 1.22 + }, { 1.23 + // check that the url() is not allowed 1.24 + style: "color:blue;background-image:url('http://example.com/test')", 1.25 + props: { color: true, fontSize: false, background: false, 1.26 + backgroundImage: false }, 1.27 + sameStyleExpected: false, 1.28 + }, { 1.29 + // check that some properties are not allowed 1.30 + style: "color:pink;position:absolute;top:10px", 1.31 + props: { color: true, position: false, top: false }, 1.32 + sameStyleExpected: false, 1.33 + }]; 1.34 + 1.35 + Task.spawn(runner).then(finishTest); 1.36 + 1.37 + function* runner() { 1.38 + const {tab} = yield loadTab(TEST_URI); 1.39 + hud = yield openConsole(tab); 1.40 + 1.41 + for (let check of checks) { 1.42 + yield checkStyle(check); 1.43 + } 1.44 + 1.45 + yield closeConsole(tab); 1.46 + } 1.47 + 1.48 + function* checkStyle(check) { 1.49 + hud.jsterm.clearOutput(); 1.50 + 1.51 + info("checkStyle " + check.style); 1.52 + hud.jsterm.execute("console.log('%cfoobar', \"" + check.style + "\")"); 1.53 + 1.54 + let [result] = yield waitForMessages({ 1.55 + webconsole: hud, 1.56 + messages: [{ 1.57 + text: "foobar", 1.58 + category: CATEGORY_WEBDEV, 1.59 + }], 1.60 + }); 1.61 + 1.62 + let msg = [...result.matched][0]; 1.63 + ok(msg, "message element"); 1.64 + 1.65 + let span = msg.querySelector(".message-body span[style]"); 1.66 + ok(span, "span element"); 1.67 + 1.68 + info("span textContent is: " + span.textContent); 1.69 + isnot(span.textContent.indexOf("foobar"), -1, "span textContent check"); 1.70 + 1.71 + let outputStyle = span.getAttribute("style").replace(/\s+|;+$/g, ""); 1.72 + if (check.sameStyleExpected) { 1.73 + is(outputStyle, check.style, "span style is correct"); 1.74 + } else { 1.75 + isnot(outputStyle, check.style, "span style is not the same"); 1.76 + } 1.77 + 1.78 + for (let prop of Object.keys(check.props)) { 1.79 + is(!!span.style[prop], check.props[prop], "property check for " + prop); 1.80 + } 1.81 + } 1.82 +}