test: fix element.handle nested frames

This commit is contained in:
Pavel 2019-12-06 15:10:30 -08:00
parent e727ee0c81
commit b45ea22660
5 changed files with 20 additions and 13 deletions

View File

@ -275,17 +275,17 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
point.y += border.y;
}
const metrics = await this._world.delegate.layoutViewport();
// Give 6 (six) extra pixels to avoid any issues on viewport edge.
// Give 15 extra pixels to avoid any issues on viewport edge.
let scrollX = 0;
if (point.x < 6)
scrollX = point.x - 6;
if (point.x > metrics.width - 6)
scrollX = point.x - metrics.width + 6;
if (point.x < 15)
scrollX = point.x - 15;
if (point.x > metrics.width - 15)
scrollX = point.x - metrics.width + 15;
let scrollY = 0;
if (point.y < 6)
scrollY = point.y - 6;
if (point.y > metrics.height - 6)
scrollY = point.y - metrics.height + 6;
if (point.y < 15)
scrollY = point.y - 15;
if (point.y > metrics.height - 15)
scrollY = point.y - metrics.height + 15;
return { point, scrollX, scrollY };
}

View File

@ -2,8 +2,11 @@
<script src='./script.js' type='text/javascript'></script>
<style>
body {
height: 100;
height: 100px;
margin: 8px;
border: 0;
background-color: #555;
}
div {
line-height: 18px;

View File

@ -1,14 +1,17 @@
<style>
body {
display: flex;
height: 100%;
height: 500px;
margin: 8px;
}
body iframe {
flex-grow: 1;
flex-shrink: 1;
border: 0;
background-color: green;
}
::-webkit-scrollbar{
display: none;
}

View File

@ -2,13 +2,14 @@
body {
display: flex;
flex-direction: column;
height: 100%;
height: 400px;
margin: 8px;
}
body iframe {
flex-grow: 1;
flex-shrink: 1;
border: 0;
}
</style>
<iframe src='./frame.html' name='uno'></iframe>

View File

@ -35,7 +35,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
const nestedFrame = page.frames().find(frame => frame.name() === 'dos');
const elementHandle = await nestedFrame.$('div');
const box = await elementHandle.boundingBox();
expect(box).toEqual({ x: 28, y: 276, width: 264, height: 18 });
expect(box).toEqual({ x: 24, y: 224, width: 268, height: 18 });
});
it('should return null for invisible elements', async({page, server}) => {
await page.setContent('<div style="display:none">hi</div>');