From 81edbbb58e5b572a9317928b9ca90efd8259f87a Mon Sep 17 00:00:00 2001 From: Zeev Rosental Date: Thu, 25 Oct 2018 21:41:37 +0300 Subject: [PATCH] fix(clicking): handle negative area results in computeQuadArea (#3413) This patch fixes a case in which computeQuadArea calculates the area size correctly, but returns the area as a negative number. This occurs when DOM.getContentQuads returns quads in a specific order. E.g. the array: [ { x: 463, y: 68.5 },{ x: 437, y: 68.5 },{ x: 437, y: 94.5 },{ x: 463, y: 94.5 } ] will receive area size of -676. --- lib/ExecutionContext.js | 2 +- test/assets/input/rotatedButton.html | 21 +++++++++++++++++++++ test/input.spec.js | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/assets/input/rotatedButton.html diff --git a/lib/ExecutionContext.js b/lib/ExecutionContext.js index c2460bc488a..25ed67e1a4b 100644 --- a/lib/ExecutionContext.js +++ b/lib/ExecutionContext.js @@ -626,7 +626,7 @@ function computeQuadArea(quad) { const p2 = quad[(i + 1) % quad.length]; area += (p1.x * p2.y - p2.x * p1.y) / 2; } - return area; + return Math.abs(area); } helper.tracePublicAPI(ElementHandle); diff --git a/test/assets/input/rotatedButton.html b/test/assets/input/rotatedButton.html new file mode 100644 index 00000000000..1bce66cf5e2 --- /dev/null +++ b/test/assets/input/rotatedButton.html @@ -0,0 +1,21 @@ + + + + Rotated button test + + + + + + + + diff --git a/test/input.spec.js b/test/input.spec.js index 5a583e00c2e..dda263b6116 100644 --- a/test/input.spec.js +++ b/test/input.spec.js @@ -312,6 +312,11 @@ module.exports.addTests = function({testRunner, expect}) { await page.click('button'); expect(await page.evaluate(() => window.result)).toBe('Clicked'); }); + it('should click a rotated button', async({page, server}) => { + await page.goto(server.PREFIX + '/input/rotatedButton.html'); + await page.click('button'); + expect(await page.evaluate(() => result)).toBe('Clicked'); + }); it('should select the text with mouse', async({page, server}) => { await page.goto(server.PREFIX + '/input/textarea.html'); await page.focus('textarea');