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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<style>
f {
display: flex;
background-color: grey;
font: 12px sans-serif;
width: 800px;
height: 42px;
margin-bottom: 5px;
}
.withZ::after {
background-color: pink;
content: "Z";
width: 100px;
height: 10px;
}
.wrap {
flex-wrap: wrap;
}
.wrapReverse {
flex-wrap: wrap-reverse;
}
b {
background-color: gold;
min-width: 100px;
height: 20px;
flex-grow: 1;
}
b::after {
content: "B";
}
c {
background-color: yellow;
width: 200px;
height: 15px;
}
c::after {
content: "C";
}
d {
background-color: orange;
width: 300px;
height: 10px;
}
d::after {
content: "D";
}
e {
background-color: silver;
width: 300px;
height: 10px;
flex-shrink: 2;
}
e::after {
content: "E";
}
</style>
<script>
"use strict";
SimpleTest.waitForExplicitFinish();
function testLineMatchesExpectedValues(line, values, lineIndex, flexIndex) {
if (typeof(values.growthState) != "undefined") {
is(line.growthState, values.growthState, "Flex index " + flexIndex + " line index " + lineIndex + " has expected growthState.");
}
if (typeof(values.crossStart) != "undefined") {
is(line.crossStart, values.crossStart, "Flex index " + flexIndex + " line index " + lineIndex + " has expected crossStart.");
}
if (typeof(values.crossSize) != "undefined") {
is(line.crossSize, values.crossSize, "Flex index " + flexIndex + " line index " + lineIndex + " has expected crossSize.");
}
if (typeof(values.itemCount) != "undefined") {
is(line.getItems().length, values.itemCount, "Flex index " + flexIndex + " line index " + lineIndex + " has expected number of items.");
}
}
function runTests() {
let expectedValues = [
// items don't fill container, no grow, shrink, or min-width
[{ crossStart: 0,
crossSize: 42,
itemCount: 2,
growthState: "growing" }],
[{ crossStart: 0,
crossSize: 42,
itemCount: 3,
growthState: "growing" }],
// items don't fill container, no grow, shrink, or min-width, with wrap and align-content:center -->
[{ crossStart: 13.5,
crossSize: 15,
itemCount: 2,
growthState: "growing" }],
[{ crossStart: 13.5,
crossSize: 15,
itemCount: 3,
growthState: "growing" }],
// items don't fill container, with grow
[{ crossStart: 0,
crossSize: 42,
itemCount: 3,
growthState: "growing" }],
[{ crossStart: 0,
crossSize: 42,
itemCount: 4,
growthState: "growing" }],
// items overfill container, with min-width, and sometimes with wrap
[{ crossStart: 0,
crossSize: 42,
itemCount: 5,
growthState: "shrinking" }],
[{ crossStart: 0,
crossSize: 21,
itemCount: 3,
growthState: "growing" },
{ crossStart: 21,
crossSize: 21,
itemCount: 2,
growthState: "growing" }],
[{ crossStart: 0,
crossSize: 42,
itemCount: 6,
growthState: "shrinking" }],
[{ crossStart: 0,
crossSize: 21,
itemCount: 3,
growthState: "growing" },
{ crossStart: 21,
crossSize: 21,
itemCount: 3,
growthState: "growing" }],
// items overfill container, with shrink and sometimes with wrap
[{ crossStart: 0,
crossSize: 42,
itemCount: 3,
growthState: "shrinking" }],
[{ crossStart: 0,
crossSize: 21,
itemCount: 2,
growthState: "growing" },
{ crossStart: 21,
crossSize: 21,
itemCount: 1,
growthState: "growing" }],
[{ crossStart: 0,
crossSize: 42,
itemCount: 4,
growthState: "shrinking" }],
[{ crossStart: 0,
crossSize: 21,
itemCount: 2,
growthState: "growing" },
{ crossStart: 21,
crossSize: 21,
itemCount: 2,
growthState: "growing" }],
// items overfill container, with wrap and different types of align-content
[{ crossStart: 0,
crossSize: 26,
itemCount: 3 },
{ crossStart: 26,
crossSize: 16,
itemCount: 1 }],
[{ crossStart: 0,
crossSize: 20,
itemCount: 3 },
{ crossStart: 20,
crossSize: 10,
itemCount: 1 }],
[{ crossStart: 12,
crossSize: 20,
itemCount: 3 },
{ crossStart: 32,
crossSize: 10,
itemCount: 1 }],
[{ crossStart: 6,
crossSize: 20,
itemCount: 3 },
{ crossStart: 26,
crossSize: 10,
itemCount: 1 }],
[{ crossStart: 0,
crossSize: 20,
itemCount: 3 },
{ crossStart: 32,
crossSize: 10,
itemCount: 1 }],
[{ crossStart: 3,
crossSize: 20,
itemCount: 3 },
{ crossStart: 29,
crossSize: 10,
itemCount: 1 }],
// items overfill container, with wrap-reverse and different types of align-content
[{ crossStart: 0,
crossSize: 26,
itemCount: 3 },
{ crossStart: 26,
crossSize: 16,
itemCount: 2 }],
[{ crossStart: 0,
crossSize: 20,
itemCount: 3 },
{ crossStart: 20,
crossSize: 10,
itemCount: 2 }],
[{ crossStart: 12,
crossSize: 20,
itemCount: 3 },
{ crossStart: 32,
crossSize: 10,
itemCount: 2 }],
[{ crossStart: 6,
crossSize: 20,
itemCount: 3 },
{ crossStart: 26,
crossSize: 10,
itemCount: 2 }],
[{ crossStart: 0,
crossSize: 20,
itemCount: 3 },
{ crossStart: 32,
crossSize: 10,
itemCount: 2 }],
[{ crossStart: 3,
crossSize: 20,
itemCount: 3 },
{ crossStart: 29,
crossSize: 10,
itemCount: 2 }],
// other strange types of flex containers
[{ itemCount: 3 }],
[{ crossStart: 100,
crossSize: 300,
mainSize: 40,
itemCount: 3 },
{ crossStart: 400,
crossSize: 300,
mainSize: 20,
itemCount: 2 }],
];
let children = document.body.children;
is(children.length, expectedValues.length, "Document has expected number of flex containers.");
for (let i = 0; i < children.length; ++i) {
let flex = children.item(i).getAsFlexContainer();
ok(flex, "Document child index " + i + " is a flex container.");
if (flex) {
let values = expectedValues[i];
let lines = flex.getLines();
is(lines.length, values.length, "Flex index " + i + " has expected number of lines.");
for (let j = 0; j < lines.length; ++j) {
testLineMatchesExpectedValues(lines[j], values[j], j, i);
}
}
}
SimpleTest.finish();
}
</script>
</head>
<body onLoad="runTests();">
<!-- items don't fill container, no grow, shrink, or min-width -->
<f><c></c><d></d></f>
<f class="withZ"><c></c><d></d></f>
<!-- items don't fill container, no grow, shrink, or min-width, with wrap and align-content:center -->
<f class="wrap" style="align-content:center"><c></c><d></d></f>
<f class="withZ wrap" style="align-content:center"><c></c><d></d></f>
<!-- items don't fill container, with grow -->
<f><b></b><c></c><d></d></f>
<f class="withZ"><b></b><c></c><d></d></f>
<!-- items overfill container, with min-width, and sometimes with wrap -->
<f><b></b><d></d><d></d><d></d><b></b></f>
<f class="wrap"><b></b><d></d><d></d><d></d><b></b></f>
<f class="withZ"><b></b><d></d><d></d><d></d><b></b></f>
<f class="wrap withZ"><b></b><d></d><d></d><d></d><b></b></f>
<!-- items overfill container, with shrink and sometimes with wrap -->
<f><d></d><d></d><e></e></f>
<f class="wrap"><d></d><d></d><e></e></f>
<f class="withZ"><d></d><d></d><e></e></f>
<f class="wrap withZ"><d></d><d></d><e></e></f>
<!-- items overfill container, with wrap and different types of align-content -->
<f class="wrap"><b></b><c></c><d></d><e></e></f>
<f class="wrap" style="align-content:flex-start"><b></b><c></c><d></d><e></e></f>
<f class="wrap" style="align-content:flex-end"><b></b><c></c><d></d><e></e></f>
<f class="wrap" style="align-content:center"><b></b><c></c><d></d><e></e></f>
<f class="wrap" style="align-content:space-between"><b></b><c></c><d></d><e></e></f>
<f class="wrap" style="align-content:space-around"><b></b><c></c><d></d><e></e></f>
<!-- items overfill container, with wrap-reverse and different types of align-content -->
<f class="wrapReverse withZ"><b></b><c></c><d></d><e></e></f>
<f class="wrapReverse withZ" style="align-content:flex-start"><b></b><c></c><d></d><e></e></f>
<f class="wrapReverse withZ" style="align-content:flex-end"><b></b><c></c><d></d><e></e></f>
<f class="wrapReverse withZ" style="align-content:center"><b></b><c></c><d></d><e></e></f>
<f class="wrapReverse withZ" style="align-content:space-between"><b></b><c></c><d></d><e></e></f>
<f class="wrapReverse withZ" style="align-content:space-around"><b></b><c></c><d></d><e></e></f>
<!-- other strange types of flex containers -->
<f style="overflow:scroll"><d></d><d></d><e></e></f>
<f class="wrap" style="flex-direction:column; align-content:center"><c></c><d></d><c></c><d></d><e></e></f>
</body>
</html>
|