Title: [246657] trunk
Revision
246657
Author
[email protected]
Date
2019-06-20 15:28:47 -0700 (Thu, 20 Jun 2019)

Log Message

Add unit test for UIContextMenuConfiguration API
https://bugs.webkit.org/show_bug.cgi?id=199043

Reviewed by Wenson Hsieh.

Source/WebKit:

* UIProcess/API/APIPageConfiguration.cpp:
(API::PageConfiguration::copy const):
* UIProcess/API/APIPageConfiguration.h:
(API::PageConfiguration::clickInteractionDriverForTesting const):
(API::PageConfiguration::setClickInteractionDriverForTesting):
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration _setClickInteractionDriverForTesting:]):
(-[WKWebViewConfiguration _clickInteractionDriverForTesting]):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _registerPreview]):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm: Added.
(-[TestContextMenuUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
(-[TestContextMenuUIDelegate webView:contextMenuWillPresentForElement:]):
(-[TestContextMenuUIDelegate webView:contextMenuForElement:willCommitWithAnimator:]):
(-[TestContextMenuUIDelegate webView:contextMenuDidEndForElement:]):
(TEST):
* TestWebKitAPI/cocoa/TestContextMenuDriver.h: Added.
* TestWebKitAPI/cocoa/TestContextMenuDriver.mm: Added.
(-[TestContextMenuDriver delegate]):
(-[TestContextMenuDriver setDelegate:]):
(-[TestContextMenuDriver view]):
(-[TestContextMenuDriver setView:]):
(-[TestContextMenuDriver allowableMovement]):
(-[TestContextMenuDriver setAllowableMovement:]):
(-[TestContextMenuDriver primaryGestureRecognizer]):
(-[TestContextMenuDriver setPrimaryGestureRecognizer:]):
(-[TestContextMenuDriver touchDuration]):
(-[TestContextMenuDriver setTouchDuration:]):
(-[TestContextMenuDriver locationInCoordinateSpace:]):
(-[TestContextMenuDriver cancelInteraction]):
(-[TestContextMenuDriver begin:]):
(-[TestContextMenuDriver clickDown]):
(-[TestContextMenuDriver clickUp]):
(-[TestContextMenuDriver end]):
* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (246656 => 246657)


--- trunk/Source/WebKit/ChangeLog	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Source/WebKit/ChangeLog	2019-06-20 22:28:47 UTC (rev 246657)
@@ -1,3 +1,21 @@
+2019-06-20  Alex Christensen  <[email protected]>
+
+        Add unit test for UIContextMenuConfiguration API
+        https://bugs.webkit.org/show_bug.cgi?id=199043
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/API/APIPageConfiguration.cpp:
+        (API::PageConfiguration::copy const):
+        * UIProcess/API/APIPageConfiguration.h:
+        (API::PageConfiguration::clickInteractionDriverForTesting const):
+        (API::PageConfiguration::setClickInteractionDriverForTesting):
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration _setClickInteractionDriverForTesting:]):
+        (-[WKWebViewConfiguration _clickInteractionDriverForTesting]):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _registerPreview]):
+
 2019-06-20  Alexander Mikhaylenko  <[email protected]>
 
         [GTK] Enable navigation swipe layout tests

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (246656 => 246657)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2019-06-20 22:28:47 UTC (rev 246657)
@@ -1190,6 +1190,30 @@
 @property (nonatomic, copy) UIContextMenuContentPreviewProvider previewProvider;
 @property (nonatomic, copy) UIContextMenuActionProvider actionProvider;
 @end
