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