browser/devtools/shared/test/browser_outputparser.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
michael@0 5 let {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
michael@0 6 let {OutputParser} = devtools.require("devtools/output-parser");
michael@0 7
michael@0 8 let parser;
michael@0 9 let doc;
michael@0 10
michael@0 11 function test() {
michael@0 12 waitForExplicitFinish();
michael@0 13
michael@0 14 gBrowser.selectedTab = gBrowser.addTab();
michael@0 15 gBrowser.selectedBrowser.addEventListener("load", function onload() {
michael@0 16 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
michael@0 17 waitForFocus(init, content);
michael@0 18 doc = content.document;
michael@0 19 }, true);
michael@0 20
michael@0 21 content.location = "data:text/html,<h1>browser_outputParser.js</h1>" +
michael@0 22 "<div></div>";
michael@0 23 }
michael@0 24
michael@0 25 function init() {
michael@0 26 parser = new OutputParser();
michael@0 27 testParseCssProperty();
michael@0 28 }
michael@0 29
michael@0 30 function testParseCssProperty() {
michael@0 31 let frag = parser.parseCssProperty("border", "1px solid red", {
michael@0 32 colorSwatchClass: "test-colorswatch"
michael@0 33 });
michael@0 34
michael@0 35 let target = doc.querySelector("div");
michael@0 36 ok(target, "captain, we have the div");
michael@0 37 target.appendChild(frag);
michael@0 38
michael@0 39 is(target.innerHTML,
michael@0 40 '1px solid <span style="background-color:red" class="test-colorswatch"></span><span>#F00</span>',
michael@0 41 "CSS property correctly parsed");
michael@0 42
michael@0 43 target.innerHTML = "";
michael@0 44
michael@0 45 let frag = parser.parseCssProperty("background-image", "linear-gradient(to right, #F60 10%, rgba(0,0,0,1))", {
michael@0 46 colorSwatchClass: "test-colorswatch",
michael@0 47 colorClass: "test-color"
michael@0 48 });
michael@0 49 target.appendChild(frag);
michael@0 50 is(target.innerHTML,
michael@0 51 'linear-gradient(to right, <span style="background-color:#F60" class="test-colorswatch"></span><span class="test-color">#F60</span> 10%, ' +
michael@0 52 '<span style="background-color:rgba(0,0,0,1)" class="test-colorswatch"></span><span class="test-color">#000</span>)',
michael@0 53 "Gradient CSS property correctly parsed");
michael@0 54
michael@0 55 target.innerHTML = "";
michael@0 56
michael@0 57 testParseHTMLAttribute();
michael@0 58 }
michael@0 59
michael@0 60 function testParseHTMLAttribute() {
michael@0 61 let attrib = "color:red; font-size: 12px; background-image: " +
michael@0 62 "url(chrome://branding/content/about-logo.png)";
michael@0 63 let frag = parser.parseHTMLAttribute(attrib, {
michael@0 64 urlClass: "theme-link",
michael@0 65 colorClass: "theme-color"
michael@0 66 });
michael@0 67
michael@0 68 let target = doc.querySelector("div");
michael@0 69 ok(target, "captain, we have the div");
michael@0 70 target.appendChild(frag);
michael@0 71
michael@0 72 let expected = 'color:<span class="theme-color">#F00</span>; font-size: 12px; ' +
michael@0 73 'background-image: url(\'<a href="chrome://branding/content/about-logo.png" ' +
michael@0 74 'class="theme-link" ' +
michael@0 75 'target="_blank">chrome://branding/content/about-logo.png</a>\')';
michael@0 76
michael@0 77 is(target.innerHTML, expected, "HTML Attribute correctly parsed");
michael@0 78 target.innerHTML = "";
michael@0 79 testParseNonCssHTMLAttribute();
michael@0 80 }
michael@0 81
michael@0 82 function testParseNonCssHTMLAttribute() {
michael@0 83 let attrib = "someclass background someotherclass red";
michael@0 84 let frag = parser.parseHTMLAttribute(attrib);
michael@0 85
michael@0 86 let target = doc.querySelector("div");
michael@0 87 ok(target, "captain, we have the div");
michael@0 88 target.appendChild(frag);
michael@0 89
michael@0 90 let expected = 'someclass background someotherclass red';
michael@0 91
michael@0 92 is(target.innerHTML, expected, "Non-CSS HTML Attribute correctly parsed");
michael@0 93 target.innerHTML = "";
michael@0 94 finishUp();
michael@0 95 }
michael@0 96
michael@0 97
michael@0 98 function finishUp() {
michael@0 99 Services = Loader = OutputParser = parser = doc = null;
michael@0 100 gBrowser.removeCurrentTab();
michael@0 101 finish();
michael@0 102 }

mercurial