Skip to content

Commit ad4c88c

Browse files
[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. Source/WebKit2: 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: Tools: 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:]): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@212254 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 79667cd commit ad4c88c

16 files changed

+764
-3
lines changed

Source/WebKit2/ChangeLog

+48
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
1+
2017-02-13 Wenson Hsieh <[email protected]>
2+
3+
[WK2] Add test infrastructure and unit tests for data interaction
4+
https://bugs.webkit.org/show_bug.cgi?id=168159
5+
<rdar://problem/30477634>
6+
7+
Reviewed by Tim Horton.
8+
9+
Adds support at the WebKit2 layer for testing data interaction. Introduces the _WKTestingDelegate, which a
10+
protocol which can specified for a WKWebView and used to install mock objects and simulate the state of the
11+
platform. By default, this delegate is nil, which results in normal behavior. For data interaction, we are able
12+
to specify a mock data interaction gesture recognizer for use by the WKContentView to simulate firing a long
13+
press and subsequent movement. This gesture recognizer is used in place of the regular data interaction gesture
14+
recognizer, and allows for TestWebKitAPI to drive interaction without actually sending events through the
15+
UIApplication. The _WKTestingDelegate also contains optional method hooks which are invoked at key points in
16+
time when performing a data interaction gesture.
17+
18+
Since all methods of the testing delegate are optional, the testing delegate can be easily extended to support
19+
testing for other features -- the idea is that leaving all but the relevant methods in the protocol
20+
unimplemented will result in default behavior for everything other than those methods, so a client need only
21+
implement and add WebKit2 hooks for a few methods to support testing for a new feature.
22+
23+
* UIProcess/API/Cocoa/WKWebView.mm:
24+
(-[WKWebView _testingDelegate]):
25+
(-[WKWebView _setTestingDelegate:]):
26+
27+
Specify the testing delegate to use for this WKWebView (see above for more details).
28+
29+
(-[WKWebView _simulateDataInteractionGestureRecognized]):
30+
(-[WKWebView _simulateDataInteractionEntered:]):
31+
(-[WKWebView _simulateDataInteractionUpdated:]):
32+
(-[WKWebView _simulateDataInteractionPerformOperation:]):
33+
(-[WKWebView _simulateDataInteractionEnded:]):
34+
(-[WKWebView _simulateDataInteractionSessionDidEnd:withOperation:]):
35+
(-[WKWebView _simulateFailedDataInteractionWithIndex:]):
36+
(-[WKWebView _simulateWillBeginDataInteractionWithIndex:withSession:]):
37+
(-[WKWebView _simulatedItemsForDataInteractionWithIndex:]):
38+
39+
Used by TestWebKitAPI to drive data interaction tests. See DataInteractionTests.mm.
40+
41+
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
42+
* UIProcess/API/Cocoa/_WKTestingDelegate.h: Added.
43+
* UIProcess/ios/WKContentViewInteraction.h:
44+
* UIProcess/ios/WKContentViewInteraction.mm:
45+
(-[WKContentView setupInteraction]):
46+
(-[WKContentView _dataInteractionGestureRecognizer]):
47+
* WebKit2.xcodeproj/project.pbxproj:
48+
149
2017-02-13 Eric Carlson <[email protected]>
250

351
[MediaStream Mac] Video capture needs access to /Library/CoreMediaIO/Plug-Ins/DAL/

Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

+79
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#import "_WKInputDelegate.h"
8787
#import "_WKRemoteObjectRegistryInternal.h"
8888
#import "_WKSessionStateInternal.h"
89+
#import "_WKTestingDelegate.h"
8990
#import "_WKVisitedLinkStoreInternal.h"
9091
#import "_WKWebsitePoliciesInternal.h"
9192
#import <WebCore/GraphicsContextCG.h>
@@ -286,6 +287,8 @@ @implementation WKWebView {
286287
std::unique_ptr<WebKit::WebViewImpl> _impl;
287288
RetainPtr<WKTextFinderClient> _textFinderClient;
288289
#endif
290+
291+
id<_WKTestingDelegate> _testingDelegate;
289292
}
290293

