test_getSelectorWarnings.html (2988B)
1 <!DOCTYPE html> 2 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 3 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 4 <style id="test"></style> 5 <script> 6 const sheet = test.sheet; 7 8 function unconstrainedHas(index) { 9 return { index: index, kind: "UnconstrainedHas" }; 10 } 11 12 function siblingCombinatorAfterScope(index) { 13 return { index: index, kind: "SiblingCombinatorAfterScope" }; 14 } 15 16 function testRule(rule, expected) { 17 const index = sheet.insertRule(rule); 18 const warnings = sheet.rules[index].getSelectorWarnings(); 19 is(warnings.length, expected.length, "Got expected number of warnings"); 20 for (let i = 0; i < expected.length; i++) { 21 is(warnings[i].index, expected[i].index, "Warning is generated for expected index"); 22 is(warnings[i].kind, expected[i].kind, "Warning kind is as expected"); 23 } 24 sheet.deleteRule(index); 25 } 26 27 // No selector to check. 28 testRule(".foo {}", []); 29 // Fully constrained `:has` 30 testRule(".bar:has(.foo), :is(#bar):has(.foo) {}", []); 31 // Unconstrained `:has`: Selector around it is unconstrained 32 testRule(":has(.foo) {}", [unconstrainedHas(0)]); 33 testRule(":has(.foo) .bar {}", [unconstrainedHas(0)]); 34 testRule(".bar:has(.foo), :has(.foo) {}", [unconstrainedHas(1)]); 35 testRule("*:has(.foo), *|*:has(.foo) {}", [unconstrainedHas(0), unconstrainedHas(1)]); 36 testRule(":is(.bar *):has(.foo), :is(.bar):has(.foo), :is(:where(.bar ~ *)):has(.foo) {}", [unconstrainedHas(0), unconstrainedHas(2)]); 37 testRule(":is(.bar *):has(.foo), :is(.bar):has(.foo), :is(:where(.bar ~ *)):has(.foo) {}", [unconstrainedHas(0), unconstrainedHas(2)]); 38 testRule(":is(.bar, *):has(.foo) {}", [unconstrainedHas(0)]); 39 testRule(":is(:has(bar) *):has(.foo) {}", [unconstrainedHas(0)]); 40 // Unconstrained `:has`: Selector inside it is unconstrained 41 testRule(".bar:has(*) {}", [unconstrainedHas(0)]); 42 testRule(".bar:has(* .foo), .bar:has(:is(*) .foo) {}", [unconstrainedHas(0), unconstrainedHas(1)]); 43 testRule(".bar:has(:is(* .bar) .foo), .bar:has(:is(:where(* .baz) .bar) .foo) {}", [unconstrainedHas(0), unconstrainedHas(1)]); 44 testRule(".bar:has(:is(*, .bar) .foo) {}", [unconstrainedHas(0)]); 45 testRule(":is(:has(*) .bar):has(.foo) {}", [unconstrainedHas(0)]); 46 testRule(":is(:has(*)):has(.foo) {}", [unconstrainedHas(0)]); 47 // `:scope` selector with sibling 48 testRule(":scope ~ .foo {}", [siblingCombinatorAfterScope(0)]); 49 testRule(":scope ~ .foo, :scope + .foo {}", [siblingCombinatorAfterScope(0), siblingCombinatorAfterScope(1)]); 50 testRule(":scope .foo, :scope ~ .foo {}", [siblingCombinatorAfterScope(1)]); 51 testRule(":is(.foo :scope) ~ .bar, :is(.foo :scope) + .bar {}", [siblingCombinatorAfterScope(0), siblingCombinatorAfterScope(1)]); 52 testRule(":is(:scope .foo) ~ .bar, :is(:scope > .foo) ~ .bar {}", []); 53 testRule(":is(.foo :is(.bar :is(.baz :scope))) ~ .baa {}", [siblingCombinatorAfterScope(0)]); 54 testRule(".foo:has(:scope ~ .bar) {}", []); 55 testRule(".foo:has(:scope) ~ .bar {}", []); 56 </script>