+
+@protocol _UIClickInteractionDriverDelegate;
+@protocol _UIClickInteractionDriving <NSObject>
+@property (nonatomic, weak) id <_UIClickInteractionDriverDelegate> delegate;
+@end
+
+@class _UIClickPresentationInteraction;
+@interface UIContextMenuInteraction (Radar51288435)
+@property (nonatomic, strong) _UIClickPresentationInteraction *presentationInteraction;
+@end
+
+@interface _UIClickInteraction : NSObject <UIInteraction>
+@end
+
+@interface _UIClickPresentationInteraction : NSObject <UIInteraction>
+@end
+@interface _UIClickPresentationInteraction (NeededUntil51288435Fixed)
+@property (nonatomic, strong) _UIClickInteraction *previewClickInteraction;
+@end
+
+@interface _UIClickInteraction (Radar51288435)
+@property (nonatomic, strong) id<_UIClickInteractionDriving> driver;
+@end
+
 #endif
 
 WTF_EXTERN_C_BEGIN

Modified: trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.cpp (246656 => 246657)


--- trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.cpp	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.cpp	2019-06-20 22:28:47 UTC (rev 246657)
@@ -73,6 +73,7 @@
 #if PLATFORM(IOS_FAMILY)
     copy->m_alwaysRunsAtForegroundPriority = this->m_alwaysRunsAtForegroundPriority;
     copy->m_canShowWhileLocked = this->m_canShowWhileLocked;
+    copy->m_clickInteractionDriverForTesting = this->m_clickInteractionDriverForTesting;
 #endif
     copy->m_initialCapitalizationEnabled = this->m_initialCapitalizationEnabled;
     copy->m_waitsForPaintAfterViewDidMoveToWindow = this->m_waitsForPaintAfterViewDidMoveToWindow;

Modified: trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.h (246656 => 246657)


--- trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.h	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.h	2019-06-20 22:28:47 UTC (rev 246657)
@@ -31,6 +31,11 @@
 #include <wtf/Forward.h>
 #include <wtf/GetPtr.h>
 
+#if PLATFORM(IOS_FAMILY)
+OBJC_PROTOCOL(_UIClickInteractionDriving);
+#include <wtf/RetainPtr.h>
+#endif
+
 namespace WebKit {
 class VisitedLinkStore;
 class WebPageGroup;
@@ -98,6 +103,9 @@
     
     bool canShowWhileLocked() const { return m_canShowWhileLocked; }
     void setCanShowWhileLocked(bool canShowWhileLocked) { m_canShowWhileLocked = canShowWhileLocked; }
+
+    const RetainPtr<_UIClickInteractionDriving>& clickInteractionDriverForTesting() const { return m_clickInteractionDriverForTesting; }
+    void setClickInteractionDriverForTesting(RetainPtr<_UIClickInteractionDriving>&& driver) { m_clickInteractionDriverForTesting = WTFMove(driver); }
 #endif
     bool initialCapitalizationEnabled() { return m_initialCapitalizationEnabled; }
     void setInitialCapitalizationEnabled(bool initialCapitalizationEnabled) { m_initialCapitalizationEnabled = initialCapitalizationEnabled; }
@@ -151,6 +159,7 @@
 #if PLATFORM(IOS_FAMILY)
     bool m_alwaysRunsAtForegroundPriority { false };
     bool m_canShowWhileLocked { false };
+    RetainPtr<_UIClickInteractionDriving> m_clickInteractionDriverForTesting;
 #endif
     bool m_initialCapitalizationEnabled { true };
     bool m_waitsForPaintAfterViewDidMoveToWindow { true };

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm (246656 => 246657)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2019-06-20 22:28:47 UTC (rev 246657)
@@ -791,6 +791,16 @@
     return _pageConfiguration->canShowWhileLocked();
 }
 