291294
- (instancetype)initWithFrame:(CGRect)frame
@@ -4874,6 +4877,16 @@ - (NSDictionary *)_contentsOfUserInterfaceItem:(NSString *)userInterfaceItem
48744877
#endif
48754878
}
48764879

4880+
- (id<_WKTestingDelegate>)_testingDelegate
4881+
{
4882+
return _testingDelegate;
4883+
}
4884+
4885+
- (void)_setTestingDelegate:(id<_WKTestingDelegate>)testingDelegate
4886+
{
4887+
_testingDelegate = testingDelegate;
4888+
}
4889+
48774890
#if PLATFORM(IOS)
48784891

48794892
- (CGRect)_contentVisibleRect
@@ -5098,6 +5111,72 @@ - (void)_disableBackForwardSnapshotVolatilityForTesting
50985111
WebKit::ViewSnapshotStore::singleton().setDisableSnapshotVolatilityForTesting(true);
50995112
}
51005113

5114+
5115+
- (void)_simulateDataInteractionGestureRecognized
5116+
{
5117+
#if ENABLE(DATA_INTERACTION)
5118+
[_contentView _simulateDataInteractionGestureRecognized:_testingDelegate.dataInteractionGestureRecognizer];
5119+
#endif
5120+
}
5121+
5122+
- (void)_simulateDataInteractionEntered:(id)info
5123+
{
5124+
#if ENABLE(DATA_INTERACTION)
5125+
[_contentView _simulateDataInteractionEntered:info];
5126+
#endif
5127+
}
5128+
5129+
- (void)_simulateDataInteractionUpdated:(id)info
5130+
{
5131+
#if ENABLE(DATA_INTERACTION)
5132+
[_contentView _simulateDataInteractionUpdated:info];
5133+
#endif
5134+
}
5135+
5136+
- (void)_simulateDataInteractionPerformOperation:(id)info
5137+
{
5138+
#if ENABLE(DATA_INTERACTION)
5139+
[_contentView _simulateDataInteractionPerformOperation:info];
5140+
#endif
5141+
}
5142+
5143+
- (void)_simulateDataInteractionEnded:(id)info
5144+
{
5145+
#if ENABLE(DATA_INTERACTION)
5146+
[_contentView _simulateDataInteractionEnded:info];
5147+
#endif
5148+
}
5149+
5150+
- (void)_simulateDataInteractionSessionDidEnd:(id)session withOperation:(NSUInteger)operation
5151+
{
5152+
#if ENABLE(DATA_INTERACTION)
5153+
[_contentView _simulateDataInteractionSessionDidEnd:session withOperation:operation];
5154+
#endif
5155+
}
5156+
5157+
- (void)_simulateFailedDataInteractionWithIndex:(NSInteger)sourceIndex
5158+
{
5159+
#if ENABLE(DATA_INTERACTION)
5160+
[_contentView _simulateFailedDataInteractionWithIndex:sourceIndex];
5161+
#endif
5162+
}
5163+
5164+
- (void)_simulateWillBeginDataInteractionWithIndex:(NSInteger)sourceIndex withSession:(id)session
5165+
{
5166+
#if ENABLE(DATA_INTERACTION)
5167+
[_contentView _simulateWillBeginDataInteractionWithIndex:sourceIndex withSession:session];
5168+
#endif
5169+
}
5170+
5171+
- (NSArray *)_simulatedItemsForDataInteractionWithIndex:(NSInteger)sourceIndex
5172+
{
5173+
#if ENABLE(DATA_INTERACTION)
5174+
return [_contentView _simulatedItemsForDataInteractionWithIndex:sourceIndex];
5175+
#else
5176+
return @[ ];
5177+
#endif
5178+
}
5179+
51015180
@end
51025181

51035182

Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h

+12
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
6868
@protocol _WKIconLoadingDelegate;
6969
@protocol _WKInputDelegate;
7070
@protocol _WKFullscreenDelegate;
71+
@protocol _WKTestingDelegate;
7172

7273
@interface WKWebView (WKPrivate)
7374

@@ -276,6 +277,7 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
276277
@interface WKWebView (WKTesting)
277278

