blob: 8d2e2813686d6c7a268351ff9b815dd9f81606af [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<style id="style-container">
</style>
</head>
<body>
</body>
<script>
description('Test the parsing of :nth-last-child(of) for querySelector and style.');
function testValidSelector(selectorString, expectedSerializedSelector) {
shouldNotThrow('document.querySelector(":nth-last-child(' + selectorString.replace(/\\/g, '\\\\') + ')")');
var styleContainer = document.getElementById('style-container');
styleContainer.innerHTML = ':nth-last-child(' + selectorString + ') { }';
shouldBe("document.getElementById('style-container').sheet.cssRules.length", "1");
if (!expectedSerializedSelector)
expectedSerializedSelector = selectorString;
shouldBeEqualToString("document.getElementById('style-container').sheet.cssRules[0].selectorText", ':nth-last-child(' + expectedSerializedSelector + ')');
styleContainer.innerHTML = '';
}
// There are multiple ways of parsing :nth-last-child() based on the An+B part, we should test everything.
var validNthAnPlusB = [
"even",
"odd",
"n",
"-n",
"3",
"-3",
"n+0",
"n-0",
"0n",
"3n+5",
"-3n+5",
"3n-5",
"-3n-5",
];
debug("Basic valid cases without [of selectors]");
for (var i = 0; i < validNthAnPlusB.length; ++i)
testValidSelector(validNthAnPlusB[i], validNthAnPlusB[i]);
var validRightSide = [
// Basic types.
"*",
"foobar",
"#id",
".class",
":first-child",
":last-child",
// Compound selectors.
"foobar#id.class",
".class:not(.notclass)",
"#id:empty",
// Complex selectors.
"a > b",
"a b",
"a + b",
"a ~ b",
"a + b > c ~ d e + g",
// Selector lists.
"a, a",
"a, b",
"a, b, c, d",
".foo, .bar, .baz",
"a > b, a b, a + b, a ~ b",
];
debug("Basic cases with [of selectors]");
for (var leftSideIndex = 0; leftSideIndex < validNthAnPlusB.length; ++leftSideIndex) {
for (var rightSideIndex = 0; rightSideIndex < validRightSide.length; ++rightSideIndex) {
var selectorString = validNthAnPlusB[leftSideIndex] + " of " + validRightSide[rightSideIndex];
testValidSelector(selectorString);
testValidSelector(selectorString + " ", selectorString);
}
}
</script>
<script src="../../resources/js-test-post.js"></script>
</html>