+- (void)_setClickInteractionDriverForTesting:(id<_UIClickInteractionDriving>)driver
+{
+    _pageConfiguration->setClickInteractionDriverForTesting((NSObject<_UIClickInteractionDriving> *)driver);
+}
+
+- (id <_UIClickInteractionDriving>)_clickInteractionDriverForTesting
+{
+    return _pageConfiguration->clickInteractionDriverForTesting().get();
+}
+
 #endif // PLATFORM(IOS_FAMILY)
 
 - (BOOL)_invisibleAutoplayNotPermitted

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h (246656 => 246657)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h	2019-06-20 22:28:47 UTC (rev 246657)
@@ -33,6 +33,8 @@
     _WKDragLiftDelayMedium,
     _WKDragLiftDelayLong
 } WK_API_AVAILABLE(ios(11.0));
+
+@protocol _UIClickInteractionDriving;
 #endif
 
 @class WKWebView;
@@ -84,6 +86,7 @@
 @property (nonatomic, setter=_setSystemPreviewEnabled:) BOOL _systemPreviewEnabled WK_API_AVAILABLE(ios(12.0));
 @property (nonatomic, setter=_setShouldDecidePolicyBeforeLoadingQuickLookPreview:) BOOL _shouldDecidePolicyBeforeLoadingQuickLookPreview WK_API_AVAILABLE(ios(WK_IOS_TBA));
 @property (nonatomic, setter=_setCanShowWhileLocked:) BOOL _canShowWhileLocked WK_API_AVAILABLE(ios(WK_IOS_TBA));
+@property (nonatomic, setter=_setClickInteractionDriverForTesting:) id <_UIClickInteractionDriving> _clickInteractionDriverForTesting WK_API_AVAILABLE(ios(WK_IOS_TBA));
 #else
 @property (nonatomic, setter=_setShowsURLsInToolTips:) BOOL _showsURLsInToolTips WK_API_AVAILABLE(macos(10.12));
 @property (nonatomic, setter=_setServiceControlsEnabled:) BOOL _serviceControlsEnabled WK_API_AVAILABLE(macos(10.12));

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (246656 => 246657)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-06-20 22:28:47 UTC (rev 246657)
@@ -7434,6 +7434,12 @@
         _contextMenuHasRequestedLegacyData = NO;
         [self addInteraction:_contextMenuInteraction.get()];
 
+        if (id<_UIClickInteractionDriving> driver = _webView.configuration._clickInteractionDriverForTesting) {
+            _UIClickInteraction *previewClickInteraction = [[_contextMenuInteraction presentationInteraction] previewClickInteraction];
+            [previewClickInteraction setDriver:driver];
+            [driver setDelegate:(id<_UIClickInteractionDriverDelegate>)previewClickInteraction];
+        }
+
         [self _showLinkPreviewsPreferenceChanged:nil];
 
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_showLinkPreviewsPreferenceChanged:) name:webkitShowLinkPreviewsPreferenceChangedNotification object:nil];

Modified: trunk/Tools/ChangeLog (246656 => 246657)


