From 83833f61c102cc81ad6a60c22dcfdf9676001b75 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 17 Dec 2019 18:19:35 -0700 Subject: [PATCH] feat(webkit): support referrer parameter in Page.navigate (#286) * add test for reference-policy: no-referrer --- package.json | 2 +- src/webkit/FrameManager.ts | 2 +- test/navigation.spec.js | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8ea026706c..ab95dfc835 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "playwright": { "chromium_revision": "724623", "firefox_revision": "1007", - "webkit_revision": "1043" + "webkit_revision": "1044" }, "scripts": { "unit": "node test/test.js", diff --git a/src/webkit/FrameManager.ts b/src/webkit/FrameManager.ts index bd41857616..dc07807fe4 100644 --- a/src/webkit/FrameManager.ts +++ b/src/webkit/FrameManager.ts @@ -190,7 +190,7 @@ export class FrameManager implements PageDelegate { } async navigateFrame(frame: frames.Frame, url: string, referrer: string | undefined): Promise { - await this._session.send('Page.navigate', { url, frameId: frame._id }); + await this._session.send('Page.navigate', { url, frameId: frame._id, referrer }); return {}; // We cannot get loaderId of cross-process navigation in advance. } diff --git a/test/navigation.spec.js b/test/navigation.spec.js index a1f0cfe1ca..37f2b76eb2 100644 --- a/test/navigation.spec.js +++ b/test/navigation.spec.js @@ -416,7 +416,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME } expect(error.message).toContain(url); }); - it.skip(WEBKIT)('should send referer', async({page, server}) => { + it('should send referer', async({page, server}) => { const [request1, request2] = await Promise.all([ server.waitForRequest('/grid.html'), server.waitForRequest('/digits/1.png'), @@ -429,6 +429,37 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME expect(request2.headers['referer']).toBe(server.PREFIX + '/grid.html'); expect(page.url()).toBe(server.PREFIX + '/grid.html'); }); + it('should use referer option when setExtraHTTPHeaders provides referer', async({page, server}) => { + await page.setExtraHTTPHeaders({ 'referer': 'http://microsoft.com/' }); + const [request1, request2] = await Promise.all([ + server.waitForRequest('/grid.html'), + server.waitForRequest('/digits/1.png'), + page.goto(server.PREFIX + '/grid.html', { + referer: 'http://google.com/', + }), + ]); + expect(request1.headers['referer']).toBe('http://google.com/'); + // Make sure subresources use referer specified by setExtraHTTPHeaders. + expect(request2.headers['referer']).toBe('http://microsoft.com/'); + expect(page.url()).toBe(server.PREFIX + '/grid.html'); + }); + it('should override referrer-policy', async({page, server}) => { + server.setRoute('/grid.html', (req, res) => { + res.setHeader('Referrer-Policy', 'no-referrer'); + server.serveFile(req, res, '/grid.html'); + }); + const [request1, request2] = await Promise.all([ + server.waitForRequest('/grid.html'), + server.waitForRequest('/digits/1.png'), + page.goto(server.PREFIX + '/grid.html', { + referer: 'http://microsoft.com/', + }), + ]); + expect(request1.headers['referer']).toBe('http://microsoft.com/'); + // Make sure subresources do not inherit referer. + expect(request2.headers['referer']).toBe(undefined); + expect(page.url()).toBe(server.PREFIX + '/grid.html'); + }); }); describe('Page.waitForNavigation', function() {