test: intercepted response status line (#8189)

This commit is contained in:
Yury Semikhatsky 2021-08-13 16:28:42 -07:00 committed by GitHub
parent 8231aa3919
commit 39f663834f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -487,7 +487,8 @@ class RouteImpl implements network.RouteDelegate {
return null;
const event = await this._responseInterceptedPromise;
this._interceptionId = event.requestId;
return new network.InterceptedResponse(request, event.responseStatusCode!, event.responseErrorReason!, event.responseHeaders!);
// FIXME: plumb status text from browser
return new network.InterceptedResponse(request, event.responseStatusCode!, '', event.responseHeaders!);
}
async fulfill(response: types.NormalizedFulfillResponse) {

View File

@ -113,7 +113,7 @@ it('should give access to the intercepted response', async ({page, server}) => {
const routePromise = new Promise<Route>(f => routeCallback = f);
await page.route('**/title.html', routeCallback);
const evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/title.html').catch(console.log);
const evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/title.html');
const route = await routePromise;
// @ts-expect-error
@ -127,6 +127,29 @@ it('should give access to the intercepted response', async ({page, server}) => {
await Promise.all([route.fulfill(), evalPromise]);
});
it('should give access to the intercepted response status text', async ({page, server, browserName}) => {
it.fail(browserName === 'chromium', 'Status line is not reported for intercepted responses');
await page.goto(server.EMPTY_PAGE);
server.setRoute('/title.html', (req, res) => {
res.statusCode = 200;
res.statusMessage = 'You are awesome';
res.setHeader('Content-Type', 'text/plain');
res.end();
});
let routeCallback;
const routePromise = new Promise<Route>(f => routeCallback = f);
await page.route('**/title.html', routeCallback);
const evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/title.html');
const route = await routePromise;
// @ts-expect-error
const response = await route._intercept();
expect(response.statusText()).toBe('You are awesome');
expect(response.url()).toBe(server.PREFIX + '/title.html');
await Promise.all([route.fulfill(), evalPromise]);
});
it('should give access to the intercepted response body', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);