@@ -5,7 +5,7 @@ async function expectStyles(styles: StyleExpectations) {
55 await expectPageStyles ( expect , styles ) ;
66}
77
8- async function loadBasicPage ( header = 'E2E test page' ) {
8+ async function loadBasicPage ( header : string ) {
99 await loadTestPage ( {
1010 '/' : multiline (
1111 '<!DOCTYPE html>' ,
@@ -29,6 +29,9 @@ describe('Toggling the extension', () => {
2929 // TODO: remove flakes and remove this line
3030 jest . retryTimes ( 10 , { logErrorsBeforeRetry : true } ) ;
3131
32+ const automationMenuSelector = '.header__more-settings-button' ;
33+ const automationSystemSelector = '.header__more-settings__system-dark-mode__checkbox .checkbox__input' ;
34+
3235 it ( 'should turn On/Off' , async ( ) => {
3336 await loadBasicPage ( 'Toggle on/off' ) ;
3437
@@ -69,11 +72,8 @@ describe('Toggling the extension', () => {
6972 it ( 'should follow system color scheme' , async ( ) => {
7073 await loadBasicPage ( 'Automation (color scheme)' ) ;
7174
72- const automationMenuSelector = '.header__more-settings-button' ;
73- const automationSystemSelector = '.header__more-settings__system-dark-mode__checkbox .checkbox__input' ;
7475
7576 await emulateColorScheme ( 'light' ) ;
76- await expect ( getColorScheme ( ) ) . resolves . toBe ( 'light' ) ;
7777
7878 await expectStyles ( [
7979 [ 'document' , 'background-color' , 'rgb(24, 26, 27)' ] ,
@@ -97,7 +97,6 @@ describe('Toggling the extension', () => {
9797 ] ) ;
9898
9999 await emulateColorScheme ( 'dark' ) ;
100- await expect ( getColorScheme ( ) ) . resolves . toBe ( 'dark' ) ;
101100
102101 await expectStyles ( [
103102 [ 'document' , 'background-color' , 'rgb(24, 26, 27)' ] ,
@@ -109,7 +108,6 @@ describe('Toggling the extension', () => {
109108 ] ) ;
110109
111110 await emulateColorScheme ( 'light' ) ;
112- await expect ( getColorScheme ( ) ) . resolves . toBe ( 'light' ) ;
113111
114112 await expectStyles ( [
115113 [ 'document' , 'background-color' , 'rgba(0, 0, 0, 0)' ] ,
@@ -134,6 +132,110 @@ describe('Toggling the extension', () => {
134132 await emulateColorScheme ( 'dark' ) ;
135133 } ) ;
136134
135+ // Note: this test is relevant only to Firefox and Thunderbird
136+ it ( 'should ignore color watcher messages from subframes' , async ( ) => {
137+ const darkPageExpectations : StyleExpectations = [
138+ [ 'document' , 'background-color' , 'rgb(24, 26, 27)' ] ,
139+ [ 'document' , 'color' , 'rgb(232, 230, 227)' ] ,
140+ [ 'body' , 'background-color' , 'rgb(24, 26, 27)' ] ,
141+ [ 'body' , 'color' , 'rgb(232, 230, 227)' ] ,
142+ [ 'h1' , 'color' , 'rgb(255, 26, 26)' ] ,
143+ [ 'a' , 'color' , 'rgb(51, 145, 255)' ] ,
144+ ] ;
145+
146+ const lightPageExpectations : StyleExpectations = [
147+ [ 'document' , 'background-color' , 'rgba(0, 0, 0, 0)' ] ,
148+ [ 'document' , 'color' , 'rgb(0, 0, 0)' ] ,
149+ [ 'body' , 'background-color' , 'rgba(0, 0, 0, 0)' ] ,
150+ [ 'body' , 'color' , 'rgb(0, 0, 0)' ] ,
151+ [ 'h1' , 'color' , 'rgb(255, 0, 0)' ] ,
152+ [ 'a' , 'color' , 'rgb(0, 0, 238)' ] ,
153+ ] ;
154+
155+ const darkSubframePageExpectations : StyleExpectations = [
156+ [ [ 'iframe' , 'h1' ] , 'color' , 'rgb(255, 26, 26)' ] ,
157+ [ [ 'iframe' , 'a' ] , 'color' , 'rgb(51, 145, 255)' ] ,
158+ ] ;
159+
160+ const lightSubframePageExpectations : StyleExpectations = [
161+ [ [ 'iframe' , 'h1' ] , 'color' , 'rgb(255, 0, 0)' ] ,
162+ [ [ 'iframe' , 'a' ] , 'color' , 'rgb(0, 0, 238)' ] ,
163+ ] ;
164+
165+ let loadSubframe : ( ) => void = null ;
166+ await loadTestPage ( {
167+ '/' : multiline (
168+ '<!DOCTYPE html>' ,
169+ '<html>' ,
170+ '<head>' ,
171+ ' <style>' ,
172+ ' h1 { color: red; }' ,
173+ ' </style>' ,
174+ '</head>' ,
175+ '<body>' ,
176+ ` <h1>Color scheme detector</h1>` ,
177+ ' <p>Text</p>' ,
178+ ' <a href="#">Link</a>' ,
179+ ' <iframe src="/subframe.html" style="color-scheme: light"></iframe>' ,
180+ '</body>' ,
181+ '</html>' ,
182+ ) ,
183+ '/subframe.html' : async ( _ , res ) => {
184+ res . statusCode = 200 ;
185+ res . setHeader ( 'Content-Type' , 'text/html' ) ;
186+
187+ await new Promise < void > ( ( resolve ) => loadSubframe = resolve ) ;
188+
189+ res . end (
190+ multiline (
191+ '<!DOCTYPE html>' ,
192+ '<html>' ,
193+ '<head>' ,
194+ ' <style>' ,
195+ ' h1 { color: red; }' ,
196+ ' </style>' ,
197+ '</head>' ,
198+ '<body>' ,
199+ ' <h1>Header</h1>' ,
200+ ' <p>Text</p>' ,
201+ ' <a href="#">Link</a>' ,
202+ '</body>' ,
203+ '</html>' ,
204+ ) ,
205+ 'utf8'
206+ ) ;
207+ } ,
208+ } , {
209+ waitUntil : 'domcontentloaded' ,
210+ } ) ;
211+
212+ await emulateColorScheme ( 'dark' ) ;
213+ await expectStyles ( darkPageExpectations ) ;
214+
215+ await popupUtils . click ( automationMenuSelector ) ;
216+ await popupUtils . click ( automationSystemSelector ) ;
217+
218+ await expectStyles ( darkPageExpectations ) ;
219+
220+ loadSubframe ( ) ;
221+
222+ // Ensure that the subframe received its styles
223+ await expectStyles ( darkSubframePageExpectations ) ;
224+ // Ensure that the parent frame retained its styles
225+ await expectStyles ( darkPageExpectations ) ;
226+
227+ await emulateColorScheme ( 'light' ) ;
228+
229+ await expectStyles ( lightPageExpectations ) ;
230+ await expectStyles ( lightSubframePageExpectations ) ;
231+
232+ await popupUtils . click ( automationSystemSelector ) ;
233+
234+ await expectStyles ( darkPageExpectations ) ;
235+
236+ await emulateColorScheme ( 'dark' ) ;
237+ } ) ;
238+
137239 it ( 'should have new design button on desktop' , async ( ) => {
138240 expect ( await devtoolsUtils . exists ( '.preview-design-button' ) ) ;
139241 } ) ;
0 commit comments