278279
- (NSDictionary *)_contentsOfUserInterfaceItem:(NSString *)userInterfaceItem WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
280+
@property (nonatomic, weak, setter=_setTestingDelegate:) id<_WKTestingDelegate> _testingDelegate WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
279281

280282
#if TARGET_OS_IPHONE
281283

@@ -303,6 +305,16 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
303305

304306
@property (nonatomic, readonly) NSNumber *_stableStateOverride WK_API_AVAILABLE(ios(WK_IOS_TBA));
305307

308+
- (void)_simulateDataInteractionGestureRecognized WK_API_AVAILABLE(ios(WK_IOS_TBA));
309+
- (void)_simulateDataInteractionEntered:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
310+
- (void)_simulateDataInteractionUpdated:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
311+
- (void)_simulateDataInteractionPerformOperation:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
312+
- (void)_simulateDataInteractionEnded:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
313+
- (void)_simulateDataInteractionSessionDidEnd:(id)session withOperation:(NSUInteger)operation WK_API_AVAILABLE(ios(WK_IOS_TBA));
314+
- (void)_simulateFailedDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
315+
- (void)_simulateWillBeginDataInteractionWithIndex:(NSInteger)sourceIndex withSession:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));
316+
- (NSArray *)_simulatedItemsForDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
317+
306318
#endif // TARGET_OS_IPHONE
307319

308320
#if !TARGET_OS_IPHONE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2017 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#import <WebKit/WKFoundation.h>
27+
28+
#if WK_API_ENABLED
29+
30+
#import <wtf/RetainPtr.h>
31+
32+
@class WKWebView;
33+
34+
#if TARGET_OS_IPHONE
35+
@class UIGestureRecognizer;
36+
@class UILongPressGestureRecognizer;
37+
#endif
38+
39+
NS_ASSUME_NONNULL_BEGIN
40+
41+
@protocol _WKTestingDelegate <NSObject>
42+
@optional
43+
44+
#if TARGET_OS_IPHONE
45+
@property (nonatomic, readonly) UILongPressGestureRecognizer *dataInteractionGestureRecognizer;
46+
- (void)webViewDidPerformDataInteractionControllerOperation:(WKWebView *)webView;
47+
- (void)webView:(WKWebView *)webView beginDataInteractionWithSourceIndex:(NSInteger)sourceIndex gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
48+
#endif // TARGET_OS_PHONE
49+
50+
@end
51+
52+
NS_ASSUME_NONNULL_END
53+
54+
#endif // WK_API_ENABLED

Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h

+9
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,15 @@ struct WKAutoCorrectionData {
271271
- (void)_didPerformDataInteractionControllerOperation;
272272
- (void)_didHandleStartDataInteractionRequest:(BOOL)started;
273273
- (void)_startDataInteractionWithImage:(RetainPtr<CGImageRef>)image atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint isLink:(BOOL)isLink;
274+
- (void)_simulateDataInteractionGestureRecognized:(UILongPressGestureRecognizer *)gestureRecognizer WK_API_AVAILABLE(ios(WK_IOS_TBA));
275+
- (void)_simulateDataInteractionEntered:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
276+
- (void)_simulateDataInteractionUpdated:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
277+
- (void)_simulateDataInteractionPerformOperation:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
278+
- (void)_simulateDataInteractionEnded:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
279+
- (void)_simulateDataInteractionSessionDidEnd:(id)session withOperation:(NSUInteger)operation WK_API_AVAILABLE(ios(WK_IOS_TBA));
280+
- (void)_simulateFailedDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
281+
- (void)_simulateWillBeginDataInteractionWithIndex:(NSInteger)sourceIndex withSession:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));
282+
- (NSArray *)_simulatedItemsForDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
274283
#endif
275284

276285
@end

Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

+10-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#import "_WKFocusedElementInfo.h"
6060
#import "_WKFormInputSession.h"
6161
#import "_WKInputDelegate.h"
62+
#import "_WKTestingDelegate.h"
6263
#import <CoreText/CTFont.h>
6364
#import <CoreText/CTFontDescriptor.h>
6465
#import <MobileCoreServices/UTCoreTypes.h>
@@ -557,7 +558,7 @@ - (void)setupInteraction
557558
[self _createAndConfigureLongPressGestureRecognizer];
558559

