4 https://bugzilla.mozilla.org/show_bug.cgi?id=1037519
7 <title>Test for nsIDOMUtils::selectorMatchesElement
</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
10 <style type=
"text/css">
19 outline: 1px solid gold
;
25 content: 'foo-before';
35 text-decoration: underline
;
39 font-variant: small-caps
;
44 <div id=
"foo">foo content
</div>
46 <script type=
"application/javascript">
48 const InspectorUtils = SpecialPowers.InspectorUtils;
51 var element = document.querySelector(
"#foo");
53 var elementRules = InspectorUtils.getMatchingCSSRules(element);
55 var multiSelectorRule = elementRules[
2];
56 is(multiSelectorRule.selectorText, `#foo, #bar, #foo::before`,
"Got expected multi-selector rule");
57 is (multiSelectorRule.selectorMatchesElement(
0, element), true,
59 is (multiSelectorRule.selectorMatchesElement(
1, element), false,
60 "Doesn't match #bar");
61 is (multiSelectorRule.selectorMatchesElement(
0, element,
":bogus"), false,
62 "Doesn't match #foo with a bogus pseudo");
63 is (multiSelectorRule.selectorMatchesElement(
2, element,
":bogus"), false,
64 "Doesn't match #foo::before with bogus pseudo");
65 is (multiSelectorRule.selectorMatchesElement(
0, element,
":after"), false,
66 "Does match #foo::before with the :after pseudo");
68 var nestedRule = elementRules[
4];
69 is(nestedRule.selectorText, `div&`,
"Got expected nested rule");
70 is (nestedRule.selectorMatchesElement(
0, element), true,
"Matches div&");
72 checkPseudo(
":before");
73 checkPseudo(
":after");
74 checkPseudo(
":first-letter");
75 checkPseudo(
":first-line");
79 function checkPseudo(pseudo) {
80 var rules = InspectorUtils.getMatchingCSSRules(element, pseudo);
81 var rule = rules[rules.length -
1];
83 is (rule.selectorMatchesElement(
0, element), false,
84 "Doesn't match without " + pseudo);
85 is (rule.selectorMatchesElement(
1, element), false,
86 "Doesn't match without " + pseudo);
88 is (rule.selectorMatchesElement(
0, element, pseudo), true,
89 "Matches on #foo" + pseudo);
90 is (rule.selectorMatchesElement(
1, element, pseudo), false,
91 "Doesn't match on #bar" + pseudo);
95 SimpleTest.waitForExplicitFinish();
96 addLoadEvent(do_test);