1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/styleinspector/test/browser_ruleview_edit-property-order.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ 1.5 +/* Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +// Checking properties orders and overrides in the rule-view 1.11 + 1.12 +let test = asyncTest(function*() { 1.13 + yield addTab("data:text/html;charset=utf-8,browser_ruleview_manipulation.js"); 1.14 + let {toolbox, inspector, view} = yield openRuleView(); 1.15 + 1.16 + info("Creating the test document and getting the test node"); 1.17 + content.document.body.innerHTML = '<div id="testid">Styled Node</div>'; 1.18 + let element = getNode("#testid"); 1.19 + 1.20 + yield selectNode(element, inspector); 1.21 + 1.22 + let elementStyle = view._elementStyle; 1.23 + let elementRule = elementStyle.rules[0]; 1.24 + 1.25 + info("Checking rules insertion order and checking the applied style"); 1.26 + let firstProp = elementRule.createProperty("background-color", "green", ""); 1.27 + let secondProp = elementRule.createProperty("background-color", "blue", ""); 1.28 + is(elementRule.textProps[0], firstProp, "Rules should be in addition order."); 1.29 + is(elementRule.textProps[1], secondProp, "Rules should be in addition order."); 1.30 + yield elementRule._applyingModifications; 1.31 + is(element.style.getPropertyValue("background-color"), "blue", "Second property should have been used."); 1.32 + 1.33 + info("Removing the second property and checking the applied style again"); 1.34 + secondProp.remove(); 1.35 + yield elementRule._applyingModifications; 1.36 + is(element.style.getPropertyValue("background-color"), "green", "After deleting second property, first should be used."); 1.37 + 1.38 + info("Creating a new second property and checking that the insertion order is still the same"); 1.39 + secondProp = elementRule.createProperty("background-color", "blue", ""); 1.40 + yield elementRule._applyingModifications; 1.41 + is(element.style.getPropertyValue("background-color"), "blue", "New property should be used."); 1.42 + is(elementRule.textProps[0], firstProp, "Rules shouldn't have switched places."); 1.43 + is(elementRule.textProps[1], secondProp, "Rules shouldn't have switched places."); 1.44 + 1.45 + info("Disabling the second property and checking the applied style"); 1.46 + secondProp.setEnabled(false); 1.47 + yield elementRule._applyingModifications; 1.48 + is(element.style.getPropertyValue("background-color"), "green", "After disabling second property, first value should be used"); 1.49 + 1.50 + info("Disabling the first property too and checking the applied style"); 1.51 + firstProp.setEnabled(false); 1.52 + yield elementRule._applyingModifications; 1.53 + is(element.style.getPropertyValue("background-color"), "", "After disabling both properties, value should be empty."); 1.54 + 1.55 + info("Re-enabling the second propertyt and checking the applied style"); 1.56 + secondProp.setEnabled(true); 1.57 + yield elementRule._applyingModifications; 1.58 + is(element.style.getPropertyValue("background-color"), "blue", "Value should be set correctly after re-enabling"); 1.59 + 1.60 + info("Re-enabling the first property and checking the insertion order is still respected"); 1.61 + firstProp.setEnabled(true); 1.62 + yield elementRule._applyingModifications; 1.63 + is(element.style.getPropertyValue("background-color"), "blue", "Re-enabling an earlier property shouldn't make it override a later property."); 1.64 + is(elementRule.textProps[0], firstProp, "Rules shouldn't have switched places."); 1.65 + is(elementRule.textProps[1], secondProp, "Rules shouldn't have switched places."); 1.66 + 1.67 + info("Modifying the first property and checking the applied style"); 1.68 + firstProp.setValue("purple", ""); 1.69 + yield elementRule._applyingModifications; 1.70 + is(element.style.getPropertyValue("background-color"), "blue", "Modifying an earlier property shouldn't override a later property."); 1.71 +});