layout/style/test/test_all_shorthand.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <!DOCTYPE html>
michael@0 2 <title>Test the 'all' shorthand property</title>
michael@0 3 <script src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 4 <script src="property_database.js"></script>
michael@0 5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
michael@0 6 <body>
michael@0 7
michael@0 8 <style id="stylesheet">
michael@0 9 #parent { }
michael@0 10 #child { }
michael@0 11 #child { }
michael@0 12 </style>
michael@0 13
michael@0 14 <div style="display: none">
michael@0 15 <div id="parent">
michael@0 16 <div id="child"></div>
michael@0 17 </div>
michael@0 18 </div>
michael@0 19
michael@0 20 <script>
michael@0 21 function runTest() {
michael@0 22 var sheet = document.getElementById("stylesheet").sheet;
michael@0 23 var parentRule = sheet.cssRules[0];
michael@0 24 var childRule1 = sheet.cssRules[1];
michael@0 25 var childRule2 = sheet.cssRules[2];
michael@0 26 var parent = document.getElementById("parent");
michael@0 27 var child = document.getElementById("child");
michael@0 28
michael@0 29 // Longhand properties that are NOT considered to be subproperties of the 'all'
michael@0 30 // shorthand.
michael@0 31 var excludedSubproperties = ["direction", "unicode-bidi"];
michael@0 32 var excludedSubpropertiesSet = new Set(excludedSubproperties);
michael@0 33
michael@0 34 // Longhand properties that are considered to be subproperties of the 'all'
michael@0 35 // shorthand.
michael@0 36 var includedSubproperties = Object.keys(gCSSProperties).filter(function(prop) {
michael@0 37 var info = gCSSProperties[prop];
michael@0 38 return info.type == CSS_TYPE_LONGHAND &&
michael@0 39 !excludedSubpropertiesSet.has(prop);
michael@0 40 });
michael@0 41
michael@0 42 // All longhand properties to be tested.
michael@0 43 var allSubproperties = includedSubproperties.concat(excludedSubproperties);
michael@0 44
michael@0 45
michael@0 46 // First, get the computed value for the initial value and one other value of
michael@0 47 // each property.
michael@0 48 var initialComputedValues = new Map();
michael@0 49 var otherComputedValues = new Map();
michael@0 50
michael@0 51 allSubproperties.forEach(function(prop) {
michael@0 52 parentRule.style.setProperty(prop, "initial", "");
michael@0 53 initialComputedValues.set(prop, getComputedStyle(parent, "").getPropertyValue(prop));
michael@0 54 parentRule.style.cssText = "";
michael@0 55 });
michael@0 56
michael@0 57 allSubproperties.forEach(function(prop) {
michael@0 58 var info = gCSSProperties[prop];
michael@0 59 parentRule.style.setProperty(prop, info.other_values[0], "");
michael@0 60 otherComputedValues.set(prop, getComputedStyle(parent, "").getPropertyValue(prop));
michael@0 61 parentRule.style.cssText = "";
michael@0 62 });
michael@0 63
michael@0 64
michael@0 65 // Test setting all:inherit through setProperty.
michael@0 66 includedSubproperties.forEach(function(prop) {
michael@0 67 var info = gCSSProperties[prop];
michael@0 68 parentRule.style.setProperty(prop, info.other_values[0], "");
michael@0 69 childRule1.style.setProperty(prop, "initial");
michael@0 70 childRule2.style.setProperty("all", "inherit");
michael@0 71 is(getComputedStyle(child, "").getPropertyValue(prop), otherComputedValues.get(prop),
michael@0 72 "computed value for " + prop + " when 'all:inherit' set with setProperty");
michael@0 73 parentRule.style.cssText = "";
michael@0 74 childRule1.style.cssText = "";
michael@0 75 childRule2.style.cssText = "";
michael@0 76 });
michael@0 77 excludedSubproperties.forEach(function(prop) {
michael@0 78 var info = gCSSProperties[prop];
michael@0 79 parentRule.style.setProperty(prop, info.other_values[0], "");
michael@0 80 childRule1.style.setProperty(prop, "initial");
michael@0 81 childRule2.style.setProperty("all", "inherit");
michael@0 82 is(getComputedStyle(child, "").getPropertyValue(prop), initialComputedValues.get(prop),
michael@0 83 "computed value for excluded subproperty " + prop + " when 'all:inherit' set with setProperty");
michael@0 84 parentRule.style.cssText = "";
michael@0 85 childRule1.style.cssText = "";
michael@0 86 childRule2.style.cssText = "";
michael@0 87 });
michael@0 88
michael@0 89 // Test setting all:initial through setProperty.
michael@0 90 includedSubproperties.forEach(function(prop) {
michael@0 91 var info = gCSSProperties[prop];
michael@0 92 parentRule.style.setProperty(prop, info.other_values[0], "");
michael@0 93 childRule1.style.setProperty(prop, "inherit");
michael@0 94 childRule2.style.setProperty("all", "initial");
michael@0 95 is(getComputedStyle(child, "").getPropertyValue(prop), initialComputedValues.get(prop),
michael@0 96 "computed value for " + prop + " when 'all:initial' set with setProperty");
michael@0 97 parentRule.style.cssText = "";
michael@0 98 childRule1.style.cssText = "";
michael@0 99 childRule2.style.cssText = "";
michael@0 100 });
michael@0 101 excludedSubproperties.forEach(function(prop) {
michael@0 102 var info = gCSSProperties[prop];
michael@0 103 parentRule.style.setProperty(prop, info.other_values[0], "");
michael@0 104 childRule1.style.setProperty(prop, info.other_values[0], "");
michael@0 105 childRule2.style.setProperty("all", "initial");
michael@0 106 is(getComputedStyle(child, "").getPropertyValue(prop), otherComputedValues.get(prop),
michael@0 107 "computed value for excluded subproperty " + prop + " when 'all:initial' set with setProperty");
michael@0 108 parentRule.style.cssText = "";
michael@0 109 childRule1.style.cssText = "";
michael@0 110 childRule2.style.cssText = "";
michael@0 111 });
michael@0 112
michael@0 113 // Test setting all:unset through setProperty.
michael@0 114 includedSubproperties.forEach(function(prop) {
michael@0 115 var info = gCSSProperties[prop];
michael@0 116 if (info.inherited) {
michael@0 117 parentRule.style.setProperty(prop, info.other_values[0], "");
michael@0 118 childRule1.style.setProperty(prop, "initial", "");
michael@0 119 childRule2.style.setProperty("all", "unset");
michael@0 120 is(getComputedStyle(child, "").getPropertyValue(prop), otherComputedValues.get(prop),
michael@0 121 "computed value for " + prop + " when 'all:unset' set with setProperty");
michael@0 122 } else {
michael@0 123 parentRule.style.setProperty(prop, info.other_values[0], "");
michael@0 124 childRule1.style.setProperty(prop, info.other_values[0], "");
michael@0 125 childRule2.style.setProperty("all", "unset");
michael@0 126 is(getComputedStyle(child, "").getPropertyValue(prop), initialComputedValues.get(prop),
michael@0 127 "computed value for " + prop + " when 'all:unset' set with setProperty");
michael@0 128 }
michael@0 129 parentRule.style.cssText = "";
michael@0 130 childRule1.style.cssText = "";
michael@0 131 childRule2.style.cssText = "";
michael@0 132 });
michael@0 133 excludedSubproperties.forEach(function(prop) {
michael@0 134 var info = gCSSProperties[prop];
michael@0 135 if (info.inherited) {
michael@0 136 parentRule.style.setProperty(prop, info.other_values[0], "");
michael@0 137 childRule1.style.setProperty(prop, "initial", "");
michael@0 138 childRule2.style.setProperty("all", "unset");
michael@0 139 is(getComputedStyle(child, "").getPropertyValue(prop), initialComputedValues.get(prop),
michael@0 140 "computed value for excluded subproperty " + prop + " when 'all:unset' set with setProperty");
michael@0 141 } else {
michael@0 142 parentRule.style.setProperty(prop, info.other_values[0], "");
michael@0 143 childRule1.style.setProperty(prop, info.other_values[0], "");
michael@0 144 childRule2.style.setProperty("all", "unset");
michael@0 145 is(getComputedStyle(child, "").getPropertyValue(prop), otherComputedValues.get(prop),
michael@0 146 "computed value for excluded subproperty " + prop + " when 'all:unset' set with setProperty");
michael@0 147 }
michael@0 148 parentRule.style.cssText = "";
michael@0 149 childRule1.style.cssText = "";
michael@0 150 childRule2.style.cssText = "";
michael@0 151 });
michael@0 152
michael@0 153 SimpleTest.finish();
michael@0 154 }
michael@0 155
michael@0 156 SimpleTest.waitForExplicitFinish();
michael@0 157 SpecialPowers.pushPrefEnv({ "set": [["layout.css.all-shorthand.enabled", true],
michael@0 158 ["layout.css.unset-value.enabled", true]] }, runTest);
michael@0 159 </script>

mercurial