Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle negative area results in computeQuadArea #3413

Merged
merged 5 commits into from Oct 25, 2018

Conversation

zeevrosental
Copy link
Contributor

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 } ] received area size of -676.

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.
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.
@zeevrosental zeevrosental changed the title fix(computeQuadArea): handle negative area results in computeQuadArea fix: handle negative area results in computeQuadArea Oct 15, 2018
@JoelEinbinder
Copy link
Collaborator

Thanks for the PR! Do you have a test case that covers this?

@zeevrosental
Copy link
Contributor Author

My pleasure :-)

There's no problem of creating a test case for this fix.

From what I see it has to depend only on the computeQuadArea function in order to be hermetic.
Because, if the test will depend on DOM.getContentQuads(which is the normal flow), we wouldn't know if it passes because of this fix, or because of a change in the quad order returning from getContentQuads.

Do you write tests in your package that test a single function?
What do you think should be added?

@JoelEinbinder
Copy link
Collaborator

A test for this would set up some html/css to produce quads in the right order. Then it would call elementHandle.click on the element with the strange quads, and verify that it indeed was clicked. You can find similar tests in input.spec.js

@zeevrosental
Copy link
Contributor Author

zeevrosental commented Oct 16, 2018

that's what I thought,

I was concerned that an element like that might stop producing strange quads order in future versions of chromium(because of possible change in DOM.getContentQuads),
which will cause my test not to be hermetic in the long run.

anyway, i'll create a test for this case and add it.
thanks!

added a test for the fix in computeQuadArea.
A rotated element causes the quads to be returned in a different order and to receive a negative area in previous computeQuadArea.
@zeevrosental
Copy link
Contributor Author

Hi, added a test case to the PR.
It seems the node8(macOS) coverage has failed, anything I can do concerning that?

Copy link
Contributor

@aslushnikov aslushnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, thanks!

@aslushnikov aslushnikov merged commit 81edbbb into puppeteer:master Oct 25, 2018
@zeevrosental
Copy link
Contributor Author

My pleasure,

Thanks!

@zeevrosental zeevrosental deleted the fix-computeQuadArea branch October 25, 2018 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants