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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<style>
body {
margin: 40px;
}
.wrapper {
display: grid;
width: 600px;
grid-gap: 0px;
background-color: #f00;
}
.grid1 {
grid-template-columns: 50px 0px repeat(auto-fit, 100px);
}
.grid2 {
grid-template-columns: 50px 0px [real-before] repeat(auto-fit, [before] 100px [after]) [real-after] 0px [final];
}
.grid3 {
grid-template-columns: repeat(3, 66px) [real-before] repeat(auto-fit, [before] 100px [after]) [real-after];
}
.grid4 {
grid-template-columns: repeat(2, 100px) repeat(auto-fill, 50px);
}
.grid5 {
grid-template-columns: [real-before] repeat(auto-fit, [before] 100px [after]) [real-after];
}
.grid6 {
grid-template-columns: [first] 0px [real-before] repeat(auto-fit, [before] 100px [after]) [real-after];
}
.grid7 {
grid-template-columns: [real-before] repeat(auto-fit, [before] 100px [after]) [real-after] 0px [final];
}
.grid8 {
grid-template-columns: [real-before] repeat(auto-fit, [before] 1000px [after]) [real-after];
}
.grid9 {
grid-template-columns: [real-before] repeat(auto-fit, 100px [after]) [real-after];
}
.grid10 {
grid-template-columns: [real-before] repeat(auto-fit, [before] 100px) [real-after];
}
.box {
background-color: #444;
color: #fff;
}
.a {
grid-column: auto;
}
.b {
grid-column: 4;
}
.c {
grid-column: 6;
}
.d {
grid-column: 7;
}
.e {
grid-column: 5;
}
</style>
<script>
'use strict';
SimpleTest.waitForExplicitFinish();
function testLines(elementName, grid, expectedValues) {
for (let i = 0; i < grid.cols.lines.length; i++) {
is(grid.cols.lines[i].number, (i + 1), elementName + " line " + (i + 1) + " has expected number.");
is(grid.cols.lines[i].start, expectedValues[i].start, elementName + " line " + (i + 1) + " has expected start.");
is(grid.cols.lines[i].breadth, 0, elementName + " line " + (i + 1) + " has zero breadth.");
is(grid.cols.lines[i].names + "", expectedValues[i].names, elementName + " line " + (i + 1) + " has expected names.");
}
}
function runTests() {
let wrapper = document.getElementById("wrapper1");
let grid = wrapper.getGridFragments()[0];
// test auto-fit count
is(grid.cols.tracks.length, 7, "Grid column track array reports removed auto-fit columns.");
// test resolved value of grid-template-columns
let templateColumnsText = getComputedStyle(wrapper).gridTemplateColumns;
is(templateColumnsText, "50px 0px 0px 100px 0px 0px 0px",
"Resolved value of grid-template-columns reports removed auto-fits as '0px'.");
// test starts, breadths, and states
let expectedValues = [
{ "start": 0,
"breadth": 50,
"state": "static" },
{ "start": 50,
"breadth": 0,
"state": "static" },
{ "start": 50,
"breadth": 0,
"state": "removed" },
{ "start": 50,
"breadth": 100,
"state": "repeat" },
{ "start": 150,
"breadth": 0,
"state": "removed" },
{ "start": 150,
"breadth": 0,
"state": "removed" },
{ "start": 150,
"breadth": 0,
"state": "removed" },
];
for (let i = 0; i < grid.cols.tracks.length; i++) {
is(grid.cols.tracks[i].start, expectedValues[i].start, "Column " + (i + 1) + " has expected start.");
is(grid.cols.tracks[i].breadth, expectedValues[i].breadth, "Column " + (i + 1) + " has expected breadth.");
is(grid.cols.tracks[i].state, expectedValues[i].state, "Column " + (i + 1) + " has expected state.");
}
wrapper = document.getElementById("wrapper2");
grid = wrapper.getGridFragments()[0];
// test auto-fit count
is(grid.cols.lines.length, 9, "Grid column line array reports removed auto-fit columns.");
// test resolved value of grid-template-columns
templateColumnsText = getComputedStyle(wrapper).gridTemplateColumns;
is(templateColumnsText, "50px 0px [real-before before] 0px [after before] 100px [after before] 0px [after before] 100px [after before] 0px [after real-after] 0px [final]",
"Resolved value of grid-template-columns reports lines for removed tracks.");
// test starts and names
expectedValues = [
{ "start": 0,
"names": "" },
{ "start": 50,
"names": "" },
{ "start": 50,
"names": "real-before,before" },
{ "start": 50,
"names": "after,before" },
{ "start": 150,
"names": "after,before" },
{ "start": 150,
"names": "after,before" },
{ "start": 250,
"names": "after,before" },
{ "start": 250,
"names": "after,real-after" },
{ "start": 250,
"names": "final" },
];
testLines("wrapper2", grid, expectedValues);
wrapper = document.getElementById("wrapper3");
grid = wrapper.getGridFragments()[0];
// test resolved value of grid-template-columns
templateColumnsText = getComputedStyle(wrapper).gridTemplateColumns;
is(templateColumnsText, "66px 66px 66px [real-before before] 100px [after before] 0px [after before] 100px [after before] 100px [after real-after]",
"Resolved value of grid-template-columns reports lines for removed tracks.");
wrapper = document.getElementById("wrapper4");
grid = wrapper.getGridFragments()[0];
// test auto-fill count of tracks
is(grid.cols.tracks.length, 10, "Grid column track array respects auto-fill columns.");
if (grid.cols.tracks.length == 10) {
// test for static and repeat
is(grid.cols.tracks[1].state, "static", "Grid column track 2 is marked as static.");
is(grid.cols.tracks[2].state, "repeat", "Grid column track 3 is marked as repeat.");
}
wrapper = document.getElementById("wrapper5");
grid = wrapper.getGridFragments()[0];
// test resolved value of grid-template-columns
templateColumnsText = getComputedStyle(wrapper).gridTemplateColumns;
is(templateColumnsText, "[real-before before] 0px [after before] 0px [after before] 0px [after before] 0px [after before] 0px [after before] 0px [after real-after]", "Resolved value of grid-template-columns no longer lists 'none' when all auto-fit tracks are empty.");
wrapper = document.getElementById("wrapper6");
grid = wrapper.getGridFragments()[0];
// test starts and names
expectedValues = [
{ "start": 0,
"names": "first" },
{ "start": 0,
"names": "real-before,before" },
{ "start": 0,
"names": "after,before" },
{ "start": 0,
"names": "after,before" },
{ "start": 100,
"names": "after,before" },
{ "start": 100,
"names": "after,before" },
{ "start": 100,
"names": "after,before" },
{ "start": 100,
"names": "after,real-after" },
];
testLines("wrapper6", grid, expectedValues);
wrapper = document.getElementById("wrapper7");
grid = wrapper.getGridFragments()[0];
// test starts and names
expectedValues = [
{ "start": 0,
"names": "real-before,before" },
{ "start": 0,
"names": "after,before" },
{ "start": 0,
"names": "after,before" },
{ "start": 0,
"names": "after,before" },
{ "start": 100,
"names": "after,before" },
{ "start": 100,
"names": "after,before" },
{ "start": 100,
"names": "after,real-after" },
{ "start": 100,
"names": "final" },
];
testLines("wrapper7", grid, expectedValues);
wrapper = document.getElementById("wrapper8");
grid = wrapper.getGridFragments()[0];
// test starts and names
expectedValues = [
{ "start": 0,
"names": "real-before,before" },
{ "start": 0,
"names": "after,real-after" },
];
testLines("wrapper8", grid, expectedValues);
wrapper = document.getElementById("wrapper9");
grid = wrapper.getGridFragments()[0];
// test starts and names
expectedValues = [
{ "start": 0,
"names": "real-before" },
{ "start": 0,
"names": "after" },
{ "start": 0,
"names": "after" },
{ "start": 0,
"names": "after" },
{ "start": 100,
"names": "after" },
{ "start": 200,
"names": "after" },
{ "start": 200,
"names": "after,real-after" },
];
testLines("wrapper9", grid, expectedValues);
wrapper = document.getElementById("wrapper10");
grid = wrapper.getGridFragments()[0];
// test starts and names
expectedValues = [
{ "start": 0,
"names": "real-before,before" },
{ "start": 0,
"names": "before" },
{ "start": 0,
"names": "before" },
{ "start": 0,
"names": "before" },
{ "start": 100,
"names": "before" },
{ "start": 200,
"names": "before" },
{ "start": 200,
"names": "real-after" },
];
testLines("wrapper10", grid, expectedValues);
SimpleTest.finish();
}
</script>
</head>
<body onLoad="runTests();">
<div id="wrapper1" class="wrapper grid1">
<div id="boxB" class="box b">B</div>
</div>
<br/>
<div id="wrapper2" class="wrapper grid2">
<div id="boxB" class="box b">B</div>
<div id="boxC" class="box c">C</div>
</div>
<br/>
<div id="wrapper3" class="wrapper grid3">
<div id="boxB" class="box b">B</div>
<div id="boxC" class="box c">C</div>
<div id="boxD" class="box d">D</div>
</div>
<br/>
<div id="wrapper4" class="wrapper grid4">
<div id="boxA" class="box a">A</div>
</div>
<br/>
<div id="wrapper5" class="wrapper grid5">
</div>
<br/>
<div id="wrapper6" class="wrapper grid6">
<div id="boxB" class="box b">B</div>
</div>
<br/>
<div id="wrapper7" class="wrapper grid7">
<div id="boxB" class="box b">B</div>
</div>
<br/>
<div id="wrapper8" class="wrapper grid8">
</div>
<br/>
<div id="wrapper9" class="wrapper grid9">
<div id="boxB" class="box b">B</div>
<div id="boxE" class="box e">E</div>
</div>
<br/>
<div id="wrapper10" class="wrapper grid10">
<div id="boxB" class="box b">B</div>
<div id="boxE" class="box e">E</div>
</div>
</body>
</html>
|