chore: restructure and optimise test files (#4736)

This commit is contained in:
Max Schmitt 2020-12-16 16:28:44 +01:00 committed by GitHub
parent 50b0b47993
commit 23a6e4dfe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 17 additions and 64 deletions

View file

@ -64,15 +64,13 @@ it('should dismiss the confirm prompt', async ({page}) => {
it('should be able to close context with open alert', (test, { browserName, platform }) => {
test.fixme(browserName === 'webkit' && platform === 'darwin');
}, async ({browser}) => {
const context = await browser.newContext();
}, async ({context}) => {
const page = await context.newPage();
const alertPromise = page.waitForEvent('dialog');
await page.evaluate(() => {
setTimeout(() => alert('hello'), 0);
});
await alertPromise;
await context.close();
});
it('should handle multiple alerts', async ({page}) => {

View file

@ -16,21 +16,16 @@
import { it, expect } from './fixtures';
it('should work', async ({browser}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should work', async ({page}) => {
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.evaluate(() => window['__popup'] = window.open('about:blank')),
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(true);
await context.close();
});
it('should work with window features', async ({browser, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should work with window features', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
const [popup] = await Promise.all([
page.waitForEvent('popup'),
@ -38,12 +33,9 @@ it('should work with window features', async ({browser, server}) => {
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(true);
await context.close();
});
it('should emit for immediately closed popups', async ({browser}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should emit for immediately closed popups', async ({page}) => {
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.evaluate(() => {
@ -52,12 +44,9 @@ it('should emit for immediately closed popups', async ({browser}) => {
}),
]);
expect(popup).toBeTruthy();
await context.close();
});
it('should emit for immediately closed popups 2', async ({browser, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should emit for immediately closed popups 2', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
const [popup] = await Promise.all([
page.waitForEvent('popup'),
@ -67,12 +56,9 @@ it('should emit for immediately closed popups 2', async ({browser, server}) => {
}),
]);
expect(popup).toBeTruthy();
await context.close();
});
it('should be able to capture alert', async ({browser}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should be able to capture alert', async ({page}) => {
const evaluatePromise = page.evaluate(() => {
const win = window.open('');
win.alert('hello');
@ -82,24 +68,18 @@ it('should be able to capture alert', async ({browser}) => {
expect(dialog.message()).toBe('hello');
await dialog.dismiss();
await evaluatePromise;
await context.close();
});
it('should work with empty url', async ({browser}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should work with empty url', async ({page}) => {
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.evaluate(() => window['__popup'] = window.open('')),
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(true);
await context.close();
});
it('should work with noopener and no url', async ({browser}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should work with noopener and no url', async ({page}) => {
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.evaluate(() => window['__popup'] = window.open(undefined, null, 'noopener')),
@ -108,24 +88,18 @@ it('should work with noopener and no url', async ({browser}) => {
expect(popup.url().split('#')[0]).toBe('about:blank');
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
await context.close();
});
it('should work with noopener and about:blank', async ({browser}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should work with noopener and about:blank', async ({page}) => {
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.evaluate(() => window['__popup'] = window.open('about:blank', null, 'noopener')),
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
await context.close();
});
it('should work with noopener and url', async ({browser, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should work with noopener and url', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
const [popup] = await Promise.all([
page.waitForEvent('popup'),
@ -133,12 +107,9 @@ it('should work with noopener and url', async ({browser, server}) => {
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
await context.close();
});
it('should work with clicking target=_blank', async ({browser, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should work with clicking target=_blank', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.setContent('<a target=_blank rel="opener" href="/one-style.html">yo</a>');
const [popup] = await Promise.all([
@ -147,12 +118,9 @@ it('should work with clicking target=_blank', async ({browser, server}) => {
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(true);
await context.close();
});
it('should work with fake-clicking target=_blank and rel=noopener', async ({browser, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should work with fake-clicking target=_blank and rel=noopener', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.setContent('<a target=_blank rel=noopener href="/one-style.html">yo</a>');
const [popup] = await Promise.all([
@ -161,12 +129,9 @@ it('should work with fake-clicking target=_blank and rel=noopener', async ({brow
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
await context.close();
});
it('should work with clicking target=_blank and rel=noopener', async ({browser, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should work with clicking target=_blank and rel=noopener', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.setContent('<a target=_blank rel=noopener href="/one-style.html">yo</a>');
const [popup] = await Promise.all([
@ -175,12 +140,9 @@ it('should work with clicking target=_blank and rel=noopener', async ({browser,
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
await context.close();
});
it('should not treat navigations as new popups', async ({browser, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should not treat navigations as new popups', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.setContent('<a target=_blank rel=noopener href="/one-style.html">yo</a>');
const [popup] = await Promise.all([
@ -190,7 +152,6 @@ it('should not treat navigations as new popups', async ({browser, server}) => {
let badSecondPopup = false;
page.on('popup', () => badSecondPopup = true);
await popup.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
await context.close();
expect(badSecondPopup).toBe(false);
});

View file

@ -18,9 +18,7 @@
import { it, expect } from './fixtures';
import { attachFrame } from './utils';
it('exposeBinding should work', async ({browser}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('exposeBinding should work', async ({page}) => {
let bindingSource;
await page.exposeBinding('add', (source, a, b) => {
bindingSource = source;
@ -29,11 +27,10 @@ it('exposeBinding should work', async ({browser}) => {
const result = await page.evaluate(async function() {
return window['add'](5, 6);
});
expect(bindingSource.context).toBe(context);
expect(bindingSource.context).toBe(page.context());
expect(bindingSource.page).toBe(page);
expect(bindingSource.frame).toBe(page.mainFrame());
expect(result).toEqual(11);
await context.close();
});
it('should work', async ({page, server}) => {

View file

@ -140,9 +140,7 @@ it('should wait for load state of newPage', async ({browser, context, page, serv
expect(await newPage.evaluate(() => document.readyState)).toBe('complete');
});
it('should resolve after popup load', async ({browser, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
it('should resolve after popup load', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
// Stall the 'load' by delaying css.
let cssResponse;
@ -162,7 +160,6 @@ it('should resolve after popup load', async ({browser, server}) => {
await loadSatePromise;
expect(resolved).toBe(true);
expect(popup.url()).toBe(server.PREFIX + '/one-style.html');
await context.close();
});
it('should work for frame', async ({page, server}) => {