summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-grid/grid-definition/grid-change-auto-repeat-tracks.html
blob: c2d17ec615f0f092e54c0c4792ca4a03bc1cfe8a (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
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Support 'repeat()' notation for 'grid-template-columns' and 'grid-template-rows' properties</title>
<link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">
<link rel="help" href="http://www.w3.org/TR/css-grid-1/#repeat-notation" title="5.1.2 Repeating Rows and Columns: the 'repeat()' notation">
<meta name="assert" content="This test checks that grid-template-{rows|columns} with auto-repeat tracks recomputes the positions of automatically placed grid items.">

<link href="/css/support/grid.css" rel="stylesheet">
<style>
.grid {
  grid-auto-rows: 25px;
  grid-auto-columns: 25px;
  margin-bottom: 10px;
}
.fixedWidth {
  width: 50px;
  grid-auto-flow: row;
  grid-template-columns: repeat(auto-fill, 25px);
}
.fixedHeight {
  width: 100px;
  height: 50px;
  grid-auto-flow: column;
  grid-template-rows: repeat(auto-fill, 25px);
}
#i1-1, #i2-1 {
  grid-row: auto;
  grid-column: 1;
  background-color: orange;
}
#i1-2, #i2-2 {
  grid-row: 1;
  grid-column: auto;
  background-color: green;
}
#i1-3, #i2-3 {
  grid-row: auto;
  grid-column: auto;
  background-color: blue;
}
</style>

<div id="log"></div>

<div style="position: relative">
  <div id="grid1" class="grid fixedWidth">
    <div id="i1-1"></div>
    <div id="i1-2"></div>
    <div id="i1-3"></div>
  </div>
</div>
<div style="position: relative">
  <div id="grid2" class="grid fixedHeight">
    <div id="i2-1"></div>
    <div id="i2-2"></div>
    <div id="i2-3"></div>
  </div>
</div>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/check-layout-th.js"></script>
<script>
function setGridTemplate(id, gridTemplateRows, gridTemplateColumns) {
  let gridElement = document.getElementById(id);
  gridElement.style.gridTemplateRows = gridTemplateRows;
  gridElement.style.gridTemplateColumns = gridTemplateColumns;
}

function setGridSize(id, width, height) {
  let gridElement = document.getElementById(id);
  gridElement.style.width = width;
  gridElement.style.height = height;
}

function setGridItemPlacement(id, gridRow, gridColumn) {
  let gridItem = document.getElementById(id);
  gridItem.style.gridRow = gridRow;
  gridItem.style.gridColumn = gridColumn;
}

function testGridDefinitions(...gridItemDataList) {
  for (let gridItemData of gridItemDataList) {
    let gridItem = document.getElementById(gridItemData.id);
    gridItem.setAttribute("data-expected-width", gridItemData.width);
    gridItem.setAttribute("data-expected-height", gridItemData.height);
    gridItem.setAttribute("data-offset-x", gridItemData.x);
    gridItem.setAttribute("data-offset-y", gridItemData.y);
  }
  checkLayout(".grid", false);
}

// Test changing the number of auto-repeat tracks.
setGridTemplate('grid1', 'none', 'repeat(auto-fill, 25px)');
setGridTemplate('grid2', 'repeat(auto-fill, 25px)', 'none');
testGridDefinitions(
  { id: 'i1-1', width: '25', height: '25', x: '0', y: '25' },
  { id: 'i1-2', width: '25', height: '25', x: '0', y: '0' },
  { id: 'i1-3', width: '25', height: '25', x: '25', y: '25' },
  { id: 'i2-1', width: '25', height: '25', x: '0', y: '0' },
  { id: 'i2-2', width: '25', height: '25', x: '25', y: '0' },
  { id: 'i2-3', width: '25', height: '25', x: '25', y: '25' });

setGridTemplate('grid1', 'none', 'none');
setGridTemplate('grid2', 'none', 'none');
testGridDefinitions(
  { id: 'i1-1', width: '25', height: '25', x: '0', y: '25' },
  { id: 'i1-2', width: '25', height: '25', x: '0', y: '0' },
  { id: 'i1-3', width: '25', height: '25', x: '0', y: '50' },
  { id: 'i2-1', width: '25', height: '25', x: '0', y: '0' },
  { id: 'i2-2', width: '25', height: '25', x: '25', y: '0' },
  { id: 'i2-3', width: '25', height: '25', x: '50', y: '0' });

