Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions tests/library/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ it('CA-011 should not crash on showDirectoryPicker', async ({ page, server, brow
await page.goto(server.EMPTY_PAGE);
// "User activation is required to show a file picker." - so we click first.
await page.locator('body').click();
page.evaluate(async () => {
const dir = await (window as any).showDirectoryPicker();
return dir.name;
// In headless it throws (aborted), in headed it stalls (Test ended) and waits for the picker to be accepted.
}).catch(e => expect(e.message).toMatch(/((DOMException|AbortError): .*The user aborted a request|Test ended)/));
await page.evaluate(() => {
(window as any).showDirectoryPicker().catch(e => { (window as any).__pickerError = String(e); });
});
// The dialog will not be accepted, so we just wait for some time to
// to give the browser a chance to crash.
await page.waitForTimeout(3_000);
// In headless it throws (aborted), in headed it stalls and waits for the picker to be accepted.
const error = await page.evaluate(() => (window as any).__pickerError ?? 'stalled');
expect(error).toMatch(/((DOMException|AbortError): .*The user aborted a request|stalled)/);
});

it('CA-012 should not crash on storage.getDirectory()', {
Expand Down
17 changes: 8 additions & 9 deletions tests/library/tracing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,17 +937,15 @@ test('TR-041 should not emit after w/o before', async ({ browserType, mode }, te
const page = await context.newPage();

await context.tracing.start({ name: 'name1', snapshots: true });
const evaluatePromise = page.evaluate(() => {
console.log('started');
return new Promise(f => (window as any).callback = f);
}).catch(() => {});
await page.waitForEvent('console');
// The wait spans the chunks: its "before" is in the first chunk, and its "after" must not get into the second one.
const consolePromise = page.waitForEvent('console');
await page.evaluate(() => 1);
await context.tracing.stopChunk({ path: testInfo.outputPath('trace1.zip') });
expect(fs.existsSync(path.join(tracesDir, 'name1.trace'))).toBe(true);

await context.tracing.startChunk({ name: 'name2' });
await page.evaluateHandle(() => (window as any).callback());
await evaluatePromise;
await page.evaluate(() => console.log('started'));
await consolePromise;
await context.tracing.stop({ path: testInfo.outputPath('trace2.zip') });
expect(fs.existsSync(path.join(tracesDir, 'name2.trace'))).toBe(true);

Expand All @@ -972,19 +970,20 @@ test('TR-041 should not emit after w/o before', async ({ browserType, mode }, te
{
type: 'before',
callId: expect.any(Number),
title: 'Wait for event "console"',
},
{
type: 'before',
callId: expect.any(Number),
title: 'Wait for event "console"',
},
{
type: 'after',
callId: expect.any(Number),
},
]);
call1 = sanitized[0].callId;
expect(sanitized[1].callId).toBeGreaterThan(sanitized[0].callId);
expect(sanitized[1].callId).toBe(sanitized[2].callId);
call1 = sanitized[1].callId;
}

let call2before: number;
Expand Down
10 changes: 5 additions & 5 deletions tests/page/page-drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ it('DD-019 should handle custom dataTransfer', async ({ page, browserName, isWin
it.fixme(browserName === 'webkit' && isWindows);
await page.setContent(`<button draggable="true">Draggable</button>`);

const resultPromise = page.evaluate(() =>
new Promise(resolve => {
await page.evaluate(() => {
(window as any).__result = new Promise(resolve => {
document.addEventListener('dragstart', event => {
event.dataTransfer!.setData('custom-type', 'Hello World');
}, false);
Expand All @@ -503,15 +503,15 @@ it('DD-019 should handle custom dataTransfer', async ({ page, browserName, isWin
data: event.dataTransfer!.getData('custom-type'),
});
}, false);
})
);
});
});

await page.hover('[draggable="true"]');
await page.mouse.down();
await page.mouse.move(100, 100);
await page.mouse.up();

await expect(resultPromise).resolves.toEqual({
expect(await page.evaluate(() => (window as any).__result)).toEqual({
types: ['custom-type'],
data: 'Hello World',
});
Expand Down
15 changes: 6 additions & 9 deletions tests/page/page-evaluate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,12 @@ it('EV-062 should simulate a user gesture', async ({ page }) => {
});

it('EV-063 should throw a nice error after a navigation', async ({ page }) => {
const errorPromise = page.evaluate(() => new Promise(f => window['__resolve'] = f)).catch(e => e) as Promise<Error>;
await Promise.all([
page.waitForNavigation(),
page.evaluate(() => {
window.location.reload();
setTimeout(() => window['__resolve'](42), 1000);
})
]);
const error = await errorPromise;
const navigationPromise = page.waitForNavigation();
const error = await page.evaluate(() => new Promise(f => setTimeout(() => {
window.location.reload();
setTimeout(() => f(42), 1000);
}, 0))).catch(e => e) as Error;
await navigationPromise;
expect(error.message).toContain('navigation');
});

Expand Down
6 changes: 3 additions & 3 deletions tests/page/page-request-fulfill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ it('RO-100 should not throw if request was cancelled by the page', async ({ page
const interceptPromise = new Promise<Route>(f => interceptCallback = f);
await page.route('**/data.json', route => interceptCallback(route));
await page.goto(server.EMPTY_PAGE);
page.evaluate(url => {
await page.evaluate(url => {
globalThis.controller = new AbortController();
return fetch(url, { signal: globalThis.controller.signal });
}, server.PREFIX + '/data.json').catch(() => {});
fetch(url, { signal: globalThis.controller.signal }).catch(() => {});
}, server.PREFIX + '/data.json');
const route = await interceptPromise;
const failurePromise = page.waitForEvent('requestfailed');
await page.evaluate(() => globalThis.controller.abort());
Expand Down
49 changes: 23 additions & 26 deletions tests/page/page-route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,48 +230,45 @@ it('RO-012 should pause intercepted XHR until continue', async ({ page, server,
const routePromise = new Promise(r => resolveRoute = r);
await page.route('**/global-var.html', async route => resolveRoute(route));
let xhrFinished = false;
const statusPromise = page.evaluate(async () => {
const request = new XMLHttpRequest();
request.open('GET', '/global-var.html', false); // `false` makes the request synchronous
request.send(null);
return request.status;
}).then(r => {
xhrFinished = true;
return r;
page.on('requestfinished', request => {
if (request.url().endsWith('/global-var.html'))
xhrFinished = true;
});
// The synchronous request blocks the page, so it is started from a timer.
await page.evaluate(() => {
(window as any).__statusPromise = new Promise(resolve => setTimeout(() => {
const request = new XMLHttpRequest();
request.open('GET', '/global-var.html', false); // `false` makes the request synchronous
request.send(null);
resolve(request.status);
}, 0));
});
const route = await routePromise;
// Check that intercepted request is actually paused.
await new Promise(r => setTimeout(r, 500));
expect(xhrFinished).toBe(false);
const [status] = await Promise.all([
statusPromise,
(route as any).continue()
]);
expect(status).toBe(200);
await (route as any).continue();
expect(await page.evaluate(() => (window as any).__statusPromise)).toBe(200);
});

it('RO-013 should pause intercepted fetch request until continue', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
let resolveRoute;
const routePromise = new Promise(r => resolveRoute = r);
await page.route('**/global-var.html', async route => resolveRoute(route));
let fetchFinished = false;
const statusPromise = page.evaluate(async () => {
const response = await fetch('/global-var.html');
return response.status;
}).then(r => {
fetchFinished = true;
return r;
await page.evaluate(() => {
(window as any).__fetchFinished = false;
(window as any).__statusPromise = fetch('/global-var.html').then(response => {
(window as any).__fetchFinished = true;
return response.status;
});
});
const route = await routePromise;
// Check that intercepted request is actually paused.
await new Promise(r => setTimeout(r, 500));
expect(fetchFinished).toBe(false);
const [status] = await Promise.all([
statusPromise,
(route as any).continue()
]);
expect(status).toBe(200);
expect(await page.evaluate(() => (window as any).__fetchFinished)).toBe(false);
await (route as any).continue();
expect(await page.evaluate(() => (window as any).__statusPromise)).toBe(200);
});

it('RO-014 should work with custom referer headers', async ({ page, server, browserName, browserMajorVersion }) => {
Expand Down
Loading