summaryrefslogtreecommitdiffstats
path: root/dom/grid/test/chrome/test_grid_implicit.html
blob: 1f714265838d9a2a230f5580fe9420c8db52e316 (plain)
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
<!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;
	grid-gap: 10px;
	grid-auto-columns: 20px;
	grid-auto-rows: 20px;
	background-color: #f00;
}

.template1 {
	grid-template-columns: 100px 50px 100px;
	grid-template-rows: 50px [areaD-start middle] 50px [areaD-end];
	grid-template-areas: "areaA areaA ....."
						 "..... areaC areaC";
}

.template2 {
	grid-template-areas: "..... areaA ......";
    grid-template-columns: [areaA-start] 50px 50px 50px;
}

.template3 {
	grid-template-columns: [areaA-start areaB-end areaC-end areaD-start] 50px [areaA-end areaB-start areaC-start areaD-end];
	grid-template-rows: [areaA-end areaB-start areaC-end] 50px [areaA-start areaB-end areaC-start];
}

.template4 {
	grid-template-columns: 100px 50px 100px;
	grid-template-rows: 50px;
}

.box {
	background-color: #444;
	color: #fff;
}
.a {
	grid-area: areaA;
}
.b {
	grid-row: span got-this-name-implicitly / 2;
	grid-column: areaA-end / span 2;
}
.c {
	grid-area: areaC;
}
.d {
	grid-area: areaD;
}
.e {
	grid-column: -7 / 5;
}
</style>

<script>
'use strict';

SimpleTest.waitForExplicitFinish();

