Skip to content

Commit 49384b9

Browse files
[WK2] Add infrastructure and unit tests for file uploads using data interaction
https://bugs.webkit.org/show_bug.cgi?id=170903 <rdar://problem/31314689> Reviewed by Tim Horton. Source/WebKit2: See Tools/ChangeLog for more details. Makes a small adjustment to _simulateDataInteractionUpdated: to return a BOOL indicating whether or not to allow the operation to proceed. This is necessary for testing scenarios where multiple files are being "data interacted" onto an element. See <https://bugs.webkit.org/show_bug.cgi?id=170880> for more details about the change this patch is testing. * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _simulateDataInteractionUpdated:]): * UIProcess/API/Cocoa/WKWebViewPrivate.h: * UIProcess/ios/WKContentViewInteraction.h: Tools: Adds 5 new unit tests covering different cases of uploading files through data interaction, as well as infrastructure for simulating UIItemProviders that load file data. Makes a few adjustments to the DataInteractionSimulator along the way, detailed in the per-method annotations below. See <https://bugs.webkit.org/show_bug.cgi?id=170880> for more details about the change this patch is testing. New tests: DataInteractionTests.ExternalSourceImageToFileInput DataInteractionTests.ExternalSourceHTMLToUploadArea DataInteractionTests.ExternalSourceImageAndHTMLToSingleFileInput DataInteractionTests.ExternalSourceImageAndHTMLToMultipleFileInput DataInteractionTests.ExternalSourceImageAndHTMLToUploadArea * TestWebKitAPI/Tests/ios/DataInteractionTests.mm: (testIconImage): (temporaryURLForDataInteractionFileLoad): (cleanUpDataInteractionTemporaryPath): Creates and tears down temporary file directories for testing data interaction. (-[UIItemProvider registerFileRepresentationForTypeIdentifier:withData:filename:]): (TestWebKitAPI::TEST): * TestWebKitAPI/ios/DataInteractionSimulator.h: * TestWebKitAPI/ios/DataInteractionSimulator.mm: Make necessary changes to be able to test what happens when data interaction ends over an element with no operation. Previously, we would always simulate performing a data interaction operation when ending the simulation, but this causes us to wait indefinitely for a data operation response to arrive in the UI process. Instead, we need to note whether or not the content view is allowing data interaction, and only perform an operation and wait for the -didPerform call if the operation was allowed. Otherwise, we immediately transition the phase to Cancelled and end the run. (-[DataInteractionSimulator _resetSimulatedState]): (-[DataInteractionSimulator runFrom:to:]): (-[DataInteractionSimulator _concludeDataInteractionAndPerformOperationIfNecessary]): (-[DataInteractionSimulator _advanceProgress]): (-[DataInteractionSimulator externalItemProviders]): (-[DataInteractionSimulator setExternalItemProviders:]): Previously, we hard-coded DataInteractionSimulator to only support a single external item provider. In order to test the scenario where multiple files are being "data interacted" into a file-type input, we generalize this to take multiple item providers. (-[DataInteractionSimulator externalItemProvider]): Deleted. (-[DataInteractionSimulator setExternalItemProvider:]): Deleted. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@215502 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent ea12fb4 commit 49384b9

File tree

8 files changed

+262
-24
lines changed

8 files changed

+262
-24
lines changed

Source/WebKit2/ChangeLog

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2017-04-18 Wenson Hsieh <[email protected]>
2+
3+
[WK2] Add infrastructure and unit tests for file uploads using data interaction
4+
https://bugs.webkit.org/show_bug.cgi?id=170903
5+
<rdar://problem/31314689>
6+
7+
Reviewed by Tim Horton.
8+
9+
See Tools/ChangeLog for more details. Makes a small adjustment to _simulateDataInteractionUpdated: to return a
10+
BOOL indicating whether or not to allow the operation to proceed. This is necessary for testing scenarios where
11+
multiple files are being "data interacted" onto an element. See <https://bugs.webkit.org/show_bug.cgi?id=170880>
12+
for more details about the change this patch is testing.
13+
14+
* UIProcess/API/Cocoa/WKWebView.mm:
15+
(-[WKWebView _simulateDataInteractionUpdated:]):
16+
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
17+
* UIProcess/ios/WKContentViewInteraction.h:
18+
119
2017-04-18 Wenson Hsieh <[email protected]>
220

