2 <title>Test for InspectorUtils.getMatchingCSSRules for starting style
</title>
3 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
4 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css">
22 background-color: salmon;
26 background-color: tomato;
29 background-color: gold;
35 <tagnametwo></tagnametwo>
38 * This test checks that InspectorUtils.getMatchingCSSRules setting
39 * withStartingStyle:true returns correct style set in various cases.
40 * To avoid effects from UA sheets, we use an element with "unknowntagname".
43 const InspectorUtils
= SpecialPowers
.InspectorUtils
;
45 add_task(async
function testBasic() {
46 info("Check the basic case of @starting-style")
48 const styleSheet
= document
.styleSheets
[1];
49 const el
= document
.querySelector("tagname");
50 let rules
= InspectorUtils
.getMatchingCSSRules(el
, "", false, true);
51 is(rules
.length
, 3, "Expected rules");
55 styleSheet
.cssRules
[0].cssRules
[0].cssText
,
56 "first returned rule is the one in the top-level starting-style rule"
61 styleSheet
.cssRules
[1].cssText
,
62 "second returned rule is top-level tagname rule"
67 styleSheet
.cssRules
[1].cssRules
[0].cssRules
[0].cssText
,
68 "third returned rule is the starting-style nested in tagname rule"
72 "Check that starting style rules are not returned when withStartingStyle " +
75 rules
= InspectorUtils
.getMatchingCSSRules(el
, "", false);
76 is(rules
.length
, 1, "Expected rules");
80 styleSheet
.cssRules
[1].cssText
,
81 "Only returned rule is top-level tagname rule"
85 add_task(async
function testCombinator() {
86 info("Check that @starting-style with child/descendant combinator " +
87 "selectors are retrieved")
89 const styleSheet
= document
.styleSheets
[1];
90 const el
= document
.querySelector("tagnametwo");
91 const rules
= InspectorUtils
.getMatchingCSSRules(el
, "", false, true);
92 is(rules
.length
, 3, "Got expected rules");
96 styleSheet
.cssRules
[2].cssRules
[0].cssText
,
97 "first returned rule for `tagnametwo` is the one in the top-level " +
103 styleSheet
.cssRules
[3].cssText
,
104 "second returned rule for `tagnametwo` is top-level `body tagnametwo` rule"
109 styleSheet
.cssRules
[3].cssRules
[0].cssRules
[0].cssText
,
110 "third returned rule for `tagnametwo` is the starting-style nested " +
111 "in `body tagnametwo` rule"