2020-08-05 01:09:24 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2017 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.
|
|
|
|
*/
|
|
|
|
|
2020-08-20 07:32:12 +03:00
|
|
|
import { options } from './playwright.fixtures';
|
2020-08-05 01:09:24 +03:00
|
|
|
|
2020-08-20 22:51:05 +03:00
|
|
|
const CRASH_FAIL = (options.FIREFOX && WIN) || options.WIRE;
|
2020-08-05 01:09:24 +03:00
|
|
|
// Firefox Win: it just doesn't crash sometimes.
|
2020-08-18 22:48:32 +03:00
|
|
|
function crash(pageImpl, browserName) {
|
|
|
|
if (browserName === 'chromium')
|
2020-08-15 04:25:32 +03:00
|
|
|
pageImpl.mainFrame().goto('chrome://crash').catch(e => {});
|
2020-08-18 22:48:32 +03:00
|
|
|
else if (browserName === 'webkit')
|
2020-08-05 01:09:24 +03:00
|
|
|
pageImpl._delegate._session.send('Page.crash', {}).catch(e => {});
|
2020-08-18 22:48:32 +03:00
|
|
|
else if (browserName === 'firefox')
|
2020-08-05 01:09:24 +03:00
|
|
|
pageImpl._delegate._session.send('Page.crash', {}).catch(e => {});
|
|
|
|
}
|
|
|
|
|
2020-08-18 22:48:32 +03:00
|
|
|
it.fail(CRASH_FAIL)('should emit crash event when page crashes', async({page, browserName, toImpl}) => {
|
2020-08-05 01:09:24 +03:00
|
|
|
await page.setContent(`<div>This page should crash</div>`);
|
2020-08-18 22:48:32 +03:00
|
|
|
crash(toImpl(page), browserName);
|
2020-08-05 01:09:24 +03:00
|
|
|
await new Promise(f => page.on('crash', f));
|
|
|
|
});
|
|
|
|
|
2020-08-18 22:48:32 +03:00
|
|
|
it.fail(CRASH_FAIL)('should throw on any action after page crashes', async({page, browserName, toImpl}) => {
|
2020-08-05 01:09:24 +03:00
|
|
|
await page.setContent(`<div>This page should crash</div>`);
|
2020-08-18 22:48:32 +03:00
|
|
|
crash(toImpl(page), browserName);
|
2020-08-05 01:09:24 +03:00
|
|
|
await page.waitForEvent('crash');
|
|
|
|
const err = await page.evaluate(() => {}).then(() => null, e => e);
|
|
|
|
expect(err).toBeTruthy();
|
|
|
|
expect(err.message).toContain('crash');
|
|
|
|
});
|
|
|
|
|
2020-08-18 22:48:32 +03:00
|
|
|
it.fail(CRASH_FAIL)('should cancel waitForEvent when page crashes', async({page, browserName, toImpl}) => {
|
2020-08-05 01:09:24 +03:00
|
|
|
await page.setContent(`<div>This page should crash</div>`);
|
|
|
|
const promise = page.waitForEvent('response').catch(e => e);
|
2020-08-18 22:48:32 +03:00
|
|
|
crash(toImpl(page), browserName);
|
2020-08-05 01:09:24 +03:00
|
|
|
const error = await promise;
|
|
|
|
expect(error.message).toContain('Page crashed');
|
|
|
|
});
|
|
|
|
|
2020-08-18 22:48:32 +03:00
|
|
|
it.fail(CRASH_FAIL)('should cancel navigation when page crashes', async({page, browserName, toImpl, server}) => {
|
2020-08-05 01:09:24 +03:00
|
|
|
await page.setContent(`<div>This page should crash</div>`);
|
|
|
|
server.setRoute('/one-style.css', () => {});
|
|
|
|
const promise = page.goto(server.PREFIX + '/one-style.html').catch(e => e);
|
|
|
|
await page.waitForNavigation({ waitUntil: 'domcontentloaded' });
|
2020-08-18 22:48:32 +03:00
|
|
|
crash(toImpl(page), browserName);
|
2020-08-05 01:09:24 +03:00
|
|
|
const error = await promise;
|
|
|
|
expect(error.message).toContain('Navigation failed because page crashed');
|
|
|
|
});
|
|
|
|
|
2020-08-18 22:48:32 +03:00
|
|
|
it.fail(CRASH_FAIL)('should be able to close context when page crashes', async({page, browserName, toImpl}) => {
|
2020-08-05 01:09:24 +03:00
|
|
|
await page.setContent(`<div>This page should crash</div>`);
|
2020-08-18 22:48:32 +03:00
|
|
|
crash(toImpl(page), browserName);
|
2020-08-05 01:09:24 +03:00
|
|
|
await page.waitForEvent('crash');
|
|
|
|
await page.context().close();
|
|
|
|
});
|