321
[WK2] Support DataTransfer::files() when performing a DHTML data interaction

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -5409,10 +5409,12 @@ - (void)_simulateDataInteractionEntered:(id)info
54095409
#endif
54105410
}
54115411

5412-
- (void)_simulateDataInteractionUpdated:(id)info
5412+
- (BOOL)_simulateDataInteractionUpdated:(id)info
54135413
{
54145414
#if ENABLE(DATA_INTERACTION)
5415-
[_contentView _simulateDataInteractionUpdated:info];
5415+
return [_contentView _simulateDataInteractionUpdated:info];
5416+
#else
5417+
return NO;
54165418
#endif
54175419
}
54185420

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
328328
- (NSDictionary *)_propertiesOfLayerWithID:(unsigned long long)layerID WK_API_AVAILABLE(ios(WK_IOS_TBA));
329329

330330
- (void)_simulateDataInteractionEntered:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
331-
- (void)_simulateDataInteractionUpdated:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
331+
- (BOOL)_simulateDataInteractionUpdated:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
332332
- (void)_simulateDataInteractionPerformOperation:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
333333
- (void)_simulateDataInteractionEnded:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
334334
- (void)_simulateDataInteractionSessionDidEnd:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));

Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ struct WKAutoCorrectionData {
295295
- (void)_didChangeDataInteractionCaretRect:(CGRect)previousRect currentRect:(CGRect)rect;
296296

297297
- (void)_simulateDataInteractionEntered:(id)info;
298-
- (void)_simulateDataInteractionUpdated:(id)info;
298+
- (BOOL)_simulateDataInteractionUpdated:(id)info;
299299
- (void)_simulateDataInteractionPerformOperation:(id)info;
300300
- (void)_simulateDataInteractionEnded:(id)info;
301301
- (void)_simulateDataInteractionSessionDidEnd:(id)session;

Tools/ChangeLog

+53
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
2017-04-18 Wenson Hsieh <[email protected]>
2+
3+
[WK2] Add infrastructure and unit tests for file uploads using data interaction
4+
https://bugs.webkit.org/show_bug.cgi?id=170903
5+
<rdar://problem/31314689>
6+
7+
Reviewed by Tim Horton.
8+
9+
Adds 5 new unit tests covering different cases of uploading files through data interaction, as well as
10+
infrastructure for simulating UIItemProviders that load file data. Makes a few adjustments to the
11+
DataInteractionSimulator along the way, detailed in the per-method annotations below. See
12+
<https://bugs.webkit.org/show_bug.cgi?id=170880> for more details about the change this patch is testing.
13+
14+
New tests:
15+
DataInteractionTests.ExternalSourceImageToFileInput
16+
DataInteractionTests.ExternalSourceHTMLToUploadArea
17+
DataInteractionTests.ExternalSourceImageAndHTMLToSingleFileInput
18+
DataInteractionTests.ExternalSourceImageAndHTMLToMultipleFileInput
19+
DataInteractionTests.ExternalSourceImageAndHTMLToUploadArea
20+
21+
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
22+
(testIconImage):
23+
(temporaryURLForDataInteractionFileLoad):
24+
(cleanUpDataInteractionTemporaryPath):
25+
26+
Creates and tears down temporary file directories for testing data interaction.
27+
28+
(-[UIItemProvider registerFileRepresentationForTypeIdentifier:withData:filename:]):
29+
(TestWebKitAPI::TEST):
30+
* TestWebKitAPI/ios/DataInteractionSimulator.h:
31+
* TestWebKitAPI/ios/DataInteractionSimulator.mm:
32+
33+
Make necessary changes to be able to test what happens when data interaction ends over an element with no
34+
operation. Previously, we would always simulate performing a data interaction operation when ending the
35+
simulation, but this causes us to wait indefinitely for a data operation response to arrive in the UI process.
36+
Instead, we need to note whether or not the content view is allowing data interaction, and only perform an
37+
operation and wait for the -didPerform call if the operation was allowed. Otherwise, we immediately transition
38+
the phase to Cancelled and end the run.
39+
40+
(-[DataInteractionSimulator _resetSimulatedState]):
41+
(-[DataInteractionSimulator runFrom:to:]):
42+
(-[DataInteractionSimulator _concludeDataInteractionAndPerformOperationIfNecessary]):
43+
(-[DataInteractionSimulator _advanceProgress]):
44+
(-[DataInteractionSimulator externalItemProviders]):
45+
(-[DataInteractionSimulator setExternalItemProviders:]):
46+
47+
Previously, we hard-coded DataInteractionSimulator to only support a single external item provider. In order to
48+
test the scenario where multiple files are being "data interacted" into a file-type input, we generalize this to
49+
take multiple item providers.
50+
51+
(-[DataInteractionSimulator externalItemProvider]): Deleted.
52+
(-[DataInteractionSimulator setExternalItemProvider:]): Deleted.
53+
154
2017-04-18 John Wilander <[email protected]>
255

356
Make WebCore::topPrivatelyControlledDomain() return "localhost" for localhost

Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm

+156-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,47 @@
3737
#import <WebKit/WKWebViewConfigurationPrivate.h>
3838
#import <WebKit/_WKProcessPoolConfiguration.h>
3939

40+
typedef void (^FileLoadCompletionBlock)(NSURL *, BOOL, NSError *);
41+
42+
static UIImage *testIconImage()
43+
{
44+
return [UIImage imageNamed:@"TestWebKitAPI.resources/icon.png"];
45+
}
46+
47+
static NSURL *temporaryURLForDataInteractionFileLoad(NSString *temporaryFileName)
48+
{
49+
NSString *temporaryDirectoryPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"data-interaction"];
50+
if (![[NSFileManager defaultManager] fileExistsAtPath:temporaryDirectoryPath])
51+
[[NSFileManager defaultManager] createDirectoryAtPath:temporaryDirectoryPath withIntermediateDirectories:YES attributes:nil error:nil];
52+
return [NSURL fileURLWithPath:[temporaryDirectoryPath stringByAppendingPathComponent:temporaryFileName]];
53+
}
54+
55+
static void cleanUpDataInteractionTemporaryPath()
56+
{
57+
NSArray *temporaryDirectoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] includingPropertiesForKeys:nil options:0 error:nil];
58+
for (NSURL *url in temporaryDirectoryContents) {
59+
if ([url.lastPathComponent rangeOfString:@"data-interaction"].location != NSNotFound)
60+
[[NSFileManager defaultManager] removeItemAtURL:url error:nil];
61+
}
62+
}
63+
64+
@implementation UIItemProvider (DataInteractionTests)
65+
66+
- (void)registerFileRepresentationForTypeIdentifier:(NSString *)typeIdentifier withData:(NSData *)data filename:(NSString *)filename
67+
{
68+
RetainPtr<NSData> retainedData = data;
69+
RetainPtr<NSURL> retainedTemporaryURL = temporaryURLForDataInteractionFileLoad(filename);
70+
[self registerFileRepresentationForTypeIdentifier:typeIdentifier fileOptions:0 visibility:NSItemProviderRepresentationVisibilityAll loadHandler: [retainedData, retainedTemporaryURL] (FileLoadCompletionBlock block) -> NSProgress * {
71+
[retainedData writeToFile:[retainedTemporaryURL path] atomically:YES];
72+
dispatch_async(dispatch_get_main_queue(), [retainedTemporaryURL, capturedBlock = makeBlockPtr(block)] {
73+
capturedBlock(retainedTemporaryURL.get(), NO, nil);
74+
});
75+
return nil;
76+
}];
77+
}
78+
79+
@end
80+
4081
@implementation TestWKWebView (DataInteractionTests)
4182

