|
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/ */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 // Checking properties orders and overrides in the rule-view |
|
8 |
|
9 let test = asyncTest(function*() { |
|
10 yield addTab("data:text/html;charset=utf-8,browser_ruleview_manipulation.js"); |
|
11 let {toolbox, inspector, view} = yield openRuleView(); |
|
12 |
|
13 info("Creating the test document and getting the test node"); |
|
14 content.document.body.innerHTML = '<div id="testid">Styled Node</div>'; |
|
15 let element = getNode("#testid"); |
|
16 |
|
17 yield selectNode(element, inspector); |
|
18 |
|
19 let elementStyle = view._elementStyle; |
|
20 let elementRule = elementStyle.rules[0]; |
|
21 |
|
22 info("Checking rules insertion order and checking the applied style"); |
|
23 let firstProp = elementRule.createProperty("background-color", "green", ""); |
|
24 let secondProp = elementRule.createProperty("background-color", "blue", ""); |
|
25 is(elementRule.textProps[0], firstProp, "Rules should be in addition order."); |
|
26 is(elementRule.textProps[1], secondProp, "Rules should be in addition order."); |
|
27 yield elementRule._applyingModifications; |
|
28 is(element.style.getPropertyValue("background-color"), "blue", "Second property should have been used."); |
|
29 |
|
30 info("Removing the second property and checking the applied style again"); |
|
31 secondProp.remove(); |
|
32 yield elementRule._applyingModifications; |
|
33 is(element.style.getPropertyValue("background-color"), "green", "After deleting second property, first should be used."); |
|
34 |
|
35 info("Creating a new second property and checking that the insertion order is still the same"); |
|
36 secondProp = elementRule.createProperty("background-color", "blue", ""); |
|
37 yield elementRule._applyingModifications; |
|
38 is(element.style.getPropertyValue("background-color"), "blue", "New property should be used."); |
|
39 is(elementRule.textProps[0], firstProp, "Rules shouldn't have switched places."); |
|
40 is(elementRule.textProps[1], secondProp, "Rules shouldn't have switched places."); |
|
41 |
|
42 info("Disabling the second property and checking the applied style"); |
|
43 secondProp.setEnabled(false); |
|
44 yield elementRule._applyingModifications; |
|
45 is(element.style.getPropertyValue("background-color"), "green", "After disabling second property, first value should be used"); |
|
46 |
|
47 info("Disabling the first property too and checking the applied style"); |
|
48 firstProp.setEnabled(false); |
|
49 yield elementRule._applyingModifications; |
|
50 is(element.style.getPropertyValue("background-color"), "", "After disabling both properties, value should be empty."); |
|
51 |
|
52 info("Re-enabling the second propertyt and checking the applied style"); |
|
53 secondProp.setEnabled(true); |
|
54 yield elementRule._applyingModifications; |
|
55 is(element.style.getPropertyValue("background-color"), "blue", "Value should be set correctly after re-enabling"); |
|
56 |
|
57 info("Re-enabling the first property and checking the insertion order is still respected"); |
|
58 firstProp.setEnabled(true); |
|
59 yield elementRule._applyingModifications; |
|
60 is(element.style.getPropertyValue("background-color"), "blue", "Re-enabling an earlier property shouldn't make it override a later property."); |
|
61 is(elementRule.textProps[0], firstProp, "Rules shouldn't have switched places."); |
|
62 is(elementRule.textProps[1], secondProp, "Rules shouldn't have switched places."); |
|
63 |
|
64 info("Modifying the first property and checking the applied style"); |
|
65 firstProp.setValue("purple", ""); |
|
66 yield elementRule._applyingModifications; |
|
67 is(element.style.getPropertyValue("background-color"), "blue", "Modifying an earlier property shouldn't override a later property."); |
|
68 }); |