From eded38c82a5f2ff1742958549b782cc974b80405 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 26 Apr 2018 13:32:23 -0700 Subject: [PATCH] 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. --- test/network.spec.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/network.spec.js b/test/network.spec.js index 45b7557e4b9..08e0a2672c2 100644 --- a/test/network.spec.js +++ b/test/network.spec.js @@ -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; +}