Diff
Modified: trunk/Source/WebKit2/ChangeLog (212253 => 212254)
--- trunk/Source/WebKit2/ChangeLog 2017-02-13 23:07:44 UTC (rev 212253)
+++ trunk/Source/WebKit2/ChangeLog 2017-02-13 23:10:10 UTC (rev 212254)
@@ -1,3 +1,51 @@
+2017-02-13 Wenson Hsieh <[email protected]>
+
+ [WK2] Add test infrastructure and unit tests for data interaction
+ https://bugs.webkit.org/show_bug.cgi?id=168159
+ <rdar://problem/30477634>
+
+ Reviewed by Tim Horton.
+
+ Adds support at the WebKit2 layer for testing data interaction. Introduces the _WKTestingDelegate, which a
+ protocol which can specified for a WKWebView and used to install mock objects and simulate the state of the
+ platform. By default, this delegate is nil, which results in normal behavior. For data interaction, we are able
+ to specify a mock data interaction gesture recognizer for use by the WKContentView to simulate firing a long
+ press and subsequent movement. This gesture recognizer is used in place of the regular data interaction gesture
+ recognizer, and allows for TestWebKitAPI to drive interaction without actually sending events through the
+ UIApplication. The _WKTestingDelegate also contains optional method hooks which are invoked at key points in
+ time when performing a data interaction gesture.
+
+ Since all methods of the testing delegate are optional, the testing delegate can be easily extended to support
+ testing for other features -- the idea is that leaving all but the relevant methods in the protocol
+ unimplemented will result in default behavior for everything other than those methods, so a client need only
+ implement and add WebKit2 hooks for a few methods to support testing for a new feature.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _testingDelegate]):
+ (-[WKWebView _setTestingDelegate:]):
+
+ Specify the testing delegate to use for this WKWebView (see above for more details).
+
+ (-[WKWebView _simulateDataInteractionGestureRecognized]):
+ (-[WKWebView _simulateDataInteractionEntered:]):
+ (-[WKWebView _simulateDataInteractionUpdated:]):
+ (-[WKWebView _simulateDataInteractionPerformOperation:]):
+ (-[WKWebView _simulateDataInteractionEnded:]):
+ (-[WKWebView _simulateDataInteractionSessionDidEnd:withOperation:]):
+ (-[WKWebView _simulateFailedDataInteractionWithIndex:]):
+ (-[WKWebView _simulateWillBeginDataInteractionWithIndex:withSession:]):
+ (-[WKWebView _simulatedItemsForDataInteractionWithIndex:]):
+
+ Used by TestWebKitAPI to drive data interaction tests. See DataInteractionTests.mm.
+
+ * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+ * UIProcess/API/Cocoa/_WKTestingDelegate.h: Added.
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView setupInteraction]):
+ (-[WKContentView _dataInteractionGestureRecognizer]):
+ * WebKit2.xcodeproj/project.pbxproj:
+
2017-02-13 Eric Carlson <[email protected]>
[MediaStream Mac] Video capture needs access to /Library/CoreMediaIO/Plug-Ins/DAL/
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (212253 => 212254)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2017-02-13 23:07:44 UTC (rev 212253)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2017-02-13 23:10:10 UTC (rev 212254)
@@ -86,6 +86,7 @@
#import "_WKInputDelegate.h"
#import "_WKRemoteObjectRegistryInternal.h"
#import "_WKSessionStateInternal.h"
+#import "_WKTestingDelegate.h"
#import "_WKVisitedLinkStoreInternal.h"
#import "_WKWebsitePoliciesInternal.h"
#import <WebCore/GraphicsContextCG.h>
@@ -286,6 +287,8 @@
std::unique_ptr<WebKit::WebViewImpl> _impl;
RetainPtr<WKTextFinderClient> _textFinderClient;
#endif
+
+ id<_WKTestingDelegate> _testingDelegate;
}
- (instancetype)initWithFrame:(CGRect)frame
@@ -4874,6 +4877,16 @@
#endif
}
+- (id<_WKTestingDelegate>)_testingDelegate
+{
+ return _testingDelegate;
+}
+
+- (void)_setTestingDelegate:(id<_WKTestingDelegate>)testingDelegate
+{
+ _testingDelegate = testingDelegate;
+}
+
#if PLATFORM(IOS)
- (CGRect)_contentVisibleRect
@@ -5098,6 +5111,72 @@
WebKit::ViewSnapshotStore::singleton().setDisableSnapshotVolatilityForTesting(true);
}
+
+- (void)_simulateDataInteractionGestureRecognized
+{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionGestureRecognized:_testingDelegate.dataInteractionGestureRecognizer];
+#endif
+}
+
+- (void)_simulateDataInteractionEntered:(id)info
+{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionEntered:info];
+#endif
+}
+
+- (void)_simulateDataInteractionUpdated:(id)info
+{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionUpdated:info];
+#endif
+}
+
+- (void)_simulateDataInteractionPerformOperation:(id)info
+{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionPerformOperation:info];
+#endif
+}
+
+- (void)_simulateDataInteractionEnded:(id)info
+{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionEnded:info];
+#endif
+}
+
+- (void)_simulateDataInteractionSessionDidEnd:(id)session withOperation:(NSUInteger)operation
+{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionSessionDidEnd:session withOperation:operation];
+#endif
+}
+
+- (void)_simulateFailedDataInteractionWithIndex:(NSInteger)sourceIndex
+{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateFailedDataInteractionWithIndex:sourceIndex];
+#endif
+}
+
+- (void)_simulateWillBeginDataInteractionWithIndex:(NSInteger)sourceIndex withSession:(id)session
+{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateWillBeginDataInteractionWithIndex:sourceIndex withSession:session];
+#endif
+}
+
+- (NSArray *)_simulatedItemsForDataInteractionWithIndex:(NSInteger)sourceIndex
+{
+#if ENABLE(DATA_INTERACTION)
+ return [_contentView _simulatedItemsForDataInteractionWithIndex:sourceIndex];
+#else
+ return @[ ];
+#endif
+}
+
@end
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (212253 => 212254)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-02-13 23:07:44 UTC (rev 212253)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-02-13 23:10:10 UTC (rev 212254)
@@ -68,6 +68,7 @@
@protocol _WKIconLoadingDelegate;
@protocol _WKInputDelegate;
@protocol _WKFullscreenDelegate;
+@protocol _WKTestingDelegate;
@interface WKWebView (WKPrivate)
@@ -276,6 +277,7 @@
@interface WKWebView (WKTesting)
- (NSDictionary *)_contentsOfUserInterfaceItem:(NSString *)userInterfaceItem WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, weak, setter=_setTestingDelegate:) id<_WKTestingDelegate> _testingDelegate WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
#if TARGET_OS_IPHONE
@@ -303,6 +305,16 @@
@property (nonatomic, readonly) NSNumber *_stableStateOverride WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionGestureRecognized WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionEntered:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionUpdated:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionPerformOperation:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionEnded:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionSessionDidEnd:(id)session withOperation:(NSUInteger)operation WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateFailedDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateWillBeginDataInteractionWithIndex:(NSInteger)sourceIndex withSession:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (NSArray *)_simulatedItemsForDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
#endif // TARGET_OS_IPHONE
#if !TARGET_OS_IPHONE
Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKTestingDelegate.h (0 => 212254)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKTestingDelegate.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKTestingDelegate.h 2017-02-13 23:10:10 UTC (rev 212254)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 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 <WebKit/WKFoundation.h>
+
+#if WK_API_ENABLED
+
+#import <wtf/RetainPtr.h>
+
+@class WKWebView;
+
+#if TARGET_OS_IPHONE
+@class UIGestureRecognizer;
+@class UILongPressGestureRecognizer;
+#endif
+
+NS_ASSUME_NONNULL_BEGIN
+
+@protocol _WKTestingDelegate <NSObject>
+@optional
+
+#if TARGET_OS_IPHONE
+@property (nonatomic, readonly) UILongPressGestureRecognizer *dataInteractionGestureRecognizer;
+- (void)webViewDidPerformDataInteractionControllerOperation:(WKWebView *)webView;
+- (void)webView:(WKWebView *)webView beginDataInteractionWithSourceIndex:(NSInteger)sourceIndex gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
+#endif // TARGET_OS_PHONE
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#endif // WK_API_ENABLED
Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h (212253 => 212254)
--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h 2017-02-13 23:07:44 UTC (rev 212253)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h 2017-02-13 23:10:10 UTC (rev 212254)
@@ -271,6 +271,15 @@
- (void)_didPerformDataInteractionControllerOperation;
- (void)_didHandleStartDataInteractionRequest:(BOOL)started;
- (void)_startDataInteractionWithImage:(RetainPtr<CGImageRef>)image atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint isLink:(BOOL)isLink;
+- (void)_simulateDataInteractionGestureRecognized:(UILongPressGestureRecognizer *)gestureRecognizer WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionEntered:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionUpdated:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionPerformOperation:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionEnded:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionSessionDidEnd:(id)session withOperation:(NSUInteger)operation WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateFailedDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateWillBeginDataInteractionWithIndex:(NSInteger)sourceIndex withSession:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (NSArray *)_simulatedItemsForDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
#endif
@end
Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (212253 => 212254)
--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2017-02-13 23:07:44 UTC (rev 212253)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2017-02-13 23:10:10 UTC (rev 212254)
@@ -59,6 +59,7 @@
#import "_WKFocusedElementInfo.h"
#import "_WKFormInputSession.h"
#import "_WKInputDelegate.h"
+#import "_WKTestingDelegate.h"
#import <CoreText/CTFont.h>
#import <CoreText/CTFontDescriptor.h>
#import <MobileCoreServices/UTCoreTypes.h>
@@ -557,7 +558,7 @@
[self _createAndConfigureLongPressGestureRecognizer];
#if ENABLE(DATA_INTERACTION)
- _dataInteractionGestureRecognizer = adoptNS([[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(_dataInteractionGestureRecognizer:)]);
+ _dataInteractionGestureRecognizer = adoptNS([[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(_dataInteractionGestureRecognized:)]);
[_dataInteractionGestureRecognizer setDelay:0.5];
[_dataInteractionGestureRecognizer setDelegate:self];
[_dataInteractionGestureRecognizer _setRequiresQuietImpulse:YES];
@@ -1467,6 +1468,14 @@
return _positionInformation.hasDataInteractionAtPosition;
}
+- (UILongPressGestureRecognizer *)_dataInteractionGestureRecognizer
+{
+ if ([_webView._testingDelegate respondsToSelector:@selector(dataInteractionGestureRecognizer)])
+ return _webView._testingDelegate.dataInteractionGestureRecognizer;
+
+ return _dataInteractionGestureRecognizer.get();
+}
+
#endif
- (BOOL)pointIsNearMarkedText:(CGPoint)point
Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (212253 => 212254)
--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2017-02-13 23:07:44 UTC (rev 212253)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2017-02-13 23:10:10 UTC (rev 212254)
@@ -1947,6 +1947,7 @@
ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A22F0FF1289FCD90085E74F /* WKBundlePageOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
EDCA71B7128DDA8C00201B26 /* WKBundlePageOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A22F1001289FCD90085E74F /* WKBundlePageOverlay.cpp */; };
F036978815F4BF0500C3A80E /* WebColorPicker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F036978715F4BF0500C3A80E /* WebColorPicker.cpp */; };
+ F43370971E4D72ED00052B0E /* _WKTestingDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = F43370961E4D6A4400052B0E /* _WKTestingDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
F6113E25126CE1820057D0A7 /* APIUserContentURLPattern.h in Headers */ = {isa = PBXBuildFile; fileRef = F6113E24126CE1820057D0A7 /* APIUserContentURLPattern.h */; };
F6113E28126CE19B0057D0A7 /* WKUserContentURLPattern.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6113E26126CE19B0057D0A7 /* WKUserContentURLPattern.cpp */; };
F6113E29126CE19B0057D0A7 /* WKUserContentURLPattern.h in Headers */ = {isa = PBXBuildFile; fileRef = F6113E27126CE19B0057D0A7 /* WKUserContentURLPattern.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -4197,6 +4198,7 @@
E4E8648E1B1673FB00C82F40 /* VersionChecks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VersionChecks.h; sourceTree = "<group>"; };
E4E8648F1B1673FB00C82F40 /* VersionChecks.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VersionChecks.mm; sourceTree = "<group>"; };
F036978715F4BF0500C3A80E /* WebColorPicker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebColorPicker.cpp; sourceTree = "<group>"; };
+ F43370961E4D6A4400052B0E /* _WKTestingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKTestingDelegate.h; sourceTree = "<group>"; };
F6113E24126CE1820057D0A7 /* APIUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIUserContentURLPattern.h; sourceTree = "<group>"; };
F6113E26126CE19B0057D0A7 /* WKUserContentURLPattern.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKUserContentURLPattern.cpp; sourceTree = "<group>"; };
F6113E27126CE19B0057D0A7 /* WKUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserContentURLPattern.h; sourceTree = "<group>"; };
@@ -5397,6 +5399,7 @@
1A002D3F196B329400B9AD44 /* _WKSessionState.h */,
1A002D3E196B329400B9AD44 /* _WKSessionState.mm */,
1A002D42196B337000B9AD44 /* _WKSessionStateInternal.h */,
+ F43370961E4D6A4400052B0E /* _WKTestingDelegate.h */,
2D6B371918A967AD0042AE80 /* _WKThumbnailView.h */,
2D6B371A18A967AD0042AE80 /* _WKThumbnailView.mm */,
2DACE64D18ADBFF000E4CA76 /* _WKThumbnailViewInternal.h */,
@@ -8623,6 +8626,7 @@
373CEAD6185417AE008C363D /* WKNSData.h in Headers */,
371A19421824D29300F32A5E /* WKNSDictionary.h in Headers */,
372CAF0B1833FD910040AC27 /* WKNSError.h in Headers */,
+ F43370971E4D72ED00052B0E /* _WKTestingDelegate.h in Headers */,
375E0E141D66432700EFEC2C /* WKNSNumber.h in Headers */,
378E1A4A18208CD60031007A /* WKNSString.h in Headers */,
378E1A4E18208D700031007A /* WKNSURL.h in Headers */,
Modified: trunk/Tools/ChangeLog (212253 => 212254)
--- trunk/Tools/ChangeLog 2017-02-13 23:07:44 UTC (rev 212253)
+++ trunk/Tools/ChangeLog 2017-02-13 23:10:10 UTC (rev 212254)
@@ -1,3 +1,56 @@
+2017-02-13 Wenson Hsieh <[email protected]>
+
+ [WK2] Add test infrastructure and unit tests for data interaction
+ https://bugs.webkit.org/show_bug.cgi?id=168159
+ <rdar://problem/30477634>
+
+ Reviewed by Tim Horton.
+
+ Uses the testing delegate introduced in WebKit2 to override the gesture recognizer used to initiate data
+ interaction. Instead of being driven by UIKit, the DataInteractionSimulator drives this overridden gesture
+ recognizer by making the WKContentView call its dataInteractionGestureRecognized method. To simulate an actual
+ gesture being performed, we fire the gesture recognizer (or call the data interaction delegate methods, if the
+ gesture has already been recognized) at regular intervals over the course of the test.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit2Cocoa/autofocus-contenteditable.html: Added.
+ * TestWebKitAPI/Tests/WebKit2Cocoa/image-and-contenteditable.html: Added.
+ * TestWebKitAPI/Tests/WebKit2Cocoa/image-and-textarea.html: Added.
+
+ New test pages for data interaction.
+
+ * TestWebKitAPI/Tests/ios/DataInteractionTests.mm: Added.
+ (TestWebKitAPI::runTestsExpectingToObserveEvents):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/cocoa/TestWKWebView.mm:
+ (-[TestWKWebView stringByEvaluatingJavaScript:]):
+ * TestWebKitAPI/ios/DataInteractionSimulator.h: Added.
+ * TestWebKitAPI/ios/DataInteractionSimulator.mm: Added.
+ (-[MockLongPressGestureRecognizer initWithWindow:]):
+ (-[MockLongPressGestureRecognizer locationInView:]):
+ (-[MockLongPressGestureRecognizer state]):
+ (-[MockLongPressGestureRecognizer numberOfTouches]):
+ (-[DataInteractionSimulator initWithWebView:startLocation:endLocation:]):
+ (-[DataInteractionSimulator dealloc]):
+ (-[DataInteractionSimulator run]):
+
+ Performs a data interaction gesture from the start location to the end location with linear interpolation. For
+ now, the timestep and progress per tick are 30ms and 3.33%, respectively, which means that tests should complete
+ in a little under 1 second, though this can be easily changed to be configurable in the future if needed.
+
+ (-[DataInteractionSimulator _advanceProgress]):
+
+ Fired periodically to drive the data interaction gesture. Schedules a call of itself until the test is
+ completed, and calls _finishDataInteraction when progress is at 1.
+
+ (-[DataInteractionSimulator _finishDataInteraction]):
+ (-[DataInteractionSimulator _currentLocation]):
+ (-[DataInteractionSimulator _scheduleAdvanceProgress]):
+ (-[DataInteractionSimulator _recognizeGestureAtLocation:withState:]):
+ (-[DataInteractionSimulator dataInteractionGestureRecognizer]):
+ (-[DataInteractionSimulator webViewDidPerformDataInteractionControllerOperation:]):
+ (-[DataInteractionSimulator webView:beginDataInteractionWithSourceIndex:gestureRecognizer:]):
+
2017-02-13 Alex Christensen <[email protected]>
Percent should be allowed in non-special URL hosts
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (212253 => 212254)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2017-02-13 23:07:44 UTC (rev 212253)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2017-02-13 23:10:10 UTC (rev 212254)
@@ -553,12 +553,17 @@
E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
F415086D1DA040C50044BE9B /* play-audio-on-click.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F415086C1DA040C10044BE9B /* play-audio-on-click.html */; };
F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
+ F45B960C1E50708800CFAC5D /* autofocus-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F45B960B1E50708200CFAC5D /* autofocus-contenteditable.html */; };
F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */; };
F4BFA68E1E4AD08000154298 /* DragAndDropPasteboardTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */; };
F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */; };
+ F4D4F3B61E4E2BCB00BB2767 /* DataInteractionSimulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */; };
+ F4D4F3B91E4E36E400BB2767 /* DataInteractionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B71E4E36E400BB2767 /* DataInteractionTests.mm */; };
+ F4D4F3BC1E4E511F00BB2767 /* image-and-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4D4F3BB1E4E50EF00BB2767 /* image-and-contenteditable.html */; };
F4F137921D9B683E002BEC57 /* large-video-test-now-playing.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */; };
F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; };
F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; };
+ F4F93F341E4E918D00E33E2E /* image-and-textarea.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F93F331E4E918500E33E2E /* image-and-textarea.html */; };
F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; };
F660AA1515A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA1415A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp */; };
F6B7BE9517469212008A3445 /* DidAssociateFormControls_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6B7BE92174691EF008A3445 /* DidAssociateFormControls_Bundle.cpp */; };
@@ -630,6 +635,9 @@
files = (
C25CCA0D1E5141840026CB8A /* AllAhem.svg in Copy Resources */,
C25CCA0B1E5140C10026CB8A /* LineBreaking.html in Copy Resources */,
+ F45B960C1E50708800CFAC5D /* autofocus-contenteditable.html in Copy Resources */,
+ F4F93F341E4E918D00E33E2E /* image-and-textarea.html in Copy Resources */,
+ F4D4F3BC1E4E511F00BB2767 /* image-and-contenteditable.html in Copy Resources */,
F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */,
C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */,
C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */,
@@ -1373,12 +1381,18 @@
F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
F415086C1DA040C10044BE9B /* play-audio-on-click.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "play-audio-on-click.html"; sourceTree = "<group>"; };
F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "large-input-field-focus-onload.html"; path = "Tests/WebKit2Cocoa/large-input-field-focus-onload.html"; sourceTree = SOURCE_ROOT; };
+ F45B960B1E50708200CFAC5D /* autofocus-contenteditable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autofocus-contenteditable.html"; sourceTree = "<group>"; };
F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-page-contenteditable.html"; sourceTree = "<group>"; };
F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropPasteboardTests.mm; sourceTree = "<group>"; };
F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "enormous-video-with-sound.html"; sourceTree = "<group>"; };
+ F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataInteractionSimulator.mm; sourceTree = "<group>"; };
+ F4D4F3B51E4E2BCB00BB2767 /* DataInteractionSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataInteractionSimulator.h; sourceTree = "<group>"; };
+ F4D4F3B71E4E36E400BB2767 /* DataInteractionTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataInteractionTests.mm; sourceTree = "<group>"; };
+ F4D4F3BB1E4E50EF00BB2767 /* image-and-contenteditable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "image-and-contenteditable.html"; sourceTree = "<group>"; };
F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-test-now-playing.html"; sourceTree = "<group>"; };
F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-size-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "skinny-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
+ F4F93F331E4E918500E33E2E /* image-and-textarea.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "image-and-textarea.html"; sourceTree = "<group>"; };
F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; };
F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback_Bundle.cpp; sourceTree = "<group>"; };
F660AA1215A619C8003A1243 /* InjectedBundleInitializationUserDataCallbackWins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleInitializationUserDataCallbackWins.cpp; sourceTree = "<group>"; };
@@ -1617,6 +1631,8 @@
isa = PBXGroup;
children = (
2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */,
+ F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */,
+ F4D4F3B51E4E2BCB00BB2767 /* DataInteractionSimulator.h */,
);
path = ios;
sourceTree = "<group>";
@@ -1666,6 +1682,7 @@
children = (
A1C4FB6F1BACCEFA003742D0 /* Resources */,
7560917719259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm */,
+ F4D4F3B71E4E36E400BB2767 /* DataInteractionTests.mm */,
);
path = ios;
sourceTree = "<group>";
@@ -1702,6 +1719,8 @@
A16F66B81C40E9E100BD4D24 /* Resources */ = {
isa = PBXGroup;
children = (
+ F45B960B1E50708200CFAC5D /* autofocus-contenteditable.html */,
+ F4F93F331E4E918500E33E2E /* image-and-textarea.html */,
F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */,
F415086C1DA040C10044BE9B /* play-audio-on-click.html */,
F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */,
@@ -1750,6 +1769,7 @@
51A5877C1D1B3D8D004BA9AF /* IndexedDBMultiProcess-3.html */,
51B1EE941C80FADD0064FB98 /* IndexedDBPersistence-1.html */,
51B1EE951C80FADD0064FB98 /* IndexedDBPersistence-2.html */,
+ F4D4F3BB1E4E50EF00BB2767 /* image-and-contenteditable.html */,
2E1B7B011D41B1B3007558B4 /* large-video-hides-controls-after-seek-to-end.html */,
2E1B7AFF1D41A95F007558B4 /* large-video-seek-after-ending.html */,
2E1DFDF01D42E14400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html */,
@@ -2624,6 +2644,7 @@
7A909A831D877480007E10F8 /* IntSize.cpp in Sources */,
7CCE7EEF1A411AE600447C4C /* EphemeralSessionPushStateNoHistoryCallback.cpp in Sources */,
7CCE7EF01A411AE600447C4C /* EvaluateJavaScript.cpp in Sources */,
+ F4D4F3B91E4E36E400BB2767 /* DataInteractionTests.mm in Sources */,
7CCE7EF11A411AE600447C4C /* FailedLoad.cpp in Sources */,
7C83E04F1D0A641800FEBCF3 /* FileSystem.cpp in Sources */,
7CCE7EF31A411AE600447C4C /* Find.cpp in Sources */,
@@ -2676,6 +2697,7 @@
7C83E0C01D0A652700FEBCF3 /* LoadInvalidURLRequest.mm in Sources */,
7CCE7F001A411AE600447C4C /* LoadPageOnCrash.cpp in Sources */,
51E6A8941D2F1C0A00C004B6 /* LocalStorageClear.mm in Sources */,
+ F4D4F3B61E4E2BCB00BB2767 /* DataInteractionSimulator.mm in Sources */,
46C519DA1D355AB200DAA51A /* LocalStorageNullEntries.mm in Sources */,
7CCE7EB21A411A5100447C4C /* MemoryCacheAddImageToCacheIOS.mm in Sources */,
7CCE7EC51A411A7E00447C4C /* MemoryCacheDisableWithinResourceLoadDelegate.mm in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/autofocus-contenteditable.html (0 => 212254)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/autofocus-contenteditable.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/autofocus-contenteditable.html 2017-02-13 23:10:10 UTC (rev 212254)
@@ -0,0 +1,38 @@
+<head>
+ <meta name="viewport" content="width=device-width">
+ <style>
+ body {
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ }
+
+ #source, #editor {
+ width: 100%;
+ height: 200px;
+ font-size: 200px;
+ white-space: nowrap;
+ }
+
+ #editor {
+ border: black 1px solid;
+ }
+ </style>
+</head>
+
+<body>
+ <div contenteditable id="source">Hello world</div>
+ <div contenteditable id="editor"></div>
+ <script>
+ function postEventType(event) {
+ webkit.messageHandlers.testHandler.postMessage(event.type);
+ }
+
+ editor.addEventListener("drop", postEventType);
+ editor.addEventListener("dragenter", postEventType);
+ editor.addEventListener("dragover", postEventType);
+
+ let text = source.childNodes[0];
+ getSelection().setBaseAndExtent(text, 0, text, text.data.length);
+ </script>
+</body>
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-and-contenteditable.html (0 => 212254)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-and-contenteditable.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-and-contenteditable.html 2017-02-13 23:10:10 UTC (rev 212254)
@@ -0,0 +1,33 @@
+<head>
+ <meta name="viewport" content="width=device-width">
+ <style>
+ body {
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ }
+
+ #source, #editor {
+ width: 200px;
+ height: 200px;
+ }
+
+ #editor {
+ border: black 1px solid;
+ }
+ </style>
+</head>
+
+<body>
+ <div><img id="source" src=""
+ <div contenteditable id="editor"></div>
+ <script>
+ function postEventType(event) {
+ webkit.messageHandlers.testHandler.postMessage(event.type);
+ }
+
+ editor.addEventListener("drop", postEventType);
+ editor.addEventListener("dragenter", postEventType);
+ editor.addEventListener("dragover", postEventType);
+ </script>
+</body>
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-and-textarea.html (0 => 212254)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-and-textarea.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-and-textarea.html 2017-02-13 23:10:10 UTC (rev 212254)
@@ -0,0 +1,33 @@
+<head>
+ <meta name="viewport" content="width=device-width">
+ <style>
+ body {
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ }
+
+ #source, #editor {
+ width: 200px;
+ height: 200px;
+ }
+
+ #editor {
+ border: black 1px solid;
+ }
+ </style>
+</head>
+
+<body>
+ <div><img id="source" src=""
+ <textarea contenteditable id="editor"></textarea>
+ <script>
+ function postEventType(event) {
+ webkit.messageHandlers.testHandler.postMessage(event.type);
+ }
+
+ editor.addEventListener("drop", postEventType);
+ editor.addEventListener("dragenter", postEventType);
+ editor.addEventListener("dragover", postEventType);
+ </script>
+</body>
Added: trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (0 => 212254)
--- trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm 2017-02-13 23:10:10 UTC (rev 212254)
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "config.h"
+
+#if ENABLE(DATA_INTERACTION)
+
+#import "DataInteractionSimulator.h"
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+
+namespace TestWebKitAPI {
+
+static void runTestsExpectingToObserveEvents(TestWKWebView *webView, NSArray *eventNamesToObserve, dispatch_block_t test)
+{
+ NSMutableSet *observedEvents = [NSMutableSet set];
+ for (NSString *eventName in eventNamesToObserve) {
+ [webView performAfterReceivingMessage:eventName action:^() {
+ [observedEvents addObject:eventName];
+ }];
+ }
+
+ test();
+
+ for (NSString *eventName in eventNamesToObserve)
+ EXPECT_TRUE([observedEvents containsObject:eventName]);
+}
+
+TEST(DataInteractionTests, ImageToContentEditable)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ runTestsExpectingToObserveEvents(webView.get(), @[ DataInteractionEnterEventName, DataInteractionOverEventName, DataInteractionPerformOperationEventName ], ^() {
+ [webView synchronouslyLoadTestPageNamed:@"image-and-contenteditable"];
+
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get() startLocation:CGPointMake(100, 100) endLocation:CGPointMake(100, 300)]);
+ [dataInteractionSimulator run];
+
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!!editor.querySelector('img')"].boolValue);
+ });
+}
+
+TEST(DataInteractionTests, ImageToTextarea)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ runTestsExpectingToObserveEvents(webView.get(), @[ DataInteractionEnterEventName, DataInteractionOverEventName, DataInteractionPerformOperationEventName ], ^() {
+ [webView synchronouslyLoadTestPageNamed:@"image-and-textarea"];
+
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get() startLocation:CGPointMake(100, 100) endLocation:CGPointMake(100, 300)]);
+ [dataInteractionSimulator run];
+
+ NSURL *imageURL = [NSURL fileURLWithPath:[webView stringByEvaluatingJavaScript:@"editor.value"]];
+ EXPECT_WK_STREQ("icon.png", imageURL.lastPathComponent);
+ });
+}
+
+TEST(DataInteractionTests, ContentEditableToContentEditable)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ runTestsExpectingToObserveEvents(webView.get(), @[ DataInteractionEnterEventName, DataInteractionOverEventName, DataInteractionPerformOperationEventName ], ^() {
+ [webView synchronouslyLoadTestPageNamed:@"autofocus-contenteditable"];
+
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get() startLocation:CGPointMake(100, 100) endLocation:CGPointMake(100, 300)]);
+ [dataInteractionSimulator run];
+
+ EXPECT_EQ([webView stringByEvaluatingJavaScript:@"source.textContent"].length, 0UL);
+ EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"editor.textContent"].UTF8String);
+ });
+}
+
+} // namespace TestWebKitAPI
+
+#endif // ENABLE(DATA_INTERACTION)
Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm (212253 => 212254)
--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm 2017-02-13 23:07:44 UTC (rev 212253)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm 2017-02-13 23:10:10 UTC (rev 212254)
@@ -215,13 +215,13 @@
__block NSString *evalResult = nil;
[self evaluateJavaScript:script completionHandler:^(id result, NSError *error)
{
- evalResult = [NSString stringWithFormat:@"%@", result];
+ evalResult = [[NSString alloc] initWithFormat:@"%@", result];
isWaitingForJavaScript = true;
EXPECT_TRUE(!error);
}];
TestWebKitAPI::Util::run(&isWaitingForJavaScript);
- return evalResult;
+ return [evalResult autorelease];
}
- (void)waitForMessage:(NSString *)message
Added: trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h (0 => 212254)
--- trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h (rev 0)
+++ trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h 2017-02-13 23:10:10 UTC (rev 212254)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#if ENABLE(DATA_INTERACTION)
+
+#import <UIKit/UIItemProvider.h>
+#import <UIKit/UIKit.h>
+#import <WebKit/WebKit.h>
+#import <WebKit/_WKTestingDelegate.h>
+#import <wtf/BlockPtr.h>
+
+@class MockLongPressGestureRecognizer;
+@class MockDataInteractionInfo;
+
+extern NSString * const DataInteractionEnterEventName;
+extern NSString * const DataInteractionOverEventName;
+extern NSString * const DataInteractionPerformOperationEventName;
+
+typedef NS_ENUM(NSInteger, DataInteractionPhase) {
+ DataInteractionUnrecognized = 1,
+ DataInteractionBegan = 2,
+ DataInteractionEntered = 3,
+ DataInteractionPerforming = 4
+};
+
+@interface DataInteractionSimulator : NSObject<_WKTestingDelegate> {
+ RetainPtr<WKWebView> _webView;
+ RetainPtr<MockLongPressGestureRecognizer> _gestureRecognizer;
+ RetainPtr<MockDataInteractionInfo> _dataInteractionInfo;
+ CGPoint _startLocation;
+ CGPoint _endLocation;
+
+ double _gestureProgress;
+ bool _isDoneWithDataInteraction;
+ DataInteractionPhase _phase;
+}
+
+- (instancetype)initWithWebView:(WKWebView *)webView startLocation:(CGPoint)startLocation endLocation:(CGPoint)endLocation;
+- (void)run;
+
+@end
+
+#endif // ENABLE(DATA_INTERACTION)
Added: trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm (0 => 212254)
--- trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm 2017-02-13 23:10:10 UTC (rev 212254)
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "config.h"
+#include "DataInteractionSimulator.h"
+
+#if ENABLE(DATA_INTERACTION)
+
+#import "PlatformUtilities.h"
+#import <UIKit/UIItemProvider_Private.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+using namespace TestWebKitAPI;
+
+#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/DataInteractionSimulatorAdditions.mm>)
+#include <WebKitAdditions/DataInteractionSimulatorAdditions.mm>
+#endif
+
+@interface MockLongPressGestureRecognizer : UILongPressGestureRecognizer {
+ RetainPtr<UIWindow> _window;
+}
+
+@property (nonatomic) CGPoint mockLocationInWindow;
+@property (nonatomic) UIGestureRecognizerState mockState;
+@property (nonatomic) NSInteger mockNumberOfTouches;
+
+@end
+
+@implementation MockLongPressGestureRecognizer
+
+- (instancetype)initWithWindow:(UIWindow *)window
+{
+ if (self = [super init]) {
+ _window = window;
+ _mockState = UIGestureRecognizerStatePossible;
+ _mockNumberOfTouches = 0;
+ _mockLocationInWindow = CGPointZero;
+ }
+ return self;
+}
+
+- (CGPoint)locationInView:(UIView *)view
+{
+ return [view convertPoint:_mockLocationInWindow fromView:_window.get()];
+}
+
+- (UIGestureRecognizerState)state
+{
+ return _mockState;
+}
+
+- (NSUInteger)numberOfTouches
+{
+ return _mockNumberOfTouches;
+}
+
+@end
+
+static double progressIncrementStep = 0.033;
+static double progressTimeStep = 0.03;
+
+@implementation DataInteractionSimulator
+
+- (instancetype)initWithWebView:(WKWebView *)webView startLocation:(CGPoint)startLocation endLocation:(CGPoint)endLocation
+{
+ if (self = [super init]) {
+ _webView = webView;
+ _gestureRecognizer = adoptNS([[MockLongPressGestureRecognizer alloc] initWithWindow:webView.window]);
+ _startLocation = startLocation;
+ _endLocation = endLocation;
+
+ [_gestureRecognizer setMockNumberOfTouches:0];
+ [_webView _setTestingDelegate:self];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ if ([_webView _testingDelegate] == self)
+ [_webView _setTestingDelegate:nil];
+
+ [super dealloc];
+}
+
+- (void)run
+{
+ _gestureProgress = 0;
+ _phase = DataInteractionUnrecognized;
+ _isDoneWithDataInteraction = NO;
+ [_gestureRecognizer setMockNumberOfTouches:1];
+
+ [self _recognizeGestureAtLocation:_startLocation withState:UIGestureRecognizerStateBegan];
+ [self _scheduleAdvanceProgress];
+
+ TestWebKitAPI::Util::run(&_isDoneWithDataInteraction);
+ [_gestureRecognizer setMockNumberOfTouches:0];
+}
+
+- (void)_advanceProgress
+{
+ _gestureProgress = std::min(1.0, std::max(0.0, progressIncrementStep + _gestureProgress));
+ [_dataInteractionInfo setMockLocationInWindow:self._currentLocation];
+ if (_gestureProgress >= 1) {
+ [self _finishDataInteraction];
+ return;
+ }
+
+ switch (_phase) {
+ case DataInteractionUnrecognized:
+ [self _recognizeGestureAtLocation:self._currentLocation withState:UIGestureRecognizerStateChanged];
+ [self _scheduleAdvanceProgress];
+ break;
+ case DataInteractionBegan:
+ [_webView _simulateDataInteractionEntered:_dataInteractionInfo.get()];
+ _phase = DataInteractionEntered;
+ [self _scheduleAdvanceProgress];
+ break;
+ case DataInteractionEntered:
+ [_dataInteractionInfo setMockLocationInWindow:self._currentLocation];
+ [_webView _simulateDataInteractionUpdated:_dataInteractionInfo.get()];
+ [self _scheduleAdvanceProgress];
+ break;
+ default:
+ break;
+ }
+}
+
+- (void)_finishDataInteraction
+{
+ _phase = DataInteractionPerforming;
+ [_webView _simulateDataInteractionPerformOperation:_dataInteractionInfo.get()];
+ [_webView _simulateDataInteractionEnded:_dataInteractionInfo.get()];
+ [_webView _simulateDataInteractionSessionDidEnd:nil withOperation:0];
+}
+
+- (CGPoint)_currentLocation
+{
+ CGFloat distanceX = _endLocation.x - _startLocation.x;
+ CGFloat distanceY = _endLocation.y - _startLocation.y;
+ return { _startLocation.x + _gestureProgress * distanceX, _startLocation.y + _gestureProgress * distanceY };
+}
+
+- (void)_scheduleAdvanceProgress
+{
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_advanceProgress) object:nil];
+ [self performSelector:@selector(_advanceProgress) withObject:nil afterDelay:progressTimeStep];
+}
+
+- (void)_recognizeGestureAtLocation:(CGPoint)locationInWindow withState:(UIGestureRecognizerState)state
+{
+ [_gestureRecognizer setMockState:state];
+ [_gestureRecognizer setMockLocationInWindow:locationInWindow];
+ [_webView _simulateDataInteractionGestureRecognized];
+}
+
+#pragma mark - _WKTestingDelegate
+
+- (UILongPressGestureRecognizer *)dataInteractionGestureRecognizer
+{
+ return _gestureRecognizer.get();
+}
+
+- (void)webViewDidPerformDataInteractionControllerOperation:(WKWebView *)webView
+{
+ _isDoneWithDataInteraction = true;
+}
+
+- (void)webView:(WKWebView *)webView beginDataInteractionWithSourceIndex:(NSInteger)sourceIndex gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
+{
+ _phase = DataInteractionBegan;
+
+ // End the data interaction gesture recognizer.
+ auto location = self._currentLocation;
+ [self _recognizeGestureAtLocation:location withState:UIGestureRecognizerStateEnded];
+
+ // Officially begin data interaction by initializing the info.
+ NSArray *items = [_webView _simulatedItemsForDataInteractionWithIndex:sourceIndex];
+ _dataInteractionInfo = adoptNS([[MockDataInteractionInfo alloc] initWithItems:items location:location window:[_webView window]]);
+ [_webView _simulateWillBeginDataInteractionWithIndex:sourceIndex withSession:nil];
+}
+
+@end
+
+#endif // ENABLE(DATA_INTERACTION)