@@ -14,8 +14,28 @@ const TEST_URI = `
1414 p {
1515 color: white;
1616 }
17+
18+ @scope (.scope-root) to (.scope-limit) {
19+ .b {
20+ background-color: hotpink;
21+ }
22+ }
23+
24+ :where(.b) {
25+ background-color: gold;
26+ }
1727 </style>
1828 <p>Testing the selector highlighter</p>
29+ <aside class="for-scope">
30+ <div class="scope-root">
31+ <article class="b in-scope">article in scope</article>
32+ <h2 class="b in-scope">h2 in scope</h2>
33+ <div class="scope-limit">
34+ <code class="b outside-scope">code after scope limit</code>
35+ </div>
36+ </div>
37+ <section class="b outside-scope">section outside scope</section>
38+ </aside>
1939` ;
2040
2141add_task ( async function ( ) {
@@ -45,4 +65,54 @@ add_task(async function () {
4565 "p" ,
4666 "The right selector option is passed to the highlighter"
4767 ) ;
68+ info ( "Hide the highlighter for the `p` selector" ) ;
69+ await clickSelectorIcon ( view , "p" ) ;
70+
71+ info ( "Check that the highlighter works for rules in @scope" ) ;
72+ await selectNode ( "article.in-scope" , inspector ) ;
73+
74+ await clickSelectorIcon ( view , ".b" ) ;
75+
76+ // Here we want to check that the selector highlighter is shown for article.b.in-scope and
77+ // h2.b.in-scope, but not code.b.outside-scope, nor section.b.outside-scope.
78+ // The event we get from the highlighter doesn't really indicate which elements the highlighter
79+ // is shown for, so we need to check the highlighter markup directly
80+ await SpecialPowers . spawn ( gBrowser . selectedBrowser , [ ] , ( ) => {
81+ const doc = content . document ;
82+
83+ // Highlighters are rendered in the shadow DOM, let's get the shadow roots first
84+ const roots = doc . getConnectedShadowRoots ( ) ;
85+ const highlightedInfobarContent = roots
86+ . map (
87+ root =>
88+ root . querySelector (
89+ ".highlighter-container.box-model #box-model-infobar-container"
90+ ) ?. textContent
91+ )
92+ . filter ( text => ! ! text )
93+ // The order of highlighter elements in the DOM tree isn't guaranteed,
94+ // let's sort the selector texts.
95+ . sort ( ) ;
96+
97+ is (
98+ highlightedInfobarContent . length ,
99+ 2 ,
100+ "2 selector highlighters are displayed"
101+ ) ;
102+ if ( highlightedInfobarContent . length != 2 ) {
103+ return ;
104+ }
105+
106+ is (
107+ highlightedInfobarContent [ 0 ] ,
108+ "article.b.in-scope" ,
109+ "The first highlighter is displayed for the first node in scope"
110+ ) ;
111+
112+ is (
113+ highlightedInfobarContent [ 1 ] ,
114+ "h2.b.in-scope" ,
115+ "The second highlighter is displayed for the second node in scope"
116+ ) ;
117+ } ) ;
48118} ) ;
0 commit comments