function runTests() {
	// test the first grid wrapper
	let wrapper = document.getElementById("wrapper1");
	let grid = wrapper.getGridFragments()[0];
	
	// test column and row line counts
	is(grid.cols.lines.length, 6,
		"Grid.cols.lines property has length that respects implicit expansion."
	);
	is(grid.rows.lines.length, 4,
		"Grid.rows.lines property has length that respects implicit expansion."
	);

	if ((grid.cols.lines.length == 6) &&
	    (grid.rows.lines.length == 4)) {

		// test explicit / implicit lines
		is(grid.cols.lines[0].type, "explicit", "Grid column line 1 is explicit.");
		is(grid.cols.lines[4].type, "implicit", "Grid column line 5 is implicit.");
		is(grid.cols.lines[5].type, "implicit", "Grid column line 6 is implicit.");
		
		is(grid.rows.lines[0].type, "implicit", "Grid row line 0 is implicit.");
		is(grid.rows.lines[0].number, 0, "Grid row line 0 has correct number.");
		is(grid.rows.lines[1].type, "explicit", "Grid row line 1 is explicit.");
		is(grid.rows.lines[1].number, 1, "Grid row line 1 has correct number.");
		is(grid.rows.lines[3].type, "explicit", "Grid row line 3 is explicit.");
		is(grid.rows.lines[3].number, 3, "Grid row line 3 has correct number.");
		
		// test that row line 1 gets the name forced on it by placement of item B
		todo_isnot(grid.rows.lines[0].names.indexOf("got-this-name-implicitly"), -1,
			"Grid row line 1 has the name 'got-this-name-implicitly'."
		);
		
		// test that row line 3 gets its explicit name
		isnot(grid.rows.lines[2].names.indexOf("middle"), -1,
			"Grid row line 3 has the name 'middle'."
		);
		
		// test the names of the implicit column lines that were created for area 'areaD'
		isnot(grid.cols.lines[4].names.indexOf("areaD-start"), -1,
			"Grid column line 5 has the name 'areaD-start'."
		);
		isnot(grid.cols.lines[5].names.indexOf("areaD-end"), -1,
			"Grid column line 6 has the name 'areaD-end'."
		);
	}

	// test column and row track counts
	is(grid.cols.tracks.length, 5,
		"Grid.cols.tracks property has length that respects implicit expansion."
	);
	is(grid.rows.tracks.length, 3,
		"Grid.rows.tracks property has length that respects implicit expansion."
	);

	if ((grid.cols.tracks.length == 5) &&
	    (grid.rows.tracks.length == 3)) {

		// test explicit / implicit tracks
		is(grid.cols.tracks[0].type, "explicit", "Grid column track 1 is explicit.");
		is(grid.cols.tracks[3].type, "implicit", "Grid column track 4 is implicit.");
		is(grid.cols.tracks[4].type, "implicit", "Grid column track 5 is implicit.");

		is(grid.rows.tracks[0].type, "implicit", "Grid row track 1 is implicit.");
		is(grid.rows.tracks[1].type, "explicit", "Grid row track 2 is explicit.");
		is(grid.rows.tracks[2].type, "explicit", "Grid row track 3 is explicit.");
	}

	// test area count
	is(grid.areas.length, 3,
		"Grid.areas property has length that respects implicit expansion."
	);

	for (var i = 0; i < grid.areas.length; i++) {
		var area = grid.areas[i];
		if (area.name == "areaD") {
			is(area.type, "implicit", area.name + " is implicit.");

			// test lines of implicit areas
			is(area.rowStart, 3, area.name + " has start row line of 3.");
			is(area.rowEnd, 4, area.name + " has end row line of 4.");
			is(area.columnStart, 5, area.name + " has start column line of 5.");
			is(area.columnEnd, 6, area.name + " has end column line of 6.");
		} else {
			is(area.type, "explicit", area.name + " is explicit.");
		}
	}
	
	
	// test the second grid wrapper
	wrapper = document.getElementById("wrapper2");
	grid = wrapper.getGridFragments()[0];
	
	// test column and row line counts
	is(grid.cols.lines.length, 4,
		"Grid.cols.lines property doesn't expand due to an explicit line declaration."
	);
	is(grid.rows.lines.length, 2,
		"Grid.rows.lines property has length that respects implicit expansion."
	);
	
	// test area count
	is(grid.areas.length, 1,
		"Grid.areas property has length that respects implicit expansion."
	);
	
	for (var i = 0; i < grid.areas.length; i++) {
		var area = grid.areas[i];
		if (area.name == "areaA") {
			is(area.type, "implicit", area.name + " is implicit.");

			// test lines of implicit areas
			is(area.rowStart, 1, area.name + " has start row line of 1.");
			is(area.rowEnd, 2, area.name + " has end row line of 2.");
			is(area.columnStart, 1, area.name + " has start column line of 1.");
			is(area.columnEnd, 3, area.name + " has end column line of 3.");
		}
	}
	
	
	// test the third grid wrapper
	wrapper = document.getElementById("wrapper3");
	grid = wrapper.getGridFragments()[0];
	
	// test column and row line counts
	is(grid.cols.lines.length, 2,
		"Grid.cols.lines property doesn't expand due to an explicit line declaration."
	);
	is(grid.rows.lines.length, 2,
		"Grid.rows.lines property doesn't expand due to an explicit line declaration."
	);
	
	if (grid.cols.lines.length == 2 && grid.rows.lines.length == 2) {
		// check that areaC gets both the explicit line names and the implicit line names
		isnot(grid.cols.lines[0].names.indexOf("areaC-start"), -1,
			"Grid row line 1 has the name 'areaC-start'."
		);
		
		isnot(grid.cols.lines[0].names.indexOf("areaC-end"), -1,
			"Grid row line 1 has the name 'areaC-end'."
		);
		
		isnot(grid.cols.lines[1].names.indexOf("areaC-start"), -1,
			"Grid row line 2 has the name 'areaC-start'."
		);
		
		isnot(grid.cols.lines[1].names.indexOf("areaC-end"), -1,
			"Grid row line 2 has the name 'areaC-end'."
		);
	}
	
	// test area count
	is(grid.areas.length, 4,
		"Grid.areas property reports 4 areas."
	);
	
	for (var i = 0; i < grid.areas.length; i++) {
		var area = grid.areas[i];
		if (area.name == "areaC") {
			// test lines of implicit area
			is(area.rowStart, 1, area.name + " has start row line of 1.");
			is(area.rowEnd, 2, area.name + " has end row line of 2.");
			is(area.columnStart, 1, area.name + " has start column line of 1.");
			is(area.columnEnd, 2, area.name + " has end column line of 2.");
		}
	}

	// test the fourth grid wrapper
	wrapper = document.getElementById("wrapper4");
	grid = wrapper.getGridFragments()[0];

	// test column and row line counts
	is(grid.cols.lines.length, 8,
	"Grid.cols.lines property expands properly with implicit columns on both sides."
	);
	is(grid.rows.lines.length, 2,
	"Grid.rows.lines property is as expected"
	);

	if (grid.cols.lines.length == 8) {
	// check that all the lines get correct implict/explicit type and number
	let expectedType = [
		"implicit",
		"implicit",
		"implicit",
		"explicit",
		"explicit",
		"explicit",
		"explicit",
		"implicit",
		];
	let expectedNumber = [
		0,
		0,
		0,
		1,
		2,
		3,
		4,
		5,
		];

	for (let i = 0; i < grid.cols.lines.length; i++) {
		let line = grid.cols.lines[i];
		is(line.type, expectedType[i], "Line index " + i + " has expected type.");
		is(line.number, expectedNumber[i], "Line index " + i + " has expected number.");
	}
	}

	SimpleTest.finish();
}
</script>
</head>
<body onLoad="runTests();">

	<div id="wrapper1" class="wrapper template1">
		<div id="boxA" class="box a">A</div>
		<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="wrapper2" class="wrapper template2">
		<div id="boxA" class="box a">A</div>
	</div>
	
	<br/>
	
	<div id="wrapper3" class="wrapper template3">
		<div id="boxC" class="box c">C</div>
	</div>

	<div id="wrapper4" class="wrapper template4">
		<div id="boxE" class="box e">E</div>
	</div>

</body>
</html>