mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 06:02:57 +03:00
feat(webkit): allow to run beforeunload when closing page (#264)
This commit is contained in:
parent
bfb8df29bb
commit
974f82073f
@ -190,9 +190,10 @@ export class Browser extends EventEmitter implements BrowserInterface {
|
|||||||
target._didClose();
|
target._didClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
_closePage(page: Page) {
|
_closePage(page: Page, runBeforeUnload: boolean) {
|
||||||
this._connection.send('Target.close', {
|
this._connection.send('Target.close', {
|
||||||
targetId: Target.fromPage(page)._targetId
|
targetId: Target.fromPage(page)._targetId,
|
||||||
|
runBeforeUnload
|
||||||
}).catch(debugError);
|
}).catch(debugError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,9 +400,7 @@ export class FrameManager implements PageDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async closePage(runBeforeUnload: boolean): Promise<void> {
|
async closePage(runBeforeUnload: boolean): Promise<void> {
|
||||||
if (runBeforeUnload)
|
(this._page.browser() as Browser)._closePage(this._page, runBeforeUnload);
|
||||||
throw new Error('Not implemented');
|
|
||||||
(this._page.browser() as Browser)._closePage(this._page);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getBoundingBoxForScreenshot(handle: dom.ElementHandle<Node>): Promise<types.Rect | null> {
|
getBoundingBoxForScreenshot(handle: dom.ElementHandle<Node>): Promise<types.Rect | null> {
|
||||||
|
@ -40,7 +40,7 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
|
|||||||
await newPage.close();
|
await newPage.close();
|
||||||
expect(await browser.pages()).not.toContain(newPage);
|
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();
|
const newPage = await context.newPage();
|
||||||
await newPage.goto(server.PREFIX + '/beforeunload.html');
|
await newPage.goto(server.PREFIX + '/beforeunload.html');
|
||||||
// We have to interact with a page so that 'beforeunload' handlers
|
// 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');
|
const dialog = await waitEvent(newPage, 'dialog');
|
||||||
expect(dialog.type()).toBe('beforeunload');
|
expect(dialog.type()).toBe('beforeunload');
|
||||||
expect(dialog.defaultValue()).toBe('');
|
expect(dialog.defaultValue()).toBe('');
|
||||||
if (CHROME || WEBKIT)
|
if (CHROME)
|
||||||
expect(dialog.message()).toBe('');
|
expect(dialog.message()).toBe('');
|
||||||
|
else if (WEBKIT)
|
||||||
|
expect(dialog.message()).toBe('Leave?');
|
||||||
else
|
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.');
|
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 dialog.accept();
|
||||||
await pageClosingPromise;
|
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();
|
const newPage = await context.newPage();
|
||||||
await newPage.goto(server.PREFIX + '/beforeunload.html');
|
await newPage.goto(server.PREFIX + '/beforeunload.html');
|
||||||
// We have to interact with a page so that 'beforeunload' handlers
|
// We have to interact with a page so that 'beforeunload' handlers
|
||||||
|
Loading…
Reference in New Issue
Block a user