2020-08-04 01:23:53 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2021-04-03 00:23:42 +03:00
|
|
|
import { test as it, expect } from './config/pageTest';
|
2021-04-06 01:51:45 +03:00
|
|
|
import { attachFrame } from './config/utils';
|
2020-08-04 01:23:53 +03:00
|
|
|
|
|
|
|
it('should work', async ({ page, server }) => {
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2020-09-19 01:52:14 +03:00
|
|
|
await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
2020-08-04 01:23:53 +03:00
|
|
|
const frame = page.frames()[1];
|
|
|
|
const elementHandle = await frame.evaluateHandle(() => document.body);
|
|
|
|
expect(await elementHandle.ownerFrame()).toBe(frame);
|
|
|
|
});
|
2020-08-05 21:43:40 +03:00
|
|
|
|
2020-08-04 01:23:53 +03:00
|
|
|
it('should work for cross-process iframes', async ({ page, server }) => {
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2020-09-19 01:52:14 +03:00
|
|
|
await attachFrame(page, 'frame1', server.CROSS_PROCESS_PREFIX + '/empty.html');
|
2020-08-04 01:23:53 +03:00
|
|
|
const frame = page.frames()[1];
|
|
|
|
const elementHandle = await frame.evaluateHandle(() => document.body);
|
|
|
|
expect(await elementHandle.ownerFrame()).toBe(frame);
|
|
|
|
});
|
2020-08-05 21:43:40 +03:00
|
|
|
|
2021-01-23 02:22:40 +03:00
|
|
|
it('should work for document', async ({ page, server }) => {
|
2020-08-04 01:23:53 +03:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2020-09-19 01:52:14 +03:00
|
|
|
await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
2020-08-04 01:23:53 +03:00
|
|
|
const frame = page.frames()[1];
|
|
|
|
const elementHandle = await frame.evaluateHandle(() => document);
|
|
|
|
expect(await elementHandle.ownerFrame()).toBe(frame);
|
|
|
|
});
|
2020-08-05 21:43:40 +03:00
|
|
|
|
2020-08-04 01:23:53 +03:00
|
|
|
it('should work for iframe elements', async ({ page, server }) => {
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2020-09-19 01:52:14 +03:00
|
|
|
await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
2020-08-04 01:23:53 +03:00
|
|
|
const frame = page.mainFrame();
|
|
|
|
const elementHandle = await frame.evaluateHandle(() => document.querySelector('#frame1'));
|
|
|
|
expect(await elementHandle.ownerFrame()).toBe(frame);
|
|
|
|
});
|
2020-08-05 21:43:40 +03:00
|
|
|
|
2020-08-04 01:23:53 +03:00
|
|
|
it('should work for cross-frame evaluations', async ({ page, server }) => {
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2020-09-19 01:52:14 +03:00
|
|
|
await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
2020-08-04 01:23:53 +03:00
|
|
|
const frame = page.mainFrame();
|
2020-08-12 01:50:53 +03:00
|
|
|
const elementHandle = await frame.evaluateHandle(() => document.querySelector('iframe').contentWindow.document.body);
|
2020-08-04 01:23:53 +03:00
|
|
|
expect(await elementHandle.ownerFrame()).toBe(frame.childFrames()[0]);
|
|
|
|
});
|
2020-08-05 21:43:40 +03:00
|
|
|
|
2020-08-04 01:23:53 +03:00
|
|
|
it('should work for detached elements', async ({ page, server }) => {
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
const divHandle = await page.evaluateHandle(() => {
|
|
|
|
const div = document.createElement('div');
|
|
|
|
document.body.appendChild(div);
|
|
|
|
return div;
|
|
|
|
});
|
|
|
|
expect(await divHandle.ownerFrame()).toBe(page.mainFrame());
|
|
|
|
await page.evaluate(() => {
|
|
|
|
const div = document.querySelector('div');
|
|
|
|
document.body.removeChild(div);
|
|
|
|
});
|
|
|
|
expect(await divHandle.ownerFrame()).toBe(page.mainFrame());
|
|
|
|
});
|
2020-08-05 21:43:40 +03:00
|
|
|
|
2021-04-09 17:59:09 +03:00
|
|
|
it('should work for adopted elements', async ({ page, server, isElectron }) => {
|
|
|
|
it.fixme(isElectron);
|
2021-04-08 20:26:26 +03:00
|
|
|
|
2020-08-04 01:23:53 +03:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
const [popup] = await Promise.all([
|
|
|
|
page.waitForEvent('popup'),
|
2020-08-28 14:20:29 +03:00
|
|
|
page.evaluate(url => window['__popup'] = window.open(url), server.EMPTY_PAGE),
|
2020-08-04 01:23:53 +03:00
|
|
|
]);
|
|
|
|
const divHandle = await page.evaluateHandle(() => {
|
|
|
|
const div = document.createElement('div');
|
|
|
|
document.body.appendChild(div);
|
|
|
|
return div;
|
|
|
|
});
|
|
|
|
expect(await divHandle.ownerFrame()).toBe(page.mainFrame());
|
|
|
|
await popup.waitForLoadState('domcontentloaded');
|
|
|
|
await page.evaluate(() => {
|
|
|
|
const div = document.querySelector('div');
|
2020-08-28 14:20:29 +03:00
|
|
|
window['__popup'].document.body.appendChild(div);
|
2020-08-04 01:23:53 +03:00
|
|
|
});
|
|
|
|
expect(await divHandle.ownerFrame()).toBe(popup.mainFrame());
|
|
|
|
});
|