mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(route): throw on attempt to fulfill with redirect in WebKit (#4449)
This commit is contained in:
parent
cb21d5dc54
commit
a877c24f05
@ -74,6 +74,9 @@ export class WKInterceptableRequest implements network.RouteDelegate {
|
||||
}
|
||||
|
||||
async fulfill(response: types.NormalizedFulfillResponse) {
|
||||
if (300 <= response.status && response.status < 400)
|
||||
throw new Error('Cannot fulfill with redirect status: ' + response.status);
|
||||
|
||||
await this._interceptedPromise;
|
||||
|
||||
// In certain cases, protocol will return error if the request was already canceled
|
||||
|
@ -394,15 +394,17 @@ it('should intercept main resource during cross-process navigation', async ({pag
|
||||
expect(intercepted).toBe(true);
|
||||
});
|
||||
|
||||
it('should create a redirect', async ({page, server}) => {
|
||||
await page.goto(server.PREFIX + '/empty.html');
|
||||
it('should fulfill with redirect status', (test, { browserName, headful}) => {
|
||||
test.fixme(browserName === 'webkit', 'in WebKit the redirects are handled by the network stack and we intercept before');
|
||||
}, async ({page, server}) => {
|
||||
await page.goto(server.PREFIX + '/title.html');
|
||||
await page.route('**/*', async (route, request) => {
|
||||
if (request.url() !== server.PREFIX + '/redirect_this')
|
||||
return route.continue();
|
||||
await route.fulfill({
|
||||
status: 301,
|
||||
headers: {
|
||||
'location': '/empty.html',
|
||||
'location': '/title.html',
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -411,7 +413,41 @@ it('should create a redirect', async ({page, server}) => {
|
||||
const data = await fetch(url);
|
||||
return data.text();
|
||||
}, server.PREFIX + '/redirect_this');
|
||||
expect(text).toBe('');
|
||||
expect(text).toBe('<title>Woof-Woof</title>\n');
|
||||
});
|
||||
|
||||
it('should not fulfill with redirect status', (test, { browserName, headful}) => {
|
||||
test.skip(browserName !== 'webkit', 'we should support fulfill with redirect in webkit and delete this test');
|
||||
}, async ({page, server}) => {
|
||||
await page.goto(server.PREFIX + '/empty.html');
|
||||
|
||||
let status;
|
||||
let fulfill;
|
||||
let reject;
|
||||
await page.route('**/*', async (route, request) => {
|
||||
if (request.url() !== server.PREFIX + '/redirect_this')
|
||||
return route.continue();
|
||||
try {
|
||||
await route.fulfill({
|
||||
status,
|
||||
headers: {
|
||||
'location': '/empty.html',
|
||||
}
|
||||
});
|
||||
reject('fullfill didn\'t throw');
|
||||
} catch (e) {
|
||||
fulfill(e);
|
||||
}
|
||||
});
|
||||
|
||||
for (status = 300; status < 310; status++) {
|
||||
const exception = await Promise.race([
|
||||
page.evaluate(url => location.href = url, server.PREFIX + '/redirect_this'),
|
||||
new Promise((f, r) => {fulfill = f; reject = r;})
|
||||
]) as any;
|
||||
expect(exception).toBeTruthy();
|
||||
expect(exception.message.includes('Cannot fulfill with redirect status')).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should support cors with GET', async ({page, server}) => {
|
||||
|
@ -50,11 +50,16 @@ it('should amend method', async ({page, server}) => {
|
||||
});
|
||||
|
||||
it('should override request url', async ({page, server}) => {
|
||||
const request = server.waitForRequest('/empty.html');
|
||||
const request = server.waitForRequest('/global-var.html');
|
||||
await page.route('**/foo', route => {
|
||||
route.continue({ url: server.EMPTY_PAGE });
|
||||
route.continue({ url: server.PREFIX + '/global-var.html' });
|
||||
});
|
||||
await page.goto(server.PREFIX + '/foo');
|
||||
const [response] = await Promise.all([
|
||||
page.waitForEvent('response'),
|
||||
page.goto(server.PREFIX + '/foo'),
|
||||
]);
|
||||
expect(response.url()).toBe(server.PREFIX + '/foo');
|
||||
expect(await page.evaluate(() => window['globalVar'])).toBe(123);
|
||||
expect((await request).method).toBe('GET');
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user