@@ -69,6 +69,72 @@ let whitelist = [
6969 intermittent : true ,
7070 errorMessage : / P r o p e r t y c o n t a i n e d r e f e r e n c e t o i n v a l i d v a r i a b l e .* c o l o r / i,
7171 isFromDevTools : true } ,
72+
73+ // These are CSS custom properties that we found a definition of but
74+ // no reference to.
75+ // Bug 1441837
76+ { propName : "--in-content-category-text-active" ,
77+ isFromDevTools : false } ,
78+ // Bug 1441844
79+ { propName : "--chrome-nav-bar-separator-color" ,
80+ isFromDevTools : false } ,
81+ // Bug 1441855
82+ { propName : "--chrome-nav-buttons-background" ,
83+ isFromDevTools : false } ,
84+ // Bug 1441855
85+ { propName : "--chrome-nav-buttons-hover-background" ,
86+ isFromDevTools : false } ,
87+ // Bug 1441857
88+ { propName : "--muteButton-width" ,
89+ isFromDevTools : false } ,
90+ // Bug 1441857
91+ { propName : "--closedCaptionButton-width" ,
92+ isFromDevTools : false } ,
93+ // Bug 1441857
94+ { propName : "--fullscreenButton-width" ,
95+ isFromDevTools : false } ,
96+ // Bug 1441857
97+ { propName : "--durationSpan-width" ,
98+ isFromDevTools : false } ,
99+ // Bug 1441857
100+ { propName : "--durationSpan-width-long" ,
101+ isFromDevTools : false } ,
102+ // Bug 1441857
103+ { propName : "--positionDurationBox-width" ,
104+ isFromDevTools : false } ,
105+ // Bug 1441857
106+ { propName : "--positionDurationBox-width-long" ,
107+ isFromDevTools : false } ,
108+ // Bug 1441860
109+ { propName : "--rule-flex-toggle-color" ,
110+ isFromDevTools : true } ,
111+ // Bug 1441929
112+ { propName : "--theme-search-overlays-semitransparent" ,
113+ isFromDevTools : true } ,
114+ // Bug 1441878
115+ { propName : "--theme-codemirror-gutter-background" ,
116+ isFromDevTools : true } ,
117+ // Bug 1441879
118+ { propName : "--arrow-width" ,
119+ isFromDevTools : true } ,
120+ // Bug 1442300
121+ { propName : "--in-content-category-background" ,
122+ isFromDevTools : false } ,
123+ // Bug 1442314
124+ { propName : "--separator-border-image" ,
125+ isFromDevTools : true } ,
126+
127+ // Used on Linux
128+ { propName : "--in-content-box-background-odd" ,
129+ platforms : [ "win" , "macosx" ] ,
130+ isFromDevTools : false } ,
131+
132+ // These properties *are* actually referenced. Need to find why
133+ // their reference isn't getting counted.
134+ { propName : "--bezier-diagonal-color" ,
135+ isFromDevTools : true } ,
136+ { propName : "--bezier-grid-color" ,
137+ isFromDevTools : true } ,
72138] ;
73139
74140if ( ! Services . prefs . getBoolPref ( "full-screen-api.unprefix.enabled" ) ) {
@@ -194,6 +260,7 @@ function messageIsCSSError(msg) {
194260}
195261
196262let imageURIsToReferencesMap = new Map ( ) ;
263+ let customPropsToReferencesMap = new Map ( ) ;
197264
198265function processCSSRules ( sheet ) {
199266 for ( let rule of sheet . cssRules ) {
@@ -208,10 +275,11 @@ function processCSSRules(sheet) {
208275 // Note: CSSStyleRule.cssText always has double quotes around URLs even
209276 // when the original CSS file didn't.
210277 let urls = rule . cssText . match ( / u r l \( " [ ^ " ] * " \) / g) ;
211- if ( ! urls )
278+ let props = rule . cssText . match ( / ( v a r \( ) ? ( - - [ \w \- ] + ) / g) ;
279+ if ( ! urls && ! props )
212280 continue ;
213281
214- for ( let url of urls ) {
282+ for ( let url of ( urls || [ ] ) ) {
215283 // Remove the url(" prefix and the ") suffix.
216284 url = url . replace ( / u r l \( " ( .* ) " \) / , "$1" ) ;
217285 if ( url . startsWith ( "data:" ) )
@@ -229,6 +297,16 @@ function processCSSRules(sheet) {
229297 imageURIsToReferencesMap . get ( url ) . add ( baseUrl ) ;
230298 }
231299 }
300+
301+ for ( let prop of ( props || [ ] ) ) {
302+ if ( prop . startsWith ( "var(" ) ) {
303+ prop = prop . substring ( 4 ) ;
304+ let prevValue = customPropsToReferencesMap . get ( prop ) || 0 ;
305+ customPropsToReferencesMap . set ( prop , prevValue + 1 ) ;
306+ } else if ( ! customPropsToReferencesMap . has ( prop ) ) {
307+ customPropsToReferencesMap . set ( prop , undefined ) ;
308+ }
309+ }
232310 }
233311}
234312
@@ -354,6 +432,26 @@ add_task(async function checkAllTheCSS() {
354432 }
355433 }
356434
435+ // Check if all the properties that are defined are referenced.
436+ for ( let [ prop , refCount ] of customPropsToReferencesMap ) {
437+ if ( ! refCount ) {
438+ let ignored = false ;
439+ for ( let item of whitelist ) {
440+ if ( item . propName == prop &&
441+ isDevtools == item . isFromDevTools ) {
442+ item . used = true ;
443+ if ( ! item . platforms || item . platforms . includes ( AppConstants . platform ) ) {
444+ ignored = true ;
445+ }
446+ break ;
447+ }
448+ }
449+ if ( ! ignored ) {
450+ ok ( false , "custom property `" + prop + "` is not referenced" ) ;
451+ }
452+ }
453+ }
454+
357455 let messages = Services . console . getMessageArray ( ) ;
358456 // Count errors (the test output will list actual issues for us, as well
359457 // as the ok(false) in messageIsCSSError.
@@ -362,8 +460,12 @@ add_task(async function checkAllTheCSS() {
362460
363461 // Confirm that all whitelist rules have been used.
364462 for ( let item of whitelist ) {
365- if ( ! item . used && isDevtools == item . isFromDevTools && ! item . intermittent ) {
463+ if ( ! item . used &&
464+ ( ! item . platforms || item . platforms . includes ( AppConstants . platform ) ) &&
465+ isDevtools == item . isFromDevTools &&
466+ ! item . intermittent ) {
366467 ok ( false , "Unused whitelist item. " +
468+ ( item . propName ? " propName: " + item . propName : "" ) +
367469 ( item . sourceName ? " sourceName: " + item . sourceName : "" ) +
368470 ( item . errorMessage ? " errorMessage: " + item . errorMessage : "" ) ) ;
369471 }
@@ -388,4 +490,5 @@ add_task(async function checkAllTheCSS() {
388490 hiddenFrame . destroy ( ) ;
389491 hiddenFrame = null ;
390492 imageURIsToReferencesMap = null ;
493+ customPropsToReferencesMap = null ;
391494} ) ;
0 commit comments