| <!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 :matches(selectorList) for querySelector and style.'); |
| |
| function testInvalidSelector(selectorString) { |
| shouldThrowErrorName('document.querySelector(":matches(' + selectorString + ')")', 'SyntaxError'); |
| |
| var styleContainer = document.getElementById('style-container'); |
| styleContainer.innerHTML = ':matches(' + selectorString + ') { }'; |
| shouldBe("document.getElementById('style-container').sheet.cssRules.length", "0"); |
| styleContainer.innerHTML = ''; |
| } |
| |
| var validSelectorsPart2 = [ |
| // Basic types. |
| "foobar", |
| ".class", |
| ":last-child", |
| |
| // Pseudo elements. |
| "::first-letter", |
| "::before", |
| |
| // Compound selectors. |
| "foobar#id.class", |
| "#id:empty", |
| |
| // Complex selectors. |
| "a b", |
| "a ~ b", |
| |
| // Functional pseudo classes. |
| ":-webkit-any(.selector,#tama,#hanayo,#midoriko)", |
| ":nth-child(even of a, b, c)", |
| ":not(:matches(cocoa, cappuccino))", |
| ]; |
| |
| var invalidSelectors = [ |
| // Not selectors. |
| "", |
| " ", |
| ",", |
| |
| ".123class", |
| "#123id", |
| "[]", |
| "()", |
| ")", |
| "{}", |
| "}", |
| |
| // Unbalanced parenthesized functional pseudo classes. |
| ":not(", |
| ":matches(", |
| ":nth-child(2n+1 of", |
| ]; |
| |
| debug("3 :matches(valid, valid, invalid) selectors"); |
| for (var i = 0; i < validSelectorsPart2.length; ++i) { |
| for (var j = i; j < validSelectorsPart2.length; ++j) { |
| for (var k = 0; k < invalidSelectors.length; ++k) { |
| var selectorString = validSelectorsPart2[i] + ',' + validSelectorsPart2[j] + ',' + invalidSelectors[k]; |
| testInvalidSelector(selectorString); |
| } |
| } |
| } |
| |
| </script> |
| <script src="../../resources/js-test-post.js"></script> |
| </html> |