forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-alignment-of-root-elements.html
279 lines (246 loc) · 14.8 KB
/
parse-alignment-of-root-elements.html
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/alignment-parsing-utils-th.js"></script>
<html>
<body>
<p>Test to verify auto value resolution works as expected in root elements (eg. document root / shadow roots / slotted elements / elements inside slot)</p>
<div id="log"></div>
<div id="host">
<div id="slotted" slot="s1"></div>
</div>
<script>
var block = document.getElementById("host");
console.log("");
console.log("*** Test 'auto' value resolution for the document root node. ***");
test(function() {
document.documentElement.style.alignSelf = "center";
checkValues(document.documentElement, "alignSelf", "align-self", "center", "center");
document.documentElement.style.alignSelf = "auto";
checkValues(document.documentElement, "alignSelf", "align-self", "auto", "auto");
}, "Check out how the DOM's root element resolves the align-self 'auto' values.");
test(function() {
document.documentElement.style.alignItems = "center";
checkValues(document.documentElement, "alignItems", "align-items", "center", "center");
document.body.style.alignItems = "auto"; // The 'auto' value is not valid for align-items.
document.body.style.alignSelf = "auto";
checkValues(document.body, "alignItems", "align-items", "", "normal");
checkValues(document.body, "alignSelf", "align-self", "auto", "auto");
block.style.alignItems = ""; // Default value is 'normal' for align-items.
block.style.alignSelf = "auto";
checkValues(block, "alignItems", "align-items", "", "normal");
checkValues(block, "alignSelf", "align-self", "auto", "auto");
}, "Check out how the DOM's root element align-items's value is used to resolve its children's align-self 'auto' values.");
test(function() {
document.documentElement.style.alignItems = "auto"; // The 'auto' value is not valid for align-items.
checkValues(document.documentElement, "alignItems", "align-items", "center", "center");
document.documentElement.style.alignItems = ""; // Default value is 'normal' for align-items.
checkValues(document.documentElement, "alignItems", "align-items", "", "normal");
}, "Check out how the DOM's root element deals with 'auto' value in align-items.");
test(function() {
document.documentElement.style.justifySelf = "left";
checkValues(document.documentElement, "justifySelf", "justify-self", "left", "left");
document.documentElement.style.justifySelf = "auto";
checkValues(document.documentElement, "justifySelf", "justify-self", "auto", "auto");
}, "Check out how the DOM's root element resolves the justify-self 'auto' values.");
test(function() {
console.log();
document.documentElement.style.justifyItems = "center";
checkValues(document.documentElement, "justifyItems", "justify-items", "center", "center");
document.body.style.justifyItems = "legacy";
document.body.style.justifySelf = "auto";
checkValues(document.body, "justifyItems", "justify-items", "legacy", "normal");
checkValues(document.body, "justifySelf", "justify-self", "auto", "auto");
block.style.justifyItems = "legacy";
block.style.justifySelf = "auto";
checkValues(block, "justifyItems", "justify-items", "legacy", "normal");
checkValues(block, "justifySelf", "justify-self", "auto", "auto");
}, "Check out how the DOM's root element justify-items's value is used to resolve its children's justify-self 'auto' values.");
test(function() {
document.documentElement.style.justifyItems = "legacy";
checkValues(document.documentElement, "justifyItems", "justify-items", "legacy", "normal");
checkValues(document.body, "justifySelf", "justify-self", "auto", "auto");
checkValues(block, "justifySelf", "justify-self", "auto", "auto");
}, "Check out how the DOM's root element deals with 'auto' value in justify-items.");
test(function() {
document.documentElement.style.justifyItems = "legacy center";
checkValues(document.documentElement, "justifyItems", "justify-items", "legacy center", "legacy center");
document.body.style.justifyItems = "legacy";
document.body.style.justifySelf = "auto";
checkValues(document.body, "justifyItems", "justify-items", "legacy", "legacy center");
checkValues(document.body, "justifySelf", "justify-self", "auto", "auto");
block.style.justifyItems = "legacy";
block.style.justifySelf = "auto";
checkValues(block, "justifyItems", "justify-items", "legacy", "legacy center");
checkValues(block, "justifySelf", "justify-self", "auto", "auto");
}, "Check out how the DOM's root element justify-items's value with 'legacy' keyword is used to resolve any descendant's justify-items 'auto' values.");
test(function() {
document.documentElement.style.justifyItems = "legacy";
checkValues(document.body, "justifyItems", "justify-items", "legacy", "normal");
checkValues(document.body, "justifySelf", "justify-self", "auto", "auto");
checkValues(block, "justifyItems", "justify-items", "legacy", "normal");
checkValues(block, "justifySelf", "justify-self", "auto", "auto");
}, "Check out how the DOM's root element recomputes its descendant's style when 'legacy' keyword is removed from its justify-items value.");
console.log("");
console.log("*** Test 'auto' value resolution for the shadow DOM root node. ***");
var shadowHost = document.getElementById("host")
var shadowRoot = shadowHost.attachShadow({mode:"open"});
var shadowNode = document.createElement('div');
shadowRoot.appendChild(shadowNode);
console.log("");
console.log();
test(function() {
shadowHost.style.alignItems = "center";
shadowNode.style.alignItems = "end";
checkValues(shadowHost, "alignItems", "align-items", "center", "center");
checkValues(shadowNode, "alignItems", "align-items", "end", "end");
shadowNode.style.alignItems = "";
checkValues(shadowNode, "alignItems", "align-items", "", "normal");
shadowNode.style.alignSelf = "auto";
checkValues(shadowNode, "alignSelf", "align-self", "auto", "auto");
}, "Shadow Node inherits from ShadowHost to resolve the 'auto' values for align-self.");
test(function() {
shadowHost.style.justifyItems = "center";
shadowNode.style.justifyItems = "right";
checkValues(shadowHost, "justifyItems", "justify-items", "center", "center");
checkValues(shadowNode, "justifyItems", "justify-items", "right", "right");
shadowNode.style.justifyItems = "";
checkValues(shadowNode, "justifyItems", "justify-items", "", "normal");
shadowNode.style.justifySelf = "auto";
checkValues(shadowNode, "justifySelf", "justify-self", "auto", "auto");
}, "Shadow Node inherits from ShadowHost to resolve the 'auto' values for justify-self.");
test(function() {
shadowHost.style.justifyItems = "legacy";
shadowNode.style.justifyItems = "right";
shadowNode.style.justifySelf = "auto";
checkValues(shadowHost, "justifyItems", "justify-items", "legacy", "normal");
checkValues(shadowNode, "justifyItems", "justify-items", "right", "right");
checkValues(shadowNode, "justifySelf", "justify-self", "auto", "auto");
checkValues(shadowHost, "justifyItems", "justify-items", "legacy", "normal");
document.documentElement.style.justifyItems = "legacy center";
checkValues(document.documentElement, "justifyItems", "justify-items", "legacy center", "legacy center");
checkValues(shadowHost, "justifyItems", "justify-items", "legacy", "legacy center");
checkValues(shadowNode, "justifyItems", "justify-items", "right", "right");
checkValues(shadowNode, "justifySelf", "justify-self", "auto", "auto");
shadowNode.style.justifyItems = "legacy";
checkValues(shadowNode, "justifyItems", "justify-items", "legacy", "legacy center");
document.documentElement.style.justifyItems = "legacy";
}, "Check out how the 'legacy' keyword in justify-items propagates from the DOM Tree to the Shadow Node.");
console.log("");
console.log("*** Test 'auto' value resolution for the shadow DOM 'slotted' elements. ***");
var slotted = document.getElementById("slotted");
test(function() {
shadowHost.style.alignItems = "center";
shadowNode.style.alignItems = "start";
slotted.style.alignItems = "end";
checkValues(slotted, "alignItems", "align-items", "end", "end");
slotted.style.alignItems = "";
checkValues(slotted, "alignItems", "align-items", "", "normal");
slotted.style.alignSelf = "start";
checkValues(slotted, "alignSelf", "align-self", "start", "start");
slotted.style.alignSelf = "auto";
checkValues(slotted, "alignSelf", "align-self", "auto", "auto");
}, "Check out how align-self uses the 'shadowHost' as 'slotted' element's parent while 'slot' is not assigned.");
test(function() {
shadowHost.style.justifyItems = "center";
shadowNode.style.justifyItems = "right";
slotted.style.justifyItems = "left";
checkValues(slotted, "justifyItems", "justify-items", "left", "left");
slotted.style.justifyItems = "";
checkValues(slotted, "justifyItems", "justify-items", "", "normal");
slotted.style.justifySelf = "start";
checkValues(slotted, "justifySelf", "justify-self", "start", "start");
slotted.style.justifySelf = "auto";
checkValues(slotted, "justifySelf", "justify-self", "auto", "auto");
}, "Check out how justify-self uses the 'shadowHost' as 'slotted' element's parent while 'slot' is not assigned.");
test(function() {
shadowHost.style.justifyItems = "legacy";
shadowNode.style.justifyItems = "right";
checkValues(shadowHost, "justifyItems", "justify-items", "legacy", "normal");
checkValues(shadowNode, "justifyItems", "justify-items", "right", "right");
document.documentElement.style.justifyItems = "legacy center";
checkValues(document.documentElement, "justifyItems", "justify-items", "legacy center", "legacy center");
checkValues(shadowHost, "justifyItems", "justify-items", "legacy", "legacy center");
slotted.style.justifyItems = "legacy";
checkValues(slotted, "justifyItems", "justify-items", "legacy", "normal");
slotted.style.justifySelf = "auto";
checkValues(slotted, "justifySelf", "justify-self", "auto", "auto");
shadowNode.style.justifyItems = "legacy";
checkValues(shadowNode, "justifyItems", "justify-items", "legacy", "legacy center");
checkValues(slotted, "justifyItems", "justify-items", "legacy", "normal");
checkValues(slotted, "justifySelf", "justify-self", "auto", "auto");
document.documentElement.style.justifyItems = "legacy";
}, "Check out how the 'legacy' keyword in justify-items affects the 'slotted' elements while 'slot' is not assigned.");
// Slot element is assigned now.
var slot = document.createElement('slot');
slot.setAttribute('name', 's1');
shadowNode.appendChild(slot);
test(function() {
shadowHost.style.alignItems = "center";
shadowNode.style.alignItems = "end";
slotted.style.alignItems = "start";
checkValues(slotted, "alignItems", "align-items", "start", "start");
slotted.style.alignItems = "";
checkValues(slotted, "alignItems", "align-items", "", "normal");
slotted.style.alignSelf = "start";
checkValues(slotted, "alignSelf", "align-self", "start", "start");
slotted.style.alignSelf = "auto";
checkValues(slotted, "alignSelf", "align-self", "auto", "auto");
}, "Check out how align-self uses the 'slot' element's parent (Shadow Node) as 'slotted' element' s parent after the 'slot' is assigned.");
test(function() {
shadowHost.style.justifyItems = "center";
shadowNode.style.justifyItems = "right";
slotted.style.justifyItems = "left";
checkValues(slotted, "justifyItems", "justify-items", "left", "left");
slotted.style.justifyItems = "";
checkValues(slotted, "justifyItems", "justify-items", "", "normal");
slotted.style.justifySelf = "start";
checkValues(slotted, "justifySelf", "justify-self", "start", "start");
slotted.style.justifySelf = "auto";
checkValues(slotted, "justifySelf", "justify-self", "auto", "auto");
}, "Check out how justify-self uses the 'slot' element's parent (Shadow Node) as 'slotted' element' s parent after the 'slot' is assigned.");
test(function() {
shadowHost.style.justifyItems = "legacy";
shadowNode.style.justifyItems = "right";
checkValues(shadowHost, "justifyItems", "justify-items", "legacy", "normal");
checkValues(shadowNode, "justifyItems", "justify-items", "right", "right");
document.documentElement.style.justifyItems = "legacy center";
checkValues(document.documentElement, "justifyItems", "justify-items", "legacy center", "legacy center");
checkValues(shadowHost, "justifyItems", "justify-items", "legacy", "legacy center");
slotted.style.justifyItems = "legacy";
checkValues(slotted, "justifyItems", "justify-items", "legacy", "normal"); // Shadow host is not the parent now, but ShadowNode.
slotted.style.justifySelf = "auto";
checkValues(slotted, "justifySelf", "justify-self", "auto", "auto"); // Shadow host is not the parent now, but ShadowNode.
shadowNode.style.justifyItems = "legacy";
checkValues(shadowNode, "justifyItems", "justify-items", "legacy", "legacy center");
checkValues(slotted, "justifyItems", "justify-items", "legacy", "legacy center"); // Now that shadowNode is auto, 'legacy' applies.
checkValues(slotted, "justifySelf", "justify-self", "auto", "auto"); // Now that shadowNode is auto, 'legacy' applies.
document.documentElement.style.justifyItems = "legacy";
}, "Check out how the 'legacy' keyword affects the 'slotted' elements after the 'slot' is assigned.");
test(function() {
shadowHost.style.alignItems = "center";
shadowNode.style.alignItems = "end";
slot.style.alignItems = "start";
checkValues(slot, "alignItems", "align-items", "start", "start");
slot.style.alignItems = "";
checkValues(slot, "alignItems", "align-items", "", "normal");
slot.style.alignSelf = "start";
checkValues(slot, "alignSelf", "align-self", "start", "start");
slot.style.alignSelf = "auto";
checkValues(slot, "alignSelf", "align-self", "auto", "auto");
}, "The 'slot' element should not use its parent inside the ShadowDOM tree to resolve the align-self 'auto' values because Blink does not support slots in the flat tree.");
test(function() {
shadowHost.style.justifyItems = "center";
shadowNode.style.justifyItems = "right";
slot.style.justifyItems = "left";
checkValues(slot, "justifyItems", "justify-items", "left", "left");
slot.style.justifyItems = "legacy";
checkValues(slot, "justifyItems", "justify-items", "legacy", "normal");
slot.style.justifySelf = "left";
checkValues(slot, "justifySelf", "justify-self", "left", "left");
slot.style.justifySelf = "auto";
checkValues(slot, "justifySelf", "justify-self", "auto", "auto");
}, "The 'slot' element should not use its parent inside the ShadowDOM tree to resolve the justify-self 'auto' values because Blink does not support slots in the flat tree.");
</script>
</body>
</html>