--- trunk/Tools/ChangeLog	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Tools/ChangeLog	2019-06-20 22:28:47 UTC (rev 246657)
@@ -1,3 +1,37 @@
+2019-06-20  Alex Christensen  <[email protected]>
+
+        Add unit test for UIContextMenuConfiguration API
+        https://bugs.webkit.org/show_bug.cgi?id=199043
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm: Added.
+        (-[TestContextMenuUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
+        (-[TestContextMenuUIDelegate webView:contextMenuWillPresentForElement:]):
+        (-[TestContextMenuUIDelegate webView:contextMenuForElement:willCommitWithAnimator:]):
+        (-[TestContextMenuUIDelegate webView:contextMenuDidEndForElement:]):
+        (TEST):
+        * TestWebKitAPI/cocoa/TestContextMenuDriver.h: Added.
+        * TestWebKitAPI/cocoa/TestContextMenuDriver.mm: Added.
+        (-[TestContextMenuDriver delegate]):
+        (-[TestContextMenuDriver setDelegate:]):
+        (-[TestContextMenuDriver view]):
+        (-[TestContextMenuDriver setView:]):
+        (-[TestContextMenuDriver allowableMovement]):
+        (-[TestContextMenuDriver setAllowableMovement:]):
+        (-[TestContextMenuDriver primaryGestureRecognizer]):
+        (-[TestContextMenuDriver setPrimaryGestureRecognizer:]):
+        (-[TestContextMenuDriver touchDuration]):
+        (-[TestContextMenuDriver setTouchDuration:]):
+        (-[TestContextMenuDriver locationInCoordinateSpace:]):
+        (-[TestContextMenuDriver cancelInteraction]):
+        (-[TestContextMenuDriver begin:]):
+        (-[TestContextMenuDriver clickDown]):
+        (-[TestContextMenuDriver clickUp]):
+        (-[TestContextMenuDriver end]):
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2019-06-20  Aakash Jain  <[email protected]>
 
         [ews-app] Status bubble should not turn orange when any build step is skipped

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (246656 => 246657)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-06-20 22:28:47 UTC (rev 246657)
@@ -319,6 +319,7 @@
 		5C23DF0B2246015800F454B6 /* Challenge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C23DF0A2245C9D700F454B6 /* Challenge.mm */; };
 		5C2936931D5BF70D00DEAB1E /* CookieAcceptPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */; };
 		5C2936961D5C00ED00DEAB1E /* CookieMessage.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5C2936941D5BFD1900DEAB1E /* CookieMessage.html */; };
+		5C3B1D2622A74F6700BCF4D0 /* ContextMenus.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C3B1D2522A74EA400BCF4D0 /* ContextMenus.mm */; };
 		5C4259462266A68A0039AA7A /* BasicProposedCredentialPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C42594422669E9B0039AA7A /* BasicProposedCredentialPlugIn.mm */; };
 		5C4A84951F7EEFFC00ACFC54 /* Configuration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C4A84941F7EEFD400ACFC54 /* Configuration.mm */; };
 		5C69BDD51F82A7EF000F4F4B /* _javascript_DuringNavigation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C69BDD41F82A7EB000F4F4B /* _javascript_DuringNavigation.mm */; };
@@ -349,6 +350,7 @@
 		5CCB10E3213457D800AC5AF0 /* RestoreSessionStateWithoutNavigation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CCB10DE2134579D00AC5AF0 /* RestoreSessionStateWithoutNavigation.mm */; };
 		5CCB10E4213457E000AC5AF0 /* ShouldGoToBackForwardListItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CCB10DF2134579D00AC5AF0 /* ShouldGoToBackForwardListItem.mm */; };
 		5CE354D91E70DA5C00BEFE3B /* WKContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CE354D81E70D9C300BEFE3B /* WKContentExtensionStore.mm */; };
+		5CE7594922A883D200C12409 /* TestContextMenuDriver.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CE7594722A883A500C12409 /* TestContextMenuDriver.mm */; };
 		5CEAB5E11FA939F400A77FAA /* _WKInputDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CEAB5DF1FA937CB00A77FAA /* _WKInputDelegate.mm */; };
 		5CF540E92257E67C00E6BC0E /* DownloadThread.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CF540E82257E64B00E6BC0E /* DownloadThread.mm */; };
 		5CFACF63226F73C60056C7D0 /* libboringssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CFACF62226F73C60056C7D0 /* libboringssl.a */; };
