test: url bar navigation vs js redirect (#21640)

The tests document current behavior when url bar navigation competes
with a js redirect.

Fixes #20749
This commit is contained in:
Yury Semikhatsky 2023-03-13 17:53:39 -07:00 коммит произвёл GitHub
Родитель 809725e114
Коммит 6b3e7faad5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 89 добавлений и 0 удалений

Просмотреть файл

@ -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);