test: verify file url interception works as expected (#2451)

This was fixed upstream: https://crrev.com/550319
Rolled into pptr: https://github.com/GoogleChrome/puppeteer/pull/2393

Fixes #1506.
This commit is contained in:
Andrey Lushnikov 2018-04-26 13:32:23 -07:00 committed by GitHub
parent 8a62b10fd0
commit eded38c82a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -459,6 +459,18 @@ module.exports.addTests = function({testRunner, expect}) {
await page.goto(server.EMPTY_PAGE);
expect(error.message).toContain('Request Interception is not enabled');
});
it('should work with file URLs', async({page, server}) => {
await page.setRequestInterception(true);
const urls = new Set();
page.on('request', request => {
urls.add(request.url().split('/').pop());
request.continue();
});
await page.goto(pathToFileURL(path.join(__dirname, 'assets', 'one-style.html')));
expect(urls.size).toBe(2);
expect(urls.has('one-style.html')).toBe(true);
expect(urls.has('one-style.css')).toBe(true);
});
});
describe('Request.respond', function() {
@ -573,5 +585,16 @@ module.exports.addTests = function({testRunner, expect}) {
expect(response.status()).toBe(401);
});
});
};
/**
* @param {string} path
* @return {string}
*/
function pathToFileURL(path) {
let pathName = path.replace(/\\/g, '/');
// Windows drive letter must be prefixed with a slash.
if (!pathName.startsWith('/'))
pathName = '/' + pathName;
return 'file://' + pathName;
}