test: add missing tests (#965)
Chromium tests on Linux now call all our API methods and events at least once!
This commit is contained in:
parent
1d84f38e5e
commit
bfaf191c98
|
|
@ -216,7 +216,7 @@ export class Page extends platform.EventEmitter {
|
|||
}
|
||||
|
||||
async $wait(selector: string, options?: types.TimeoutOptions & { visibility?: types.Visibility }): Promise<dom.ElementHandle<Element> | null> {
|
||||
return this.waitForSelector(selector, options);
|
||||
return this.mainFrame().$wait(selector, options);
|
||||
}
|
||||
|
||||
evaluateHandle: types.EvaluateHandle = async (pageFunction, ...args) => {
|
||||
|
|
|
|||
|
|
@ -27,39 +27,39 @@ module.exports.describe = function({testRunner, expect, WEBKIT}) {
|
|||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||
|
||||
// Permissions API is not implemented in WebKit (see https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API)
|
||||
describe('Permissions', function() {
|
||||
describe.skip(WEBKIT)('Permissions', function() {
|
||||
function getPermission(page, name) {
|
||||
return page.evaluate(name => navigator.permissions.query({name}).then(result => result.state), name);
|
||||
}
|
||||
|
||||
it.skip(WEBKIT)('should be prompt by default', async({page, server, context}) => {
|
||||
it('should be prompt by default', async({page, server, context}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(await getPermission(page, 'geolocation')).toBe('prompt');
|
||||
});
|
||||
it.skip(WEBKIT)('should deny permission when not listed', async({page, server, context}) => {
|
||||
it('should deny permission when not listed', async({page, server, context}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await context.setPermissions(server.EMPTY_PAGE, []);
|
||||
expect(await getPermission(page, 'geolocation')).toBe('denied');
|
||||
});
|
||||
it.skip(WEBKIT)('should fail when bad permission is given', async({page, server, context}) => {
|
||||
it('should fail when bad permission is given', async({page, server, context}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
let error = {};
|
||||
await context.setPermissions(server.EMPTY_PAGE, ['foo']).catch(e => error = e);
|
||||
expect(error.message).toBe('Unknown permission: foo');
|
||||
});
|
||||
it.skip(WEBKIT)('should grant permission when listed', async({page, server, context}) => {
|
||||
it('should grant permission when listed', async({page, server, context}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await context.setPermissions(server.EMPTY_PAGE, ['geolocation']);
|
||||
expect(await getPermission(page, 'geolocation')).toBe('granted');
|
||||
});
|
||||
it.skip(WEBKIT)('should reset permissions', async({page, server, context}) => {
|
||||
it('should reset permissions', async({page, server, context}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await context.setPermissions(server.EMPTY_PAGE, ['geolocation']);
|
||||
expect(await getPermission(page, 'geolocation')).toBe('granted');
|
||||
await context.clearPermissions();
|
||||
expect(await getPermission(page, 'geolocation')).toBe('prompt');
|
||||
});
|
||||
it.skip(WEBKIT)('should trigger permission onchange', async({page, server, context}) => {
|
||||
it('should trigger permission onchange', async({page, server, context}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.evaluate(() => {
|
||||
window['events'] = [];
|
||||
|
|
@ -78,7 +78,7 @@ module.exports.describe = function({testRunner, expect, WEBKIT}) {
|
|||
await context.clearPermissions();
|
||||
expect(await page.evaluate(() => window['events'])).toEqual(['prompt', 'denied', 'granted', 'prompt']);
|
||||
});
|
||||
it.skip(WEBKIT)('should isolate permissions between browser contexs', async({page, server, context, newContext}) => {
|
||||
it('should isolate permissions between browser contexs', async({page, server, context, newContext}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const otherContext = await newContext();
|
||||
const otherPage = await otherContext.newPage();
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
|
|||
await playwright.launch(options).catch(e => waitError = e);
|
||||
expect(waitError.message).toContain('Failed to launch');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Playwright.launchPersistent', function() {
|
||||
it('should have default URL when launching browser', async function() {
|
||||
const userDataDir = await makeUserDataDir();
|
||||
const browserContext = await playwright.launchPersistent(userDataDir, defaultBrowserOptions);
|
||||
|
|
@ -68,12 +71,20 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
|
|||
await browserContext.close();
|
||||
await removeUserDataDir(userDataDir);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Playwright.launchServer', function() {
|
||||
it('should return child_process instance', async () => {
|
||||
const userDataDir = await makeUserDataDir();
|
||||
const browserServer = await playwright.launchServer(userDataDir, defaultBrowserOptions);
|
||||
const browserServer = await playwright.launchServer(defaultBrowserOptions);
|
||||
expect(browserServer.process().pid).toBeGreaterThan(0);
|
||||
await browserServer.close();
|
||||
await removeUserDataDir(userDataDir);
|
||||
});
|
||||
it('should fire close event', async () => {
|
||||
const browserServer = await playwright.launchServer(defaultBrowserOptions);
|
||||
await Promise.all([
|
||||
utils.waitEvent(browserServer, 'close'),
|
||||
browserServer.close(),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -80,18 +80,22 @@ beforeEach(async({server, httpsServer}) => {
|
|||
const products = ['WebKit', 'Firefox', 'Chromium'];
|
||||
let product;
|
||||
let events;
|
||||
let missingCoverage;
|
||||
if (process.env.BROWSER === 'firefox') {
|
||||
product = 'Firefox';
|
||||
events = {
|
||||
...require('../lib/events').Events,
|
||||
...require('../lib/chromium/events').Events,
|
||||
};
|
||||
missingCoverage = ['browserContext.setGeolocation', 'elementHandle.scrollIntoViewIfNeeded', 'page.setOfflineMode'];
|
||||
} else if (process.env.BROWSER === 'webkit') {
|
||||
product = 'WebKit';
|
||||
events = require('../lib/events').Events;
|
||||
missingCoverage = ['browserContext.clearPermissions'];
|
||||
} else {
|
||||
product = 'Chromium';
|
||||
events = require('../lib/events').Events;
|
||||
missingCoverage = [];
|
||||
}
|
||||
|
||||
describe(product, () => {
|
||||
|
|
@ -108,7 +112,7 @@ describe(product, () => {
|
|||
return;
|
||||
filteredApi[name] = api[name];
|
||||
});
|
||||
utils.recordAPICoverage(testRunner, filteredApi, events);
|
||||
utils.recordAPICoverage(testRunner, filteredApi, events, missingCoverage);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -79,18 +79,24 @@ const utils = module.exports = {
|
|||
return promisified;
|
||||
},
|
||||
|
||||
recordAPICoverage: function(testRunner, api, events) {
|
||||
recordAPICoverage: function(testRunner, api, events, ignoredMethodsArray = []) {
|
||||
const coverage = new Map();
|
||||
const ignoredMethods = new Set(ignoredMethodsArray);
|
||||
for (const [className, classType] of Object.entries(api))
|
||||
traceAPICoverage(coverage, events, className, classType);
|
||||
const focus = testRunner.hasFocusedTestsOrSuites();
|
||||
(focus ? testRunner.fdescribe : testRunner.describe)(COVERAGE_TESTSUITE_NAME, () => {
|
||||
(focus ? testRunner.fit : testRunner.it)('should call all API methods', () => {
|
||||
const missingMethods = [];
|
||||
const extraIgnoredMethods = [];
|
||||
for (const method of coverage.keys()) {
|
||||
if (!coverage.get(method))
|
||||
if (!coverage.get(method) && !ignoredMethods.has(method))
|
||||
missingMethods.push(method);
|
||||
else if (coverage.get(method) && ignoredMethods.has(method))
|
||||
extraIgnoredMethods.push(method);
|
||||
}
|
||||
if (extraIgnoredMethods.length)
|
||||
throw new Error('Certain API Methods are called and should not be ignored: ' + extraIgnoredMethods.join(', '));
|
||||
if (missingMethods.length)
|
||||
throw new Error('Certain API Methods are not called: ' + missingMethods.join(', '));
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue