From f08f33458ffc13d00a0e69236e746ccf52154682 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 3 Nov 2017 00:02:41 -0700 Subject: [PATCH] test: validate headless reading cookies written by headful (#1266) This test ensures that Chrome Headless can successfully read cookies written by Chrome Headful. References #921 --- .travis.yml | 4 ++++ test/test.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/.travis.yml b/.travis.yml index 130bcf26889..2efff4d6633 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,10 @@ cache: yarn: true directories: - node_modules +# allow headful tests +before_install: + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" install: - yarn install # puppeteer's install script downloads Chrome diff --git a/test/test.js b/test/test.js index 61c1bc60fcd..14468c910c5 100644 --- a/test/test.js +++ b/test/test.js @@ -165,6 +165,26 @@ describe('Puppeteer', function() { await browser2.close(); rm(userDataDir); })); + xit('headless should be able to read cookies written by headful', SX(async function() { + const userDataDir = fs.mkdtempSync(path.join(__dirname, 'test-user-data-dir')); + const options = Object.assign({userDataDir}, defaultBrowserOptions); + // Write a cookie in headful chrome + options.headless = false; + const headfulBrowser = await puppeteer.launch(options); + const headfulPage = await headfulBrowser.newPage(); + await headfulPage.goto(EMPTY_PAGE); + await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT'); + await headfulBrowser.close(); + // Read the cookie from headless chrome + options.headless = true; + const headlessBrowser = await puppeteer.launch(options); + const headlessPage = await headlessBrowser.newPage(); + await headlessPage.goto(EMPTY_PAGE); + const cookie = await headlessPage.evaluate(() => document.cookie); + await headlessBrowser.close(); + rm(userDataDir); + expect(cookie).toBe('foo=true'); + })); }); describe('Puppeteer.connect', function() { it('should be able to connect multiple times to the same browser', SX(async function() {