WebKit should disallow beforeunload alerts from web pages users have never interacted...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Mar 2017 21:14:23 +0000 (21:14 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Mar 2017 21:14:23 +0000 (21:14 +0000)
commitc5eb447432d08c497cac62fd580a5ba02fdf9898
treebf4e580887cb676db6c00018945c0412cf4a9f9e
parentcf590d890587f9d1a9bb491c6d0ed49cf3408d42
WebKit should disallow beforeunload alerts from web pages users have never interacted with
https://bugs.webkit.org/show_bug.cgi?id=169936
<rdar://problem/23798897>

Reviewed by Brent Fulgham.

LayoutTests/imported/w3c:

* web-platform-tests/html/browsers/browsing-the-web/unloading-documents/beforeunload-canceling-expected.txt:
* web-platform-tests/html/webappapis/scripting/events/compile-event-handler-settings-objects-expected.txt:
Rebaseline now that the CONFIRM MESSAGE lines are now longer shown. This is because there is no user interaction
with the page.

Source/WebCore:

WebKit should disallow beforeunload alerts from web pages users have never interacted with.
This reduces the risk of annoyance to the user and is allowed by the specification:
- https://html.spec.whatwg.org/multipage/browsers.html#prompt-to-unload-a-document (Step 8):
which says:
"""
The user agent is encouraged to avoid asking the user for confirmation if it judges that doing
so would be annoying, deceptive, or pointless. A simple heuristic might be that if the user
has not interacted with the document, the user agent would not ask for confirmation before
unloading it.
"""

Firefox already implements this, Chrome does not.

Tests: fast/events/beforeunload-alert-no-user-interaction.html
       fast/events/beforeunload-alert-user-interaction.html
       fast/events/beforeunload-alert-user-interaction2.html

* loader/FrameLoader.cpp:
(WebCore::shouldAskForNavigationConfirmation):
(WebCore::FrameLoader::dispatchBeforeUnloadEvent):

LayoutTests:

* fast/events/before-unload-return-string-conversion-expected.txt:
* fast/events/before-unload-returnValue-expected.txt:
Rebaseline now that the CONFIRM MESSAGE is no longer shown. This is because there is
no user interaction with the page.

* fast/events/beforeunload-alert-no-user-interaction-expected.txt: Added.
* fast/events/beforeunload-alert-no-user-interaction.html: Added.
* fast/events/beforeunload-alert-user-interaction-expected.txt: Added.
* fast/events/beforeunload-alert-user-interaction.html: Added.
* fast/events/beforeunload-alert-user-interaction2-expected.txt: Added.
* fast/events/beforeunload-alert-user-interaction2.html: Added.
Add layout test coverage.

* fast/loader/form-submission-after-beforeunload-cancel.html:
* fast/loader/show-only-one-beforeunload-dialog.html:
* http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin.html:
* http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin.html:
Simulate user interaction with the page so that the CONFIRM MESSAGE log lines are still
shown.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214277 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/before-unload-return-string-conversion-expected.txt
LayoutTests/fast/events/before-unload-returnValue-expected.txt
LayoutTests/fast/events/beforeunload-alert-no-user-interaction-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-alert-no-user-interaction.html [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-alert-user-interaction-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-alert-user-interaction.html [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-alert-user-interaction2-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/beforeunload-alert-user-interaction2.html [new file with mode: 0644]
LayoutTests/fast/loader/form-submission-after-beforeunload-cancel.html
LayoutTests/fast/loader/show-only-one-beforeunload-dialog.html
LayoutTests/http/tests/misc/iframe-beforeunload-dialog-matching-ancestor-securityorigin.html
LayoutTests/http/tests/misc/iframe-beforeunload-dialog-not-matching-ancestor-securityorigin.html
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/browsers/browsing-the-web/unloading-documents/beforeunload-canceling-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/events/compile-event-handler-settings-objects-expected.txt
LayoutTests/platform/ios-simulator/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/loader/FrameLoader.cpp