REGRESSION(r211643): Dismissing WKActionSheet should not also dismiss its presenting...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Mar 2018 19:25:19 +0000 (19:25 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Mar 2018 19:25:19 +0000 (19:25 +0000)
commita6fc25b5217f7419e473138f96cc8d29b1326c87
tree0b7f27a05202bbf2c9ec3f40ae88708346410874
parenta3dc2a80d5906d18cda0a4b28e8292f9f786ad73
REGRESSION(r211643): Dismissing WKActionSheet should not also dismiss its presenting view controller
https://bugs.webkit.org/show_bug.cgi?id=183549
<rdar://problem/34960698>

Reviewed by Andy Estes.

Source/WebKit:

Fixes the bug by dismissing the presented view controller (i.e. the action sheet or the view controller being
presented during rotation) rather than the presenting view controller.

Test: ActionSheetTests.DismissingActionSheetShouldNotDismissPresentingViewController

* UIProcess/ios/WKActionSheet.mm:
(-[WKActionSheet doneWithSheet:]):

Tools:

Add TestWebKitAPI support for testing WKWebViews embedded within presented view controllers, and use this to
check that dismissing an action sheet does not additionally cause the view controller being used to present the
web view to also dismiss.

* TestWebKitAPI/ClassMethodSwizzler.h: Added.
* TestWebKitAPI/ClassMethodSwizzler.mm: Added.
(TestWebKitAPI::ClassMethodSwizzler::ClassMethodSwizzler):
(TestWebKitAPI::ClassMethodSwizzler::~ClassMethodSwizzler):

Add ClassMethodSwizzler, an RAII which swizzles an Objective-C class method over its lifetime.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/ios/ActionSheetTests.mm:

Add a new API test that loads a view controller which embeds a WKWebView, and verifies that presenting and then
dismissing an action sheet from that web view does not cause the view controller to also dismiss.

(TestWebKitAPI::setOverrideViewControllerForFullscreenPresentation):
(TestWebKitAPI::overrideViewControllerForFullscreenPresentation):

Mock +[UIViewController _viewControllerForFullScreenPresentationFromView:] to return the web view. This works
around the fact that TestWebKitAPI is not a UI application, so certain pieces of UIKit API and SPI need to be
stubbed or mocked to simulate being a UI application. We can remove these workarounds once
https://webkit.org/b/175204 is addressed, and TestWebKitAPI becomes a UI application that can actually maintain
a root view controller and key window.

(TestWebKitAPI::TEST):
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[TestWKWebView initWithFrame:configuration:addToWindow:]):

Add a new initializer for TestWKWebView that doesn't force the view to be hosted within a UIWindow. This is used
by TestWKWebViewController to create a TestWKWebView in -loadView.

* TestWebKitAPI/ios/TestWKWebViewController.h: Added.
* TestWebKitAPI/ios/TestWKWebViewController.mm: Added.
(-[TestWKWebViewControllerWindow _beginKeyWindowDeferral]):
(-[TestWKWebViewControllerWindow _endKeyWindowDeferral]):

Stub out these methods to prevent UIKit from hitting assertions when making this UIWindow the key window. This
can also be removed once TestWebKitAPI is a UI application.

(-[TestWKWebViewController initWithFrame:configuration:]):
(-[TestWKWebViewController loadView]):
(-[TestWKWebViewController webView]):
(-[TestWKWebViewController dismissViewControllerAnimated:completion:]):
(-[TestWKWebViewController dismissalHandler]):
(-[TestWKWebViewController setDismissalHandler:]):

Add a UIViewController helper subclass whose -view is a WKWebView. The new API test presents this view
controller. Tests may also provide a dismissalHandler, which is invoked when the view controller is being
dismissed. The new API test uses this hook to verify that the view controller containing the web view isn't also
dismissed after the action sheet goes away.

* TestWebKitAPI/ios/UIKitSPI.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229542 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/WKActionSheet.mm
Tools/ChangeLog
Tools/TestWebKitAPI/ClassMethodSwizzler.h [new file with mode: 0644]
Tools/TestWebKitAPI/ClassMethodSwizzler.mm [new file with mode: 0644]
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/ios/ActionSheetTests.mm
Tools/TestWebKitAPI/cocoa/TestWKWebView.h
Tools/TestWebKitAPI/cocoa/TestWKWebView.mm
Tools/TestWebKitAPI/ios/TestWKWebViewController.h [new file with mode: 0644]
Tools/TestWebKitAPI/ios/TestWKWebViewController.mm [new file with mode: 0644]
Tools/TestWebKitAPI/ios/UIKitSPI.h