blob: 1b78a2a99c5f7d10e77639cba9689080e7a2d2f5 [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-child(of) for querySelector and style.');
function testInvalidSelector(selectorString) {
shouldThrowErrorName('document.querySelector(":nth-child(' + selectorString + ')")', 'SyntaxError');
var styleContainer = document.getElementById('style-container');
styleContainer.innerHTML = ':nth-child(' + selectorString + ') { }';
shouldBe("document.getElementById('style-container').sheet.cssRules.length", "0");
styleContainer.innerHTML = '';
}
// There are multiple ways of parsing :nth-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("Test invalid selectors:");
// Missing space characters.
for (var i = 0; i < validNthAnPlusB.length; ++i) {
testInvalidSelector(validNthAnPlusB[i] + " of");
testInvalidSelector(validNthAnPlusB[i] + " of ");
testInvalidSelector(validNthAnPlusB[i] + " of.class");
testInvalidSelector(validNthAnPlusB[i] + "of .class");
}
// Use valid identifier but not "of" as a separator.
for (var i = 0; i < validNthAnPlusB.length; ++i) {
testInvalidSelector(validNthAnPlusB[i] + " empty .class");
testInvalidSelector(validNthAnPlusB[i] + " from .class");
testInvalidSelector(validNthAnPlusB[i] + " to .class");
testInvalidSelector(validNthAnPlusB[i] + " webkit .class");
}
// Matching pseudo elements do not make any sense.
for (var i = 0; i < validNthAnPlusB.length; ++i) {
testInvalidSelector(validNthAnPlusB[i] + " of ::first-letter");
testInvalidSelector(validNthAnPlusB[i] + " of ::before");
testInvalidSelector(validNthAnPlusB[i] + " of ::after");
testInvalidSelector(validNthAnPlusB[i] + " of ::-webkit-custom");
testInvalidSelector(validNthAnPlusB[i] + " of .foo, ::before");
testInvalidSelector(validNthAnPlusB[i] + " of ::before, .foo");
testInvalidSelector(validNthAnPlusB[i] + " of -webkit-any(::before, .foo)");
testInvalidSelector(validNthAnPlusB[i] + " of :nth-child(2n+1 of ::before)");
testInvalidSelector(validNthAnPlusB[i] + " of :not(::before)");
}
// Invalid identifiers, syntax, etc.
for (var i = 0; i < validNthAnPlusB.length; ++i) {
testInvalidSelector(validNthAnPlusB[i] + " of .123class");
testInvalidSelector(validNthAnPlusB[i] + " of #123id");
testInvalidSelector(validNthAnPlusB[i] + " of []");
testInvalidSelector(validNthAnPlusB[i] + " of ()");
testInvalidSelector(validNthAnPlusB[i] + " of )");
testInvalidSelector(validNthAnPlusB[i] + " of {}");
testInvalidSelector(validNthAnPlusB[i] + " of }");
}
</script>
<script src="../../resources/js-test-post.js"></script>
</html>