(global, testServer, corsServer, page)
| 257 | } |
| 258 | |
| 259 | assignTestGlobals(global, testServer, corsServer, page) { |
| 260 | global.getColorScheme = async () => { |
| 261 | if (global.product === 'firefox') { |
| 262 | return await global.backgroundUtils.getColorScheme(); |
| 263 | } |
| 264 | const isDark = await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches); |
| 265 | return isDark ? 'dark' : 'light'; |
| 266 | }; |
| 267 | |
| 268 | global.pageUtils.evaluateScript = async (script) => await page.evaluate(script); |
| 269 | |
| 270 | global.expectPageStyles = async (expect, expectations) => { |
| 271 | if (!Array.isArray(expectations[0])) { |
| 272 | expectations = [expectations]; |
| 273 | } |
| 274 | const errors = await page.evaluate(this.checkPageStylesInBrowserContext, expectations); |
| 275 | expect(errors.join('\n')).toBe(''); |
| 276 | }; |
| 277 | |
| 278 | global.emulateColorScheme = async (colorScheme) => { |
| 279 | if (global.product === 'firefox') { |
| 280 | await global.pageUtils.emulateColorScheme(colorScheme); |
| 281 | await global.backgroundUtils.emulateColorScheme(colorScheme); |
| 282 | const newPageColorScheme = await global.backgroundUtils.getColorScheme(); |
| 283 | const newBGColorScheme = await global.pageUtils.getColorScheme(); |
| 284 | if (newPageColorScheme !== colorScheme || newBGColorScheme !== colorScheme) { |
| 285 | throw new Error('Failed to apply new color scheme'); |
| 286 | } |
| 287 | return; |
| 288 | } |
| 289 | await page.emulateMediaFeatures([{name: 'prefers-color-scheme', value: colorScheme}]); |
| 290 | if (global.product === 'edge') { |
| 291 | const page = await this.getChromiumMV2BackgroundPage(); |
| 292 | await page.emulateMediaFeatures([{name: 'prefers-color-scheme', value: colorScheme}]); |
| 293 | } |
| 294 | }; |
| 295 | |
| 296 | global.loadTestPage = async (paths, gotoOptions) => { |
| 297 | const {cors, ...testPaths} = paths; |
| 298 | testServer.setPaths(testPaths); |
| 299 | cors && corsServer.setPaths(cors); |
| 300 | await this.openTestPage(`http://localhost:${TEST_SERVER_PORT}`, gotoOptions); |
| 301 | }; |
| 302 | |
| 303 | global.corsURL = corsServer.url; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Creates a server and returns once extension connects to it |
no test coverage detected