feat(firefox): support Request.postData (#3999)

This commit is contained in:
Andrey Lushnikov 2019-02-13 13:11:50 -08:00 committed by GitHub
parent 13224a761e
commit fbf36438e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 10 deletions

View File

@ -99,6 +99,7 @@ class Request {
this._id = payload.requestId;
this._redirectChain = redirectChain;
this._url = payload.url;
this._postData = payload.postData;
this._response = null;
this._isNavigationRequest = payload.isNavigationRequest;
this._method = payload.method;
@ -108,6 +109,10 @@ class Request {
this._headers[name.toLowerCase()] = value;
}
postData() {
return this._postData;
}
headers() {
return {...this._headers};
}

View File

@ -9,7 +9,7 @@
"node": ">=8.9.4"
},
"puppeteer": {
"firefox_revision": "ac50a00d0cb3522407d3c84ec85360cbc4d14c9c"
"firefox_revision": "32fc518d9228fd0115c0a4fd4bd341780bdba2fc"
},
"scripts": {
"install": "node install.js",

View File

@ -140,6 +140,22 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
});
});
describe('Request.postData', function() {
it('should work', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
server.setRoute('/post', (req, res) => res.end());
let request = null;
page.on('request', r => request = r);
await page.evaluate(() => fetch('./post', { method: 'POST', body: JSON.stringify({foo: 'bar'})}));
expect(request).toBeTruthy();
expect(request.postData()).toBe('{"foo":"bar"}');
});
it('should be |undefined| when there is no post data', async({page, server}) => {
const response = await page.goto(server.EMPTY_PAGE);
expect(response.request().postData()).toBe(undefined);
});
});
describe('Network Events', function() {
it('Page.Events.Request', async({page, server}) => {
const requests = [];
@ -153,15 +169,6 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
expect(requests[0].frame() === page.mainFrame()).toBe(true);
expect(requests[0].frame().url()).toBe(server.EMPTY_PAGE);
});
it_fails_ffox('Page.Events.Request should report post data', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
server.setRoute('/post', (req, res) => res.end());
let request = null;
page.on('request', r => request = r);
await page.evaluate(() => fetch('./post', { method: 'POST', body: JSON.stringify({foo: 'bar'})}));
expect(request).toBeTruthy();
expect(request.postData()).toBe('{"foo":"bar"}');
});
it('Page.Events.Response', async({page, server}) => {
const responses = [];
page.on('response', response => responses.push(response));