forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
headless: do not close WebContents if beforeunload was dismissed
Currently, headless can dismiss beforeunload dialogs, but the target page will still proceed to close since default implementation in content/ disregards BeforeUnload results: https://source.chromium.org/chromium/chromium/src/+/master:content/public/browser/web_contents_delegate.cc;l=64?q=BeforeUnloadFired%20f:content&ss=chromium%2Fchromium%2Fsrc This patch changes this. Change-Id: I2c1a04dde390dbb90ac8c547187405fa513d0723 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2516217 Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org> Reviewed-by: Andrey Kosyakov <caseq@chromium.org> Cr-Commit-Position: refs/heads/master@{#823751}
- Loading branch information
1 parent
7007308
commit 82064ac
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
headless/test/data/protocol/page/page-before-unload-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Tests beforeunload dialog. | ||
beforeunload | ||
beforeunload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
(async function(testRunner) { | ||
const {page, session, dp} = await testRunner.startBlank( | ||
`Tests beforeunload dialog.`); | ||
|
||
await dp.Page.enable(); | ||
dp.Page.navigate({url: testRunner.url('/resources/beforeunload.html')}); | ||
await dp.Page.onceLoadEventFired(); | ||
|
||
// Click to activate beforeunload handling. | ||
await dp.Input.dispatchMouseEvent({ | ||
type: 'mousePressed', | ||
button: 'left', | ||
buttons: 0, | ||
clickCount: 1, | ||
x: 1, | ||
y: 1, | ||
}); | ||
await dp.Input.dispatchMouseEvent({ | ||
type: 'mouseReleased', | ||
button: 'left', | ||
buttons: 0, | ||
clickCount: 1, | ||
x: 1, | ||
y: 1, | ||
}); | ||
|
||
// Try closing first time. | ||
dp.Page.close(); | ||
const dialog = await dp.Page.onceJavascriptDialogOpening(); | ||
|
||
testRunner.log(dialog.params.type); | ||
|
||
dp.Page.handleJavaScriptDialog({ accept: false, }); | ||
await dp.Page.javascriptDialogClosed(); | ||
|
||
// Try closing second time. This will make sure that | ||
// the page didn't close after the first beforeunload dialog | ||
// was canceled. | ||
dp.Page.close(); | ||
const dialog2 = await dp.Page.onceJavascriptDialogOpening(); | ||
testRunner.log(dialog2.params.type); | ||
await dp.Page.handleJavaScriptDialog({ accept: true, }), | ||
|
||
testRunner.completeTest(); | ||
}) |
12 changes: 12 additions & 0 deletions
12
headless/test/data/protocol/page/resources/beforeunload.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
</body> | ||
<script> | ||
window.onbeforeunload=function(e){ | ||
return 'foo'; | ||
} | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters