WebKit Bugzilla
Attachment 357080 Details for
Bug 192570
: [iOS] Support dropping contact card data (public.vcard) in editable content
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
First pass
bug-192570-20181211155326.patch (text/plain), 27.42 KB, created by
Wenson Hsieh
on 2018-12-11 15:53:26 PST
(
hide
)
Description:
First pass
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2018-12-11 15:53:26 PST
Size:
27.42 KB
patch
obsolete
>Subversion Revision: 239061 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index ce40be3952dfeca764dadce194fc1bd8d612829a..3746d1d4cc9981158ed7121e268eeed540e93798 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,53 @@ >+2018-12-11 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [iOS] Support dropping contact card data (public.vcard) in editable content >+ https://bugs.webkit.org/show_bug.cgi?id=192570 >+ <rdar://problem/35626913> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Adds support for accepting vCard (.vcf) data via drop on iOS. See below for more details. >+ >+ Tests: DragAndDropTests.ExternalSourceContactIntoEditableAreas >+ DragAndDropTests.ExternalSourceMapItemAndContactToUploadArea >+ DragAndDropTests.ExternalSourceMapItemIntoEditableAreas >+ WKAttachmentTestsIOS.InsertDroppedContactAsAttachment >+ WKAttachmentTestsIOS.InsertDroppedMapItemAsAttachment >+ >+ * editing/WebContentReader.h: >+ * editing/cocoa/WebContentReaderCocoa.mm: >+ (WebCore::attachmentForFilePath): >+ >+ Pull out logic to create an attachment from a file path out into a static helper. Use this in `readFilePaths` >+ as well as `readVirtualContactFile`. >+ >+ (WebCore::WebContentReader::readFilePaths): >+ (WebCore::WebContentReader::readVirtualContactFile): >+ >+ Add a pasteboard reading method that reads a vCard file (with an optional URL) as web content. The resulting >+ fragment consists of either an anchor and an attachment element, or just an attachment element if the URL is >+ empty. In the case of an `MKMapItem`, the URL is populated, so we generate both elements; when dragging a >+ contact, there is no associated URL, so we only have an attachment. >+ >+ * platform/Pasteboard.h: >+ * platform/ios/PasteboardIOS.mm: >+ (WebCore::Pasteboard::readPasteboardWebContentDataForType): >+ >+ Augment this to take the current `PasteboardItemInfo` as well; use this item information to get a file path for >+ "public.vcard" data, which is then passed on to the web content reader. Additionally, by returning >+ `ReaderResult::DidNotReadType` here, we prevent the web content reader from extracting the plain text contents >+ of the vCard and dumping it as plain text in the editable element (this would otherwise happen, since >+ "public.vcard" conforms to "public.text"). >+ >+ (WebCore::Pasteboard::read): >+ (WebCore::Pasteboard::readRespectingUTIFidelities): >+ * platform/ios/WebItemProviderPasteboard.mm: >+ (-[NSItemProvider web_fileUploadContentTypes]): >+ >+ Prevent the "com.apple.mapkit.map-item" UTI from being considered as file upload content. This special case is >+ tricky, since "com.apple.mapkit.map-item" conforms to "public.content", yet its corresponding data is only >+ suitable for deserialization into an `MKMapItem`. >+ > 2018-12-11 Wenson Hsieh <wenson_hsieh@apple.com> > > [iOS] Send the full list of file upload URLs and types in PasteboardItemInfo >diff --git a/Source/WebCore/editing/WebContentReader.h b/Source/WebCore/editing/WebContentReader.h >index e000a547bce873e56b58dca304f3d870fbd4f16d..c774b4a205943d8d4def7626399e43d55c3531e7 100644 >--- a/Source/WebCore/editing/WebContentReader.h >+++ b/Source/WebCore/editing/WebContentReader.h >@@ -77,6 +77,7 @@ private: > bool readRTF(SharedBuffer&) override; > bool readImage(Ref<SharedBuffer>&&, const String& type) override; > bool readURL(const URL&, const String& title) override; >+ bool readVirtualContactFile(const String& filePath, const URL&, const String& urlTitle) override; > #endif > bool readPlainText(const String&) override; > }; >@@ -94,6 +95,7 @@ private: > #if PLATFORM(COCOA) > bool readWebArchive(SharedBuffer&) override; > bool readFilePaths(const Vector<String>&) override { return false; } >+ bool readVirtualContactFile(const String&, const URL&, const String&) override { return false; } > bool readHTML(const String&) override; > bool readRTFD(SharedBuffer&) override; > bool readRTF(SharedBuffer&) override; >diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >index 41ee05ca697a03780f4e94926812fc8bef168a7a..ca702f5bd673b066cdd97a0f69957879ece316e2 100644 >--- a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >+++ b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >@@ -45,6 +45,7 @@ > #import "HTMLAttachmentElement.h" > #import "HTMLBRElement.h" > #import "HTMLBodyElement.h" >+#import "HTMLDivElement.h" > #import "HTMLIFrameElement.h" > #import "HTMLImageElement.h" > #import "HTMLObjectElement.h" >@@ -714,6 +715,45 @@ bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type) > return fragment; > } > >+#if ENABLE(ATTACHMENT_ELEMENT) >+ >+static Ref<Element> attachmentForFilePath(Frame& frame, const String& path) >+{ >+ auto document = makeRef(*frame.document()); >+ auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document); >+ if (!supportsClientSideAttachmentData(frame)) { >+ attachment->setFile(File::create(path), HTMLAttachmentElement::UpdateDisplayAttributes::Yes); >+ return attachment; >+ } >+ >+ String contentType; >+ std::optional<uint64_t> fileSizeForDisplay; >+ if (FileSystem::fileIsDirectory(path, FileSystem::ShouldFollowSymbolicLinks::Yes)) >+ contentType = kUTTypeDirectory; >+ else { >+ long long fileSize; >+ FileSystem::getFileSize(path, fileSize); >+ fileSizeForDisplay = fileSize; >+ contentType = File::contentTypeForFile(path); >+ if (contentType.isEmpty()) >+ contentType = kUTTypeData; >+ } >+ >+ frame.editor().registerAttachmentIdentifier(attachment->ensureUniqueIdentifier(), contentType, path); >+ >+ if (contentTypeIsSuitableForInlineImageRepresentation(contentType)) { >+ auto image = HTMLImageElement::create(document); >+ image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(path))); >+ image->setAttachmentElement(WTFMove(attachment)); >+ return image; >+ } >+ >+ attachment->updateAttributes(WTFMove(fileSizeForDisplay), contentType, FileSystem::pathGetFileName(path)); >+ return attachment; >+} >+ >+#endif // ENABLE(ATTACHMENT_ELEMENT) >+ > bool WebContentReader::readFilePaths(const Vector<String>& paths) > { > if (paths.isEmpty() || !frame.document()) >@@ -725,42 +765,36 @@ bool WebContentReader::readFilePaths(const Vector<String>& paths) > > #if ENABLE(ATTACHMENT_ELEMENT) > if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) { >- for (auto& path : paths) { >- auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document); >- if (supportsClientSideAttachmentData(frame)) { >- String contentType; >- std::optional<uint64_t> fileSizeForDisplay; >- if (FileSystem::fileIsDirectory(path, FileSystem::ShouldFollowSymbolicLinks::Yes)) >- contentType = kUTTypeDirectory; >- else { >- long long fileSize; >- FileSystem::getFileSize(path, fileSize); >- fileSizeForDisplay = fileSize; >- contentType = File::contentTypeForFile(path); >- if (contentType.isEmpty()) >- contentType = kUTTypeData; >- } >- frame.editor().registerAttachmentIdentifier(attachment->ensureUniqueIdentifier(), contentType, path); >- if (contentTypeIsSuitableForInlineImageRepresentation(contentType)) { >- auto image = HTMLImageElement::create(document); >- image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(path))); >- image->setAttachmentElement(WTFMove(attachment)); >- fragment->appendChild(image); >- } else { >- attachment->updateAttributes(WTFMove(fileSizeForDisplay), contentType, FileSystem::pathGetFileName(path)); >- fragment->appendChild(attachment); >- } >- } else { >- attachment->setFile(File::create(path), HTMLAttachmentElement::UpdateDisplayAttributes::Yes); >- fragment->appendChild(attachment); >- } >- } >+ for (auto& path : paths) >+ fragment->appendChild(attachmentForFilePath(frame, path)); > } > #endif > > return true; > } > >+bool WebContentReader::readVirtualContactFile(const String& filePath, const URL& url, const String& urlTitle) >+{ >+ if (filePath.isEmpty() || !frame.document()) >+ return false; >+ >+#if ENABLE(ATTACHMENT_ELEMENT) >+ auto& document = *frame.document(); >+ if (!fragment) >+ fragment = document.createDocumentFragment(); >+ >+ if (!url.isEmpty()) >+ readURL(url, urlTitle); >+ >+ auto attachmentContainer = HTMLDivElement::create(*frame.document()); >+ attachmentContainer->setInlineStyleProperty(CSSPropertyDisplay, CSSValueBlock, true); >+ attachmentContainer->appendChild(attachmentForFilePath(frame, filePath)); >+ fragment->appendChild(WTFMove(attachmentContainer)); >+#endif >+ >+ return true; >+} >+ > bool WebContentReader::readURL(const URL& url, const String& title) > { > if (url.isEmpty()) >diff --git a/Source/WebCore/platform/Pasteboard.h b/Source/WebCore/platform/Pasteboard.h >index c59b842ba9367929643c024544bd2f67f2604625..79d819beaf39e8c27a96e5ec59f4d3ebf30ba27e 100644 >--- a/Source/WebCore/platform/Pasteboard.h >+++ b/Source/WebCore/platform/Pasteboard.h >@@ -137,6 +137,7 @@ public: > #if PLATFORM(COCOA) > virtual bool readWebArchive(SharedBuffer&) = 0; > virtual bool readFilePaths(const Vector<String>&) = 0; >+ virtual bool readVirtualContactFile(const String& filePath, const URL&, const String& urlTitle) = 0; > virtual bool readHTML(const String&) = 0; > virtual bool readRTFD(SharedBuffer&) = 0; > virtual bool readRTF(SharedBuffer&) = 0; >@@ -287,7 +288,7 @@ private: > DidNotReadType, > PasteboardWasChangedExternally > }; >- ReaderResult readPasteboardWebContentDataForType(PasteboardWebContentReader&, PasteboardStrategy&, NSString *type, int itemIndex); >+ ReaderResult readPasteboardWebContentDataForType(PasteboardWebContentReader&, PasteboardStrategy&, NSString *type, int itemIndex, const PasteboardItemInfo&); > #endif > > #if PLATFORM(WIN) >diff --git a/Source/WebCore/platform/ios/PasteboardIOS.mm b/Source/WebCore/platform/ios/PasteboardIOS.mm >index 1d9b05788c6c6084b36e76e55026c751fe23e241..86e7e634f0600c35fca8ca53a3aea3c3c5b8457f 100644 >--- a/Source/WebCore/platform/ios/PasteboardIOS.mm >+++ b/Source/WebCore/platform/ios/PasteboardIOS.mm >@@ -181,7 +181,7 @@ static bool isTypeAllowedByReadingPolicy(NSString *type, WebContentReadingPolicy > || [type isEqualToString:(__bridge NSString *)kUTTypeFlatRTFD]; > } > >-Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(PasteboardWebContentReader& reader, PasteboardStrategy& strategy, NSString *type, int itemIndex) >+Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(PasteboardWebContentReader& reader, PasteboardStrategy& strategy, NSString *type, int itemIndex, const PasteboardItemInfo& info) > { > if ([type isEqualToString:WebArchivePboardType] || [type isEqualToString:(__bridge NSString *)kUTTypeWebArchive]) { > auto buffer = strategy.readBufferFromPasteboard(itemIndex, type, m_pasteboardName); >@@ -197,6 +197,28 @@ Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(Pastebo > return !htmlString.isNull() && reader.readHTML(htmlString) ? ReaderResult::ReadType : ReaderResult::DidNotReadType; > } > >+ if ([type isEqualToString:(__bridge NSString *)kUTTypeVCard]) { >+ bool canCreateAttachments = false; >+#if ENABLE(ATTACHMENT_ELEMENT) >+ if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) >+ canCreateAttachments = true; >+#endif >+ if (canCreateAttachments) { >+ auto path = info.pathForContentType(kUTTypeVCard); >+ if (path.isEmpty()) >+ return ReaderResult::DidNotReadType; >+ >+ String title; >+ auto url = strategy.readURLFromPasteboard(itemIndex, m_pasteboardName, title); >+ if (m_changeCount != changeCount()) >+ return ReaderResult::PasteboardWasChangedExternally; >+ >+ if (reader.readVirtualContactFile(path, url, title)) >+ return ReaderResult::ReadType; >+ } >+ return ReaderResult::DidNotReadType; >+ } >+ > #if !PLATFORM(IOSMAC) > if ([type isEqualToString:(__bridge NSString *)kUTTypeFlatRTFD]) { > RefPtr<SharedBuffer> buffer = strategy.readBufferFromPasteboard(itemIndex, kUTTypeFlatRTFD, m_pasteboardName); >@@ -269,7 +291,7 @@ void Pasteboard::read(PasteboardWebContentReader& reader, WebContentReadingPolic > if (!isTypeAllowedByReadingPolicy(type, policy)) > continue; > >- auto itemResult = readPasteboardWebContentDataForType(reader, strategy, type, i); >+ auto itemResult = readPasteboardWebContentDataForType(reader, strategy, type, i, strategy.informationForItemAtIndex(i, m_pasteboardName)); > if (itemResult == ReaderResult::PasteboardWasChangedExternally) > return; > >@@ -309,7 +331,7 @@ void Pasteboard::readRespectingUTIFidelities(PasteboardWebContentReader& reader, > if (!isTypeAllowedByReadingPolicy(type, policy)) > continue; > >- result = readPasteboardWebContentDataForType(reader, strategy, type, index); >+ result = readPasteboardWebContentDataForType(reader, strategy, type, index, info); > if (result == ReaderResult::PasteboardWasChangedExternally) > return; > if (result == ReaderResult::ReadType) >diff --git a/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm b/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm >index a8cecf6f8972c1d614f6107c879892a54c90711b..96296cb8d321e20fc3f4261e14392eb6d0762167 100644 >--- a/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm >+++ b/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm >@@ -80,6 +80,12 @@ - (NSArray<NSString *> *)web_fileUploadContentTypes > if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeURL)) > continue; > >+ if ([identifier isEqualToString:@"com.apple.mapkit.map-item"]) { >+ // This type conforms to "public.content", yet the corresponding data is only a serialization of MKMapItem and isn't suitable for file uploads. >+ // Ignore over this type representation for the purposes of file uploads, in favor of "public.vcard" data. >+ continue; >+ } >+ > if (typeConformsToTypes(identifier, Pasteboard::supportedFileUploadPasteboardTypes())) > [types addObject:identifier]; > } >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index c3ecd73e1c8c91b60992950203416e02ff03712c..3d31ef39610553eb101984cd820aad6d1976afa1 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,27 @@ >+2018-12-11 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [iOS] Support dropping contact card data (public.vcard) in editable content >+ https://bugs.webkit.org/show_bug.cgi?id=192570 >+ <rdar://problem/35626913> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm: >+ >+ Add API tests to verify that registering `MKMapItem`s and `CNContact`s to item providers and dropping them in >+ attachment-enabled rich text editable areas inserts attachment elements (and in the case of `MKMapItem`, >+ additionally inserts a link). >+ >+ * TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm: >+ (TestWebKitAPI::createMapItemForTesting): >+ (TestWebKitAPI::createContactItemForTesting): >+ >+ Add API tests to verify that dropping map items and contact items into rich and plain editable areas behaves as >+ expected (in the case where a URL is present, e.g. dropping a map item, we insert the URL as an anchor, and when >+ there is no other suitable representation in the item provider, we do nothing at all, which is the case for the >+ dropped `CNContact`). Also, add a test to verify that drag and drop can be used to upload these items as .vcf >+ files. >+ > 2018-12-10 Don Olmstead <don.olmstead@sony.com> > > [CMake] Add ENABLE_RESOURCE_LOAD_STATISTICS to WebKitFeatures.cmake >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm >index 94472adf90e162a4e665d21a672b0d650748dc4d..e5668a8a61bcace4b21fa47a6153d2125af0891f 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm >@@ -31,16 +31,26 @@ > #import "TestNavigationDelegate.h" > #import "TestWKWebView.h" > #import "WKWebViewConfigurationExtras.h" >+#import <Contacts/Contacts.h> >+#import <MapKit/MapKit.h> > #import <WebKit/WKPreferencesRefPrivate.h> > #import <WebKit/WKWebViewPrivate.h> > #import <WebKit/WebArchive.h> > #import <WebKit/WebKitPrivate.h> > #import <wtf/RetainPtr.h> >+#import <wtf/SoftLinking.h> > > #if PLATFORM(IOS_FAMILY) > #import <MobileCoreServices/MobileCoreServices.h> > #endif > >+SOFT_LINK_FRAMEWORK(Contacts) >+SOFT_LINK_CLASS(Contacts, CNMutableContact) >+ >+SOFT_LINK_FRAMEWORK(MapKit) >+SOFT_LINK_CLASS(MapKit, MKMapItem) >+SOFT_LINK_CLASS(MapKit, MKPlacemark) >+ > #define USES_MODERN_ATTRIBUTED_STRING_CONVERSION ((PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)) > > #if WK_API_ENABLED && !PLATFORM(WATCHOS) && !PLATFORM(TVOS) >@@ -1808,6 +1818,56 @@ TEST(WKAttachmentTestsIOS, DragAttachmentInsertedAsData) > [dragAndDropSimulator endDataTransfer]; > } > >+TEST(WKAttachmentTestsIOS, InsertDroppedMapItemAsAttachment) >+{ >+ auto placemark = adoptNS([allocMKPlacemarkInstance() initWithCoordinate:CLLocationCoordinate2DMake(37.3327, -122.0053)]); >+ auto mapItem = adoptNS([allocMKMapItemInstance() initWithPlacemark:placemark.get()]); >+ [mapItem setName:@"Apple Park"]; >+ >+ auto itemProvider = adoptNS([[NSItemProvider alloc] init]); >+ [itemProvider registerObject:mapItem.get() visibility:NSItemProviderRepresentationVisibilityAll]; >+ [itemProvider setSuggestedName:[mapItem name]]; >+ >+ auto webView = webViewForTestingAttachments(); >+ auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]); >+ [simulator setExternalItemProviders:@[ itemProvider.get() ]]; >+ [simulator runFrom:CGPointMake(25, 25) to:CGPointMake(100, 100)]; >+ >+ NSURL *droppedLinkURL = [NSURL URLWithString:[webView valueOfAttribute:@"href" forQuerySelector:@"a"]]; >+ [webView expectElementTag:@"A" toComeBefore:@"ATTACHMENT"]; >+ EXPECT_WK_STREQ("maps.apple.com", droppedLinkURL.host); >+ EXPECT_WK_STREQ("Apple Park.vcf", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]); >+ EXPECT_WK_STREQ("text/vcard", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]); >+ EXPECT_EQ(1U, [simulator insertedAttachments].count); >+ _WKAttachmentInfo *info = [simulator insertedAttachments].firstObject.info; >+ EXPECT_WK_STREQ("Apple Park.vcf", info.name); >+ EXPECT_WK_STREQ("text/vcard", info.contentType); >+} >+ >+TEST(WKAttachmentTestsIOS, InsertDroppedContactAsAttachment) >+{ >+ auto contact = adoptNS([allocCNMutableContactInstance() init]); >+ [contact setGivenName:@"Ben"]; >+ [contact setFamilyName:@"Bitdiddle"]; >+ >+ auto itemProvider = adoptNS([[NSItemProvider alloc] init]); >+ [itemProvider registerObject:contact.get() visibility:NSItemProviderRepresentationVisibilityAll]; >+ [itemProvider setSuggestedName:@"Ben"]; >+ >+ auto webView = webViewForTestingAttachments(); >+ auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]); >+ [simulator setExternalItemProviders:@[ itemProvider.get() ]]; >+ [simulator runFrom:CGPointMake(25, 25) to:CGPointMake(100, 100)]; >+ >+ [webView expectElementCount:0 querySelector:@"a"]; >+ EXPECT_WK_STREQ("Ben.vcf", [webView stringByEvaluatingJavaScript:@"document.querySelector('attachment').title"]); >+ EXPECT_WK_STREQ("text/vcard", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]); >+ EXPECT_EQ(1U, [simulator insertedAttachments].count); >+ _WKAttachmentInfo *info = [simulator insertedAttachments].firstObject.info; >+ EXPECT_WK_STREQ("Ben.vcf", info.name); >+ EXPECT_WK_STREQ("text/vcard", info.contentType); >+} >+ > #if HAVE(PENCILKIT) > static BOOL forEachViewInHierarchy(UIView *view, void(^mapFunction)(UIView *subview, BOOL *stop)) > { >diff --git a/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm b/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm >index ba9f79f58ca9316360d31d7a3e31f27eabe7b68e..0e64c3c87c72f062a105a0fa7a0381f46849515c 100644 >--- a/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm >+++ b/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm >@@ -33,6 +33,8 @@ > #import "TestWKWebView.h" > #import "UIKitSPI.h" > #import "WKWebViewConfigurationExtras.h" >+#import <Contacts/Contacts.h> >+#import <MapKit/MapKit.h> > #import <MobileCoreServices/MobileCoreServices.h> > #import <UIKit/NSItemProvider+UIKitAdditions.h> > #import <WebKit/WKPreferencesPrivate.h> >@@ -42,6 +44,14 @@ > #import <WebKit/WebItemProviderPasteboard.h> > #import <WebKit/_WKProcessPoolConfiguration.h> > #import <wtf/Seconds.h> >+#import <wtf/SoftLinking.h> >+ >+SOFT_LINK_FRAMEWORK(Contacts) >+SOFT_LINK_CLASS(Contacts, CNMutableContact) >+ >+SOFT_LINK_FRAMEWORK(MapKit) >+SOFT_LINK_CLASS(MapKit, MKMapItem) >+SOFT_LINK_CLASS(MapKit, MKPlacemark) > > typedef void (^FileLoadCompletionBlock)(NSURL *, BOOL, NSError *); > typedef void (^DataLoadCompletionBlock)(NSData *, NSError *); >@@ -187,8 +197,6 @@ static void checkDragCaretRectIsContainedInRect(CGRect caretRect, CGRect contain > NSLog(@"Expected caret rect: %@ to fit within container rect: %@", NSStringFromCGRect(caretRect), NSStringFromCGRect(containerRect)); > } > >-#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 >- > static void checkJSONWithLogging(NSString *jsonString, NSDictionary *expected) > { > BOOL success = TestWebKitAPI::Util::jsonMatchesExpectedValues(jsonString, expected); >@@ -251,8 +259,6 @@ static void runTestWithTemporaryFolder(void(^runTest)(NSURL *folderURL)) > } > } > >-#endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 >- > namespace TestWebKitAPI { > > TEST(DragAndDropTests, ImageToContentEditable) >@@ -1061,7 +1067,76 @@ TEST(DragAndDropTests, ExternalSourceOverrideDropFileUpload) > EXPECT_FALSE([simulator lastKnownDropProposal].precise); > } > >-#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 >+static RetainPtr<NSItemProvider> createMapItemForTesting() >+{ >+ auto placemark = adoptNS([allocMKPlacemarkInstance() initWithCoordinate:CLLocationCoordinate2DMake(37.3327, -122.0053)]); >+ auto item = adoptNS([allocMKMapItemInstance() initWithPlacemark:placemark.get()]); >+ [item setName:@"Apple Park"]; >+ >+ auto itemProvider = adoptNS([[NSItemProvider alloc] init]); >+ [itemProvider registerObject:item.get() visibility:NSItemProviderRepresentationVisibilityAll]; >+ [itemProvider setSuggestedName:[item name]]; >+ >+ return itemProvider; >+} >+ >+static RetainPtr<NSItemProvider> createContactItemForTesting() >+{ >+ auto contact = adoptNS([allocCNMutableContactInstance() init]); >+ [contact setGivenName:@"Ben"]; >+ [contact setFamilyName:@"Bitdiddle"]; >+ >+ auto itemProvider = adoptNS([[NSItemProvider alloc] init]); >+ [itemProvider registerObject:contact.get() visibility:NSItemProviderRepresentationVisibilityAll]; >+ [itemProvider setSuggestedName:@"Ben"]; >+ >+ return itemProvider; >+} >+ >+TEST(DragAndDropTests, ExternalSourceMapItemIntoEditableAreas) >+{ >+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); >+ [webView synchronouslyLoadTestPageNamed:@"contenteditable-and-textarea"]; >+ [webView _synchronouslyExecuteEditCommand:@"Delete" argument:nil]; >+ >+ auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]); >+ [simulator setExternalItemProviders:@[ createMapItemForTesting().autorelease() ]]; >+ [simulator runFrom:CGPointMake(0, 0) to:CGPointMake(100, 100)]; >+ EXPECT_WK_STREQ("Apple Park", [webView stringByEvaluatingJavaScript:@"document.querySelector('div[contenteditable]').textContent"]); >+ NSURL *firstURL = [NSURL URLWithString:[webView stringByEvaluatingJavaScript:@"document.querySelector('a').href"]]; >+ EXPECT_WK_STREQ("maps.apple.com", firstURL.host); >+ >+ [simulator runFrom:CGPointMake(0, 0) to:CGPointMake(100, 300)]; >+ NSURL *secondURL = [NSURL URLWithString:[webView stringByEvaluatingJavaScript:@"document.querySelector('textarea').value"]]; >+ EXPECT_WK_STREQ("maps.apple.com", secondURL.host); >+} >+ >+TEST(DragAndDropTests, ExternalSourceContactIntoEditableAreas) >+{ >+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); >+ [webView synchronouslyLoadTestPageNamed:@"contenteditable-and-textarea"]; >+ [webView _synchronouslyExecuteEditCommand:@"Delete" argument:nil]; >+ >+ auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]); >+ [simulator setExternalItemProviders:@[ createContactItemForTesting().autorelease() ]]; >+ [simulator runFrom:CGPointMake(0, 0) to:CGPointMake(100, 100)]; >+ EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"document.querySelector('div[contenteditable]').textContent"]); >+ >+ [simulator runFrom:CGPointMake(0, 0) to:CGPointMake(100, 300)]; >+ EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"document.querySelector('textarea').textContent"]); >+} >+ >+TEST(DragAndDropTests, ExternalSourceMapItemAndContactToUploadArea) >+{ >+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); >+ [webView synchronouslyLoadTestPageNamed:@"file-uploading"]; >+ >+ auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]); >+ [simulator setExternalItemProviders:@[ createMapItemForTesting().autorelease(), createContactItemForTesting().autorelease() ]]; >+ [simulator runFrom:CGPointMake(200, 100) to:CGPointMake(100, 300)]; >+ >+ EXPECT_WK_STREQ("text/vcard, text/vcard", [webView stringByEvaluatingJavaScript:@"output.value"]); >+} > > static RetainPtr<TestWKWebView> setUpTestWebViewForDataTransferItems() > { >@@ -1143,8 +1218,6 @@ TEST(DragAndDropTests, ExternalSourceDataTransferItemGetPlainTextFileAsEntry) > EXPECT_WK_STREQ([expectedOutput componentsJoinedByString:@"\n"], [webView stringByEvaluatingJavaScript:@"output.value"]); > } > >-#endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 >- > TEST(DragAndDropTests, ExternalSourceOverrideDropInsertURL) > { > auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); >@@ -1562,8 +1635,6 @@ TEST(DragAndDropTests, DragLiftPreviewDataTransferSetDragImage) > checkCGRectIsEqualToCGRectWithLogging({{0, 400}, {215, 174}}, [simulator liftPreviews][0].view.frame); > } > >-#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 >- > static NSData *testIconImageData() > { > return [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png" inDirectory:@"TestWebKitAPI.resources"]]; >@@ -1987,8 +2058,6 @@ TEST(DragAndDropTests, DataTransferSanitizeHTML) > TestWebKitAPI::Util::run(&done); > } > >-#endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 >- > } // namespace TestWebKitAPI > > #endif // ENABLE(DRAG_SUPPORT) && PLATFORM(IOS_FAMILY) && WK_API_ENABLED
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192570
:
357080
|
357084
|
357085
|
357258