4283
- (BOOL)editorContainsImageElement
@@ -273,6 +314,118 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
273314
checkSelectionRectsWithLogging(@[ ], [dataInteractionSimulator finalSelectionRects]);
274315
}
275316

317+
TEST(DataInteractionTests, ExternalSourceImageToFileInput)
318+
{
319+
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
320+
[webView synchronouslyLoadTestPageNamed:@"file-uploading"];
321+
322+
RetainPtr<UIItemProvider> simulatedImageItemProvider = adoptNS([[UIItemProvider alloc] init]);
323+
NSData *imageData = UIImageJPEGRepresentation(testIconImage(), 0.5);
324+
[simulatedImageItemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeJPEG withData:imageData filename:@"image.png"];
325+
326+
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
327+
[dataInteractionSimulator setExternalItemProviders:@[ simulatedImageItemProvider.get() ]];
328+
[dataInteractionSimulator runFrom:CGPointMake(200, 100) to:CGPointMake(100, 100)];
329+
330+
NSString *outputValue = [webView stringByEvaluatingJavaScript:@"output.value"];
331+
EXPECT_WK_STREQ("image/jpeg", outputValue.UTF8String);
332+
333+
cleanUpDataInteractionTemporaryPath();
334+
}
335+
336+
TEST(DataInteractionTests, ExternalSourceHTMLToUploadArea)
337+
{
338+
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
339+
[webView synchronouslyLoadTestPageNamed:@"file-uploading"];
340+
341+
RetainPtr<UIItemProvider> simulatedHTMLItemProvider = adoptNS([[UIItemProvider alloc] init]);
342+
NSData *htmlData = [@"<body contenteditable></body>" dataUsingEncoding:NSUTF8StringEncoding];
343+
[simulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeHTML withData:htmlData filename:@"index.html"];
344+
345+
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
346+
[dataInteractionSimulator setExternalItemProviders:@[ simulatedHTMLItemProvider.get() ]];
347+
[dataInteractionSimulator runFrom:CGPointMake(200, 300) to:CGPointMake(100, 300)];
348+
349+
NSString *outputValue = [webView stringByEvaluatingJavaScript:@"output.value"];
350+
EXPECT_WK_STREQ("text/html", outputValue.UTF8String);
351+
352+
cleanUpDataInteractionTemporaryPath();
353+
}
354+
355+
TEST(DataInteractionTests, ExternalSourceImageAndHTMLToSingleFileInput)
356+
{
357+
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
358+
[webView synchronouslyLoadTestPageNamed:@"file-uploading"];
359+
360+
RetainPtr<UIItemProvider> simulatedImageItemProvider = adoptNS([[UIItemProvider alloc] init]);
361+
NSData *imageData = UIImageJPEGRepresentation(testIconImage(), 0.5);
362+
[simulatedImageItemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeJPEG withData:imageData filename:@"image.png"];
363+
364+
RetainPtr<UIItemProvider> simulatedHTMLItemProvider = adoptNS([[UIItemProvider alloc] init]);
365+
NSData *htmlData = [@"<body contenteditable></body>" dataUsingEncoding:NSUTF8StringEncoding];
366+
[simulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeHTML withData:htmlData filename:@"index.html"];
367+
368+
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
369+
[dataInteractionSimulator setExternalItemProviders:@[ simulatedHTMLItemProvider.get(), simulatedImageItemProvider.get() ]];
370+
[dataInteractionSimulator runFrom:CGPointMake(200, 100) to:CGPointMake(100, 100)];
371+
372+
NSString *outputValue = [webView stringByEvaluatingJavaScript:@"output.value"];
373+
EXPECT_WK_STREQ("", outputValue.UTF8String);
374+
375+
cleanUpDataInteractionTemporaryPath();
376+
}
377+
378+
TEST(DataInteractionTests, ExternalSourceImageAndHTMLToMultipleFileInput)
379+
{
380+
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
381+
[webView synchronouslyLoadTestPageNamed:@"file-uploading"];
382+
[webView stringByEvaluatingJavaScript:@"input.setAttribute('multiple', '')"];
383+
384+
RetainPtr<UIItemProvider> simulatedImageItemProvider = adoptNS([[UIItemProvider alloc] init]);
385+
NSData *imageData = UIImageJPEGRepresentation(testIconImage(), 0.5);
386+
[simulatedImageItemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeJPEG withData:imageData filename:@"image.png"];
387+
388+
RetainPtr<UIItemProvider> simulatedHTMLItemProvider = adoptNS([[UIItemProvider alloc] init]);
389+
NSData *htmlData = [@"<body contenteditable></body>" dataUsingEncoding:NSUTF8StringEncoding];
390+
[simulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeHTML withData:htmlData filename:@"index.html"];
391+
392+
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
393+
[dataInteractionSimulator setExternalItemProviders:@[ simulatedHTMLItemProvider.get(), simulatedImageItemProvider.get() ]];
394+
[dataInteractionSimulator runFrom:CGPointMake(200, 100) to:CGPointMake(100, 100)];
395+
396+
NSString *outputValue = [webView stringByEvaluatingJavaScript:@"output.value"];
397+
EXPECT_WK_STREQ("image/jpeg, text/html", outputValue.UTF8String);
398+
399+
cleanUpDataInteractionTemporaryPath();
400+
}
401+
402+
TEST(DataInteractionTests, ExternalSourceImageAndHTMLToUploadArea)
403+
{
404+
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
405+
[webView synchronouslyLoadTestPageNamed:@"file-uploading"];
406+
407+
RetainPtr<UIItemProvider> simulatedImageItemProvider = adoptNS([[UIItemProvider alloc] init]);
408+
NSData *imageData = UIImageJPEGRepresentation(testIconImage(), 0.5);
409+
[simulatedImageItemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeJPEG withData:imageData filename:@"image.png"];
410+
411+
RetainPtr<UIItemProvider> firstSimulatedHTMLItemProvider = adoptNS([[UIItemProvider alloc] init]);
412+
NSData *firstHTMLData = [@"<body contenteditable></body>" dataUsingEncoding:NSUTF8StringEncoding];
413+
[firstSimulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeHTML withData:firstHTMLData filename:@"index.html"];
414+
415+
RetainPtr<UIItemProvider> secondSimulatedHTMLItemProvider = adoptNS([[UIItemProvider alloc] init]);
416+
NSData *secondHTMLData = [@"<html><body>hello world</body></html>" dataUsingEncoding:NSUTF8StringEncoding];
417+
[secondSimulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeHTML withData:secondHTMLData filename:@"index.html"];
418+
419+
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
420+
[dataInteractionSimulator setExternalItemProviders:@[ simulatedImageItemProvider.get(), firstSimulatedHTMLItemProvider.get(), secondSimulatedHTMLItemProvider.get() ]];
421+
[dataInteractionSimulator runFrom:CGPointMake(200, 300) to:CGPointMake(100, 300)];
422+
423+
NSString *outputValue = [webView stringByEvaluatingJavaScript:@"output.value"];
424+
EXPECT_WK_STREQ("image/jpeg, text/html, text/html", outputValue.UTF8String);
425+
426+
cleanUpDataInteractionTemporaryPath();
427+
}
428+
276429
TEST(DataInteractionTests, ExternalSourceUTF8PlainTextOnly)
277430
{
278431
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
@@ -286,7 +439,7 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
286439
completionBlock([textPayload dataUsingEncoding:NSUTF8StringEncoding], nil);
287440
return [NSProgress discreteProgressWithTotalUnitCount:100];
288441
}];
289-
[dataInteractionSimulator setExternalItemProvider:simulatedItemProvider.get()];
442+
[dataInteractionSimulator setExternalItemProviders:@[ simulatedItemProvider.get() ]];
290443
[dataInteractionSimulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)];
291444
EXPECT_WK_STREQ(textPayload.UTF8String, [webView stringByEvaluatingJavaScript:@"editor.textContent"].UTF8String);
292445
checkSelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 1936, 227) ], [dataInteractionSimulator finalSelectionRects]);
@@ -297,15 +450,14 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
297450
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
298451
[webView synchronouslyLoadTestPageNamed:@"autofocus-contenteditable"];
299452

