feat(webkit): allow to run beforeunload when closing page (#264)

This commit is contained in:
Yury Semikhatsky 2019-12-16 18:33:36 -07:00 committed by Andrey Lushnikov
parent bfb8df29bb
commit 974f82073f
3 changed files with 9 additions and 8 deletions

View File

@ -190,9 +190,10 @@ export class Browser extends EventEmitter implements BrowserInterface {
target._didClose();
}
_closePage(page: Page) {
_closePage(page: Page, runBeforeUnload: boolean) {
this._connection.send('Target.close', {
targetId: Target.fromPage(page)._targetId
targetId: Target.fromPage(page)._targetId,
runBeforeUnload
}).catch(debugError);
}

View File

@ -400,9 +400,7 @@ export class FrameManager implements PageDelegate {
}
async closePage(runBeforeUnload: boolean): Promise<void> {
if (runBeforeUnload)
throw new Error('Not implemented');
(this._page.browser() as Browser)._closePage(this._page);
(this._page.browser() as Browser)._closePage(this._page, runBeforeUnload);
}
getBoundingBoxForScreenshot(handle: dom.ElementHandle<Node>): Promise<types.Rect | null> {

View File

@ -40,7 +40,7 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
await newPage.close();
expect(await browser.pages()).not.toContain(newPage);
});
it.skip(WEBKIT)('should run beforeunload if asked for', async({context, server}) => {
it('should run beforeunload if asked for', async({context, server}) => {
const newPage = await context.newPage();
await newPage.goto(server.PREFIX + '/beforeunload.html');
// We have to interact with a page so that 'beforeunload' handlers
@ -50,14 +50,16 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
const dialog = await waitEvent(newPage, 'dialog');
expect(dialog.type()).toBe('beforeunload');
expect(dialog.defaultValue()).toBe('');
if (CHROME || WEBKIT)
if (CHROME)
expect(dialog.message()).toBe('');
else if (WEBKIT)
expect(dialog.message()).toBe('Leave?');
else
expect(dialog.message()).toBe('This page is asking you to confirm that you want to leave - data you have entered may not be saved.');
await dialog.accept();
await pageClosingPromise;
});
it.skip(WEBKIT)('should *not* run beforeunload by default', async({context, server}) => {
it('should *not* run beforeunload by default', async({context, server}) => {
const newPage = await context.newPage();
await newPage.goto(server.PREFIX + '/beforeunload.html');
// We have to interact with a page so that 'beforeunload' handlers