chore: move test under correct file (#11745)

This commit is contained in:
Nikolay Vitkov 2024-01-24 16:24:17 +01:00 committed by GitHub
parent 398b31de26
commit 230d041a4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 176 additions and 175 deletions

View File

@ -23,6 +23,12 @@
"parameters": ["webDriverBiDi"],
"expectations": ["SKIP"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext BrowserContext.overridePermissions *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[chromiumonly.spec] Chromium-Specific Launcher tests *",
"platforms": ["darwin", "linux", "win32"],
@ -215,12 +221,6 @@
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[page.spec] Page BrowserContext.overridePermissions *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup *",
"platforms": ["darwin", "linux", "win32"],
@ -341,6 +341,12 @@
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext BrowserContext.overridePermissions should be prompt by default",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext should close all belonging targets once closing context",
"platforms": ["darwin", "linux", "win32"],
@ -852,12 +858,6 @@
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[page.spec] Page BrowserContext.overridePermissions should be prompt by default",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[page.spec] Page Page.addScriptTag should throw when added with content to the CSP page",
"platforms": ["darwin", "linux", "win32"],
@ -1297,6 +1297,42 @@
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext BrowserContext.overridePermissions should deny permission when not listed",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext BrowserContext.overridePermissions should grant permission when listed",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext BrowserContext.overridePermissions should grant persistent-storage",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext BrowserContext.overridePermissions should isolate permissions between browser contexts",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext BrowserContext.overridePermissions should reset permissions",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext BrowserContext.overridePermissions should trigger permission onchange",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext should close all belonging targets once closing context",
"platforms": ["darwin", "linux", "win32"],
@ -2786,42 +2822,6 @@
"parameters": ["cdp", "chrome"],
"expectations": ["PASS", "TIMEOUT"]
},
{
"testIdPattern": "[page.spec] Page BrowserContext.overridePermissions should deny permission when not listed",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[page.spec] Page BrowserContext.overridePermissions should grant permission when listed",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[page.spec] Page BrowserContext.overridePermissions should grant persistent-storage",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[page.spec] Page BrowserContext.overridePermissions should isolate permissions between browser contexts",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[page.spec] Page BrowserContext.overridePermissions should reset permissions",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[page.spec] Page BrowserContext.overridePermissions should trigger permission onchange",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[page.spec] Page Page.addScriptTag should throw when added with content to the CSP page",
"platforms": ["darwin", "linux", "win32"],

View File

@ -6,6 +6,7 @@
import expect from 'expect';
import {TimeoutError} from 'puppeteer';
import type {Page} from 'puppeteer-core/internal/api/Page.js';
import {getTestState, setupTestBrowserHooks} from './mocha-utils.js';
import {waitEvent} from './utils.js';
@ -237,4 +238,131 @@ describe('BrowserContext', function () {
expect(browser.browserContexts()[1]!.id).toBeDefined();
await context.close();
});
describe('BrowserContext.overridePermissions', function () {
function getPermission(page: Page, name: PermissionName) {
return page.evaluate(name => {
return navigator.permissions.query({name}).then(result => {
return result.state;
});
}, name);
}
it('should be prompt by default', async () => {
const {page, server} = await getTestState();
await page.goto(server.EMPTY_PAGE);
expect(await getPermission(page, 'geolocation')).toBe('prompt');
});
it('should deny permission when not listed', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
await context.overridePermissions(server.EMPTY_PAGE, []);
expect(await getPermission(page, 'geolocation')).toBe('denied');
});
it('should fail when bad permission is given', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
let error!: Error;
await context
// @ts-expect-error purposeful bad input for test
.overridePermissions(server.EMPTY_PAGE, ['foo'])
.catch(error_ => {
return (error = error_);
});
expect(error.message).toBe('Unknown permission: foo');
});
it('should grant permission when listed', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
await context.overridePermissions(server.EMPTY_PAGE, ['geolocation']);
expect(await getPermission(page, 'geolocation')).toBe('granted');
});
it('should reset permissions', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
await context.overridePermissions(server.EMPTY_PAGE, ['geolocation']);
expect(await getPermission(page, 'geolocation')).toBe('granted');
await context.clearPermissionOverrides();
expect(await getPermission(page, 'geolocation')).toBe('prompt');
});
it('should trigger permission onchange', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => {
(globalThis as any).events = [];
return navigator.permissions
.query({name: 'geolocation'})
.then(function (result) {
(globalThis as any).events.push(result.state);
result.onchange = function () {
(globalThis as any).events.push(result.state);
};
});
});
expect(
await page.evaluate(() => {
return (globalThis as any).events;
})
).toEqual(['prompt']);
await context.overridePermissions(server.EMPTY_PAGE, []);
expect(
await page.evaluate(() => {
return (globalThis as any).events;
})
).toEqual(['prompt', 'denied']);
await context.overridePermissions(server.EMPTY_PAGE, ['geolocation']);
expect(
await page.evaluate(() => {
return (globalThis as any).events;
})
).toEqual(['prompt', 'denied', 'granted']);
await context.clearPermissionOverrides();
expect(
await page.evaluate(() => {
return (globalThis as any).events;
})
).toEqual(['prompt', 'denied', 'granted', 'prompt']);
});
it('should isolate permissions between browser contexts', async () => {
const {page, server, context, browser} = await getTestState();
await page.goto(server.EMPTY_PAGE);
const otherContext = await browser.createIncognitoBrowserContext();
const otherPage = await otherContext.newPage();
await otherPage.goto(server.EMPTY_PAGE);
expect(await getPermission(page, 'geolocation')).toBe('prompt');
expect(await getPermission(otherPage, 'geolocation')).toBe('prompt');
await context.overridePermissions(server.EMPTY_PAGE, []);
await otherContext.overridePermissions(server.EMPTY_PAGE, [
'geolocation',
]);
expect(await getPermission(page, 'geolocation')).toBe('denied');
expect(await getPermission(otherPage, 'geolocation')).toBe('granted');
await context.clearPermissionOverrides();
expect(await getPermission(page, 'geolocation')).toBe('prompt');
expect(await getPermission(otherPage, 'geolocation')).toBe('granted');
await otherContext.close();
});
it('should grant persistent-storage', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
expect(await getPermission(page, 'persistent-storage')).not.toBe(
'granted'
);
await context.overridePermissions(server.EMPTY_PAGE, [
'persistent-storage',
]);
expect(await getPermission(page, 'persistent-storage')).toBe('granted');
});
});
});

