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 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
2 /* Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/ */
5 "use strict";
7 // Check that inherited properties appear as such in the rule-view
9 let {ELEMENT_STYLE} = devtools.require("devtools/server/actors/styles");
11 let test = asyncTest(function*() {
12 yield addTab("data:text/html;charset=utf-8,browser_inspector_changes.js");
13 let {toolbox, inspector, view} = yield openRuleView();
15 yield simpleInherit(inspector, view);
16 yield emptyInherit(inspector, view);
17 yield elementStyleInherit(inspector, view);
18 });
20 function* simpleInherit(inspector, view) {
21 let style = '' +
22 '#test2 {' +
23 ' background-color: green;' +
24 ' color: purple;' +
25 '}';
27 let styleNode = addStyle(content.document, style);
28 content.document.body.innerHTML = '<div id="test2"><div id="test1">Styled Node</div></div>';
30 yield selectNode("#test1", inspector);
32 let elementStyle = view._elementStyle;
33 is(elementStyle.rules.length, 2, "Should have 2 rules.");
35 let elementRule = elementStyle.rules[0];
36 ok(!elementRule.inherited, "Element style attribute should not consider itself inherited.");
38 let inheritRule = elementStyle.rules[1];
39 is(inheritRule.selectorText, "#test2", "Inherited rule should be the one that includes inheritable properties.");
40 ok(!!inheritRule.inherited, "Rule should consider itself inherited.");
41 is(inheritRule.textProps.length, 1, "Should only display one inherited style");
42 let inheritProp = inheritRule.textProps[0];
43 is(inheritProp.name, "color", "color should have been inherited.");
45 styleNode.remove();
46 }
48 function* emptyInherit(inspector, view) {
49 // No inheritable styles, this rule shouldn't show up.
50 let style = '' +
51 '#test2 {' +
52 ' background-color: green;' +
53 '}';
55 let styleNode = addStyle(content.document, style);
56 content.document.body.innerHTML = '<div id="test2"><div id="test1">Styled Node</div></div>';
58 yield selectNode("#test1", inspector);
60 let elementStyle = view._elementStyle;
61 is(elementStyle.rules.length, 1, "Should have 1 rule.");
63 let elementRule = elementStyle.rules[0];
64 ok(!elementRule.inherited, "Element style attribute should not consider itself inherited.");
66 styleNode.parentNode.removeChild(styleNode);
67 }
69 function* elementStyleInherit(inspector, view) {
70 content.document.body.innerHTML = '<div id="test2" style="color: red"><div id="test1">Styled Node</div></div>';
72 yield selectNode("#test1", inspector);
74 let elementStyle = view._elementStyle;
75 is(elementStyle.rules.length, 2, "Should have 2 rules.");
77 let elementRule = elementStyle.rules[0];
78 ok(!elementRule.inherited, "Element style attribute should not consider itself inherited.");
80 let inheritRule = elementStyle.rules[1];
81 is(inheritRule.domRule.type, ELEMENT_STYLE, "Inherited rule should be an element style, not a rule.");
82 ok(!!inheritRule.inherited, "Rule should consider itself inherited.");
83 is(inheritRule.textProps.length, 1, "Should only display one inherited style");
84 let inheritProp = inheritRule.textProps[0];
85 is(inheritProp.name, "color", "color should have been inherited.");
86 }