Skip to content

Commit a32023b

Browse files
Switch based on API presence
1 parent 6860c54 commit a32023b

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

injected/integration-test/web-compat.spec.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import { test as base, expect } from '@playwright/test';
33

44
const test = testContextForExtension(base);
55

6+
// Shared test runner for running the same test suite with different API states
7+
function createApiTestRunner(testName, testFunction) {
8+
test.describe(testName, () => {
9+
test.describe('with API deleted', () => {
10+
testFunction({ removeApi: true });
11+
});
12+
13+
test.describe('with API shimmed', () => {
14+
testFunction({ removeApi: false });
15+
});
16+
});
17+
}
18+
619
test.describe('Ensure safari interface is injected', () => {
720
test('should expose window.safari when enabled', async ({ page }) => {
821
await gotoAndWait(page, '/blank.html', { site: { enabledFeatures: [] } });
@@ -306,7 +319,7 @@ const permissionsTestCases = {
306319
},
307320
};
308321

309-
test.describe('Permissions API', () => {
322+
createApiTestRunner('Permissions API', async ({ removeApi }) => {
310323
function checkObjectDescriptorIsNotPresent() {
311324
const descriptor = Object.getOwnPropertyDescriptor(window.navigator, 'permissions');
312325
return descriptor === undefined;
@@ -336,40 +349,40 @@ test.describe('Permissions API', () => {
336349

337350
test.describe('enabled feature', () => {
338351
test('should expose window.navigator.permissions when enabled', async ({ page }) => {
339-
await setupPermissionsTest(page, { removePermissions: true });
352+
await setupPermissionsTest(page, { removePermissions: removeApi });
340353
await permissionsTestCases.testPermissionsExposed(page);
341354
const modifiedDescriptorSerialization = await page.evaluate(checkObjectDescriptorIsNotPresent);
342355
// This fails in a test condition purely because we have to add a descriptor to modify the prop
343356
expect(modifiedDescriptorSerialization).toEqual(false);
344357
});
345358

346359
test('should throw error when permission not supported', async ({ page }) => {
347-
await setupPermissionsTest(page, { removePermissions: true });
360+
await setupPermissionsTest(page, { removePermissions: removeApi });
348361
await permissionsTestCases.testUnsupportedPermission(page);
349362
});
350363

351364
test('should return prompt by default', async ({ page }) => {
352-
await setupPermissionsTest(page, { removePermissions: true });
365+
await setupPermissionsTest(page, { removePermissions: removeApi });
353366
await permissionsTestCases.testDefaultPrompt(page);
354367
});
355368

356369
test('should return updated name when configured', async ({ page }) => {
357-
await setupPermissionsTest(page, { removePermissions: true });
370+
await setupPermissionsTest(page, { removePermissions: removeApi });
358371
await permissionsTestCases.testNameOverride(page);
359372
});
360373

361374
test('should propagate result from native when configured', async ({ page }) => {
362-
await setupPermissionsTest(page, { removePermissions: true });
375+
await setupPermissionsTest(page, { removePermissions: removeApi });
363376
await permissionsTestCases.testNativePermissionSuccess(page);
364377
});
365378

366379
test('should default to prompt when native sends unexpected response', async ({ page }) => {
367-
await setupPermissionsTest(page, { removePermissions: true });
380+
await setupPermissionsTest(page, { removePermissions: removeApi });
368381
await permissionsTestCases.testNativePermissionUnexpectedResponse(page);
369382
});
370383

371384
test('should default to prompt when native error occurs', async ({ page }) => {
372-
await setupPermissionsTest(page, { removePermissions: true });
385+
await setupPermissionsTest(page, { removePermissions: removeApi });
373386
await permissionsTestCases.testNativePermissionError(page);
374387
});
375388
});

0 commit comments

Comments
 (0)