test: improve test coverage for Request.continue (#4096)
Drive-by: add clarification to docs/api.md regarding chaning "URL". References #4030
This commit is contained in:
parent
f32d77e074
commit
1623bef264
@ -3214,7 +3214,7 @@ Exception is immediately thrown if the request interception is not enabled.
|
||||
|
||||
#### request.continue([overrides])
|
||||
- `overrides` <[Object]> Optional request overwrites, which can be one of the following:
|
||||
- `url` <[string]> If set, the request url will be changed
|
||||
- `url` <[string]> If set, the request url will be changed. This is not a redirect. The request will be silently forwarded to the new url. For example, the address bar will show the original url.
|
||||
- `method` <[string]> If set changes the request method (e.g. `GET` or `POST`)
|
||||
- `postData` <[string]> If set changes the post data of request
|
||||
- `headers` <[Object]> If set changes the request HTTP headers
|
||||
|
@ -513,20 +513,6 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
|
||||
]);
|
||||
expect(request.headers['referer']).toBe('http://google.com/');
|
||||
});
|
||||
it_fails_ffox('should amend HTTP headers', async({page, server}) => {
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
const headers = Object.assign({}, request.headers());
|
||||
headers['FOO'] = 'bar';
|
||||
request.continue({ headers });
|
||||
});
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const [request] = await Promise.all([
|
||||
server.waitForRequest('/sleep.zzz'),
|
||||
page.evaluate(() => fetch('/sleep.zzz'))
|
||||
]);
|
||||
expect(request.headers['foo']).toBe('bar');
|
||||
});
|
||||
it('should fail navigation when aborting main resource', async({page, server}) => {
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => request.abort());
|
||||
@ -731,6 +717,66 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
|
||||
});
|
||||
});
|
||||
|
||||
describe_fails_ffox('Request.continue', function() {
|
||||
it('should work', async({page, server}) => {
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => request.continue());
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
});
|
||||
it('should amend HTTP headers', async({page, server}) => {
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
const headers = Object.assign({}, request.headers());
|
||||
headers['FOO'] = 'bar';
|
||||
request.continue({ headers });
|
||||
});
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const [request] = await Promise.all([
|
||||
server.waitForRequest('/sleep.zzz'),
|
||||
page.evaluate(() => fetch('/sleep.zzz'))
|
||||
]);
|
||||
expect(request.headers['foo']).toBe('bar');
|
||||
});
|
||||
it('should redirect in a way non-observable to page', async({page, server}) => {
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
const redirectURL = request.url().includes('/empty.html') ? server.PREFIX + '/consolelog.html' : undefined;
|
||||
request.continue({ url: redirectURL });
|
||||
});
|
||||
let consoleMessage = null;
|
||||
page.on('console', msg => consoleMessage = msg);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(page.url()).toBe(server.EMPTY_PAGE);
|
||||
expect(consoleMessage.text()).toBe('yellow');
|
||||
});
|
||||
it('should amend method', async({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
request.continue({ method: 'POST' });
|
||||
});
|
||||
const [request] = await Promise.all([
|
||||
server.waitForRequest('/sleep.zzz'),
|
||||
page.evaluate(() => fetch('/sleep.zzz'))
|
||||
]);
|
||||
expect(request.method).toBe('POST');
|
||||
});
|
||||
it('should amend post data', async({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
request.continue({ postData: 'doggo' });
|
||||
});
|
||||
const [serverRequest] = await Promise.all([
|
||||
server.waitForRequest('/sleep.zzz'),
|
||||
page.evaluate(() => fetch('/sleep.zzz', { method: 'POST', body: 'birdy' }))
|
||||
]);
|
||||
expect(await serverRequest.postBody).toBe('doggo');
|
||||
});
|
||||
});
|
||||
|
||||
describe_fails_ffox('Request.respond', function() {
|
||||
it('should work', async({page, server}) => {
|
||||
await page.setRequestInterception(true);
|
||||
|
@ -189,6 +189,11 @@ class TestServer {
|
||||
else
|
||||
throw error;
|
||||
});
|
||||
request.postBody = new Promise(resolve => {
|
||||
let body = '';
|
||||
request.on('data', chunk => body += chunk);
|
||||
request.on('end', () => resolve(body));
|
||||
});
|
||||
const pathName = url.parse(request.url).path;
|
||||
if (this._auths.has(pathName)) {
|
||||
const auth = this._auths.get(pathName);
|
||||
|
Loading…
Reference in New Issue
Block a user