<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[245839] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/245839">245839</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2019-05-28 19:56:09 -0700 (Tue, 28 May 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Respect NSItemProvider's registered types when dropping files that are loaded in-place
https://bugs.webkit.org/show_bug.cgi?id=198315
<rdar://problem/51183762>

Reviewed by Tim Horton.

Source/WebCore:

Currently, logic in PasteboardIOS.mm and WebContentReaderCocoa.mm attempts to deduce the content type from the
file path when dropping attachments on iOS. Instead, we should be plumbing the content type through to the
reader.

Test: WKAttachmentTestsIOS.InsertDroppedImageWithNonImageFileExtension

* editing/WebContentReader.h:
* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::typeForAttachmentElement):

Add a helper method to determine which type to use in attachment elements. This makes the paste
(attachmentForData) and drop (attachmentForFilePaths) behave the same way, with respect to the type attribute
used to represent the attachment.

(WebCore::attachmentForFilePath):

Use the content type, if specified; otherwise, fall back to deducing it from the file path.

(WebCore::attachmentForData):
(WebCore::WebContentReader::readFilePath):
* platform/Pasteboard.h:
(WebCore::PasteboardWebContentReader::readFilePath):

Pass the highest fidelity representation's content type to the web content reader.

* platform/ios/PasteboardIOS.mm:
(WebCore::Pasteboard::readRespectingUTIFidelities):

Tools:

Adds a new API test to verify that when dropping a file that is loaded in-place with a file extension that is
not a .png (but was registered to the item provider as "public.png"), the resulting attachment is contained in
an image element, and the resulting attachment info indicates that the dropped attachment is a png file.

