Title: [248900] trunk
Revision
248900
Author
[email protected]
Date
2019-08-20 09:10:43 -0700 (Tue, 20 Aug 2019)

Log Message

REGRESSION: Open in New Tab is missing from context menu
https://bugs.webkit.org/show_bug.cgi?id=200909
<rdar://problem/54476169>

Reviewed by Simon Fraser.

Source/WebKit:

Don't assume the new API if webView:contextMenuWillPresentForElement:
is implemented.

* UIProcess/ios/WKContentViewInteraction.mm:
(needsDeprecatedPreviewAPI):

Tools:

Add a new test that runs through the legacy context menu
flow, and verifies that it will be called if there aren't
appropriate delegates for the new API.

* TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
(contextMenuWebViewDriver):
(-[TestContextMenuUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
(TEST):
(-[LegacyPreviewViewController previewActionItems]):
(-[LegacyContextMenuUIDelegate webView:shouldPreviewElement:]):
(-[LegacyContextMenuUIDelegate webView:previewingViewControllerForElement:defaultActions:]):
(-[LegacyContextMenuUIDelegate webView:contextMenuWillPresentForElement:]):
(-[LegacyContextMenuUIDelegate _webView:contextMenuDidEndForElement:]):
* TestWebKitAPI/cocoa/TestContextMenuDriver.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (248899 => 248900)


--- trunk/Source/WebKit/ChangeLog	2019-08-20 13:26:06 UTC (rev 248899)
+++ trunk/Source/WebKit/ChangeLog	2019-08-20 16:10:43 UTC (rev 248900)
@@ -1,3 +1,17 @@
+2019-08-20  Dean Jackson  <[email protected]>
+
+        REGRESSION: Open in New Tab is missing from context menu
+        https://bugs.webkit.org/show_bug.cgi?id=200909
+        <rdar://problem/54476169>
+
+        Reviewed by Simon Fraser.
+
+        Don't assume the new API if webView:contextMenuWillPresentForElement:
+        is implemented.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (needsDeprecatedPreviewAPI):
+
 2019-08-20  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Support for _javascript_ BigInt

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (248899 => 248900)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-08-20 13:26:06 UTC (rev 248899)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-08-20 16:10:43 UTC (rev 248900)
@@ -7719,8 +7719,9 @@
 static bool needsDeprecatedPreviewAPI(id<WKUIDelegate> delegate)
 {
     // FIXME: Replace these with booleans in UIDelegate.h.
-    // Note that we explicitly do not test for @selector(_webView:contextMenuDidEndForElement:) since
-    // that's used by MobileSafari to clean up state even though they haven't moved to the new API.
+    // Note that we explicitly do not test for @selector(_webView:contextMenuDidEndForElement:)
+    // and @selector(webView:contextMenuWillPresentForElement) since the methods are used by MobileSafari
+    // to manage state despite the app not moving to the new API.
 
     return delegate
     && ![delegate respondsToSelector:@selector(_webView:contextMenuConfigurationForElement:completionHandler:)]
@@ -7728,7 +7729,6 @@
     && ![delegate respondsToSelector:@selector(_webView:contextMenuForElement:willCommitWithAnimator:)]
     && ![delegate respondsToSelector:@selector(webView:contextMenuForElement:willCommitWithAnimator:)]
     && ![delegate respondsToSelector:@selector(_webView:contextMenuWillPresentForElement:)]
-    && ![delegate respondsToSelector:@selector(webView:contextMenuWillPresentForElement:)]
     && ![delegate respondsToSelector:@selector(webView:contextMenuDidEndForElement:)]
     && ([delegate respondsToSelector:@selector(webView:shouldPreviewElement:)]
         || [delegate respondsToSelector:@selector(webView:previewingViewControllerForElement:defaultActions:)]

Modified: trunk/Tools/ChangeLog (248899 => 248900)


--- trunk/Tools/ChangeLog	2019-08-20 13:26:06 UTC (rev 248899)
+++ trunk/Tools/ChangeLog	2019-08-20 16:10:43 UTC (rev 248900)
@@ -1,3 +1,26 @@
+2019-08-20  Dean Jackson  <[email protected]>
+
+        REGRESSION: Open in New Tab is missing from context menu
+        https://bugs.webkit.org/show_bug.cgi?id=200909
+        <rdar://problem/54476169>
+
+        Reviewed by Simon Fraser.
+
+        Add a new test that runs through the legacy context menu
+        flow, and verifies that it will be called if there aren't
+        appropriate delegates for the new API.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
+        (contextMenuWebViewDriver):
+        (-[TestContextMenuUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
+        (TEST):
+        (-[LegacyPreviewViewController previewActionItems]):
+        (-[LegacyContextMenuUIDelegate webView:shouldPreviewElement:]):
+        (-[LegacyContextMenuUIDelegate webView:previewingViewControllerForElement:defaultActions:]):
+        (-[LegacyContextMenuUIDelegate webView:contextMenuWillPresentForElement:]):
+        (-[LegacyContextMenuUIDelegate _webView:contextMenuDidEndForElement:]):
+        * TestWebKitAPI/cocoa/TestContextMenuDriver.h:
+
 2019-08-19  Yusuke Suzuki  <[email protected]>
 
         [JSC] OSR entry to Wasm OMG

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm (248899 => 248900)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm	2019-08-20 13:26:06 UTC (rev 248899)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm	2019-08-20 16:10:43 UTC (rev 248900)
@@ -37,9 +37,27 @@
 static bool contextMenuRequested;
 static bool willPresentCalled;
 static bool willCommitCalled;
+static bool previewingViewControllerCalled;
+static bool previewActionItemsCalled;
 static bool didEndCalled;
-static RetainPtr<NSURL> simpleURL;
+static RetainPtr<NSURL> linkURL;
 
+static RetainPtr<TestContextMenuDriver> contextMenuWebViewDriver(Class delegateClass)
+{
+    static auto window = adoptNS([[UIWindow alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    static auto driver = adoptNS([TestContextMenuDriver new]);
+    static auto uiDelegate = adoptNS((NSObject<WKUIDelegate> *)[delegateClass new]);
+    static auto configuration = adoptNS([WKWebViewConfiguration new]);
+    [configuration _setClickInteractionDriverForTesting:driver.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()];
+    linkURL = [NSURL URLWithString:@"http://127.0.0.1/"];
+    [webView synchronouslyLoadHTMLString:[NSString stringWithFormat:@"<a href=''>This is a link</a>", linkURL.get()]];
+    return driver;
+}
+
 @interface TestContextMenuUIDelegate : NSObject <WKUIDelegate>
 @end
 
@@ -47,7 +65,7 @@
 
 - (void)webView:(WKWebView *)webView contextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo completionHandler:(void(^)(UIContextMenuConfiguration * _Nullable))completionHandler
 {
-    EXPECT_TRUE([elementInfo.linkURL.absoluteString isEqualToString:[simpleURL absoluteString]]);
+    EXPECT_TRUE([elementInfo.linkURL.absoluteString isEqualToString:[linkURL absoluteString]]);
     contextMenuRequested = true;
     UIContextMenuContentPreviewProvider previewProvider = ^UIViewController * ()
     {
@@ -77,25 +95,9 @@
 
 @end
 
-static RetainPtr<TestContextMenuDriver> contextMenuWebViewDriver()
-{
-    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()];
-    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();
+    auto driver = contextMenuWebViewDriver([TestContextMenuUIDelegate class]);
     [driver begin:^(BOOL result) {
         EXPECT_TRUE(result);
         [driver clickDown];
@@ -110,7 +112,7 @@
 
 TEST(WebKit, ContextMenuEnd)
 {
-    auto driver = contextMenuWebViewDriver();
+    auto driver = contextMenuWebViewDriver([TestContextMenuUIDelegate class]);
     [driver begin:^(BOOL result) {
         EXPECT_TRUE(result);
         [driver end];
@@ -121,4 +123,73 @@
     EXPECT_FALSE(willCommitCalled);
     EXPECT_TRUE(didEndCalled);
 }
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#pragma clang diagnostic ignored "-Wdeprecated-implementations"
+
+@interface LegacyPreviewViewController : UIViewController
+@end
+
+@implementation LegacyPreviewViewController
+
+- (NSArray<UIPreviewAction *> *)previewActionItems
+{
+    previewActionItemsCalled = true;
+    return @[
+        [UIPreviewAction actionWithTitle:@"Action" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *, UIViewController *) { }]
+    ];
+}
+
+@end
+
+@interface LegacyContextMenuUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation LegacyContextMenuUIDelegate
+
+- (BOOL)webView:(WKWebView *)webView shouldPreviewElement:(WKPreviewElementInfo *)elementInfo
+{
+    EXPECT_TRUE([elementInfo.linkURL.absoluteString isEqualToString:[linkURL absoluteString]]);
+    contextMenuRequested = true;
+    return YES;
+}
+
+- (UIViewController *)webView:(WKWebView *)webView previewingViewControllerForElement:(WKPreviewElementInfo *)elementInfo defaultActions:(NSArray<id <WKPreviewActionItem>> *)previewActions
+{
+    EXPECT_TRUE(previewActions.count);
+    previewingViewControllerCalled = true;
+    return [LegacyPreviewViewController new];
+}
+
+/* Even though this is non-legacy API, it should not be enough to trigger the non-legacy flow. */
+- (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo
+{
+    willPresentCalled = true;
+}
+
+/* Even though this is non-legacy API, it should not be enough to trigger the non-legacy flow. */
+- (void)_webView:(WKWebView *)webView contextMenuDidEndForElement:(WKContextMenuElementInfo *)elementInfo
+{
+}
+
+@end
+
+TEST(WebKit, ContextMenuLegacy)
+{
+    auto driver = contextMenuWebViewDriver([LegacyContextMenuUIDelegate class]);
+    [driver begin:^(BOOL result) {
+        EXPECT_TRUE(result);
+        [driver clickDown];
+        [driver clickUp];
+    }];
+    TestWebKitAPI::Util::run(&previewActionItemsCalled);
+    EXPECT_TRUE(contextMenuRequested);
+    EXPECT_TRUE(previewingViewControllerCalled);
+    EXPECT_TRUE(willPresentCalled);
+}
+
+#pragma clang diagnostic pop
+
+
 #endif // PLATFORM(IOS) && USE(UICONTEXTMENU)

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestContextMenuDriver.h (248899 => 248900)


--- trunk/Tools/TestWebKitAPI/cocoa/TestContextMenuDriver.h	2019-08-20 13:26:06 UTC (rev 248899)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestContextMenuDriver.h	2019-08-20 16:10:43 UTC (rev 248900)
@@ -30,9 +30,11 @@
 #if PLATFORM(IOS) && USE(UICONTEXTMENU)
 
 @protocol _UIClickInteractionDriverDelegate;
-@protocol _UIClickInteractionDriving;
+@protocol _UIClickInteractionDriving <NSObject>
+@property (nonatomic, weak) id<_UIClickInteractionDriverDelegate> delegate;
+@end
 
-@interface TestContextMenuDriver : NSObject {
+@interface TestContextMenuDriver : NSObject <_UIClickInteractionDriving> {
     WeakObjCPtr<id<_UIClickInteractionDriverDelegate>> _delegate;
     WeakObjCPtr<UIView> _view;
     CGFloat _allowableMovement;
@@ -39,6 +41,7 @@
     RetainPtr<UIGestureRecognizer> _primaryGestureRecognizer;
     NSTimeInterval _touchDuration;
 }
+
 - (void)begin:(void(^)(BOOL))completionHandler;
 - (void)clickDown;
 - (void)clickUp;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to