300-
UIImage *testImage = [UIImage imageNamed:@"TestWebKitAPI.resources/icon.png"];
301453
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
302454
RetainPtr<UIItemProvider> simulatedItemProvider = adoptNS([[UIItemProvider alloc] init]);
303455
[simulatedItemProvider registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypeJPEG options:nil loadHandler:^NSProgress *(UIItemProviderDataLoadCompletionBlock completionBlock)
304456
{
305-
completionBlock(UIImageJPEGRepresentation(testImage, 0.5), nil);
457+
completionBlock(UIImageJPEGRepresentation(testIconImage(), 0.5), nil);
306458
return [NSProgress discreteProgressWithTotalUnitCount:100];
307459
}];
308-
[dataInteractionSimulator setExternalItemProvider:simulatedItemProvider.get()];
460+
[dataInteractionSimulator setExternalItemProviders:@[ simulatedItemProvider.get() ]];
309461
[dataInteractionSimulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)];
310462
EXPECT_TRUE([webView editorContainsImageElement]);
311463
checkSelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 215, 174) ], [dataInteractionSimulator finalSelectionRects]);

Tools/TestWebKitAPI/ios/DataInteractionSimulator.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ typedef NS_ENUM(NSInteger, DataInteractionPhase) {
5454
RetainPtr<MockDataInteractionSession> _dataInteractionSession;
5555
RetainPtr<MockDataOperationSession> _dataOperationSession;
5656
RetainPtr<NSMutableArray> _observedEventNames;
57-
RetainPtr<UIItemProvider> _externalItemProvider;
57+
RetainPtr<NSArray> _externalItemProviders;
5858
RetainPtr<NSArray *> _sourceItemProviders;
5959
RetainPtr<NSArray *> _finalSelectionRects;
6060
CGPoint _startLocation;
6161
CGPoint _endLocation;
6262

63+
BOOL _shouldPerformOperation;
6364
double _currentProgress;
6465
bool _isDoneWithCurrentRun;
6566
DataInteractionPhase _phase;
@@ -71,7 +72,7 @@ typedef NS_ENUM(NSInteger, DataInteractionPhase) {
7172
@property (nonatomic) BOOL shouldEnsureUIApplication;
7273
@property (nonatomic) BlockPtr<BOOL(_WKActivatedElementInfo *)> showCustomActionSheetBlock;
7374
@property (nonatomic) BlockPtr<NSArray *(NSArray *)> convertItemProvidersBlock;
74-
@property (nonatomic, strong) UIItemProvider *externalItemProvider;
75+
@property (nonatomic, strong) NSArray *externalItemProviders;
7576
@property (nonatomic, readonly) NSArray *sourceItemProviders;
7677
@property (nonatomic, readonly) NSArray *observedEventNames;
7778
@property (nonatomic, readonly) NSArray *finalSelectionRects;

0 commit comments

Comments
 (0)