mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: add Prettier (#5825)
This commit is contained in:
@@ -18,77 +18,101 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const utils = require('./utils');
|
||||
const expect = require('expect');
|
||||
const {getTestState,setupTestBrowserHooks,setupTestPageAndContextHooks} = require('./mocha-utils');
|
||||
const {
|
||||
getTestState,
|
||||
setupTestBrowserHooks,
|
||||
setupTestPageAndContextHooks,
|
||||
} = require('./mocha-utils');
|
||||
|
||||
describe('network', function() {
|
||||
describe('network', function () {
|
||||
setupTestBrowserHooks();
|
||||
setupTestPageAndContextHooks();
|
||||
|
||||
describe('Page.Events.Request', function() {
|
||||
it('should fire for navigation requests', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describe('Page.Events.Request', function () {
|
||||
it('should fire for navigation requests', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const requests = [];
|
||||
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
|
||||
page.on(
|
||||
'request',
|
||||
(request) => !utils.isFavicon(request) && requests.push(request)
|
||||
);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(requests.length).toBe(1);
|
||||
});
|
||||
itFailsFirefox('should fire for iframes', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should fire for iframes', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const requests = [];
|
||||
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
|
||||
page.on(
|
||||
'request',
|
||||
(request) => !utils.isFavicon(request) && requests.push(request)
|
||||
);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
||||
expect(requests.length).toBe(2);
|
||||
});
|
||||
it('should fire for fetches', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should fire for fetches', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const requests = [];
|
||||
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
|
||||
page.on(
|
||||
'request',
|
||||
(request) => !utils.isFavicon(request) && requests.push(request)
|
||||
);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.evaluate(() => fetch('/empty.html'));
|
||||
expect(requests.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Request.frame', function() {
|
||||
it('should work for main frame navigation request', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describe('Request.frame', function () {
|
||||
it('should work for main frame navigation request', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const requests = [];
|
||||
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
|
||||
page.on(
|
||||
'request',
|
||||
(request) => !utils.isFavicon(request) && requests.push(request)
|
||||
);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(requests.length).toBe(1);
|
||||
expect(requests[0].frame()).toBe(page.mainFrame());
|
||||
});
|
||||
itFailsFirefox('should work for subframe navigation request', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should work for subframe navigation request', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const requests = [];
|
||||
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
|
||||
page.on(
|
||||
'request',
|
||||
(request) => !utils.isFavicon(request) && requests.push(request)
|
||||
);
|
||||
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
||||
expect(requests.length).toBe(1);
|
||||
expect(requests[0].frame()).toBe(page.frames()[1]);
|
||||
});
|
||||
it('should work for fetch requests', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should work for fetch requests', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
let requests = [];
|
||||
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
|
||||
page.on(
|
||||
'request',
|
||||
(request) => !utils.isFavicon(request) && requests.push(request)
|
||||
);
|
||||
await page.evaluate(() => fetch('/digits/1.png'));
|
||||
requests = requests.filter(request => !request.url().includes('favicon'));
|
||||
requests = requests.filter(
|
||||
(request) => !request.url().includes('favicon')
|
||||
);
|
||||
expect(requests.length).toBe(1);
|
||||
expect(requests[0].frame()).toBe(page.mainFrame());
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Request.headers', function() {
|
||||
it('should work', async() => {
|
||||
const {page, server, isChrome} = getTestState();
|
||||
describeFailsFirefox('Request.headers', function () {
|
||||
it('should work', async () => {
|
||||
const { page, server, isChrome } = getTestState();
|
||||
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
if (isChrome)
|
||||
@@ -98,9 +122,9 @@ describe('network', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Response.headers', function() {
|
||||
it('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Response.headers', function () {
|
||||
it('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
server.setRoute('/empty.html', (req, res) => {
|
||||
res.setHeader('foo', 'bar');
|
||||
@@ -111,19 +135,24 @@ describe('network', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Response.fromCache', function() {
|
||||
it('should return |false| for non-cached content', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Response.fromCache', function () {
|
||||
it('should return |false| for non-cached content', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.fromCache()).toBe(false);
|
||||
});
|
||||
|
||||
it('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const responses = new Map();
|
||||
page.on('response', r => !utils.isFavicon(r.request()) && responses.set(r.url().split('/').pop(), r));
|
||||
page.on(
|
||||
'response',
|
||||
(r) =>
|
||||
!utils.isFavicon(r.request()) &&
|
||||
responses.set(r.url().split('/').pop(), r)
|
||||
);
|
||||
|
||||
// Load and re-load to make sure it's cached.
|
||||
await page.goto(server.PREFIX + '/cached/one-style.html');
|
||||
@@ -137,23 +166,25 @@ describe('network', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Response.fromServiceWorker', function() {
|
||||
it('should return |false| for non-service-worker content', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Response.fromServiceWorker', function () {
|
||||
it('should return |false| for non-service-worker content', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.fromServiceWorker()).toBe(false);
|
||||
});
|
||||
|
||||
it('Response.fromServiceWorker', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('Response.fromServiceWorker', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const responses = new Map();
|
||||
page.on('response', r => responses.set(r.url().split('/').pop(), r));
|
||||
page.on('response', (r) => responses.set(r.url().split('/').pop(), r));
|
||||
|
||||
// Load and re-load to make sure serviceworker is installed and running.
|
||||
await page.goto(server.PREFIX + '/serviceworkers/fetch/sw.html', {waitUntil: 'networkidle2'});
|
||||
await page.evaluate(async() => await window.activationPromise);
|
||||
await page.goto(server.PREFIX + '/serviceworkers/fetch/sw.html', {
|
||||
waitUntil: 'networkidle2',
|
||||
});
|
||||
await page.evaluate(async () => await window.activationPromise);
|
||||
await page.reload();
|
||||
|
||||
expect(responses.size).toBe(2);
|
||||
@@ -164,36 +195,41 @@ describe('network', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Request.postData', function() {
|
||||
it('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Request.postData', function () {
|
||||
it('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
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'})}));
|
||||
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() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should be |undefined| when there is no post data', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.request().postData()).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Response.text', function() {
|
||||
it('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Response.text', function () {
|
||||
it('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const response = await page.goto(server.PREFIX + '/simple.json');
|
||||
const responseText = (await response.text()).trimEnd();
|
||||
expect(responseText).toBe('{"foo": "bar"}');
|
||||
});
|
||||
it('should return uncompressed text', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should return uncompressed text', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
server.enableGzip('/simple.json');
|
||||
const response = await page.goto(server.PREFIX + '/simple.json');
|
||||
@@ -201,8 +237,8 @@ describe('network', function() {
|
||||
const responseText = (await response.text()).trimEnd();
|
||||
expect(responseText).toBe('{"foo": "bar"}');
|
||||
});
|
||||
it('should throw when requesting body of redirected response', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should throw when requesting body of redirected response', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
server.setRedirect('/foo.html', '/empty.html');
|
||||
const response = await page.goto(server.PREFIX + '/foo.html');
|
||||
@@ -211,11 +247,13 @@ describe('network', function() {
|
||||
const redirected = redirectChain[0].response();
|
||||
expect(redirected.status()).toBe(302);
|
||||
let error = null;
|
||||
await redirected.text().catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Response body is unavailable for redirect responses');
|
||||
await redirected.text().catch((error_) => (error = error_));
|
||||
expect(error.message).toContain(
|
||||
'Response body is unavailable for redirect responses'
|
||||
);
|
||||
});
|
||||
it('should wait until response completes', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should wait until response completes', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
// Setup server to trap request.
|
||||
@@ -229,11 +267,14 @@ describe('network', function() {
|
||||
});
|
||||
// Setup page to trap response.
|
||||
let requestFinished = false;
|
||||
page.on('requestfinished', r => requestFinished = requestFinished || r.url().includes('/get'));
|
||||
page.on(
|
||||
'requestfinished',
|
||||
(r) => (requestFinished = requestFinished || r.url().includes('/get'))
|
||||
);
|
||||
// send request and wait for server response
|
||||
const [pageResponse] = await Promise.all([
|
||||
page.waitForResponse(r => !utils.isFavicon(r.request())),
|
||||
page.evaluate(() => fetch('./get', {method: 'GET'})),
|
||||
page.waitForResponse((r) => !utils.isFavicon(r.request())),
|
||||
page.evaluate(() => fetch('./get', { method: 'GET' })),
|
||||
server.waitForRequest('/get'),
|
||||
]);
|
||||
|
||||
@@ -244,45 +285,49 @@ describe('network', function() {
|
||||
|
||||
const responseText = pageResponse.text();
|
||||
// Write part of the response and wait for it to be flushed.
|
||||
await new Promise(x => serverResponse.write('wor', x));
|
||||
await new Promise((x) => serverResponse.write('wor', x));
|
||||
// Finish response.
|
||||
await new Promise(x => serverResponse.end('ld!', x));
|
||||
await new Promise((x) => serverResponse.end('ld!', x));
|
||||
expect(await responseText).toBe('hello world!');
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Response.json', function() {
|
||||
it('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Response.json', function () {
|
||||
it('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const response = await page.goto(server.PREFIX + '/simple.json');
|
||||
expect(await response.json()).toEqual({foo: 'bar'});
|
||||
expect(await response.json()).toEqual({ foo: 'bar' });
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Response.buffer', function() {
|
||||
it('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Response.buffer', function () {
|
||||
it('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const response = await page.goto(server.PREFIX + '/pptr.png');
|
||||
const imageBuffer = fs.readFileSync(path.join(__dirname, 'assets', 'pptr.png'));
|
||||
const imageBuffer = fs.readFileSync(
|
||||
path.join(__dirname, 'assets', 'pptr.png')
|
||||
);
|
||||
const responseBuffer = await response.buffer();
|
||||
expect(responseBuffer.equals(imageBuffer)).toBe(true);
|
||||
});
|
||||
it('should work with compression', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should work with compression', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
server.enableGzip('/pptr.png');
|
||||
const response = await page.goto(server.PREFIX + '/pptr.png');
|
||||
const imageBuffer = fs.readFileSync(path.join(__dirname, 'assets', 'pptr.png'));
|
||||
const imageBuffer = fs.readFileSync(
|
||||
path.join(__dirname, 'assets', 'pptr.png')
|
||||
);
|
||||
const responseBuffer = await response.buffer();
|
||||
expect(responseBuffer.equals(imageBuffer)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Response.statusText', function() {
|
||||
it('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Response.statusText', function () {
|
||||
it('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
server.setRoute('/cool', (req, res) => {
|
||||
res.writeHead(200, 'cool!');
|
||||
@@ -293,12 +338,12 @@ describe('network', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Network Events', function() {
|
||||
it('Page.Events.Request', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Network Events', function () {
|
||||
it('Page.Events.Request', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const requests = [];
|
||||
page.on('request', request => requests.push(request));
|
||||
page.on('request', (request) => requests.push(request));
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(requests.length).toBe(1);
|
||||
expect(requests[0].url()).toBe(server.EMPTY_PAGE);
|
||||
@@ -308,11 +353,11 @@ describe('network', function() {
|
||||
expect(requests[0].frame() === page.mainFrame()).toBe(true);
|
||||
expect(requests[0].frame().url()).toBe(server.EMPTY_PAGE);
|
||||
});
|
||||
it('Page.Events.Response', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('Page.Events.Response', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const responses = [];
|
||||
page.on('response', response => responses.push(response));
|
||||
page.on('response', (response) => responses.push(response));
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(responses.length).toBe(1);
|
||||
expect(responses[0].url()).toBe(server.EMPTY_PAGE);
|
||||
@@ -321,22 +366,22 @@ describe('network', function() {
|
||||
expect(responses[0].request()).toBeTruthy();
|
||||
const remoteAddress = responses[0].remoteAddress();
|
||||
// Either IPv6 or IPv4, depending on environment.
|
||||
expect(remoteAddress.ip.includes('::1') || remoteAddress.ip === '127.0.0.1').toBe(true);
|
||||
expect(
|
||||
remoteAddress.ip.includes('::1') || remoteAddress.ip === '127.0.0.1'
|
||||
).toBe(true);
|
||||
expect(remoteAddress.port).toBe(server.PORT);
|
||||
});
|
||||
|
||||
it('Page.Events.RequestFailed', async() => {
|
||||
const {page, server, isChrome} = getTestState();
|
||||
it('Page.Events.RequestFailed', async () => {
|
||||
const { page, server, isChrome } = getTestState();
|
||||
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
if (request.url().endsWith('css'))
|
||||
request.abort();
|
||||
else
|
||||
request.continue();
|
||||
page.on('request', (request) => {
|
||||
if (request.url().endsWith('css')) request.abort();
|
||||
else request.continue();
|
||||
});
|
||||
const failedRequests = [];
|
||||
page.on('requestfailed', request => failedRequests.push(request));
|
||||
page.on('requestfailed', (request) => failedRequests.push(request));
|
||||
await page.goto(server.PREFIX + '/one-style.html');
|
||||
expect(failedRequests.length).toBe(1);
|
||||
expect(failedRequests[0].url()).toContain('one-style.css');
|
||||
@@ -348,11 +393,11 @@ describe('network', function() {
|
||||
expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
|
||||
expect(failedRequests[0].frame()).toBeTruthy();
|
||||
});
|
||||
it('Page.Events.RequestFinished', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('Page.Events.RequestFinished', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const requests = [];
|
||||
page.on('requestfinished', request => requests.push(request));
|
||||
page.on('requestfinished', (request) => requests.push(request));
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(requests.length).toBe(1);
|
||||
expect(requests[0].url()).toBe(server.EMPTY_PAGE);
|
||||
@@ -360,24 +405,32 @@ describe('network', function() {
|
||||
expect(requests[0].frame() === page.mainFrame()).toBe(true);
|
||||
expect(requests[0].frame().url()).toBe(server.EMPTY_PAGE);
|
||||
});
|
||||
it('should fire events in proper order', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should fire events in proper order', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const events = [];
|
||||
page.on('request', request => events.push('request'));
|
||||
page.on('response', response => events.push('response'));
|
||||
page.on('requestfinished', request => events.push('requestfinished'));
|
||||
page.on('request', (request) => events.push('request'));
|
||||
page.on('response', (response) => events.push('response'));
|
||||
page.on('requestfinished', (request) => events.push('requestfinished'));
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(events).toEqual(['request', 'response', 'requestfinished']);
|
||||
});
|
||||
it('should support redirects', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should support redirects', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const events = [];
|
||||
page.on('request', request => events.push(`${request.method()} ${request.url()}`));
|
||||
page.on('response', response => events.push(`${response.status()} ${response.url()}`));
|
||||
page.on('requestfinished', request => events.push(`DONE ${request.url()}`));
|
||||
page.on('requestfailed', request => events.push(`FAIL ${request.url()}`));
|
||||
page.on('request', (request) =>
|
||||
events.push(`${request.method()} ${request.url()}`)
|
||||
);
|
||||
page.on('response', (response) =>
|
||||
events.push(`${response.status()} ${response.url()}`)
|
||||
);
|
||||
page.on('requestfinished', (request) =>
|
||||
events.push(`DONE ${request.url()}`)
|
||||
);
|
||||
page.on('requestfailed', (request) =>
|
||||
events.push(`FAIL ${request.url()}`)
|
||||
);
|
||||
server.setRedirect('/foo.html', '/empty.html');
|
||||
const FOO_URL = server.PREFIX + '/foo.html';
|
||||
const response = await page.goto(FOO_URL);
|
||||
@@ -387,23 +440,27 @@ describe('network', function() {
|
||||
`DONE ${FOO_URL}`,
|
||||
`GET ${server.EMPTY_PAGE}`,
|
||||
`200 ${server.EMPTY_PAGE}`,
|
||||
`DONE ${server.EMPTY_PAGE}`
|
||||
`DONE ${server.EMPTY_PAGE}`,
|
||||
]);
|
||||
|
||||
// Check redirect chain
|
||||
const redirectChain = response.request().redirectChain();
|
||||
expect(redirectChain.length).toBe(1);
|
||||
expect(redirectChain[0].url()).toContain('/foo.html');
|
||||
expect(redirectChain[0].response().remoteAddress().port).toBe(server.PORT);
|
||||
expect(redirectChain[0].response().remoteAddress().port).toBe(
|
||||
server.PORT
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Request.isNavigationRequest', () => {
|
||||
itFailsFirefox('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const requests = new Map();
|
||||
page.on('request', request => requests.set(request.url().split('/').pop(), request));
|
||||
page.on('request', (request) =>
|
||||
requests.set(request.url().split('/').pop(), request)
|
||||
);
|
||||
server.setRedirect('/rrredirect', '/frames/one-frame.html');
|
||||
await page.goto(server.PREFIX + '/rrredirect');
|
||||
expect(requests.get('rrredirect').isNavigationRequest()).toBe(true);
|
||||
@@ -412,11 +469,11 @@ describe('network', function() {
|
||||
expect(requests.get('script.js').isNavigationRequest()).toBe(false);
|
||||
expect(requests.get('style.css').isNavigationRequest()).toBe(false);
|
||||
});
|
||||
itFailsFirefox('should work with request interception', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should work with request interception', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const requests = new Map();
|
||||
page.on('request', request => {
|
||||
page.on('request', (request) => {
|
||||
requests.set(request.url().split('/').pop(), request);
|
||||
request.continue();
|
||||
});
|
||||
@@ -429,22 +486,22 @@ describe('network', function() {
|
||||
expect(requests.get('script.js').isNavigationRequest()).toBe(false);
|
||||
expect(requests.get('style.css').isNavigationRequest()).toBe(false);
|
||||
});
|
||||
it('should work when navigating to image', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should work when navigating to image', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
const requests = [];
|
||||
page.on('request', request => requests.push(request));
|
||||
page.on('request', (request) => requests.push(request));
|
||||
await page.goto(server.PREFIX + '/pptr.png');
|
||||
expect(requests[0].isNavigationRequest()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Page.setExtraHTTPHeaders', function() {
|
||||
it('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Page.setExtraHTTPHeaders', function () {
|
||||
it('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.setExtraHTTPHeaders({
|
||||
foo: 'bar'
|
||||
foo: 'bar',
|
||||
});
|
||||
const [request] = await Promise.all([
|
||||
server.waitForRequest('/empty.html'),
|
||||
@@ -452,53 +509,55 @@ describe('network', function() {
|
||||
]);
|
||||
expect(request.headers['foo']).toBe('bar');
|
||||
});
|
||||
it('should throw for non-string header values', async() => {
|
||||
const {page} = getTestState();
|
||||
it('should throw for non-string header values', async () => {
|
||||
const { page } = getTestState();
|
||||
|
||||
let error = null;
|
||||
try {
|
||||
await page.setExtraHTTPHeaders({'foo': 1});
|
||||
await page.setExtraHTTPHeaders({ foo: 1 });
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toBe('Expected value of header "foo" to be String, but "number" is found.');
|
||||
expect(error.message).toBe(
|
||||
'Expected value of header "foo" to be String, but "number" is found.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describeFailsFirefox('Page.authenticate', function() {
|
||||
it('should work', async() => {
|
||||
const {page, server} = getTestState();
|
||||
describeFailsFirefox('Page.authenticate', function () {
|
||||
it('should work', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
server.setAuth('/empty.html', 'user', 'pass');
|
||||
let response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.status()).toBe(401);
|
||||
await page.authenticate({
|
||||
username: 'user',
|
||||
password: 'pass'
|
||||
password: 'pass',
|
||||
});
|
||||
response = await page.reload();
|
||||
expect(response.status()).toBe(200);
|
||||
});
|
||||
it('should fail if wrong credentials', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should fail if wrong credentials', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
// Use unique user/password since Chrome caches credentials per origin.
|
||||
server.setAuth('/empty.html', 'user2', 'pass2');
|
||||
await page.authenticate({
|
||||
username: 'foo',
|
||||
password: 'bar'
|
||||
password: 'bar',
|
||||
});
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.status()).toBe(401);
|
||||
});
|
||||
it('should allow disable authentication', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should allow disable authentication', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
// Use unique user/password since Chrome caches credentials per origin.
|
||||
server.setAuth('/empty.html', 'user3', 'pass3');
|
||||
await page.authenticate({
|
||||
username: 'user3',
|
||||
password: 'pass3'
|
||||
password: 'pass3',
|
||||
});
|
||||
let response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.status()).toBe(200);
|
||||
@@ -508,5 +567,4 @@ describe('network', function() {
|
||||
expect(response.status()).toBe(401);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user