From fb710120e941c051964214e4bc6a0c4857dec67a Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 22 Jan 2019 23:24:14 -0500 Subject: [PATCH] feat(page): use secondary world to drive clicks (#3828) References #2671 --- lib/FrameManager.js | 14 +++++++------- test/click.spec.js | 6 ++++++ test/mouse.spec.js | 6 ++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/FrameManager.js b/lib/FrameManager.js index a5c72ae0..1f5d967e 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -472,7 +472,7 @@ class Frame { * @return {!Promise} */ async content() { - return this._mainWorld.content(); + return this._secondaryWorld.content(); } /** @@ -480,7 +480,7 @@ class Frame { * @param {!{timeout?: number, waitUntil?: string|!Array}=} options */ async setContent(html, options = {}) { - return this._mainWorld.setContent(html, options); + return this._secondaryWorld.setContent(html, options); } /** @@ -539,21 +539,21 @@ class Frame { * @param {!{delay?: number, button?: "left"|"right"|"middle", clickCount?: number}=} options */ async click(selector, options) { - return this._mainWorld.click(selector, options); + return this._secondaryWorld.click(selector, options); } /** * @param {string} selector */ async focus(selector) { - return this._mainWorld.focus(selector); + return this._secondaryWorld.focus(selector); } /** * @param {string} selector */ async hover(selector) { - return this._mainWorld.hover(selector); + return this._secondaryWorld.hover(selector); } /** @@ -569,7 +569,7 @@ class Frame { * @param {string} selector */ async tap(selector) { - return this._mainWorld.tap(selector); + return this._secondaryWorld.tap(selector); } /** @@ -634,7 +634,7 @@ class Frame { * @return {!Promise} */ async title() { - return this._mainWorld.title(); + return this._secondaryWorld.title(); } /** diff --git a/test/click.spec.js b/test/click.spec.js index 061a8089..945e068b 100644 --- a/test/click.spec.js +++ b/test/click.spec.js @@ -28,6 +28,12 @@ module.exports.addTests = function({testRunner, expect}) { await page.click('button'); expect(await page.evaluate(() => result)).toBe('Clicked'); }); + it('should click the button if window.Node is removed', async({page, server}) => { + await page.goto(server.PREFIX + '/input/button.html'); + await page.evaluate(() => delete window.Node); + await page.click('button'); + expect(await page.evaluate(() => result)).toBe('Clicked'); + }); it('should click the button after navigation ', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); await page.click('button'); diff --git a/test/mouse.spec.js b/test/mouse.spec.js index d16c3178..018b0857 100644 --- a/test/mouse.spec.js +++ b/test/mouse.spec.js @@ -64,6 +64,12 @@ module.exports.addTests = function({testRunner, expect}) { await page.hover('#button-91'); expect(await page.evaluate(() => document.querySelector('button:hover').id)).toBe('button-91'); }); + it('should trigger hover state with removed window.Node', async({page, server}) => { + await page.goto(server.PREFIX + '/input/scrollable.html'); + await page.evaluate(() => delete window.Node); + await page.hover('#button-6'); + expect(await page.evaluate(() => document.querySelector('button:hover').id)).toBe('button-6'); + }); it('should set modifier keys on click', async({page, server}) => { await page.goto(server.PREFIX + '/input/scrollable.html'); await page.evaluate(() => document.querySelector('#button-3').addEventListener('mousedown', e => window.lastEvent = e, true));