559560
#if ENABLE(DATA_INTERACTION)
560-
_dataInteractionGestureRecognizer = adoptNS([[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(_dataInteractionGestureRecognizer:)]);
561+
_dataInteractionGestureRecognizer = adoptNS([[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(_dataInteractionGestureRecognized:)]);
561562
[_dataInteractionGestureRecognizer setDelay:0.5];
562563
[_dataInteractionGestureRecognizer setDelegate:self];
563564
[_dataInteractionGestureRecognizer _setRequiresQuietImpulse:YES];
@@ -1467,6 +1468,14 @@ - (BOOL)pointIsInDataInteractionContent:(CGPoint)point
14671468
return _positionInformation.hasDataInteractionAtPosition;
14681469
}
14691470

1471+
- (UILongPressGestureRecognizer *)_dataInteractionGestureRecognizer
1472+
{
1473+
if ([_webView._testingDelegate respondsToSelector:@selector(dataInteractionGestureRecognizer)])
1474+
return _webView._testingDelegate.dataInteractionGestureRecognizer;
1475+
1476+
return _dataInteractionGestureRecognizer.get();
1477+
}
1478+
14701479
#endif
14711480

14721481
- (BOOL)pointIsNearMarkedText:(CGPoint)point

Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,7 @@
19471947
ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A22F0FF1289FCD90085E74F /* WKBundlePageOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
19481948
EDCA71B7128DDA8C00201B26 /* WKBundlePageOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A22F1001289FCD90085E74F /* WKBundlePageOverlay.cpp */; };
19491949
F036978815F4BF0500C3A80E /* WebColorPicker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F036978715F4BF0500C3A80E /* WebColorPicker.cpp */; };
1950+
F43370971E4D72ED00052B0E /* _WKTestingDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = F43370961E4D6A4400052B0E /* _WKTestingDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
19501951
F6113E25126CE1820057D0A7 /* APIUserContentURLPattern.h in Headers */ = {isa = PBXBuildFile; fileRef = F6113E24126CE1820057D0A7 /* APIUserContentURLPattern.h */; };
19511952
F6113E28126CE19B0057D0A7 /* WKUserContentURLPattern.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6113E26126CE19B0057D0A7 /* WKUserContentURLPattern.cpp */; };
19521953
F6113E29126CE19B0057D0A7 /* WKUserContentURLPattern.h in Headers */ = {isa = PBXBuildFile; fileRef = F6113E27126CE19B0057D0A7 /* WKUserContentURLPattern.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -4197,6 +4198,7 @@
41974198
E4E8648E1B1673FB00C82F40 /* VersionChecks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VersionChecks.h; sourceTree = "<group>"; };
41984199
E4E8648F1B1673FB00C82F40 /* VersionChecks.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VersionChecks.mm; sourceTree = "<group>"; };
41994200
F036978715F4BF0500C3A80E /* WebColorPicker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebColorPicker.cpp; sourceTree = "<group>"; };
4201+
F43370961E4D6A4400052B0E /* _WKTestingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKTestingDelegate.h; sourceTree = "<group>"; };
42004202
F6113E24126CE1820057D0A7 /* APIUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIUserContentURLPattern.h; sourceTree = "<group>"; };
42014203
F6113E26126CE19B0057D0A7 /* WKUserContentURLPattern.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKUserContentURLPattern.cpp; sourceTree = "<group>"; };
42024204
F6113E27126CE19B0057D0A7 /* WKUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserContentURLPattern.h; sourceTree = "<group>"; };
@@ -5397,6 +5399,7 @@
53975399
1A002D3F196B329400B9AD44 /* _WKSessionState.h */,
53985400
1A002D3E196B329400B9AD44 /* _WKSessionState.mm */,
53995401
1A002D42196B337000B9AD44 /* _WKSessionStateInternal.h */,
5402+
F43370961E4D6A4400052B0E /* _WKTestingDelegate.h */,
54005403
2D6B371918A967AD0042AE80 /* _WKThumbnailView.h */,
54015404
2D6B371A18A967AD0042AE80 /* _WKThumbnailView.mm */,
54025405
2DACE64D18ADBFF000E4CA76 /* _WKThumbnailViewInternal.h */,
@@ -8623,6 +8626,7 @@
86238626
373CEAD6185417AE008C363D /* WKNSData.h in Headers */,
86248627
371A19421824D29300F32A5E /* WKNSDictionary.h in Headers */,
86258628
372CAF0B1833FD910040AC27 /* WKNSError.h in Headers */,
8629+
F43370971E4D72ED00052B0E /* _WKTestingDelegate.h in Headers */,
86268630
375E0E141D66432700EFEC2C /* WKNSNumber.h in Headers */,
86278631
378E1A4A18208CD60031007A /* WKNSString.h in Headers */,
86288632
378E1A4E18208D700031007A /* WKNSURL.h in Headers */,

Tools/ChangeLog

+53
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
2017-02-13 Wenson Hsieh <[email protected]>
2+
3+
[WK2] Add test infrastructure and unit tests for data interaction
4+
https://bugs.webkit.org/show_bug.cgi?id=168159
5+
<rdar://problem/30477634>
6+
7+
Reviewed by Tim Horton.
8+
9+
Uses the testing delegate introduced in WebKit2 to override the gesture recognizer used to initiate data
10+
interaction. Instead of being driven by UIKit, the DataInteractionSimulator drives this overridden gesture
11+
recognizer by making the WKContentView call its dataInteractionGestureRecognized method. To simulate an actual
12+
gesture being performed, we fire the gesture recognizer (or call the data interaction delegate methods, if the
13+
gesture has already been recognized) at regular intervals over the course of the test.
14+
15+
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
16+
* TestWebKitAPI/Tests/WebKit2Cocoa/autofocus-contenteditable.html: Added.
17+
* TestWebKitAPI/Tests/WebKit2Cocoa/image-and-contenteditable.html: Added.
18+
* TestWebKitAPI/Tests/WebKit2Cocoa/image-and-textarea.html: Added.
19+
20+
New test pages for data interaction.
21+
22+
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm: Added.
23+
(TestWebKitAPI::runTestsExpectingToObserveEvents):
24+
(TestWebKitAPI::TEST):
25+
* TestWebKitAPI/cocoa/TestWKWebView.mm:
26+
(-[TestWKWebView stringByEvaluatingJavaScript:]):
27+
* TestWebKitAPI/ios/DataInteractionSimulator.h: Added.
28+
* TestWebKitAPI/ios/DataInteractionSimulator.mm: Added.
29+
(-[MockLongPressGestureRecognizer initWithWindow:]):
30+
(-[MockLongPressGestureRecognizer locationInView:]):
31+
(-[MockLongPressGestureRecognizer state]):
32+
(-[MockLongPressGestureRecognizer numberOfTouches]):
33+
(-[DataInteractionSimulator initWithWebView:startLocation:endLocation:]):
34+
(-[DataInteractionSimulator dealloc]):
35+
(-[DataInteractionSimulator run]):
36+
37+
Performs a data interaction gesture from the start location to the end location with linear interpolation. For
38+
now, the timestep and progress per tick are 30ms and 3.33%, respectively, which means that tests should complete
39+
in a little under 1 second, though this can be easily changed to be configurable in the future if needed.
40+
41+
(-[DataInteractionSimulator _advanceProgress]):
42+
43+
Fired periodically to drive the data interaction gesture. Schedules a call of itself until the test is
44+
completed, and calls _finishDataInteraction when progress is at 1.
45+
46+
(-[DataInteractionSimulator _finishDataInteraction]):
47+
(-[DataInteractionSimulator _currentLocation]):
48+
(-[DataInteractionSimulator _scheduleAdvanceProgress]):
49+
(-[DataInteractionSimulator _recognizeGestureAtLocation:withState:]):
50+
(-[DataInteractionSimulator dataInteractionGestureRecognizer]):
51+
(-[DataInteractionSimulator webViewDidPerformDataInteractionControllerOperation:]):
52+
(-[DataInteractionSimulator webView:beginDataInteractionWithSourceIndex:gestureRecognizer:]):
53+
154
2017-02-13 Alex Christensen <[email protected]>
255

356
Percent should be allowed in non-special URL hosts

0 commit comments

Comments
 (0)