setGridTemplate('grid1', 'none', '5px repeat(auto-fill, 20px)');
setGridTemplate('grid2', 'repeat(auto-fill, 20px) 3px', 'none');
testGridDefinitions(
  { id: 'i1-1', width: '5', height: '25', x: '0', y: '25' },
  { id: 'i1-2', width: '5', height: '25', x: '0', y: '0' },
  { id: 'i1-3', width: '20', height: '25', x: '5', y: '25' },
  { id: 'i2-1', width: '25', height: '20', x: '0', y: '0' },
  { id: 'i2-2', width: '25', height: '20', x: '25', y: '0' },
  { id: 'i2-3', width: '25', height: '20', x: '25', y: '20' });

setGridTemplate('grid1', 'none', '5px repeat(auto-fill, 22px)');
setGridTemplate('grid2', 'repeat(auto-fill, 18px) 3px', 'none');
testGridDefinitions(
  { id: 'i1-1', width: '5', height: '25', x: '0', y: '25' },
  { id: 'i1-2', width: '5', height: '25', x: '0', y: '0' },
  { id: 'i1-3', width: '22', height: '25', x: '5', y: '25' },
  { id: 'i2-1', width: '25', height: '18', x: '0', y: '0' },
  { id: 'i2-2', width: '25', height: '18', x: '25', y: '0' },
  { id: 'i2-3', width: '25', height: '18', x: '25', y: '18' });

setGridTemplate('grid1', 'none', 'repeat(auto-fill, 45px)');
setGridTemplate('grid2', 'repeat(auto-fill, 45px)', 'none');
testGridDefinitions(
  { id: 'i1-1', width: '45', height: '25', x: '0', y: '25' },
  { id: 'i1-2', width: '45', height: '25', x: '0', y: '0' },
  { id: 'i1-3', width: '45', height: '25', x: '0', y: '50' },
  { id: 'i2-1', width: '25', height: '45', x: '0', y: '0' },
  { id: 'i2-2', width: '25', height: '45', x: '25', y: '0' },
  { id: 'i2-3', width: '25', height: '45', x: '50', y: '0' });

// Test changing the size of the grid.
setGridSize('grid1', '100px', 'auto');
setGridSize('grid2', '100px', '100px');
testGridDefinitions(
  { id: 'i1-1', width: '45', height: '25', x: '0', y: '25' },
  { id: 'i1-2', width: '45', height: '25', x: '0', y: '0' },
  { id: 'i1-3', width: '45', height: '25', x: '45', y: '25' },
  { id: 'i2-1', width: '25', height: '45', x: '0', y: '0' },
  { id: 'i2-2', width: '25', height: '45', x: '25', y: '0' },
  { id: 'i2-3', width: '25', height: '45', x: '25', y: '45' });

// Move the third item so that there is an empty track between it and the others.
setGridItemPlacement('i1-3', 'auto', '3');
setGridItemPlacement('i2-3', '3', 'auto');
testGridDefinitions(
  { id: 'i1-1', width: '45', height: '25', x: '0', y: '25' },
  { id: 'i1-2', width: '45', height: '25', x: '0', y: '0' },
  { id: 'i1-3', width: '25', height: '25', x: '90', y: '25' },
  { id: 'i2-1', width: '25', height: '45', x: '0', y: '0' },
  { id: 'i2-2', width: '25', height: '45', x: '25', y: '0' },
  { id: 'i2-3', width: '25', height: '25', x: '25', y: '90' });

// Set the same templates, but using auto-fit instead of auto-fill. The empty track should collapse.
setGridTemplate('grid1', 'none', 'repeat(auto-fit, 45px)');
setGridTemplate('grid2', 'repeat(auto-fit, 45px)', 'none');
testGridDefinitions(
  { id: 'i1-1', width: '45', height: '25', x: '0', y: '25' },
  { id: 'i1-2', width: '45', height: '25', x: '0', y: '0' },
  { id: 'i1-3', width: '25', height: '25', x: '45', y: '25' },
  { id: 'i2-1', width: '25', height: '45', x: '0', y: '0' },
  { id: 'i2-2', width: '25', height: '45', x: '25', y: '0' },
  { id: 'i2-3', width: '25', height: '25', x: '25', y: '45' });

done();
</script>