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 }) => { it('should be able to close context with open alert', (test, { browserName, platform }) => {
test.fixme(browserName === 'webkit' && platform === 'darwin'); test.fixme(browserName === 'webkit' && platform === 'darwin');
}, async ({browser}) => { }, async ({context}) => {
const context = await browser.newContext();
const page = await context.newPage(); const page = await context.newPage();
const alertPromise = page.waitForEvent('dialog'); const alertPromise = page.waitForEvent('dialog');
await page.evaluate(() => { await page.evaluate(() => {
setTimeout(() => alert('hello'), 0); setTimeout(() => alert('hello'), 0);
}); });
await alertPromise; await alertPromise;
await context.close();
}); });
it('should handle multiple alerts', async ({page}) => { it('should handle multiple alerts', async ({page}) => {

View file

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

View file

@ -18,9 +18,7 @@
import { it, expect } from './fixtures'; import { it, expect } from './fixtures';
import { attachFrame } from './utils'; import { attachFrame } from './utils';
it('exposeBinding should work', async ({browser}) => { it('exposeBinding should work', async ({page}) => {
const context = await browser.newContext();
const page = await context.newPage();
let bindingSource; let bindingSource;
await page.exposeBinding('add', (source, a, b) => { await page.exposeBinding('add', (source, a, b) => {
bindingSource = source; bindingSource = source;
@ -29,11 +27,10 @@ it('exposeBinding should work', async ({browser}) => {
const result = await page.evaluate(async function() { const result = await page.evaluate(async function() {
return window['add'](5, 6); return window['add'](5, 6);
}); });
expect(bindingSource.context).toBe(context); expect(bindingSource.context).toBe(page.context());
expect(bindingSource.page).toBe(page); expect(bindingSource.page).toBe(page);
expect(bindingSource.frame).toBe(page.mainFrame()); expect(bindingSource.frame).toBe(page.mainFrame());
expect(result).toEqual(11); expect(result).toEqual(11);
await context.close();
}); });
it('should work', async ({page, server}) => { 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'); expect(await newPage.evaluate(() => document.readyState)).toBe('complete');
}); });
it('should resolve after popup load', async ({browser, server}) => { it('should resolve after popup load', async ({page, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
// Stall the 'load' by delaying css. // Stall the 'load' by delaying css.
let cssResponse; let cssResponse;
@ -162,7 +160,6 @@ it('should resolve after popup load', async ({browser, server}) => {
await loadSatePromise; await loadSatePromise;
expect(resolved).toBe(true); expect(resolved).toBe(true);
expect(popup.url()).toBe(server.PREFIX + '/one-style.html'); expect(popup.url()).toBe(server.PREFIX + '/one-style.html');
await context.close();
}); });
it('should work for frame', async ({page, server}) => { it('should work for frame', async ({page, server}) => {