2020-01-31 19:54:11 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2020-04-09 01:19:09 +03:00
|
|
|
const utils = require('./utils');
|
|
|
|
const { makeUserDataDir, removeUserDataDir } = utils;
|
2020-07-17 23:02:50 +03:00
|
|
|
const {FFOX, CHROMIUM, WEBKIT, WIN, MAC} = testOptions;
|
2020-01-31 19:54:11 +03:00
|
|
|
|
2020-04-09 01:19:09 +03:00
|
|
|
describe('Headful', function() {
|
2020-04-13 08:19:26 +03:00
|
|
|
it('should have default url when launching browser', async ({browserType, defaultBrowserOptions}) => {
|
2020-04-09 01:19:09 +03:00
|
|
|
const userDataDir = await makeUserDataDir();
|
2020-04-13 08:19:26 +03:00
|
|
|
const browserContext = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, headless: false });
|
2020-04-09 01:19:09 +03:00
|
|
|
const urls = browserContext.pages().map(page => page.url());
|
|
|
|
expect(urls).toEqual(['about:blank']);
|
|
|
|
await browserContext.close();
|
|
|
|
await removeUserDataDir(userDataDir);
|
2020-01-31 19:54:11 +03:00
|
|
|
});
|
2020-04-13 08:19:26 +03:00
|
|
|
it.slow().fail(WIN && CHROMIUM)('headless should be able to read cookies written by headful', async({browserType, defaultBrowserOptions, server}) => {
|
2020-04-09 01:19:09 +03:00
|
|
|
// see https://github.com/microsoft/playwright/issues/717
|
|
|
|
const userDataDir = await makeUserDataDir();
|
|
|
|
// Write a cookie in headful chrome
|
2020-04-13 08:19:26 +03:00
|
|
|
const headfulContext = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, headless: false});
|
2020-04-09 01:19:09 +03:00
|
|
|
const headfulPage = await headfulContext.newPage();
|
|
|
|
await headfulPage.goto(server.EMPTY_PAGE);
|
|
|
|
await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
|
|
|
|
await headfulContext.close();
|
|
|
|
// Read the cookie from headless chrome
|
2020-04-13 08:19:26 +03:00
|
|
|
const headlessContext = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, headless: true});
|
2020-04-09 01:19:09 +03:00
|
|
|
const headlessPage = await headlessContext.newPage();
|
|
|
|
await headlessPage.goto(server.EMPTY_PAGE);
|
|
|
|
const cookie = await headlessPage.evaluate(() => document.cookie);
|
|
|
|
await headlessContext.close();
|
|
|
|
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
|
|
|
|
await removeUserDataDir(userDataDir);
|
|
|
|
expect(cookie).toBe('foo=true');
|
2020-01-31 19:54:11 +03:00
|
|
|
});
|
2020-04-13 08:19:26 +03:00
|
|
|
it.slow()('should close browser with beforeunload page', async({browserType, defaultBrowserOptions, server}) => {
|
2020-04-09 01:19:09 +03:00
|
|
|
const userDataDir = await makeUserDataDir();
|
2020-04-13 08:19:26 +03:00
|
|
|
const browserContext = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, headless: false});
|
2020-04-09 01:19:09 +03:00
|
|
|
const page = await browserContext.newPage();
|
|
|
|
await page.goto(server.PREFIX + '/beforeunload.html');
|
|
|
|
// We have to interact with a page so that 'beforeunload' handlers
|
|
|
|
// fire.
|
|
|
|
await page.click('body');
|
|
|
|
await browserContext.close();
|
|
|
|
await removeUserDataDir(userDataDir);
|
2020-01-31 19:54:11 +03:00
|
|
|
});
|
2020-04-29 18:44:09 +03:00
|
|
|
it('should not crash when creating second context', async ({browserType, defaultBrowserOptions, server}) => {
|
2020-04-29 00:20:33 +03:00
|
|
|
const browser = await browserType.launch({...defaultBrowserOptions, headless: false });
|
|
|
|
{
|
|
|
|
const browserContext = await browser.newContext();
|
|
|
|
const page = await browserContext.newPage();
|
|
|
|
await browserContext.close();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const browserContext = await browser.newContext();
|
|
|
|
const page = await browserContext.newPage();
|
|
|
|
await browserContext.close();
|
|
|
|
}
|
|
|
|
await browser.close();
|
|
|
|
});
|
2020-04-29 18:44:09 +03:00
|
|
|
it('should click background tab', async({browserType, defaultBrowserOptions, server}) => {
|
2020-04-28 19:48:44 +03:00
|
|
|
const browser = await browserType.launch({...defaultBrowserOptions, headless: false });
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.setContent(`<button>Hello</button><a target=_blank href="${server.EMPTY_PAGE}">empty.html</a>`);
|
|
|
|
await page.click('a');
|
|
|
|
await page.click('button');
|
|
|
|
await browser.close();
|
|
|
|
});
|
2020-07-09 03:09:42 +03:00
|
|
|
it('should close browser after context menu was triggered', async({browserType, defaultBrowserOptions, server}) => {
|
2020-07-02 10:45:02 +03:00
|
|
|
const browser = await browserType.launch({...defaultBrowserOptions, headless: false });
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
await page.click('body', {button: 'right'});
|
|
|
|
await browser.close();
|
|
|
|
});
|
2020-05-04 23:43:44 +03:00
|
|
|
it('should(not) block third party cookies', async({browserType, defaultBrowserOptions, server}) => {
|
|
|
|
const browser = await browserType.launch({...defaultBrowserOptions, headless: false });
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.evaluate(src => {
|
|
|
|
let fulfill;
|
|
|
|
const promise = new Promise(x => fulfill = x);
|
|
|
|
const iframe = document.createElement('iframe');
|
|
|
|
document.body.appendChild(iframe);
|
|
|
|
iframe.onload = fulfill;
|
|
|
|
iframe.src = src;
|
|
|
|
return promise;
|
|
|
|
}, server.CROSS_PROCESS_PREFIX + '/grid.html');
|
2020-05-23 03:20:42 +03:00
|
|
|
const documentCookie = await page.frames()[1].evaluate(() => {
|
|
|
|
document.cookie = 'username=John Doe';
|
|
|
|
return document.cookie;
|
|
|
|
});
|
2020-05-04 23:43:44 +03:00
|
|
|
await page.waitForTimeout(2000);
|
|
|
|
const allowsThirdParty = CHROMIUM || FFOX;
|
2020-05-26 20:22:53 +03:00
|
|
|
expect(documentCookie).toBe(allowsThirdParty ? 'username=John Doe' : '');
|
2020-05-04 23:43:44 +03:00
|
|
|
const cookies = await page.context().cookies(server.CROSS_PROCESS_PREFIX + '/grid.html');
|
|
|
|
if (allowsThirdParty) {
|
|
|
|
expect(cookies).toEqual([
|
|
|
|
{
|
|
|
|
"domain": "127.0.0.1",
|
|
|
|
"expires": -1,
|
|
|
|
"httpOnly": false,
|
|
|
|
"name": "username",
|
|
|
|
"path": "/",
|
|
|
|
"sameSite": "None",
|
|
|
|
"secure": false,
|
|
|
|
"value": "John Doe"
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
expect(cookies).toEqual([]);
|
|
|
|
}
|
|
|
|
await browser.close();
|
|
|
|
});
|
2020-05-13 04:31:17 +03:00
|
|
|
it.fail(WEBKIT)('should not override viewport size when passed null', async function({browserType, defaultBrowserOptions, server}) {
|
|
|
|
// Our WebKit embedder does not respect window features.
|
|
|
|
const browser = await browserType.launch({...defaultBrowserOptions, headless: false });
|
|
|
|
const context = await browser.newContext({ viewport: null });
|
|
|
|
const page = await context.newPage();
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
const [popup] = await Promise.all([
|
|
|
|
page.waitForEvent('popup'),
|
|
|
|
page.evaluate(() => {
|
2020-05-20 02:27:28 +03:00
|
|
|
const win = window.open(window.location.href, 'Title', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=300,top=0,left=0');
|
2020-05-13 04:31:17 +03:00
|
|
|
win.resizeTo(500, 450);
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
await popup.waitForLoadState();
|
2020-05-20 02:27:28 +03:00
|
|
|
await popup.waitForFunction(() => window.outerWidth === 500 && window.outerHeight === 450);
|
2020-05-13 04:31:17 +03:00
|
|
|
await context.close();
|
2020-07-17 23:02:50 +03:00
|
|
|
await browser.close();
|
2020-05-13 04:31:17 +03:00
|
|
|
});
|
2020-04-09 01:19:09 +03:00
|
|
|
});
|