Skip to content

Commit

Permalink
test: url bar navigation vs js redirect (#21640)
Browse files Browse the repository at this point in the history
The tests document current behavior when url bar navigation competes
with a js redirect.

Fixes #20749
  • Loading branch information
yury-s authored Mar 14, 2023
1 parent 809725e commit 6b3e7fa
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/page/page-goto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,95 @@ it('should fail when replaced by another navigation', async ({ page, server, bro
}
});

it('js redirect overrides url bar navigation ', async ({ page, server, browserName }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21574' });
server.setRoute('/a', (req, res) => {
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`
<body>
<script>
setTimeout(() => {
window.location.pathname = '/c';
}, 1000);
</script>
</body>
`);
});
const events = [];
server.setRoute('/b', async (req, res) => {
events.push('started b');
await new Promise(f => setTimeout(f, 2000));
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`BBB`);
events.push('finished b');
});
server.setRoute('/c', async (req, res) => {
events.push('started c');
await new Promise(f => setTimeout(f, 2000));
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`CCC`);
events.push('finished c');
});
await page.goto(server.PREFIX + '/a');
const error = await page.goto(server.PREFIX + '/b').then(r => null, e => e);
const expectEvents = (browserName === 'chromium') ?
['started b', 'finished b'] :
['started b', 'started c', 'finished b', 'finished c'];
await expect(() => expect(events).toEqual(expectEvents)).toPass();
expect(events).toEqual(expectEvents);
if (browserName === 'chromium') {
// Chromium prioritizes the url bar navigation over the js redirect.
expect(error).toBeFalsy();
expect(page.url()).toBe(server.PREFIX + '/b');
} else if (browserName === 'webkit') {
expect(error.message).toContain('Navigation interrupted by another one');
expect(page.url()).toBe(server.PREFIX + '/c');
} else if (browserName === 'firefox') {
expect(error.message).toContain('NS_BINDING_ABORTED');
expect(page.url()).toBe(server.PREFIX + '/c');
}
});

it('should succeed on url bar navigation when there is pending navigation', async ({ page, server, browserName }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21574' });
server.setRoute('/a', (req, res) => {
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`
<body>
<script>
setTimeout(() => {
window.location.pathname = '/c';
}, 10);
</script>
</body>
`);
});
const events = [];
server.setRoute('/b', async (req, res) => {
events.push('started b');
await new Promise(f => setTimeout(f, 2000));
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`BBB`);
events.push('finished b');
});
server.setRoute('/c', async (req, res) => {
events.push('started c');
await new Promise(f => setTimeout(f, 2000));
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`CCC`);
events.push('finished c');
});
await page.goto(server.PREFIX + '/a');
await new Promise(f => setTimeout(f, 1000));
const error = await page.goto(server.PREFIX + '/b').then(r => null, e => e);
const expectEvents = ['started c', 'started b', 'finished c', 'finished b'];
await expect(() => expect(events).toEqual(expectEvents)).toPass({ timeout: 5000 });
expect(events).toEqual(expectEvents);
expect(error).toBeFalsy();
expect(page.url()).toBe(server.PREFIX + '/b');
});


it('should work when navigating to valid url', async ({ page, server }) => {
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok()).toBe(true);
Expand Down

0 comments on commit 6b3e7fa

Please sign in to comment.