25
25
26
26
#include " config.h"
27
27
28
- #if 0
28
+ #if ENABLE(DATA_INTERACTION)
29
29
30
30
#import " DataInteractionSimulator.h"
31
31
#import " PlatformUtilities.h"
48
48
return [UIImage imageNamed: @" TestWebKitAPI.resources/icon.png" ];
49
49
}
50
50
51
- static NSURL *temporaryURLForDataInteractionFileLoad(NSString *temporaryFileName)
52
- {
53
- NSString *temporaryDirectoryPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"data-interaction"];
54
- if (![[NSFileManager defaultManager] fileExistsAtPath:temporaryDirectoryPath])
55
- [[NSFileManager defaultManager] createDirectoryAtPath:temporaryDirectoryPath withIntermediateDirectories:YES attributes:nil error:nil];
56
- return [NSURL fileURLWithPath:[temporaryDirectoryPath stringByAppendingPathComponent:temporaryFileName]];
57
- }
58
-
59
- static void cleanUpDataInteractionTemporaryPath()
60
- {
61
- NSArray *temporaryDirectoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] includingPropertiesForKeys:nil options:0 error:nil];
62
- for (NSURL *url in temporaryDirectoryContents) {
63
- if ([url.lastPathComponent rangeOfString:@"data-interaction"].location != NSNotFound)
64
- [[NSFileManager defaultManager] removeItemAtURL:url error:nil];
65
- }
66
- }
67
-
68
51
@implementation UIItemProvider (DataInteractionTests)
69
52
70
- - (void)registerFileRepresentationForTypeIdentifier:(NSString *)typeIdentifier withData:(NSData *)data filename:(NSString *)filename
71
- {
72
- RetainPtr<NSData> retainedData = data;
73
- RetainPtr<NSURL> retainedTemporaryURL = temporaryURLForDataInteractionFileLoad(filename);
74
- [self registerFileRepresentationForTypeIdentifier:typeIdentifier fileOptions:0 visibility:NSItemProviderRepresentationVisibilityAll loadHandler: [retainedData, retainedTemporaryURL] (FileLoadCompletionBlock block) -> NSProgress * {
75
- [retainedData writeToFile:[retainedTemporaryURL path] atomically:YES];
76
- dispatch_async(dispatch_get_main_queue(), [retainedTemporaryURL, capturedBlock = makeBlockPtr(block)] {
77
- capturedBlock(retainedTemporaryURL.get(), NO, nil);
78
- });
79
- return nil;
80
- }];
81
- }
82
-
83
53
- (void )registerDataRepresentationForTypeIdentifier : (NSString *)typeIdentifier withData : (NSData *)data
84
54
{
85
55
RetainPtr<NSData > retainedData = data;
@@ -342,14 +312,13 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
342
312
343
313
RetainPtr<UIItemProvider> simulatedJSONItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
344
314
NSData *jsonData = [@" { \" foo\" : \" bar\" , \" bar\" : \" baz\" }" dataUsingEncoding: NSUTF8StringEncoding];
345
- [simulatedJSONItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeJSON withData:jsonData filename:@"data.json" ];
315
+ [simulatedJSONItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeJSON withData: jsonData];
346
316
347
317
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS ([[DataInteractionSimulator alloc ] initWithWebView: webView.get ()]);
348
318
[dataInteractionSimulator setExternalItemProviders: @[ simulatedJSONItemProvider.get () ]];
349
319
[dataInteractionSimulator runFrom: CGPointMake (200 , 100 ) to: CGPointMake (100 , 100 )];
350
320
351
321
EXPECT_WK_STREQ (" application/json" , [webView stringByEvaluatingJavaScript: @" output.value" ]);
352
- cleanUpDataInteractionTemporaryPath();
353
322
}
354
323
355
324
TEST (DataInteractionTests, ExternalSourceImageToFileInput)
@@ -359,16 +328,14 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
359
328
360
329
RetainPtr<UIItemProvider> simulatedImageItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
361
330
NSData *imageData = UIImageJPEGRepresentation (testIconImage (), 0.5 );
362
- [simulatedImageItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeJPEG withData:imageData filename:@"image.png" ];
331
+ [simulatedImageItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeJPEG withData: imageData];
363
332
364
333
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS ([[DataInteractionSimulator alloc ] initWithWebView: webView.get ()]);
365
334
[dataInteractionSimulator setExternalItemProviders: @[ simulatedImageItemProvider.get () ]];
366
335
[dataInteractionSimulator runFrom: CGPointMake (200 , 100 ) to: CGPointMake (100 , 100 )];
367
336
368
337
NSString *outputValue = [webView stringByEvaluatingJavaScript: @" output.value" ];
369
338
EXPECT_WK_STREQ (" image/jpeg" , outputValue.UTF8String );
370
-
371
- cleanUpDataInteractionTemporaryPath();
372
339
}
373
340
374
341
TEST (DataInteractionTests, ExternalSourceHTMLToUploadArea)
@@ -378,16 +345,14 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
378
345
379
346
RetainPtr<UIItemProvider> simulatedHTMLItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
380
347
NSData *htmlData = [@" <body contenteditable></body>" dataUsingEncoding: NSUTF8StringEncoding];
381
- [simulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeHTML withData:htmlData filename:@"index.html" ];
348
+ [simulatedHTMLItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeHTML withData: htmlData];
382
349
383
350
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS ([[DataInteractionSimulator alloc ] initWithWebView: webView.get ()]);
384
351
[dataInteractionSimulator setExternalItemProviders: @[ simulatedHTMLItemProvider.get () ]];
385
352
[dataInteractionSimulator runFrom: CGPointMake (200 , 300 ) to: CGPointMake (100 , 300 )];
386
353
387
354
NSString *outputValue = [webView stringByEvaluatingJavaScript: @" output.value" ];
388
355
EXPECT_WK_STREQ (" text/html" , outputValue.UTF8String );
389
-
390
- cleanUpDataInteractionTemporaryPath();
391
356
}
392
357
393
358
TEST (DataInteractionTests, ExternalSourceImageAndHTMLToSingleFileInput)
@@ -397,20 +362,18 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
397
362
398
363
RetainPtr<UIItemProvider> simulatedImageItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
399
364
NSData *imageData = UIImageJPEGRepresentation (testIconImage (), 0.5 );
400
- [simulatedImageItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeJPEG withData:imageData filename:@"image.png" ];
365
+ [simulatedImageItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeJPEG withData: imageData];
401
366
402
367
RetainPtr<UIItemProvider> simulatedHTMLItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
403
368
NSData *htmlData = [@" <body contenteditable></body>" dataUsingEncoding: NSUTF8StringEncoding];
404
- [simulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeHTML withData:htmlData filename:@"index.html" ];
369
+ [simulatedHTMLItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeHTML withData: htmlData];
405
370
406
371
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS ([[DataInteractionSimulator alloc ] initWithWebView: webView.get ()]);
407
372
[dataInteractionSimulator setExternalItemProviders: @[ simulatedHTMLItemProvider.get (), simulatedImageItemProvider.get () ]];
408
373
[dataInteractionSimulator runFrom: CGPointMake (200 , 100 ) to: CGPointMake (100 , 100 )];
409
374
410
375
NSString *outputValue = [webView stringByEvaluatingJavaScript: @" output.value" ];
411
376
EXPECT_WK_STREQ (" " , outputValue.UTF8String );
412
-
413
- cleanUpDataInteractionTemporaryPath();
414
377
}
415
378
416
379
TEST (DataInteractionTests, ExternalSourceImageAndHTMLToMultipleFileInput)
@@ -421,20 +384,18 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
421
384
422
385
RetainPtr<UIItemProvider> simulatedImageItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
423
386
NSData *imageData = UIImageJPEGRepresentation (testIconImage (), 0.5 );
424
- [simulatedImageItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeJPEG withData:imageData filename:@"image.png" ];
387
+ [simulatedImageItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeJPEG withData: imageData];
425
388
426
389
RetainPtr<UIItemProvider> simulatedHTMLItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
427
390
NSData *htmlData = [@" <body contenteditable></body>" dataUsingEncoding: NSUTF8StringEncoding];
428
- [simulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeHTML withData:htmlData filename:@"index.html" ];
391
+ [simulatedHTMLItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeHTML withData: htmlData];
429
392
430
393
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS ([[DataInteractionSimulator alloc ] initWithWebView: webView.get ()]);
431
394
[dataInteractionSimulator setExternalItemProviders: @[ simulatedHTMLItemProvider.get (), simulatedImageItemProvider.get () ]];
432
395
[dataInteractionSimulator runFrom: CGPointMake (200 , 100 ) to: CGPointMake (100 , 100 )];
433
396
434
397
NSString *outputValue = [webView stringByEvaluatingJavaScript: @" output.value" ];
435
398
EXPECT_WK_STREQ (" image/jpeg, text/html" , outputValue.UTF8String );
436
-
437
- cleanUpDataInteractionTemporaryPath();
438
399
}
439
400
440
401
TEST (DataInteractionTests, ExternalSourceImageAndHTMLToUploadArea)
@@ -444,24 +405,22 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
444
405
445
406
RetainPtr<UIItemProvider> simulatedImageItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
446
407
NSData *imageData = UIImageJPEGRepresentation (testIconImage (), 0.5 );
447
- [simulatedImageItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeJPEG withData:imageData filename:@"image.png" ];
408
+ [simulatedImageItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeJPEG withData: imageData];
448
409
449
410
RetainPtr<UIItemProvider> firstSimulatedHTMLItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
450
411
NSData *firstHTMLData = [@" <body contenteditable></body>" dataUsingEncoding: NSUTF8StringEncoding];
451
- [firstSimulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeHTML withData:firstHTMLData filename:@"index.html" ];
412
+ [firstSimulatedHTMLItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeHTML withData: firstHTMLData];
452
413
453
414
RetainPtr<UIItemProvider> secondSimulatedHTMLItemProvider = adoptNS ([[UIItemProvider alloc ] init ]);
454
415
NSData *secondHTMLData = [@" <html><body>hello world</body></html>" dataUsingEncoding: NSUTF8StringEncoding];
455
- [secondSimulatedHTMLItemProvider registerFileRepresentationForTypeIdentifier :(NSString *)kUTTypeHTML withData:secondHTMLData filename:@"index.html" ];
416
+ [secondSimulatedHTMLItemProvider registerDataRepresentationForTypeIdentifier : (NSString *)kUTTypeHTML withData: secondHTMLData];
456
417
457
418
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS ([[DataInteractionSimulator alloc ] initWithWebView: webView.get ()]);
458
419
[dataInteractionSimulator setExternalItemProviders: @[ simulatedImageItemProvider.get (), firstSimulatedHTMLItemProvider.get (), secondSimulatedHTMLItemProvider.get () ]];
459
420
[dataInteractionSimulator runFrom: CGPointMake (200 , 300 ) to: CGPointMake (100 , 300 )];
460
421
461
422
NSString *outputValue = [webView stringByEvaluatingJavaScript: @" output.value" ];
462
423
EXPECT_WK_STREQ (" image/jpeg, text/html, text/html" , outputValue.UTF8String );
463
-
464
- cleanUpDataInteractionTemporaryPath();
465
424
}
466
425
467
426
TEST (DataInteractionTests, RespectsExternalSourceFidelityRankings)
0 commit comments