Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: url bar navigation vs js redirect #21640

Merged
merged 2 commits into from
Mar 14, 2023
Merged
Changes from 1 commit
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
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