From b5e53fdbf4a8eda1c2b31460f21cc5a0c43fe46e Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 1 Feb 2019 18:40:40 -0800 Subject: [PATCH] test(firefox): add puppeteer-firefox unique evaluation tests (#3891) References #3889 --- .../puppeteer-firefox/test/evaluation.spec.js | 2 +- test/assets/global-var.html | 3 ++ test/evaluation.spec.js | 43 ++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/assets/global-var.html diff --git a/experimental/puppeteer-firefox/test/evaluation.spec.js b/experimental/puppeteer-firefox/test/evaluation.spec.js index 4ba61742bab7e..0a726397d9519 100644 --- a/experimental/puppeteer-firefox/test/evaluation.spec.js +++ b/experimental/puppeteer-firefox/test/evaluation.spec.js @@ -132,7 +132,7 @@ module.exports.addTests = function({testRunner, expect, product}) { await page.goto(server.PREFIX + '/global-var.html'); expect(await page.evaluate('globalVar')).toBe(123); }); - it('should use the same sandbox', async({page}) => { + it('should modify global environment', async({page}) => { await page.evaluate(() => window.globalVar = 123); expect(await page.evaluate('globalVar')).toBe(123); }); diff --git a/test/assets/global-var.html b/test/assets/global-var.html new file mode 100644 index 0000000000000..b6be975038f06 --- /dev/null +++ b/test/assets/global-var.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/test/evaluation.spec.js b/test/evaluation.spec.js index edd0707a63a93..bc2dfaea096fb 100644 --- a/test/evaluation.spec.js +++ b/test/evaluation.spec.js @@ -23,7 +23,7 @@ try { asyncawait = false; } -module.exports.addTests = function({testRunner, expect}) { +module.exports.addTests = function({testRunner, expect, FFOX}) { const {describe, xdescribe, fdescribe} = testRunner; const {it, fit, xit} = testRunner; const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; @@ -33,6 +33,41 @@ module.exports.addTests = function({testRunner, expect}) { const result = await page.evaluate(() => 7 * 3); expect(result).toBe(21); }); + it('should transfer NaN', async({page, server}) => { + const result = await page.evaluate(a => a, NaN); + expect(Object.is(result, NaN)).toBe(true); + }); + it('should transfer -0', async({page, server}) => { + const result = await page.evaluate(a => a, -0); + expect(Object.is(result, -0)).toBe(true); + }); + it('should transfer Infinity', async({page, server}) => { + const result = await page.evaluate(a => a, Infinity); + expect(Object.is(result, Infinity)).toBe(true); + }); + it('should transfer -Infinity', async({page, server}) => { + const result = await page.evaluate(a => a, -Infinity); + expect(Object.is(result, -Infinity)).toBe(true); + }); + it('should transfer arrays', async({page, server}) => { + const result = await page.evaluate(a => a, [1, 2, 3]); + expect(result).toEqual([1,2,3]); + }); + it('should transfer arrays as arrays, not objects', async({page, server}) => { + const result = await page.evaluate(a => Array.isArray(a), [1, 2, 3]); + expect(result).toBe(true); + }); + it('should modify global environment', async({page}) => { + await page.evaluate(() => window.globalVar = 123); + expect(await page.evaluate('globalVar')).toBe(123); + }); + it('should evaluate in the page context', async({page, server}) => { + await page.goto(server.PREFIX + '/global-var.html'); + expect(await page.evaluate('globalVar')).toBe(123); + }); + (FFOX ? xit : it)('should return undefined for objects with symbols', async({page, server}) => { + expect(await page.evaluate(() => [Symbol('foo4')])).toBe(undefined); + }); (asyncawait ? it : xit)('should work with function shorthands', async({page, server}) => { // trick node6 transpiler to not touch our object. // TODO(lushnikov): remove eval once Node6 is dropped. @@ -227,6 +262,12 @@ module.exports.addTests = function({testRunner, expect}) { expect(await page.frames()[0].evaluate(() => window.FOO)).toBe('foo'); expect(await page.frames()[1].evaluate(() => window.FOO)).toBe('bar'); }); + it('should have correct execution contexts', async({page, server}) => { + await page.goto(server.PREFIX + '/frames/one-frame.html'); + expect(page.frames().length).toBe(2); + expect(await page.frames()[0].evaluate(() => document.body.textContent.trim())).toBe(''); + expect(await page.frames()[1].evaluate(() => document.body.textContent.trim())).toBe(`Hi, I'm frame`); + }); it('should execute after cross-site navigation', async({page, server}) => { await page.goto(server.EMPTY_PAGE); const mainFrame = page.mainFrame();