/**
* Copyright 2018 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const expect = require('expect');
const {getTestState, setupTestBrowserHooks, setupTestPageAndContextHooks} = require('./mocha-utils');
const utils = require('./utils');
describe('ElementHandle specs', function() {
setupTestBrowserHooks();
setupTestPageAndContextHooks();
describeFailsFirefox('ElementHandle.boundingBox', function() {
it('should work', async() => {
const {page, server} = getTestState();
await page.setViewport({width: 500, height: 500});
await page.goto(server.PREFIX + '/grid.html');
const elementHandle = await page.$('.box:nth-of-type(13)');
const box = await elementHandle.boundingBox();
expect(box).toEqual({x: 100, y: 50, width: 50, height: 50});
});
it('should handle nested frames', async() => {
const {page, server, isChrome} = getTestState();
await page.setViewport({width: 500, height: 500});
await page.goto(server.PREFIX + '/frames/nested-frames.html');
const nestedFrame = page.frames()[1].childFrames()[1];
const elementHandle = await nestedFrame.$('div');
const box = await elementHandle.boundingBox();
if (isChrome)
expect(box).toEqual({x: 28, y: 260, width: 264, height: 18});
else
expect(box).toEqual({x: 28, y: 182, width: 254, height: 18});
});
it('should return null for invisible elements', async() => {
const {page} = getTestState();
await page.setContent('
hi
');
const element = await page.$('div');
expect(await element.boundingBox()).toBe(null);
});
it('should force a layout', async() => {
const {page} = getTestState();
await page.setViewport({width: 500, height: 500});
await page.setContent('