summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/css-grid-layout/grid-template-areas-get-set.html
blob: 98ddb9e7f1c8e4dbc7490015ac39d6f1faec7777 (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
<!DOCTYPE html>
<html>
<head>
<link href="resources/grid.css" rel="stylesheet">
<style>
#gridWithSingleStringTemplate {
    grid-template-areas: "area";
}

#gridWithTwoColumnsTemplate {
    grid-template-areas: "first second";
}

#gridWithTwoRowsTemplate {
    grid-template-areas: "first"
                         "second";
}

#gridWithSpanningColumnsTemplate {
    grid-template-areas: "span span";
}

#gridWithSpanningRowsDotTemplate {
    grid-template-areas: "span"
                         ".";
}

#gridWithSpanningRowsDotsTemplate {
    grid-template-areas: "span"
                         "....";
}

#gridWithDotColumn {
    grid-template-areas: "header ."
                         "footer .";
}

#gridWithDotsColumn {
    grid-template-areas: "header ......"
                         "footer ......";
}

#gridWithDotCells {
    grid-template-areas: "first ."
                         ". second";
}

#gridWithDotsCells {
    grid-template-areas: "first ......"
                         "..... second";
}

#gridWithComplexDotAreas {
    grid-template-areas: ". header header ."
                         ". . . ."
                         "nav main main aside"
                         "nav main main aside"
                         ". . . aside"
                         ". footer footer aside";
}

#gridWithComplexDotsAreas {
    grid-template-areas: "... header header ....."
                         "... ...... ...... ....."
                         "nav main   main   aside"
                         "nav main   main   aside"
                         "... ...... ...... aside"
                         "... footer footer aside";
}

#gridWithMixedDotAndDotsAreas {
    grid-template-areas: "... title ."
                         "..  main main"
                         "nav ................... aside"
                         ". footer ......";
}

#gridWithDotsNoSpace {
    grid-template-areas: ".title...nav. ..main test";
}

#gridWithHorizontalRectangle {
    grid-template-areas: "a a a"
                         "a a a";
}

#gridWithVerticalRectangle {
    grid-template-areas: "a a"
                         "a a"
                         "a a";
}

</style>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div class="grid" id="gridWithDefaultTemplate"></div>
<div class="grid" id="gridWithSingleStringTemplate"></div>
<div class="grid" id="gridWithTwoColumnsTemplate"></div>
<div class="grid" id="gridWithTwoRowsTemplate"></div>
<div class="grid" id="gridWithSpanningColumnsTemplate"></div>
<div class="grid" id="gridWithSpanningRowsDotTemplate"></div>
<div class="grid" id="gridWithSpanningRowsDotsTemplate"></div>
<div class="grid" id="gridWithDotColumn"></div>
<div class="grid" id="gridWithDotsColumn"></div>
<div class="grid" id="gridWithDotCells"></div>
<div class="grid" id="gridWithDotsCells"></div>
<div class="grid" id="gridWithComplexDotAreas"></div>
<div class="grid" id="gridWithComplexDotsAreas"></div>
<div class="grid" id="gridWithMixedDotAndDotsAreas"></div>
<div class="grid" id="gridWithDotsNoSpace"></div>
<div class="grid" id="gridWithHorizontalRectangle"></div>
<div class="grid" id="gridWithVerticalRectangle"></div>
<script>
    description("This test checks that grid-template-areas is properly parsed.");

    function testGridTemplateAreas(gridId, expectedResult) {
        shouldBeEqualToString("window.getComputedStyle(" + gridId + ").getPropertyValue('grid-template-areas')", expectedResult);
    }

    debug("Test getting grid-template-areas set through CSS.");
    testGridTemplateAreas("gridWithDefaultTemplate", "none");
    testGridTemplateAreas("gridWithSingleStringTemplate", '"area"');
    testGridTemplateAreas("gridWithTwoColumnsTemplate", '"first second"');
    testGridTemplateAreas("gridWithTwoRowsTemplate", '"first" "second"');
    testGridTemplateAreas("gridWithSpanningColumnsTemplate", '"span span"');
    testGridTemplateAreas("gridWithSpanningRowsDotTemplate", '"span" "."');
    testGridTemplateAreas("gridWithSpanningRowsDotsTemplate", '"span" "."');
    testGridTemplateAreas("gridWithDotColumn", '"header ." "footer ."');
    testGridTemplateAreas("gridWithDotsColumn", '"header ." "footer ."');
    testGridTemplateAreas("gridWithDotCells", '"first ." ". second"');
    testGridTemplateAreas("gridWithDotsCells", '"first ." ". second"');
    testGridTemplateAreas("gridWithComplexDotAreas", '". header header ." ". . . ." "nav main main aside" "nav main main aside" ". . . aside" ". footer footer aside"');
    testGridTemplateAreas("gridWithComplexDotsAreas", '". header header ." ". . . ." "nav main main aside" "nav main main aside" ". . . aside" ". footer footer aside"');
    testGridTemplateAreas("gridWithMixedDotAndDotsAreas", '". title ." ". main main" "nav . aside" ". footer ."');
    testGridTemplateAreas("gridWithDotsNoSpace", '". title . nav . . main test"');
    testGridTemplateAreas("gridWithHorizontalRectangle", '"a a a" "a a a"');
    testGridTemplateAreas("gridWithVerticalRectangle", '"a a" "a a" "a a"');

    debug("Test grid-template-areas: initial");
    var element = document.createElement("div");
    document.body.appendChild(element);
    element.style.gridTemplateAreas = "'foobar'";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", '"foobar"')
    element.style.gridTemplateAreas = "initial";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", 'none');
    element.style.gridTemplateAreas = "'foobar'";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", '"foobar"')
    element.style.gridTemplateAreas = "none";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", 'none');
    document.body.removeChild(element);

    debug("Test grid-template-areas: inherit");
    var parentElement = document.createElement("div");
    document.body.appendChild(parentElement);
    parentElement.style.gridTemplateAreas = "'foo bar'";
    shouldBeEqualToString("window.getComputedStyle(parentElement).getPropertyValue('grid-template-areas')", '"foo bar"')

    var element = document.createElement("div");
    parentElement.appendChild(element);
    element.style.gridTemplateAreas = "inherit";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", '"foo bar"')
    document.body.removeChild(parentElement);

    debug("Test invalid grid-template-areas values.");
    var element = document.createElement("div");
    document.body.appendChild(element);

    // 'nav' is not a rectangular definition.
    element.style.gridTemplateAreas = "'nav head' 'nav nav'";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", "none")

    // 'nav' is not contiguous in the column direction.
    element.style.gridTemplateAreas = "'nav head nav'";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", "none")

    // 'nav' is not contiguous in the row direction.
    element.style.gridTemplateAreas = "'nav head' 'middle middle' 'nav footer'";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", "none")

    // The rows don't have the same number of columns.
    element.style.gridTemplateAreas = "'nav head' 'foot'";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", "none")

    // Empty rows.
    element.style.gridTemplateAreas = "'' ''";
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", "none")

    debug("");
    debug("FIXME: We currently don't validate that the named grid areas are &lt;indent&gt;.");
    // <ident> only allows a leading '-'.
    element.style.gridTemplateAreas = '"nav-up"';
    shouldBeEqualToString("window.getComputedStyle(element).getPropertyValue('grid-template-areas')", "none")
</script>
</body>
</html>