Skip to content

Commit

Permalink
chore: extract unroute behavior tests into a separate file (#28674)
Browse files Browse the repository at this point in the history
Reference #23781
  • Loading branch information
yury-s committed Dec 15, 2023
1 parent 35b61b7 commit a1a4133
Show file tree
Hide file tree
Showing 3 changed files with 302 additions and 282 deletions.
126 changes: 0 additions & 126 deletions tests/library/browsercontext-route.spec.ts
Expand Up @@ -79,102 +79,6 @@ it('should unroute', async ({ browser, server }) => {
await context.close();
});

it('unroute should not wait for pending handlers to complete', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let secondHandlerCalled = false;
await context.route(/.*/, async route => {
secondHandlerCalled = true;
await route.continue();
});
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
let continueRouteCallback;
const routeBarrier = new Promise(f => continueRouteCallback = f);
const handler = async route => {
routeCallback();
await routeBarrier;
await route.fallback();
};
await context.route(/.*/, handler);
const navigationPromise = page.goto(server.EMPTY_PAGE);
await routePromise;
await context.unroute(/.*/, handler);
continueRouteCallback();
await navigationPromise;
expect(secondHandlerCalled).toBe(true);
});

it('unrouteAll removes all handlers', async ({ page, context, server }) => {
await context.route('**/*', route => {
void route.abort();
});
await context.route('**/empty.html', route => {
void route.abort();
});
await context.unrouteAll();
await page.goto(server.EMPTY_PAGE);
});

it('unrouteAll should wait for pending handlers to complete', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let secondHandlerCalled = false;
await context.route(/.*/, async route => {
secondHandlerCalled = true;
await route.abort();
});
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
let continueRouteCallback;
const routeBarrier = new Promise(f => continueRouteCallback = f);
const handler = async route => {
routeCallback();
await routeBarrier;
await route.fallback();
};
await context.route(/.*/, handler);
const navigationPromise = page.goto(server.EMPTY_PAGE);
await routePromise;
let didUnroute = false;
const unroutePromise = context.unrouteAll({ behavior: 'wait' }).then(() => didUnroute = true);
await new Promise(f => setTimeout(f, 500));
expect(didUnroute).toBe(false);
continueRouteCallback();
await unroutePromise;
expect(didUnroute).toBe(true);
await navigationPromise;
expect(secondHandlerCalled).toBe(false);
});

it('unrouteAll should not wait for pending handlers to complete if behavior is ignoreErrors', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let secondHandlerCalled = false;
await context.route(/.*/, async route => {
secondHandlerCalled = true;
await route.abort();
});
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
let continueRouteCallback;
const routeBarrier = new Promise(f => continueRouteCallback = f);
const handler = async route => {
routeCallback();
await routeBarrier;
throw new Error('Handler error');
};
await context.route(/.*/, handler);
const navigationPromise = page.goto(server.EMPTY_PAGE);
await routePromise;
let didUnroute = false;
const unroutePromise = context.unrouteAll({ behavior: 'ignoreErrors' }).then(() => didUnroute = true);
await new Promise(f => setTimeout(f, 500));
await unroutePromise;
expect(didUnroute).toBe(true);
continueRouteCallback();
await navigationPromise.catch(e => void e);
// The error in the unrouted handler should be silently caught and remaining handler called.
expect(secondHandlerCalled).toBe(false);
});

it('should yield to page.route', async ({ browser, server }) => {
const context = await browser.newContext();
await context.route('**/empty.html', route => {
Expand Down Expand Up @@ -483,33 +387,3 @@ it('should fall back async', async ({ page, context, server }) => {
await page.goto(server.EMPTY_PAGE);
expect(intercepted).toEqual([3, 2, 1]);
});

it('page.close should not wait for active route handlers on the owning context', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
await context.route(/.*/, async route => {
routeCallback();
});
await page.route(/.*/, async route => {
await route.fallback();
});
page.goto(server.EMPTY_PAGE).catch(() => {});
await routePromise;
await page.close();
});

it('context.close should not wait for active route handlers on the owned pages', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
await page.route(/.*/, async route => {
routeCallback();
});
await page.route(/.*/, async route => {
await route.fallback();
});
page.goto(server.EMPTY_PAGE).catch(() => {});
await routePromise;
await context.close();
});

0 comments on commit a1a4133

Please sign in to comment.