@@ -1767,6 +1769,7 @@
 		5C23DF0A2245C9D700F454B6 /* Challenge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Challenge.mm; sourceTree = "<group>"; };
 		5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookieAcceptPolicy.mm; sourceTree = "<group>"; };
 		5C2936941D5BFD1900DEAB1E /* CookieMessage.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = CookieMessage.html; sourceTree = "<group>"; };
+		5C3B1D2522A74EA400BCF4D0 /* ContextMenus.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenus.mm; sourceTree = "<group>"; };
 		5C42594422669E9B0039AA7A /* BasicProposedCredentialPlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BasicProposedCredentialPlugIn.mm; sourceTree = "<group>"; };
 		5C4A84941F7EEFD400ACFC54 /* Configuration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Configuration.mm; sourceTree = "<group>"; };
 		5C5E633D1D0B67940085A025 /* UniqueRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueRef.cpp; sourceTree = "<group>"; };
@@ -1798,6 +1801,8 @@
 		5CCB10DF2134579D00AC5AF0 /* ShouldGoToBackForwardListItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ShouldGoToBackForwardListItem.mm; sourceTree = "<group>"; };
 		5CCB10E02134579D00AC5AF0 /* ResponsivenessTimer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResponsivenessTimer.mm; sourceTree = "<group>"; };
 		5CE354D81E70D9C300BEFE3B /* WKContentExtensionStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKContentExtensionStore.mm; sourceTree = "<group>"; };
+		5CE7594722A883A500C12409 /* TestContextMenuDriver.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestContextMenuDriver.mm; path = cocoa/TestContextMenuDriver.mm; sourceTree = "<group>"; };
+		5CE7594822A883A500C12409 /* TestContextMenuDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestContextMenuDriver.h; path = cocoa/TestContextMenuDriver.h; sourceTree = "<group>"; };
 		5CEAB5DF1FA937CB00A77FAA /* _WKInputDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKInputDelegate.mm; sourceTree = "<group>"; };
 		5CF540E82257E64B00E6BC0E /* DownloadThread.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DownloadThread.mm; sourceTree = "<group>"; };
 		5CFACF62226F73C60056C7D0 /* libboringssl.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libboringssl.a; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -2539,6 +2544,8 @@
 				F44A530D21B8976900DBB99C /* InstanceMethodSwizzler.h */,
 				F44A531021B8976900DBB99C /* InstanceMethodSwizzler.mm */,
 				0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */,
+				5CE7594822A883A500C12409 /* TestContextMenuDriver.h */,
+				5CE7594722A883A500C12409 /* TestContextMenuDriver.mm */,
 				2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */,
 				2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */,
 				A14FC58D1B8AE36500D107EB /* TestProtocol.h */,
@@ -2615,6 +2622,7 @@
 				A14FC5861B8991B600D107EB /* ContentFiltering.mm */,
 				A14FC5891B89927100D107EB /* ContentFilteringPlugIn.mm */,
 				5CA1DED81F74A87100E71BD3 /* ContentRuleListNotification.mm */,
+				5C3B1D2522A74EA400BCF4D0 /* ContextMenus.mm */,
 				5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */,
 				5C19A5231FD0F32600EEA323 /* CookiePrivateBrowsing.mm */,
 				9B1056411F9045C700D5583F /* CopyHTML.mm */,
@@ -4170,6 +4178,7 @@
 				37FB72971DB2E82F00E41BE4 /* ContextMenuDefaultItemsHaveTags.mm in Sources */,
 				8349D3C21DB96DDE004A9F65 /* ContextMenuDownload.mm in Sources */,
 				CD0BD0A61F79924D001AB2CF /* ContextMenuImgWithVideo.mm in Sources */,
+				5C3B1D2622A74F6700BCF4D0 /* ContextMenus.mm in Sources */,
 				5C2936931D5BF70D00DEAB1E /* CookieAcceptPolicy.mm in Sources */,
 				51D1249B1E785425002B2820 /* CookieManager.cpp in Sources */,
 				5C19A5241FD0F60100EEA323 /* CookiePrivateBrowsing.mm in Sources */,
@@ -4473,6 +4482,7 @@
 				5C9B548E223C4CBE00B150C4 /* TCPServer.cpp in Sources */,
 				7CCE7F161A411AE600447C4C /* TerminateTwice.cpp in Sources */,
 				7CCE7EA91A411A1D00447C4C /* TestBrowsingContextLoadDelegate.mm in Sources */,
