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: // Test the display of overridden declarations in the rule-view
michael@0:
michael@0: let test = asyncTest(function*() {
michael@0: yield addTab("data:text/html;charset=utf-8,browser_ruleview_override.js");
michael@0: let {toolbox, inspector, view} = yield openRuleView();
michael@0:
michael@0: yield simpleOverride(inspector, view);
michael@0: yield partialOverride(inspector, view);
michael@0: yield importantOverride(inspector, view);
michael@0: yield disableOverride(inspector, view);
michael@0: });
michael@0:
michael@0: function* createTestContent(inspector, style) {
michael@0: let onMutated = inspector.once("markupmutation");
michael@0: let styleNode = addStyle(content.document, style);
michael@0: content.document.body.innerHTML = '
Styled Node
';
michael@0: yield onMutated;
michael@0: yield selectNode("#testid", inspector);
michael@0: return styleNode;
michael@0: }
michael@0:
michael@0: function* simpleOverride(inspector, view) {
michael@0: let styleNode = yield createTestContent(inspector, '' +
michael@0: '#testid {' +
michael@0: ' background-color: blue;' +
michael@0: '} ' +
michael@0: '.testclass {' +
michael@0: ' background-color: green;' +
michael@0: '}');
michael@0:
michael@0: let elementStyle = view._elementStyle;
michael@0:
michael@0: let idRule = elementStyle.rules[1];
michael@0: let idProp = idRule.textProps[0];
michael@0: is(idProp.name, "background-color", "First ID prop should be background-color");
michael@0: ok(!idProp.overridden, "ID prop should not be overridden.");
michael@0:
michael@0: let classRule = elementStyle.rules[2];
michael@0: let classProp = classRule.textProps[0];
michael@0: is(classProp.name, "background-color", "First class prop should be background-color");
michael@0: ok(classProp.overridden, "Class property should be overridden.");
michael@0:
michael@0: // Override background-color by changing the element style.
michael@0: let elementRule = elementStyle.rules[0];
michael@0: elementRule.createProperty("background-color", "purple", "");
michael@0: yield elementRule._applyingModifications;
michael@0:
michael@0: let elementProp = elementRule.textProps[0];
michael@0: is(classProp.name, "background-color", "First element prop should now be background-color");
michael@0: ok(!elementProp.overridden, "Element style property should not be overridden");
michael@0: ok(idProp.overridden, "ID property should be overridden");
michael@0: ok(classProp.overridden, "Class property should be overridden");
michael@0:
michael@0: styleNode.remove();
michael@0: }
michael@0:
michael@0: function* partialOverride(inspector, view) {
michael@0: let styleNode = yield createTestContent(inspector, '' +
michael@0: // Margin shorthand property...
michael@0: '.testclass {' +
michael@0: ' margin: 2px;' +
michael@0: '}' +
michael@0: // ... will be partially overridden.
michael@0: '#testid {' +
michael@0: ' margin-left: 1px;' +
michael@0: '}');
michael@0:
michael@0: let elementStyle = view._elementStyle;
michael@0:
michael@0: let classRule = elementStyle.rules[2];
michael@0: let classProp = classRule.textProps[0];
michael@0: ok(!classProp.overridden,
michael@0: "Class prop shouldn't be overridden, some props are still being used.");
michael@0:
michael@0: for (let computed of classProp.computed) {
michael@0: if (computed.name.indexOf("margin-left") == 0) {
michael@0: ok(computed.overridden, "margin-left props should be overridden.");
michael@0: } else {
michael@0: ok(!computed.overridden, "Non-margin-left props should not be overridden.");
michael@0: }
michael@0: }
michael@0:
michael@0: styleNode.remove();
michael@0: }
michael@0:
michael@0: function* importantOverride(inspector, view) {
michael@0: let styleNode = yield createTestContent(inspector, '' +
michael@0: // Margin shorthand property...
michael@0: '.testclass {' +
michael@0: ' background-color: green !important;' +
michael@0: '}' +
michael@0: // ... will be partially overridden.
michael@0: '#testid {' +
michael@0: ' background-color: blue;' +
michael@0: '}');
michael@0:
michael@0: let elementStyle = view._elementStyle;
michael@0:
michael@0: let idRule = elementStyle.rules[1];
michael@0: let idProp = idRule.textProps[0];
michael@0: ok(idProp.overridden, "Not-important rule should be overridden.");
michael@0:
michael@0: let classRule = elementStyle.rules[2];
michael@0: let classProp = classRule.textProps[0];
michael@0: ok(!classProp.overridden, "Important rule should not be overridden.");
michael@0:
michael@0: styleNode.remove();
michael@0:
michael@0: let elementRule = elementStyle.rules[0];
michael@0: let elementProp = elementRule.createProperty("background-color", "purple", "important");
michael@0: yield elementRule._applyingModifications;
michael@0:
michael@0: ok(classProp.overridden, "New important prop should override class property.");
michael@0: ok(!elementProp.overridden, "New important prop should not be overriden.");
michael@0: }
michael@0:
michael@0: function* disableOverride(inspector, view) {
michael@0: let styleNode = yield createTestContent(inspector, '' +
michael@0: '#testid {' +
michael@0: ' background-color: blue;' +
michael@0: '}' +
michael@0: '.testclass {' +
michael@0: ' background-color: green;' +
michael@0: '}');
michael@0:
michael@0: let elementStyle = view._elementStyle;
michael@0:
michael@0: let idRule = elementStyle.rules[1];
michael@0: let idProp = idRule.textProps[0];
michael@0:
michael@0: idProp.setEnabled(false);
michael@0: yield idRule._applyingModifications;
michael@0:
michael@0: let classRule = elementStyle.rules[2];
michael@0: let classProp = classRule.textProps[0];
michael@0: ok(!classProp.overridden, "Class prop should not be overridden after id prop was disabled.");
michael@0:
michael@0: styleNode.remove();
michael@0: yield inspector.once("inspector-updated");
michael@0: }