diff --git a/injected/integration-test/device-enumeration.spec.js b/injected/integration-test/device-enumeration.spec.js new file mode 100644 index 0000000000..6428a61cc5 --- /dev/null +++ b/injected/integration-test/device-enumeration.spec.js @@ -0,0 +1,47 @@ +import { gotoAndWait, testContextForExtension } from './helpers/harness.js'; +import { test as base, expect } from '@playwright/test'; + +const test = testContextForExtension(base); + +test.describe('Device Enumeration Feature', () => { + test.describe('disabled feature', () => { + test('should not intercept enumerateDevices when disabled', async ({ page }) => { + await gotoAndWait(page, '/webcompat/pages/device-enumeration.html', { + site: { enabledFeatures: [] }, + }); + + // Should use native implementation + const results = await page.evaluate(() => { + // @ts-expect-error - results is set by renderResults() + return window.results; + }); + + // The test should pass with native behavior + expect(results).toBeDefined(); + }); + }); + + test.describe('enabled feature', () => { + test('should intercept enumerateDevices when enabled', async ({ page }) => { + await gotoAndWait(page, '/webcompat/pages/device-enumeration.html', { + site: { + enabledFeatures: ['webCompat'], + }, + featureSettings: { + webCompat: { + enumerateDevices: 'enabled', + }, + }, + }); + + // Should use our implementation + const results = await page.evaluate(() => { + // @ts-expect-error - results is set by renderResults() + return window.results; + }); + + // The test should pass with our implementation + expect(results).toBeDefined(); + }); + }); +}); diff --git a/injected/integration-test/pages.spec.js b/injected/integration-test/pages.spec.js index dee265bbf8..7bf7a5fc62 100644 --- a/injected/integration-test/pages.spec.js +++ b/injected/integration-test/pages.spec.js @@ -127,6 +127,15 @@ test.describe('Test integration pages', () => { ); }); + test('enumerateDevices API functionality', async ({ page }, testInfo) => { + await testPage( + page, + testInfo, + 'webcompat/pages/enumerate-devices-api-test.html', + './integration-test/test-pages/webcompat/config/enumerate-devices-api.json', + ); + }); + test('minSupportedVersion (string)', async ({ page }, testInfo) => { await testPage( page, diff --git a/injected/integration-test/test-pages/webcompat/config/enumerate-devices-api.json b/injected/integration-test/test-pages/webcompat/config/enumerate-devices-api.json new file mode 100644 index 0000000000..948e2ebae2 --- /dev/null +++ b/injected/integration-test/test-pages/webcompat/config/enumerate-devices-api.json @@ -0,0 +1,14 @@ +{ + "readme": "This config is used to test the enumerateDevices API proxy functionality.", + "version": 1, + "unprotectedTemporary": [], + "features": { + "webCompat": { + "state": "enabled", + "exceptions": [], + "settings": { + "enumerateDevices": "enabled" + } + } + } +} \ No newline at end of file diff --git a/injected/integration-test/test-pages/webcompat/index.html b/injected/integration-test/test-pages/webcompat/index.html index c7210bcb7e..4bea178bd5 100644 --- a/injected/integration-test/test-pages/webcompat/index.html +++ b/injected/integration-test/test-pages/webcompat/index.html @@ -12,6 +12,8 @@