blob: 290cbf8a9feebde56f32afe8c17054fd3264e2ef [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script>
if (window.testRunner)
testRunner.overridePreference("WebKitCSSGridLayoutEnabled", 1);
</script>
<style>
.gridItemWithPositiveInteger {
grid-column: 10;
grid-row: 15;
}
.gridItemWithNegativeInteger {
grid-column: -10;
grid-row: -15;
}
.gridItemWithAuto {
grid-column: auto;
grid-row: auto;
}
.gridItemWith2Integer {
grid-column: 10 / 15;
grid-row: 5 / 5;
}
.gridItemWithNegativePositiveInteger {
grid-column: 10 / -10;
grid-row: -8 / 5;
}
.gridItemWithBeforeSpan {
grid-column: span 2 / 4;
grid-row: 3 / span 5;
}
.gridItemWithAfterSpan {
grid-column: 2 span / 4;
grid-row: 3 / 5 span;
}
.gridItemWith2OnlySpan {
grid-column: span / span;
grid-row: span / span;
}
.gridItemWith2Auto {
grid-column: auto / auto;
grid-row: auto / auto;
}
.gridItemWithBothLongHand {
grid-end: 11;
grid-before: 4;
}
.gridItemWithNoSpace {
grid-column: auto/1;
grid-row: 5/auto;
}
.gridItemWithString {
grid-column: "first";
grid-row: "last";
}
.gridItemWithSpanString {
grid-column: 1 /span "first";
grid-row: -1 / span "last";
}
.gridItemWithSpanNumberString {
grid-column: 1 /span 3 "first";
grid-row: -1 / "last" 2 span ;
}
</style>
<script src="resources/grid-item-column-row-parsing-utils.js"></script>
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<!-- The first has no properties set on it. -->
<div id="gridItemWithNoCSSRule"></div>
<div class="gridItemWithPositiveInteger" id="gridItemWithPositiveInteger"></div>
<div class="gridItemWithNegativeInteger" id="gridItemWithNegativeInteger"></div>
<div class="gridItemWithAuto" id="gridItemWithAutoElement"></div>
<div class="gridItemWith2Integer" id="gridItemWith2IntegerElement"></div>
<div class="gridItemWithNegativePositiveInteger" id="gridItemWithNegativePositiveIntegerElement"></div>
<div class="gridItemWith2Auto" id="gridItemWith2AutoElement"></div>
<div class="gridItemWithBeforeSpan" id="gridItemWithBeforeSpanElement"></div>
<div class="gridItemWithAfterSpan" id="gridItemWithAfterSpanElement"></div>
<div class="gridItemWith2OnlySpan" id="gridItemWith2OnlySpanElement"></div>
<div class="gridItemWithNegativePositiveInteger gridItemWithBothLongHand" id="gridItemWithBothShortLongHandElement"></div>
<div class="gridItemWithNoSpace" id="gridItemWithNoSpaceElement"></div>
<div class="gridItemWithString" id="gridItemWithString"></div>
<div class="gridItemWithSpanString" id="gridItemWithSpanString"></div>
<div class="gridItemWithSpanNumberString" id="gridItemWithSpanNumberString"></div>
<script>
description('Test that setting and getting grid-column and grid-row works as expected');
debug("Test getting grid-column and grid-row set through CSS");
testColumnRowCSSParsing("gridItemWithNoCSSRule", "auto / auto", "auto / auto");
testColumnRowCSSParsing("gridItemWithPositiveInteger", "10 / auto", "15 / auto");
testColumnRowCSSParsing("gridItemWithNegativeInteger", "-10 / auto", "-15 / auto");
testColumnRowCSSParsing("gridItemWithAutoElement", "auto / auto", "auto / auto");
testColumnRowCSSParsing("gridItemWith2IntegerElement", "10 / 15", "5 / 5");
testColumnRowCSSParsing("gridItemWithNegativePositiveIntegerElement", "10 / -10", "-8 / 5");
testColumnRowCSSParsing("gridItemWithBeforeSpanElement", "span 2 / 4", "3 / span 5");
testColumnRowCSSParsing("gridItemWith2OnlySpanElement", "auto / auto", "auto / auto");
testColumnRowCSSParsing("gridItemWith2AutoElement", "auto / auto" , "auto / auto");
testColumnRowCSSParsing("gridItemWithBothShortLongHandElement", "10 / 11", "4 / 5");
testColumnRowCSSParsing("gridItemWithNoSpaceElement", "auto / 1", "5 / auto");
testColumnRowCSSParsing("gridItemWithString", "1 first / auto", "1 last / auto");
testColumnRowCSSParsing("gridItemWithSpanString", "1 / span 1 first", "-1 / span 1 last");
testColumnRowCSSParsing("gridItemWithSpanNumberString", "1 / span 3 first", "-1 / span 2 last");
debug("");
debug("Test the initial value");
var element = document.createElement("div");
document.body.appendChild(element);
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-column')", "'auto / auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-start')", "'auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-end')", "'auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-row')", "'auto / auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-before')", "'auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-after')", "'auto'");
debug("");
debug("Test getting and setting grid-column and grid-row through JS");
testColumnRowJSParsing("18", "66", "18 / auto", "66 / auto");
testColumnRowJSParsing("-55", "-40", "-55 / auto", "-40 / auto");
testColumnRowJSParsing("auto", "auto", "auto / auto", "auto / auto");
testColumnRowJSParsing("10 / 55", "1 / 10");
testColumnRowJSParsing("span 5 / 5", "4 / span 4");
testColumnRowJSParsing("-5 / 5", "4 / -4");
testColumnRowJSParsing("4 / auto", "5 / auto");
testColumnRowJSParsing("auto / 5", "auto / 8");
testColumnRowJSParsing("span / 3", "5 / span", "span 1 / 3", "5 / span 1");
testColumnRowJSParsing("'first' span / 3", "5 / 'last' span", "span 1 first / 3", "5 / span 1 last");
testColumnRowJSParsing("'first' / 'last'", "'nav' / 'last' span", "1 first / 1 last", "1 nav / span 1 last");
testColumnRowJSParsing("3 'first' / 2 'last'", "5 'nav' / 'last' 7 span", "3 first / 2 last", "5 nav / span 7 last");
testColumnRowJSParsing("3 'first' span / -3 'last'", "'last' 2 span / -1 'nav'", "span 3 first / -3 last", "span 2 last / -1 nav");
debug("");
debug("Test setting grid-column and grid-row back to 'auto' through JS");
element.style.gridColumn = "18 / 19";
element.style.gridRow = "66 / 68";
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-column')", "'18 / 19'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-start')", "'18'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-end')", "'19'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-row')", "'66 / 68'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-before')", "'66'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-after')", "'68'");
element.style.gridColumn = "auto";
element.style.gridRow = "auto";
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-column')", "'auto / auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-start')", "'auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-end')", "'auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-row')", "'auto / auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-before')", "'auto'");
shouldBe("getComputedStyle(element, '').getPropertyValue('grid-after')", "'auto'");
debug("");
debug("Test getting and setting 'initial' grid-column and grid-row through JS");
testColumnRowInitialJSParsing();
debug("");
debug("Test getting and setting 'inherit' grid-column and grid-row through JS");
testColumnRowInheritJSParsing("1 / auto", "inherit");
testColumnRowInheritJSParsing("inherit", "1 / auto");
testColumnRowInheritJSParsing("inherit", "inherit");
debug("");
debug("Test getting and setting invalid grid-column and grid-row through JS");
testColumnRowInvalidJSParsing("4 5", "5 8");
testColumnRowInvalidJSParsing("4 /", "5 /");
testColumnRowInvalidJSParsing("5 / none", "8 / foobar");
testColumnRowInvalidJSParsing("5 5", "8 auto");
testColumnRowInvalidJSParsing("5 / /", "8 / /");
// 0 is invalid.
testColumnRowInvalidJSParsing("0 / 5", "0 / 6");
testColumnRowInvalidJSParsing("6 / 0", "8 / 0");
testColumnRowInvalidJSParsing("0", "0");
testColumnRowInvalidJSParsing("span span / span span", "span span / span span");
// More than 1 <integer> and / or <string>.
testColumnRowInvalidJSParsing("5 5 / span 2", "4 4 / 3 span");
testColumnRowInvalidJSParsing("5 'first' 'last' / span 2", "'first' 4 'last' / 3 span");
testColumnRowInvalidJSParsing("5 / 'first' 'last' 2", "4 / 'first' 3 'last'");
testColumnRowInvalidJSParsing("'first' 'last' / span 2", "'first' 'last' / 3 span");
testColumnRowInvalidJSParsing("5 / 'first' 'last'", "4 / 'first' 'last'");
testColumnRowInvalidJSParsing("5 5 span / 2", "span 4 4 / 3");
testColumnRowInvalidJSParsing("span 3 5 / 1", "5 span 4 / 3");
testColumnRowInvalidJSParsing("span 'last' 'first' / 1", "span 'first' 'last' / 3");
testColumnRowInvalidJSParsing("2 / span 'last' 'first'", "3 / span 'first' 'last'");
testColumnRowInvalidJSParsing("span 1 'last' 'first' / 1", "span 'first' 'last' 7 / 3");
testColumnRowInvalidJSParsing("2 / span 'last' 3 'first'", "3 / span 'first' 5 'last'");
testColumnRowInvalidJSParsing("1 span 2 'first' / 1", "1 span 'last' 7 / 3");
testColumnRowInvalidJSParsing("2 / 3 span 3 'first'", "3 / 5 span 'first' 5");
// Negative integer or 0 are invalid for spans.
testColumnRowInvalidJSParsing("span -1 / -2", "-3 span / -4");
testColumnRowInvalidJSParsing("-1 / -2 span", "-3 / span -4");
testColumnRowInvalidJSParsing("0 span / 0", "span 0 / 0");
testColumnRowInvalidJSParsing("0 / span 0", "0 / 0 span");
testColumnRowInvalidJSParsing("span -3 'first' / 3 'last'", "'last' -2 span / 1 'nav'");
// Spans for both initial / final values is not allowed.
testColumnRowInvalidJSParsing("5 span / span 2", "span 4 / 3 span");
testColumnRowInvalidJSParsing("'first' span / span 'last'", "span 4 'first' / 3 span 'last'");
testColumnRowInvalidJSParsing("'first' 3 span / span 'last'", "span 'first' / 2 span 'last'");
testColumnRowInvalidJSParsing("'first' -1 span / span 'last'", "span -2 'first' / span 'last'");
// We don't allow span to be between the <integer> and the <string>.
testColumnRowInvalidJSParsing("'first' span 1 / 'last'", "2 span 'first' / 'last'");
testColumnRowInvalidJSParsing("3 'first' / 2 span 'last'", "5 'nav' / 'last' span 7");
testColumnRowInvalidJSParsing("3 / 1 span 2", "5 / 3 span 3");
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>