Additionally, rebaseline some existing tests.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(runTestWithTemporaryImageFile):
(TestWebKitAPI::TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreeditingWebContentReaderh">trunk/Source/WebCore/editing/WebContentReader.h</a></li>
<li><a href="#trunkSourceWebCoreeditingcocoaWebContentReaderCocoamm">trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformPasteboardh">trunk/Source/WebCore/platform/Pasteboard.h</a></li>
<li><a href="#trunkSourceWebCoreplatformiosPasteboardIOSmm">trunk/Source/WebCore/platform/ios/PasteboardIOS.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaWKAttachmentTestsmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (245838 => 245839)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2019-05-29 02:27:20 UTC (rev 245838)
+++ trunk/Source/WebCore/ChangeLog      2019-05-29 02:56:09 UTC (rev 245839)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2019-05-28  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] Respect NSItemProvider's registered types when dropping files that are loaded in-place
+        https://bugs.webkit.org/show_bug.cgi?id=198315
+        <rdar://problem/51183762>
+
+        Reviewed by Tim Horton.
+
+        Currently, logic in PasteboardIOS.mm and WebContentReaderCocoa.mm attempts to deduce the content type from the
+        file path when dropping attachments on iOS. Instead, we should be plumbing the content type through to the
+        reader.
+
+        Test: WKAttachmentTestsIOS.InsertDroppedImageWithNonImageFileExtension
+
+        * editing/WebContentReader.h:
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::typeForAttachmentElement):
+
+        Add a helper method to determine which type to use in attachment elements. This makes the paste
+        (attachmentForData) and drop (attachmentForFilePaths) behave the same way, with respect to the type attribute
+        used to represent the attachment.
+
+        (WebCore::attachmentForFilePath):
+
+        Use the content type, if specified; otherwise, fall back to deducing it from the file path.
+
+        (WebCore::attachmentForData):
+        (WebCore::WebContentReader::readFilePath):
+        * platform/Pasteboard.h:
+        (WebCore::PasteboardWebContentReader::readFilePath):
+
+        Pass the highest fidelity representation's content type to the web content reader.
+
+        * platform/ios/PasteboardIOS.mm:
+        (WebCore::Pasteboard::readRespectingUTIFidelities):
+
</ins><span class="cx"> 2019-05-28  Myles C. Maxfield  <mmaxfield@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Move idempotent text autosizing to StyleTreeResolver
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingWebContentReaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/WebContentReader.h (245838 => 245839)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/WebContentReader.h  2019-05-29 02:27:20 UTC (rev 245838)
+++ trunk/Source/WebCore/editing/WebContentReader.h     2019-05-29 02:56:09 UTC (rev 245839)
</span><span class="lines">@@ -71,7 +71,7 @@
</span><span class="cx"> private:
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     bool readWebArchive(SharedBuffer&) override;
</span><del>-    bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }) override;
</del><ins>+    bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }, const String& contentType = { }) override;
</ins><span class="cx">     bool readFilePaths(const Vector<String>&) override;
</span><span class="cx">     bool readHTML(const String&) override;
</span><span class="cx">     bool readRTFD(SharedBuffer&) override;
</span><span class="lines">@@ -95,7 +95,7 @@
</span><span class="cx"> private:
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     bool readWebArchive(SharedBuffer&) override;
</span><del>-    bool readFilePath(const String&, Optional<FloatSize> = { }) override { return false; }
</del><ins>+    bool readFilePath(const String&, Optional<FloatSize> = { }, const String& = { }) override { return false; }
</ins><span class="cx">     bool readFilePaths(const Vector<String>&) override { return false; }
</span><span class="cx">     bool readHTML(const String&) override;
</span><span class="cx">     bool readRTFD(SharedBuffer&) override;
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingcocoaWebContentReaderCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (245838 => 245839)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm      2019-05-29 02:27:20 UTC (rev 245838)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm 2019-05-29 02:56:09 UTC (rev 245839)
</span><span class="lines">@@ -695,8 +695,17 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx"> 
</span><del>-static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, Optional<FloatSize> preferredSize)
</del><ins>+static String typeForAttachmentElement(const String& contentType)
</ins><span class="cx"> {
</span><ins>+    if (contentType.isEmpty())
+        return { };
+
+    auto mimeType = mimeTypeFromContentType(contentType);
+    return mimeType.isEmpty() ? contentType : mimeType;
+}
+
+static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, Optional<FloatSize> preferredSize, const String& explicitContentType)
+{
</ins><span class="cx">     auto document = makeRef(*frame.document());
</span><span class="cx">     auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
</span><span class="cx">     if (!supportsClientSideAttachmentData(frame)) {
</span><span class="lines">@@ -704,17 +713,23 @@
</span><span class="cx">         return attachment;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    String contentType;
</del><ins>+    bool isDirectory = FileSystem::fileIsDirectory(path, FileSystem::ShouldFollowSymbolicLinks::Yes);
+    String contentType = typeForAttachmentElement(explicitContentType);
+    if (contentType.isEmpty()) {
+        if (isDirectory)
+            contentType = kUTTypeDirectory;
+        else {
+            contentType = File::contentTypeForFile(path);
+            if (contentType.isEmpty())
+                contentType = kUTTypeData;
+        }
+    }
+
</ins><span class="cx">     Optional<uint64_t> fileSizeForDisplay;
</span><del>-    if (FileSystem::fileIsDirectory(path, FileSystem::ShouldFollowSymbolicLinks::Yes))
-        contentType = kUTTypeDirectory;
-    else {
</del><ins>+    if (!isDirectory) {
</ins><span class="cx">         long long fileSize;
</span><span class="cx">         FileSystem::getFileSize(path, fileSize);
</span><span class="cx">         fileSizeForDisplay = fileSize;
</span><del>-        contentType = File::contentTypeForFile(path);
-        if (contentType.isEmpty())
-            contentType = kUTTypeData;
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     frame.editor().registerAttachmentIdentifier(attachment->ensureUniqueIdentifier(), contentType, path);
</span><span class="lines">@@ -738,8 +753,7 @@
</span><span class="cx"> {
</span><span class="cx">     auto document = makeRef(*frame.document());
</span><span class="cx">     auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
</span><del>-    auto mimeType = mimeTypeFromContentType(contentType);
-    auto typeForAttachmentElement = mimeType.isEmpty() ? contentType : mimeType;
</del><ins>+    auto attachmentType = typeForAttachmentElement(contentType);
</ins><span class="cx"> 
</span><span class="cx">     // FIXME: We should instead ask CoreServices for a preferred name corresponding to the given content type.
</span><span class="cx">     static const char* defaultAttachmentName = "file";
</span><span class="lines">@@ -751,15 +765,15 @@
</span><span class="cx">         fileName = name;
</span><span class="cx"> 
</span><span class="cx">     if (!supportsClientSideAttachmentData(frame)) {
</span><del>-        attachment->setFile(File::create(Blob::create(buffer, WTFMove(typeForAttachmentElement)), fileName));
</del><ins>+        attachment->setFile(File::create(Blob::create(buffer, WTFMove(attachmentType)), fileName));
</ins><span class="cx">         return attachment;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    frame.editor().registerAttachmentIdentifier(attachment->ensureUniqueIdentifier(), typeForAttachmentElement, fileName, buffer);
</del><ins>+    frame.editor().registerAttachmentIdentifier(attachment->ensureUniqueIdentifier(), attachmentType, fileName, buffer);
</ins><span class="cx"> 
</span><del>-    if (contentTypeIsSuitableForInlineImageRepresentation(typeForAttachmentElement)) {
</del><ins>+    if (contentTypeIsSuitableForInlineImageRepresentation(attachmentType)) {
</ins><span class="cx">         auto image = HTMLImageElement::create(document);
</span><del>-        image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(Blob::create(buffer, WTFMove(typeForAttachmentElement)), WTFMove(fileName))));
</del><ins>+        image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(Blob::create(buffer, WTFMove(attachmentType)), WTFMove(fileName))));
</ins><span class="cx">         image->setAttachmentElement(WTFMove(attachment));
</span><span class="cx">         if (preferredSize) {
</span><span class="cx">             image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
</span><span class="lines">@@ -768,13 +782,13 @@
</span><span class="cx">         return image;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    attachment->updateAttributes({ buffer.size() }, WTFMove(typeForAttachmentElement), WTFMove(fileName));
</del><ins>+    attachment->updateAttributes({ buffer.size() }, WTFMove(attachmentType), WTFMove(fileName));
</ins><span class="cx">     return attachment;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx"> 
</span><del>-bool WebContentReader::readFilePath(const String& path, Optional<FloatSize> preferredPresentationSize)
</del><ins>+bool WebContentReader::readFilePath(const String& path, Optional<FloatSize> preferredPresentationSize, const String& contentType)
</ins><span class="cx"> {
</span><span class="cx">     if (path.isEmpty() || !frame.document())
</span><span class="cx">         return false;
</span><span class="lines">@@ -785,7 +799,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx">     if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled())
</span><del>-        fragment->appendChild(attachmentForFilePath(frame, path, preferredPresentationSize));
</del><ins>+        fragment->appendChild(attachmentForFilePath(frame, path, preferredPresentationSize, contentType));
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     return true;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformPasteboardh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/Pasteboard.h (245838 => 245839)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/Pasteboard.h       2019-05-29 02:27:20 UTC (rev 245838)
+++ trunk/Source/WebCore/platform/Pasteboard.h  2019-05-29 02:56:09 UTC (rev 245839)
</span><span class="lines">@@ -136,7 +136,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     virtual bool readWebArchive(SharedBuffer&) = 0;
</span><del>-    virtual bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }) = 0;
</del><ins>+    virtual bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }, const String& contentType = { }) = 0;
</ins><span class="cx">     virtual bool readFilePaths(const Vector<String>&) = 0;
</span><span class="cx">     virtual bool readHTML(const String&) = 0;
</span><span class="cx">     virtual bool readRTFD(SharedBuffer&) = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosPasteboardIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/PasteboardIOS.mm (245838 => 245839)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/PasteboardIOS.mm       2019-05-29 02:27:20 UTC (rev 245838)
+++ trunk/Source/WebCore/platform/ios/PasteboardIOS.mm  2019-05-29 02:56:09 UTC (rev 245839)
</span><span class="lines">@@ -345,9 +345,10 @@
</span><span class="cx">         auto info = strategy.informationForItemAtIndex(index, m_pasteboardName);
</span><span class="cx">         auto attachmentFilePath = info.pathForHighestFidelityItem();
</span><span class="cx">         bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !attachmentFilePath.isEmpty();
</span><ins>+        auto contentType = info.contentTypeForHighestFidelityItem();
</ins><span class="cx">         if (canReadAttachment && prefersAttachmentRepresentation(info)) {
</span><del>-            readURLAlongsideAttachmentIfNecessary(reader, strategy, info.contentTypeForHighestFidelityItem(), m_pasteboardName, index);
-            reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize);
</del><ins>+            readURLAlongsideAttachmentIfNecessary(reader, strategy, contentType, m_pasteboardName, index);
+            reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize, contentType);
</ins><span class="cx">             continue;
</span><span class="cx">         }
</span><span class="cx"> #endif
</span><span class="lines">@@ -366,7 +367,7 @@
</span><span class="cx">         }
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx">         if (canReadAttachment && result == ReaderResult::DidNotReadType)
</span><del>-            reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize);
</del><ins>+            reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize, contentType);
</ins><span class="cx"> #endif
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (245838 => 245839)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2019-05-29 02:27:20 UTC (rev 245838)
+++ trunk/Tools/ChangeLog       2019-05-29 02:56:09 UTC (rev 245839)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2019-05-28  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] Respect NSItemProvider's registered types when dropping files that are loaded in-place
+        https://bugs.webkit.org/show_bug.cgi?id=198315
+        <rdar://problem/51183762>
+
+        Reviewed by Tim Horton.
+
+        Adds a new API test to verify that when dropping a file that is loaded in-place with a file extension that is
+        not a .png (but was registered to the item provider as "public.png"), the resulting attachment is contained in
+        an image element, and the resulting attachment info indicates that the dropped attachment is a png file.
+
+        Additionally, rebaseline some existing tests.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (runTestWithTemporaryImageFile):
+        (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2019-05-28  Yusuke Suzuki  <ysuzuki@apple.com>
</span><span class="cx"> 
</span><span class="cx">         GCHeapInspector should accept weird filename
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaWKAttachmentTestsmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (245838 => 245839)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm 2019-05-29 02:27:20 UTC (rev 245838)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm    2019-05-29 02:56:09 UTC (rev 245839)
</span><span class="lines">@@ -410,6 +410,24 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS_FAMILY)
+
+static void runTestWithTemporaryImageFile(NSString *fileName, void(^runTest)(NSURL *fileURL))
+{
+    NSFileManager *defaultManager = [NSFileManager defaultManager];
+    auto temporaryFilePath = retainPtr([NSTemporaryDirectory() stringByAppendingPathComponent:fileName]);
+    auto temporaryFileURL = retainPtr([NSURL fileURLWithPath:temporaryFilePath.get()]);
+    [defaultManager removeItemAtURL:temporaryFileURL.get() error:nil];
+    [testImageData() writeToFile:temporaryFilePath.get() atomically:YES];
+    @try {
+        runTest(temporaryFileURL.get());
+    } @finally {
+        [defaultManager removeItemAtURL:temporaryFileURL.get() error:nil];
+    }
+}
+
+#endif // PLATFORM(IOS_FAMILY)
+
</ins><span class="cx"> static void simulateFolderDragWithURL(DragAndDropSimulator *simulator, NSURL *folderURL)
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="lines">@@ -788,8 +806,13 @@
</span><span class="cx"> 
</span><span class="cx">         TestWKWebView *webView = [simulator webView];
</span><span class="cx">         auto attachment = retainPtr([simulator insertedAttachments].firstObject);
</span><ins>+#if PLATFORM(IOS_FAMILY)
+        NSString *expectedType = (__bridge NSString *)kUTTypeFolder;
+#else
+        NSString *expectedType = (__bridge NSString *)kUTTypeDirectory;
+#endif
</ins><span class="cx">         EXPECT_WK_STREQ([attachment uniqueIdentifier], [webView stringByEvaluatingJavaScript:@"document.querySelector('attachment').uniqueIdentifier"]);
</span><del>-        EXPECT_WK_STREQ((__bridge NSString *)kUTTypeDirectory, [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]);
</del><ins>+        EXPECT_WK_STREQ(expectedType, [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]);
</ins><span class="cx">         EXPECT_WK_STREQ(folderURL.lastPathComponent, [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]);
</span><span class="cx"> 
</span><span class="cx">         NSFileWrapper *image = [attachment info].fileWrapper.fileWrappers[@"image.png"];
</span><span class="lines">@@ -1704,9 +1727,9 @@
</span><span class="cx"> 
</span><span class="cx">     [webView expectElementCount:2 querySelector:@"ATTACHMENT"];
</span><span class="cx">     EXPECT_WK_STREQ("hello.rtf", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[0].getAttribute('title')"]);
</span><del>-    EXPECT_WK_STREQ("text/rtf", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[0].getAttribute('type')"]);
</del><ins>+    EXPECT_WK_STREQ((__bridge NSString *)kUTTypeFlatRTFD, [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[0].getAttribute('type')"]);
</ins><span class="cx">     EXPECT_WK_STREQ("world.txt", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[1].getAttribute('title')"]);
</span><del>-    EXPECT_WK_STREQ("text/plain", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[1].getAttribute('type')"]);
</del><ins>+    EXPECT_WK_STREQ((__bridge NSString *)kUTTypeUTF8PlainText, [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[1].getAttribute('type')"]);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TEST(WKAttachmentTestsIOS, InsertDroppedZipArchiveAsAttachment)
</span><span class="lines">@@ -1763,7 +1786,7 @@
</span><span class="cx">     [webView expectElementTagsInOrder:@[ @"ATTACHMENT", @"A", @"ATTACHMENT" ]];
</span><span class="cx"> 
</span><span class="cx">     EXPECT_WK_STREQ("first.txt", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[0].getAttribute('title')"]);
</span><del>-    EXPECT_WK_STREQ("text/plain", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[0].getAttribute('type')"]);
</del><ins>+    EXPECT_WK_STREQ((__bridge NSString *)kUTTypeUTF8PlainText, [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[0].getAttribute('type')"]);
</ins><span class="cx">     EXPECT_WK_STREQ([appleURL absoluteString], [webView valueOfAttribute:@"href" forQuerySelector:@"a"]);
</span><span class="cx">     EXPECT_WK_STREQ("second.pdf", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[1].getAttribute('title')"]);
</span><span class="cx">     EXPECT_WK_STREQ("application/pdf", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[1].getAttribute('type')"]);
</span><span class="lines">@@ -1966,6 +1989,32 @@
</span><span class="cx">     EXPECT_TRUE([webView canPerformAction:@selector(paste:) withSender:nil]);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(WKAttachmentTestsIOS, InsertDroppedImageWithNonImageFileExtension)
+{
+    runTestWithTemporaryImageFile(@"image.hello", ^(NSURL *fileURL) {
+        auto item = adoptNS([[NSItemProvider alloc] init]);
+        [item setSuggestedName:@"image.hello"];
+        [item registerFileRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePNG fileOptions:NSItemProviderFileOptionOpenInPlace visibility:NSItemProviderRepresentationVisibilityAll loadHandler:^NSProgress *(void (^callback)(NSURL *, BOOL, NSError *))
+        {
+            callback(fileURL, YES, nil);
+            return nil;
+        }];
+
+        auto webView = webViewForTestingAttachments();
+        auto dragAndDropSimulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]);
+        [dragAndDropSimulator setExternalItemProviders:@[ item.get() ]];
+        [dragAndDropSimulator runFrom:CGPointZero to:CGPointMake(50, 50)];
+
+        EXPECT_EQ(1U, [dragAndDropSimulator insertedAttachments].count);
+        _WKAttachment *attachment = [dragAndDropSimulator insertedAttachments].firstObject;
+        _WKAttachmentInfo *info = attachment.info;
+        EXPECT_WK_STREQ("image/png", info.contentType);
+        EXPECT_WK_STREQ("image.hello", info.filePath.lastPathComponent);
+        EXPECT_WK_STREQ("image.hello", info.name);
+        [webView expectElementCount:1 querySelector:@"IMG"];
+    });
+}
+
</ins><span class="cx"> #if HAVE(PENCILKIT)
</span><span class="cx"> static BOOL forEachViewInHierarchy(UIView *view, void(^mapFunction)(UIView *subview, BOOL *stop))
</span><span class="cx"> {
</span></span></pre>
</div>
</div>

</body>
</html>