+				5CE7594922A883D200C12409 /* TestContextMenuDriver.mm in Sources */,
 				F46128CB211D475100D9FADB /* TestDraggingInfo.mm in Sources */,
 				F4E0A2B82122847400AF7C7F /* TestFilePromiseReceiver.mm in Sources */,
 				F4F5BB5221667BAA002D06B9 /* TestFontOptions.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm (0 => 246657)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm	2019-06-20 22:28:47 UTC (rev 246657)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(IOS) && USE(UICONTEXTMENU)
+
+#import "TestContextMenuDriver.h"
+#import "TestWKWebView.h"
+#import "TestWKWebViewController.h"
+#import "Utilities.h"
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WebKit.h>
+
+static bool willPresentCalled;
+static bool contextMenuRequested;
+static RetainPtr<NSURL> simpleURL;
+
+@interface TestContextMenuUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation TestContextMenuUIDelegate
+
+- (void)webView:(WKWebView *)webView contextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo completionHandler:(void(^)(UIContextMenuConfiguration * _Nullable))completionHandler
+{
+    EXPECT_TRUE([elementInfo.linkURL.absoluteString isEqualToString:[simpleURL absoluteString]]);
+    contextMenuRequested = true;
+    completionHandler([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:nil actionProvider:nil]);
+}
+
+- (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo
+{
+    willPresentCalled = true;
+}
+
+- (void)webView:(WKWebView *)webView contextMenuForElement:(WKContextMenuElementInfo *)elementInfo willCommitWithAnimator:(id<UIContextMenuInteractionCommitAnimating>)animator
+{
+}
+
+- (void)webView:(WKWebView *)webView contextMenuDidEndForElement:(WKContextMenuElementInfo *)elementInfo
+{
+}
+
+@end
+
+TEST(WebKit, ContextMenuBasic)
+{
+    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]);
+    [configuration _setClickInteractionDriverForTesting:(id<_UIClickInteractionDriving>)driver.get()];
+    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()]];
+    [driver begin:^(BOOL result) {
+        if (result) {
+            [driver clickDown];
+            [driver clickUp];
+            [driver end];
+        }
+    }];
+    TestWebKitAPI::Util::run(&willPresentCalled);
+}
+
+#endif // PLATFORM(IOS) && USE(UICONTEXTMENU)

Added: trunk/Tools/TestWebKitAPI/cocoa/TestContextMenuDriver.h (0 => 246657)


--- trunk/Tools/TestWebKitAPI/cocoa/TestContextMenuDriver.h	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestContextMenuDriver.h	2019-06-20 22:28:47 UTC (rev 246657)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#import <wtf/WeakObjCPtr.h>
+
+#if PLATFORM(IOS) && USE(UICONTEXTMENU)
+
+@protocol _UIClickInteractionDriverDelegate;
+@protocol _UIClickInteractionDriving;
+
+@interface TestContextMenuDriver : NSObject {
+    WeakObjCPtr<id<_UIClickInteractionDriverDelegate>> _delegate;
+    WeakObjCPtr<UIView> _view;
+    CGFloat _allowableMovement;
+    RetainPtr<UIGestureRecognizer> _primaryGestureRecognizer;
+    NSTimeInterval _touchDuration;
+}
+- (void)begin:(void(^)(BOOL))completionHandler;
+- (void)clickDown;
+- (void)clickUp;
+- (void)end;
+@end
+
+#endif

Added: trunk/Tools/TestWebKitAPI/cocoa/TestContextMenuDriver.mm (0 => 246657)


--- trunk/Tools/TestWebKitAPI/cocoa/TestContextMenuDriver.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestContextMenuDriver.mm	2019-06-20 22:28:47 UTC (rev 246657)
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "TestContextMenuDriver.h"
+
+#import "UIKitSPI.h"
+#import <wtf/BlockPtr.h>
+
+#if PLATFORM(IOS) && USE(UICONTEXTMENU)
+
+@implementation TestContextMenuDriver
+
+- (id<_UIClickInteractionDriverDelegate>)delegate
+{
+    return _delegate.get().get();
+}
+
+- (void)setDelegate:(id<_UIClickInteractionDriverDelegate>)delegate
+{
+    _delegate = delegate;
+}
+
+- (UIView *)view
+{
+    return _view.get().get();
+}
+
+- (void)setView:(UIView *)view
+{
+    _view = view;
+}
+
+- (CGFloat)allowableMovement
+{
+    return _allowableMovement;
+}
+
+- (void)setAllowableMovement:(CGFloat)allowableMovement
+{
+    _allowableMovement = allowableMovement;
+}
+
+- (UIGestureRecognizer *)primaryGestureRecognizer
+{
+    return _primaryGestureRecognizer.get();
+}
+
+- (void)setPrimaryGestureRecognizer:(UIGestureRecognizer *)primaryGestureRecognizer
+{
+    _primaryGestureRecognizer = primaryGestureRecognizer;
+}
+
+- (NSTimeInterval)touchDuration
+{
+    return _touchDuration;
+}
+
+- (void)setTouchDuration:(NSTimeInterval)touchDuration
+{
+    _touchDuration = touchDuration;
+}
+
+- (CGPoint)locationInCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace
+{
+    return CGPointZero;
+}
+
+- (void)cancelInteraction
+{
+}
+
+- (void)begin:(void(^)(BOOL))completionHandler
+{
+    auto completionBlock = makeBlockPtr(completionHandler);
+    [self.delegate clickDriver:(id<_UIClickInteractionDriving>)self shouldBegin:^(BOOL result) {
+        [self.delegate clickDriver:(id<_UIClickInteractionDriving>)self didPerformEvent:_UIClickInteractionEventBegan];
+        completionBlock(result);
+    }];
+}
+
+- (void)clickDown
+{
+    [self.delegate clickDriver:(id<_UIClickInteractionDriving>)self didPerformEvent:_UIClickInteractionEventClickedDown];
+}
+
+- (void)clickUp
+{
+    [self.delegate clickDriver:(id<_UIClickInteractionDriving>)self didPerformEvent:_UIClickInteractionEventClickedUp];
+}
+
+- (void)end
+{
+    [self.delegate clickDriver:(id<_UIClickInteractionDriving>)self didPerformEvent:_UIClickInteractionEventEnded];
+}
+
+@end
+
+#endif

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (246656 => 246657)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-06-20 22:25:12 UTC (rev 246656)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-06-20 22:28:47 UTC (rev 246657)
@@ -199,6 +199,23 @@
 - (void)_dropInteraction:(UIDropInteraction *)interaction delayedPreviewProviderForDroppingItem:(UIDragItem *)item previewProvider:(void(^)(UITargetedDragPreview *preview))previewProvider;
 @end
 
+typedef NS_ENUM(NSUInteger, _UIClickInteractionEvent) {
+    _UIClickInteractionEventBegan = 0,
+    _UIClickInteractionEventClickedDown,
+    _UIClickInteractionEventClickedUp,
+    _UIClickInteractionEventEnded,
+    _UIClickInteractionEventCount
+};
+
+@protocol _UIClickInteractionDriving;
+@protocol _UIClickInteractionDriverDelegate <NSObject>
+- (void)clickDriver:(id<_UIClickInteractionDriving>)driver shouldBegin:(void(^)(BOOL))completion;
+- (void)clickDriver:(id<_UIClickInteractionDriving>)driver didPerformEvent:(_UIClickInteractionEvent)event;
+@optional
+- (void)clickDriver:(id<_UIClickInteractionDriving>)driver didUpdateHighlightProgress:(CGFloat)progress;
+- (BOOL)clickDriver:(id<_UIClickInteractionDriving>)driver shouldDelayGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
+@end
+
 #endif // PLATFORM(IOS)
 
 #endif // PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to