WKUIDelegate's webView:contextMenuDidEndForElement: should be called when context...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 16:34:00 +0000 (16:34 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 16:34:00 +0000 (16:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200750
<rdar://problem/54232261> and <rdar://problem/52355829>

Patch by Alex Christensen <achristensen@webkit.org> on 2019-08-15
Reviewed by Tim Horton.

Source/WebKit:

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView contextMenuInteraction:willEndForConfiguration:animator:]):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
(-[TestContextMenuUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
(-[TestContextMenuUIDelegate webView:contextMenuForElement:willCommitWithAnimator:]):
(-[TestContextMenuUIDelegate webView:contextMenuDidEndForElement:]):
(contextMenuWebViewDriver):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248717 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm

index 589e3c4..d14dc39 100644 (file)
@@ -1,3 +1,14 @@
+2019-08-15  Alex Christensen  <achristensen@webkit.org>
+
+        WKUIDelegate's webView:contextMenuDidEndForElement: should be called when context menus end
+        https://bugs.webkit.org/show_bug.cgi?id=200750
+        <rdar://problem/54232261> and <rdar://problem/52355829>
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView contextMenuInteraction:willEndForConfiguration:animator:]):
+
 2019-08-14  Brian Burg  <bburg@apple.com>
 
         Web Automation: mouse buttons are not correctly printed in SimulatedInputDispatcher log spew
index ef3ae44..f2c1c0b 100644 (file)
@@ -8369,7 +8369,7 @@ static RetainPtr<UITargetedPreview> createFallbackTargetedPreview(UIView *rootVi
 
     // FIXME: This delegate is being called more than once by UIKit. <rdar://problem/51550291>
     // This conditional avoids the WKUIDelegate being called twice too.
-    if (!_contextMenuElementInfo) {
+    if (_contextMenuElementInfo) {
         auto uiDelegate = static_cast<id<WKUIDelegatePrivate>>(_webView.UIDelegate);
         if ([uiDelegate respondsToSelector:@selector(webView:contextMenuDidEndForElement:)])
             [uiDelegate webView:_webView contextMenuDidEndForElement:_contextMenuElementInfo.get()];
index 2a59a72..c22653e 100644 (file)
@@ -1,3 +1,18 @@
+2019-08-15  Alex Christensen  <achristensen@webkit.org>
+
+        WKUIDelegate's webView:contextMenuDidEndForElement: should be called when context menus end
+        https://bugs.webkit.org/show_bug.cgi?id=200750
+        <rdar://problem/54232261> and <rdar://problem/52355829>
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
+        (-[TestContextMenuUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
+        (-[TestContextMenuUIDelegate webView:contextMenuForElement:willCommitWithAnimator:]):
+        (-[TestContextMenuUIDelegate webView:contextMenuDidEndForElement:]):
+        (contextMenuWebViewDriver):
+        (TEST):
+
 2019-08-14  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         [iOS](REGRESSION: r200487): WebKit.RequestActivatedElementInfoForRotatedImage fails on iOS 13
index 61a396d..24753c6 100644 (file)
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WebKit.h>
 
-static bool willPresentCalled;
 static bool contextMenuRequested;
+static bool willPresentCalled;
+static bool willCommitCalled;
+static bool didEndCalled;
 static RetainPtr<NSURL> simpleURL;
 
 @interface TestContextMenuUIDelegate : NSObject <WKUIDelegate>
@@ -47,7 +49,15 @@ static RetainPtr<NSURL> simpleURL;
 {
     EXPECT_TRUE([elementInfo.linkURL.absoluteString isEqualToString:[simpleURL absoluteString]]);
     contextMenuRequested = true;
-    completionHandler([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:nil actionProvider:nil]);
+    UIContextMenuContentPreviewProvider previewProvider = ^UIViewController * ()
+    {
+        return [UIViewController new];
+    };
+    UIContextMenuActionProvider actionProvider = ^UIMenu *(NSArray<UIMenuElement *> *suggestedActions)
+    {
+        return [UIMenu menuWithTitle:@"" children:suggestedActions];
+    };
+    completionHandler([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:previewProvider actionProvider:actionProvider]);
 }
 
 - (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo
@@ -57,36 +67,58 @@ static RetainPtr<NSURL> simpleURL;
 
 - (void)webView:(WKWebView *)webView contextMenuForElement:(WKContextMenuElementInfo *)elementInfo willCommitWithAnimator:(id<UIContextMenuInteractionCommitAnimating>)animator
 {
+    willCommitCalled = true;
 }
 
 - (void)webView:(WKWebView *)webView contextMenuDidEndForElement:(WKContextMenuElementInfo *)elementInfo
 {
+    didEndCalled = true;
 }
 
 @end
 
-TEST(WebKit, DISABLED_ContextMenuBasic)
+static RetainPtr<TestContextMenuDriver> contextMenuWebViewDriver()
 {
-    auto window = adoptNS([[UIWindow alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
-    auto driver = adoptNS([TestContextMenuDriver new]);
-    auto uiDelegate = adoptNS([TestContextMenuUIDelegate new]);
-    auto configuration = adoptNS([WKWebViewConfiguration new]);
+    static auto window = adoptNS([[UIWindow alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    static auto driver = adoptNS([TestContextMenuDriver new]);
+    static auto uiDelegate = adoptNS([TestContextMenuUIDelegate new]);
+    static auto configuration = adoptNS([WKWebViewConfiguration new]);
     [configuration _setClickInteractionDriverForTesting:(id<_UIClickInteractionDriving>)driver.get()];
-    auto webViewController = adoptNS([[TestWKWebViewController alloc] initWithFrame:CGRectMake(0, 0, 200, 200) configuration:configuration.get()]);
+    static auto webViewController = adoptNS([[TestWKWebViewController alloc] initWithFrame:CGRectMake(0, 0, 200, 200) configuration:configuration.get()]);
     TestWKWebView *webView = [webViewController webView];
     [window addSubview:webView];
     [webView setUIDelegate:uiDelegate.get()];
-
     simpleURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     [webView synchronouslyLoadHTMLString:[NSString stringWithFormat:@"<a href='%@'>This is a link</a>", simpleURL.get()]];
+    return driver;
+}
+
+TEST(WebKit, ContextMenuClick)
+{
+    auto driver = contextMenuWebViewDriver();
     [driver begin:^(BOOL result) {
-        if (result) {
-            [driver clickDown];
-            [driver clickUp];
-            [driver end];
-        }
+        EXPECT_TRUE(result);
+        [driver clickDown];
+        [driver clickUp];
     }];
     TestWebKitAPI::Util::run(&willPresentCalled);
+    EXPECT_TRUE(contextMenuRequested);
+    EXPECT_TRUE(willPresentCalled);
+    EXPECT_FALSE(willCommitCalled);
+    EXPECT_FALSE(didEndCalled);
 }
 
+TEST(WebKit, ContextMenuEnd)
+{
+    auto driver = contextMenuWebViewDriver();
+    [driver begin:^(BOOL result) {
+        EXPECT_TRUE(result);
+        [driver end];
+    }];
+    TestWebKitAPI::Util::run(&didEndCalled);
+    EXPECT_TRUE(contextMenuRequested);
+    EXPECT_FALSE(willPresentCalled);
+    EXPECT_FALSE(willCommitCalled);
+    EXPECT_TRUE(didEndCalled);
+}
 #endif // PLATFORM(IOS) && USE(UICONTEXTMENU)