michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
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: // Check that inherited properties appear as such in the rule-view
michael@0:
michael@0: let {ELEMENT_STYLE} = devtools.require("devtools/server/actors/styles");
michael@0:
michael@0: let test = asyncTest(function*() {
michael@0: yield addTab("data:text/html;charset=utf-8,browser_inspector_changes.js");
michael@0: let {toolbox, inspector, view} = yield openRuleView();
michael@0:
michael@0: yield simpleInherit(inspector, view);
michael@0: yield emptyInherit(inspector, view);
michael@0: yield elementStyleInherit(inspector, view);
michael@0: });
michael@0:
michael@0: function* simpleInherit(inspector, view) {
michael@0: let style = '' +
michael@0: '#test2 {' +
michael@0: ' background-color: green;' +
michael@0: ' color: purple;' +
michael@0: '}';
michael@0:
michael@0: let styleNode = addStyle(content.document, style);
michael@0: content.document.body.innerHTML = '
';
michael@0:
michael@0: yield selectNode("#test1", inspector);
michael@0:
michael@0: let elementStyle = view._elementStyle;
michael@0: is(elementStyle.rules.length, 2, "Should have 2 rules.");
michael@0:
michael@0: let elementRule = elementStyle.rules[0];
michael@0: ok(!elementRule.inherited, "Element style attribute should not consider itself inherited.");
michael@0:
michael@0: let inheritRule = elementStyle.rules[1];
michael@0: is(inheritRule.selectorText, "#test2", "Inherited rule should be the one that includes inheritable properties.");
michael@0: ok(!!inheritRule.inherited, "Rule should consider itself inherited.");
michael@0: is(inheritRule.textProps.length, 1, "Should only display one inherited style");
michael@0: let inheritProp = inheritRule.textProps[0];
michael@0: is(inheritProp.name, "color", "color should have been inherited.");
michael@0:
michael@0: styleNode.remove();
michael@0: }
michael@0:
michael@0: function* emptyInherit(inspector, view) {
michael@0: // No inheritable styles, this rule shouldn't show up.
michael@0: let style = '' +
michael@0: '#test2 {' +
michael@0: ' background-color: green;' +
michael@0: '}';
michael@0:
michael@0: let styleNode = addStyle(content.document, style);
michael@0: content.document.body.innerHTML = '';
michael@0:
michael@0: yield selectNode("#test1", inspector);
michael@0:
michael@0: let elementStyle = view._elementStyle;
michael@0: is(elementStyle.rules.length, 1, "Should have 1 rule.");
michael@0:
michael@0: let elementRule = elementStyle.rules[0];
michael@0: ok(!elementRule.inherited, "Element style attribute should not consider itself inherited.");
michael@0:
michael@0: styleNode.parentNode.removeChild(styleNode);
michael@0: }
michael@0:
michael@0: function* elementStyleInherit(inspector, view) {
michael@0: content.document.body.innerHTML = '';
michael@0:
michael@0: yield selectNode("#test1", inspector);
michael@0:
michael@0: let elementStyle = view._elementStyle;
michael@0: is(elementStyle.rules.length, 2, "Should have 2 rules.");
michael@0:
michael@0: let elementRule = elementStyle.rules[0];
michael@0: ok(!elementRule.inherited, "Element style attribute should not consider itself inherited.");
michael@0:
michael@0: let inheritRule = elementStyle.rules[1];
michael@0: is(inheritRule.domRule.type, ELEMENT_STYLE, "Inherited rule should be an element style, not a rule.");
michael@0: ok(!!inheritRule.inherited, "Rule should consider itself inherited.");
michael@0: is(inheritRule.textProps.length, 1, "Should only display one inherited style");
michael@0: let inheritProp = inheritRule.textProps[0];
michael@0: is(inheritProp.name, "color", "color should have been inherited.");
michael@0: }