View File

@ -318,133 +318,6 @@ describe('Page', function () {
});
});
describe('BrowserContext.overridePermissions', function () {
function getPermission(page: Page, name: PermissionName) {
return page.evaluate(name => {
return navigator.permissions.query({name}).then(result => {
return result.state;
});
}, name);
}
it('should be prompt by default', async () => {
const {page, server} = await getTestState();
await page.goto(server.EMPTY_PAGE);
expect(await getPermission(page, 'geolocation')).toBe('prompt');
});
it('should deny permission when not listed', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
await context.overridePermissions(server.EMPTY_PAGE, []);
expect(await getPermission(page, 'geolocation')).toBe('denied');
});
it('should fail when bad permission is given', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
let error!: Error;
await context
// @ts-expect-error purposeful bad input for test
.overridePermissions(server.EMPTY_PAGE, ['foo'])
.catch(error_ => {
return (error = error_);
});
expect(error.message).toBe('Unknown permission: foo');
});
it('should grant permission when listed', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
await context.overridePermissions(server.EMPTY_PAGE, ['geolocation']);
expect(await getPermission(page, 'geolocation')).toBe('granted');
});
it('should reset permissions', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
await context.overridePermissions(server.EMPTY_PAGE, ['geolocation']);
expect(await getPermission(page, 'geolocation')).toBe('granted');
await context.clearPermissionOverrides();
expect(await getPermission(page, 'geolocation')).toBe('prompt');
});
it('should trigger permission onchange', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => {
(globalThis as any).events = [];
return navigator.permissions
.query({name: 'geolocation'})
.then(function (result) {
(globalThis as any).events.push(result.state);
result.onchange = function () {
(globalThis as any).events.push(result.state);
};
});
});
expect(
await page.evaluate(() => {
return (globalThis as any).events;
})
).toEqual(['prompt']);
await context.overridePermissions(server.EMPTY_PAGE, []);
expect(
await page.evaluate(() => {
return (globalThis as any).events;
})
).toEqual(['prompt', 'denied']);
await context.overridePermissions(server.EMPTY_PAGE, ['geolocation']);
expect(
await page.evaluate(() => {
return (globalThis as any).events;
})
).toEqual(['prompt', 'denied', 'granted']);
await context.clearPermissionOverrides();
expect(
await page.evaluate(() => {
return (globalThis as any).events;
})
).toEqual(['prompt', 'denied', 'granted', 'prompt']);
});
it('should isolate permissions between browser contexts', async () => {
const {page, server, context, browser} = await getTestState();
await page.goto(server.EMPTY_PAGE);
const otherContext = await browser.createIncognitoBrowserContext();
const otherPage = await otherContext.newPage();
await otherPage.goto(server.EMPTY_PAGE);
expect(await getPermission(page, 'geolocation')).toBe('prompt');
expect(await getPermission(otherPage, 'geolocation')).toBe('prompt');
await context.overridePermissions(server.EMPTY_PAGE, []);
await otherContext.overridePermissions(server.EMPTY_PAGE, [
'geolocation',
]);
expect(await getPermission(page, 'geolocation')).toBe('denied');
expect(await getPermission(otherPage, 'geolocation')).toBe('granted');
await context.clearPermissionOverrides();
expect(await getPermission(page, 'geolocation')).toBe('prompt');
expect(await getPermission(otherPage, 'geolocation')).toBe('granted');
await otherContext.close();
});
it('should grant persistent-storage', async () => {
const {page, server, context} = await getTestState();
await page.goto(server.EMPTY_PAGE);
expect(await getPermission(page, 'persistent-storage')).not.toBe(
'granted'
);
await context.overridePermissions(server.EMPTY_PAGE, [
'persistent-storage',
]);
expect(await getPermission(page, 'persistent-storage')).toBe('granted');
});
});
describe('Page.setGeolocation', function () {
it('should work', async () => {
const {page, server, context} = await getTestState();