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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Grid Layout Test: only serialize 'grid' shorthands when the value can roundtrip</title>
<link rel="author" title="Daniel Libby" href="mailto:dlibby@microsoft.com">
<link rel="author" title="Kurt Catti-Schmidt" href="mailto:kschmi@microsoft.com">
<link rel="help" href="https://drafts.csswg.org/css-grid/#propdef-grid">
<meta name="assert" content="grid shorthand must not serialize when the value cannot roundtrip.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
function test_shorthand_roundtrip(cssText, properties, declarations) {
var div = document.createElement('div');
div.style.cssText = cssText;
for (let property of Object.keys(properties).sort()) {
test(function(){
const readValue = div.style[property];
if (Array.isArray(properties[property])) {
assert_in_array(readValue, properties[property], property + " serialization should be sound");
} else {
assert_equals(readValue, properties[property], property + " serialization should be canonical");
}
if (readValue != "") {
div.style[property] = "";
div.style[property] = readValue;
assert_equals(div.style[property], readValue, "serialization should round-trip");
}
}, "e.style.cssText = " + cssText + " should set " + property);
}
if (declarations) {
let cssTextSerialization = div.style.cssText;
declarations.forEach(decl => {
test(function(){
assert_true(cssTextSerialization.indexOf(decl) !== -1,
`cssText serialization ('${cssTextSerialization}') must contain contain '${decl}'`);
}, `cssText ('${cssText}') must contain '${decl}' in its serialization`);
});
}
}
test_shorthand_roundtrip('grid: auto-flow auto / 100px 100px',
{
'grid': 'none / 100px 100px',
'grid-template-areas': 'none'
});
test_shorthand_roundtrip('grid: auto-flow auto / 100px 100px; grid-template-areas: "one two" "three four"',
{
'grid': '',
'grid-template-areas': '"one two" "three four"',
'grid-auto-flow': 'row',
'grid-auto-rows': 'auto'
});
test_shorthand_roundtrip('grid: 30px 40px / 50px 60px; grid-auto-flow: column',
{
'grid': '',
'grid-template': '30px 40px / 50px 60px',
'grid-auto-flow': 'column',
}, [
'grid-template: 30px 40px / 50px 60px;',
'grid-auto-rows: auto;',
'grid-auto-columns: auto;',
'grid-auto-flow: column;'
]);
test_shorthand_roundtrip('grid: auto-flow / 10px; grid-template-rows: 20px',
{
'grid': '20px / 10px',
'grid-template': '20px / 10px'
}, [
'grid: 20px / 10px;'
]);
test_shorthand_roundtrip('grid: auto-flow / 10px; grid-template-rows: repeat(2, 20px)',
{
'grid': 'repeat(2, 20px) / 10px',
'grid-template-rows': 'repeat(2, 20px)'
});
test_shorthand_roundtrip('grid: auto-flow / 10px; grid-template-rows: repeat(2, 20px) repeat(3, 30px)',
{
'grid': 'repeat(2, 20px) repeat(3, 30px) / 10px',
'grid-template-rows': 'repeat(2, 20px) repeat(3, 30px)'
});
test_shorthand_roundtrip('grid: auto-flow / 10px; grid-template-rows: repeat(auto-fill, 20px)',
{
'grid': 'repeat(auto-fill, 20px) / 10px',
'grid-template-rows': 'repeat(auto-fill, 20px)'
});
test_shorthand_roundtrip('grid: auto-flow / 10px; grid-template-rows: repeat(auto-fit, 20px)',
{
'grid': 'repeat(auto-fit, 20px) / 10px',
'grid-template-rows': 'repeat(auto-fit, 20px)'
});
test_shorthand_roundtrip('grid: 10px / auto; grid-template-columns: 20px',
{
'grid': '10px / 20px',
'grid-template': '10px / 20px'
}, [
'grid: 10px / 20px;'
]);
test_shorthand_roundtrip('grid: auto-flow / 10px; grid-template-columns: repeat(2, 20px)',
{
'grid': 'none / repeat(2, 20px)',
'grid-template-columns': 'repeat(2, 20px)'
});
test_shorthand_roundtrip('grid: auto-flow / 10px; grid-template-columns: repeat(2, 20px) repeat(3, 30px)',
{
'grid': 'none / repeat(2, 20px) repeat(3, 30px)',
'grid-template-columns': 'repeat(2, 20px) repeat(3, 30px)'
});
test_shorthand_roundtrip('grid: auto-flow / 10px; grid-template-columns: repeat(auto-fill, 20px)',
{
'grid': 'none / repeat(auto-fill, 20px)',
'grid-template-columns': 'repeat(auto-fill, 20px)'
});
test_shorthand_roundtrip('grid: auto-flow / 10px; grid-template-columns: repeat(auto-fit, 20px)',
{
'grid': 'none / repeat(auto-fit, 20px)',
'grid-template-columns': 'repeat(auto-fit, 20px)'
});
test_shorthand_roundtrip('grid: auto-flow 1px / 2px; grid-auto-flow: inherit', { 'grid': '' });
test_shorthand_roundtrip('grid: 1px / 2px; grid-auto-flow: row', { 'grid': '1px / 2px' });
test_shorthand_roundtrip('grid: none / 2px; grid-auto-flow: row', { 'grid': 'none / 2px' });
test_shorthand_roundtrip('grid: 1px / 2px; grid-auto-columns: auto', { 'grid': '1px / 2px' });
test_shorthand_roundtrip('grid: 1px / 2px; grid-auto-rows: auto', { 'grid': '1px / 2px' });
test_shorthand_roundtrip('grid: 1px / auto-flow 2px; grid-auto-rows: auto', { 'grid': '1px / auto-flow 2px' });
test_shorthand_roundtrip('grid: 1px / auto-flow; grid-auto-columns: auto', { 'grid': '1px / auto-flow' });
test_shorthand_roundtrip('grid: auto-flow 1px / 2px; grid-auto-columns: auto', { 'grid': 'auto-flow 1px / 2px' });
test_shorthand_roundtrip('grid: auto-flow 1px / none; grid-auto-columns: auto', { 'grid': 'auto-flow 1px / none' });
test_shorthand_roundtrip('grid: auto-flow dense / 2px; grid-auto-rows: auto', { 'grid': 'auto-flow dense / 2px' });
test_shorthand_roundtrip('grid: auto-flow 1px / 2px; grid-auto-columns: 3px',
{
'grid': '',
'grid-auto-columns': '3px',
'grid-auto-rows': '1px',
'grid-auto-flow': 'row',
'grid-template-columns': '2px',
'grid-template-rows': 'none'
});
test_shorthand_roundtrip('grid: 1px / auto-flow 2px; grid-auto-rows: 3px',
{
'grid': '',
'grid-auto-columns': '2px',
'grid-auto-rows': '3px',
'grid-auto-flow': 'column',
'grid-template-columns': 'none',
'grid-template-rows': '1px'
});
test_shorthand_roundtrip('grid: none / auto-flow 1px; grid-template-columns: 3px',
{
'grid': '',
'grid-auto-columns': '1px',
'grid-auto-rows': 'auto',
'grid-auto-flow': 'column',
'grid-template-columns': '3px',
'grid-template-rows': 'none'
});
test_shorthand_roundtrip('grid: none / auto-flow 1px; grid-template-columns: repeat(2, 3px)',
{
'grid': '',
'grid-auto-columns': '1px',
'grid-auto-rows': 'auto',
'grid-auto-flow': 'column',
'grid-template-columns': 'repeat(2, 3px)',
'grid-template-rows': 'none'
});
test_shorthand_roundtrip('grid: none / auto-flow 1px; grid-template-columns: repeat(auto-fill, 3px)',
{
'grid': '',
'grid-auto-columns': '1px',
'grid-auto-rows': 'auto',
'grid-auto-flow': 'column',
'grid-template-columns': 'repeat(auto-fill, 3px)',
'grid-template-rows': 'none'
});
test_shorthand_roundtrip('grid: none / auto-flow 1px; grid-template-columns: repeat(auto-fit, 3px)',
{
'grid': '',
'grid-auto-columns': '1px',
'grid-auto-rows': 'auto',
'grid-auto-flow': 'column',
'grid-template-columns': 'repeat(auto-fit, 3px)',
'grid-template-rows': 'none'
});
test_shorthand_roundtrip('grid: auto-flow 1px / none; grid-template-rows: 3px',
{
'grid': '',
'grid-auto-columns': 'auto',
'grid-auto-rows': '1px',
'grid-auto-flow': 'row',
'grid-template-columns': 'none',
'grid-template-rows': '3px'
});
test_shorthand_roundtrip('grid: auto-flow 1px / none; grid-template-rows: repeat(2, 3px)',
{
'grid': '',
'grid-auto-columns': 'auto',
'grid-auto-rows': '1px',
'grid-auto-flow': 'row',
'grid-template-columns': 'none',
'grid-template-rows': 'repeat(2, 3px)'
});
test_shorthand_roundtrip('grid: auto-flow 1px / none; grid-template-rows: repeat(auto-fill, 3px)',
{
'grid': '',
'grid-auto-columns': 'auto',
'grid-auto-rows': '1px',
'grid-auto-flow': 'row',
'grid-template-columns': 'none',
'grid-template-rows': 'repeat(auto-fill, 3px)'
});
test_shorthand_roundtrip('grid: auto-flow 1px / none; grid-template-rows: repeat(auto-fit, 3px)',
{
'grid': '',
'grid-auto-columns': 'auto',
'grid-auto-rows': '1px',
'grid-auto-flow': 'row',
'grid-template-columns': 'none',
'grid-template-rows': 'repeat(auto-fit, 3px)'
});
test_shorthand_roundtrip('grid-template: none;',
{
'grid': '',
'grid-template-areas': 'none',
'grid-template-rows': 'none',
'grid-template-columns': 'none',
'grid-template': 'none'
});
test_shorthand_roundtrip('grid-template: auto / auto;',
{
'grid': '',
'grid-template-areas': 'none',
'grid-template-rows': 'auto',
'grid-template-columns': 'auto',
'grid-template': 'auto / auto'
});
test_shorthand_roundtrip('grid-template: [header-top] "a a a" [header-bottom] [main-top] "b b b" 1fr [main-bottom] / auto 1fr auto',
{
'grid': '',
'grid-template-areas': '"a a a" "b b b"',
'grid-template-rows': '[header-top] auto [header-bottom main-top] 1fr [main-bottom]',
'grid-template-columns': 'auto 1fr auto',
'grid-template': '[header-top] "a a a" [header-bottom main-top] "b b b" 1fr [main-bottom] / auto 1fr auto'
});
test_shorthand_roundtrip('grid-template: [header-top] "a a a" [header-bottom] [main-top] "b b b" 1fr [main-bottom] "c c c" "d d d" / auto',
{
'grid': '',
'grid-template-areas': '"a a a" "b b b" "c c c" "d d d"',
'grid-template-rows': '[header-top] auto [header-bottom main-top] 1fr [main-bottom] auto auto',
'grid-template-columns': 'auto',
'grid-template': '[header-top] "a a a" [header-bottom main-top] "b b b" 1fr [main-bottom] "c c c" "d d d" / auto'
});
test_shorthand_roundtrip('grid-template-rows: auto auto; grid-template-columns: repeat(2, 3px); grid-template-areas: "one two" "three four"',
{
'grid': '',
'grid-template-areas': '"one two" "three four"',
'grid-template-rows': 'auto auto',
'grid-template-columns': 'repeat(2, 3px)'
});
test_shorthand_roundtrip('grid-template-rows: auto auto; grid-template-columns: repeat(2, 1fr); grid-template-areas: "one two" "three four"',
{
'grid': '',
'grid-template-areas': '"one two" "three four"',
'grid-template-rows': 'auto auto',
'grid-template-columns': 'repeat(2, 1fr)'
});
test_shorthand_roundtrip('grid-template-rows: auto auto; grid-template-columns: repeat(auto-fill, 3px); grid-template-areas: "one two" "three four"',
{
'grid': '',
'grid-template-areas': '"one two" "three four"',
'grid-template-rows': 'auto auto',
'grid-template-columns': 'repeat(auto-fill, 3px)'
});
test_shorthand_roundtrip('grid-template-rows: auto auto; grid-template-columns: repeat(auto-fit, 3px); grid-template-areas: "one two" "three four"',
{
'grid': '',
'grid-template-areas': '"one two" "three four"',
'grid-template-rows': 'auto auto',
'grid-template-columns': 'repeat(auto-fit, 3px)'
});
</script>
|