Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
5 let {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
6 let {OutputParser} = devtools.require("devtools/output-parser");
8 let parser;
9 let doc;
11 function test() {
12 waitForExplicitFinish();
14 gBrowser.selectedTab = gBrowser.addTab();
15 gBrowser.selectedBrowser.addEventListener("load", function onload() {
16 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
17 waitForFocus(init, content);
18 doc = content.document;
19 }, true);
21 content.location = "data:text/html,<h1>browser_outputParser.js</h1>" +
22 "<div></div>";
23 }
25 function init() {
26 parser = new OutputParser();
27 testParseCssProperty();
28 }
30 function testParseCssProperty() {
31 let frag = parser.parseCssProperty("border", "1px solid red", {
32 colorSwatchClass: "test-colorswatch"
33 });
35 let target = doc.querySelector("div");
36 ok(target, "captain, we have the div");
37 target.appendChild(frag);
39 is(target.innerHTML,
40 '1px solid <span style="background-color:red" class="test-colorswatch"></span><span>#F00</span>',
41 "CSS property correctly parsed");
43 target.innerHTML = "";
45 let frag = parser.parseCssProperty("background-image", "linear-gradient(to right, #F60 10%, rgba(0,0,0,1))", {
46 colorSwatchClass: "test-colorswatch",
47 colorClass: "test-color"
48 });
49 target.appendChild(frag);
50 is(target.innerHTML,
51 'linear-gradient(to right, <span style="background-color:#F60" class="test-colorswatch"></span><span class="test-color">#F60</span> 10%, ' +
52 '<span style="background-color:rgba(0,0,0,1)" class="test-colorswatch"></span><span class="test-color">#000</span>)',
53 "Gradient CSS property correctly parsed");
55 target.innerHTML = "";
57 testParseHTMLAttribute();
58 }
60 function testParseHTMLAttribute() {
61 let attrib = "color:red; font-size: 12px; background-image: " +
62 "url(chrome://branding/content/about-logo.png)";
63 let frag = parser.parseHTMLAttribute(attrib, {
64 urlClass: "theme-link",
65 colorClass: "theme-color"
66 });
68 let target = doc.querySelector("div");
69 ok(target, "captain, we have the div");
70 target.appendChild(frag);
72 let expected = 'color:<span class="theme-color">#F00</span>; font-size: 12px; ' +
73 'background-image: url(\'<a href="chrome://branding/content/about-logo.png" ' +
74 'class="theme-link" ' +
75 'target="_blank">chrome://branding/content/about-logo.png</a>\')';
77 is(target.innerHTML, expected, "HTML Attribute correctly parsed");
78 target.innerHTML = "";
79 testParseNonCssHTMLAttribute();
80 }
82 function testParseNonCssHTMLAttribute() {
83 let attrib = "someclass background someotherclass red";
84 let frag = parser.parseHTMLAttribute(attrib);
86 let target = doc.querySelector("div");
87 ok(target, "captain, we have the div");
88 target.appendChild(frag);
90 let expected = 'someclass background someotherclass red';
92 is(target.innerHTML, expected, "Non-CSS HTML Attribute correctly parsed");
93 target.innerHTML = "";
94 finishUp();
95 }
98 function finishUp() {
99 Services = Loader = OutputParser = parser = doc = null;
100 gBrowser.removeCurrentTab();
101 finish();
102 }