Title: [246198] trunk/Tools
Revision
246198
Author
wenson_hs...@apple.com
Date
2019-06-07 07:42:56 -0700 (Fri, 07 Jun 2019)

Log Message

[iOS] At least 6 API tests are failing due to an exception when writing NSAttributedString to the pasteboard
https://bugs.webkit.org/show_bug.cgi?id=198641
<rdar://problem/51266310>

Reviewed by Tim Horton.

Work around a bug in a lower-level framework, which currently prevents NSAttributedStrings from being written to
UIPasteboard by way of -[NSItemProvider registerObject:visibility:]. This is because, when saving a
representation of "public.rtfd" to disk, the default suggested filename (determined using CoreServices APIs
_UTTypeCreateSuggestedFilename and UTTypeCopyDescription) ends up being nil; UIKit then subsequently tries to
append nil as a path component using -URLByAppendingPathComponent:, which throws an exception. This only
reproduces on iOS simulator.

To work around this for the time being, simply avoid writing a representation of "public.rtfd" to disk. This
representation is actually ignored by most clients anyways (including WebKit), in favor of using
"com.apple.flat-rtfd".

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(applyWorkaroundToAllowWritingAttributedStringsToItemProviders):
(-[TestWKWebView initWithFrame:configuration:addToWindow:]):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (246197 => 246198)


--- trunk/Tools/ChangeLog	2019-06-07 14:17:49 UTC (rev 246197)
+++ trunk/Tools/ChangeLog	2019-06-07 14:42:56 UTC (rev 246198)
@@ -1,3 +1,28 @@
+2019-06-07  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [iOS] At least 6 API tests are failing due to an exception when writing NSAttributedString to the pasteboard
+        https://bugs.webkit.org/show_bug.cgi?id=198641
+        <rdar://problem/51266310>
+
+        Reviewed by Tim Horton.
+
+        Work around a bug in a lower-level framework, which currently prevents NSAttributedStrings from being written to
+        UIPasteboard by way of -[NSItemProvider registerObject:visibility:]. This is because, when saving a
+        representation of "public.rtfd" to disk, the default suggested filename (determined using CoreServices APIs
+        _UTTypeCreateSuggestedFilename and UTTypeCopyDescription) ends up being nil; UIKit then subsequently tries to
+        append nil as a path component using -URLByAppendingPathComponent:, which throws an exception. This only
+        reproduces on iOS simulator.
+
+        To work around this for the time being, simply avoid writing a representation of "public.rtfd" to disk. This
+        representation is actually ignored by most clients anyways (including WebKit), in favor of using
+        "com.apple.flat-rtfd".
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/cocoa/TestWKWebView.mm:
+        (applyWorkaroundToAllowWritingAttributedStringsToItemProviders):
+        (-[TestWKWebView initWithFrame:configuration:addToWindow:]):
+
 2019-06-06  Carlos Garcia Campos  <cgar...@igalia.com>
 
         REGRESSION(r244857): [GTK][WPE] Many tests are no longer run in the bots after r244857

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (246197 => 246198)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2019-06-07 14:17:49 UTC (rev 246197)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2019-06-07 14:42:56 UTC (rev 246198)
@@ -1010,10 +1010,10 @@
 
 TEST(WKAttachmentTests, InsertPastedAttributedStringContainingImage)
 {
+    auto webView = webViewForTestingAttachments();
     platformCopyRichTextWithImage();
 
     RetainPtr<_WKAttachment> attachment;
-    auto webView = webViewForTestingAttachments();
     {
         ObserveAttachmentUpdatesForScope observer(webView.get());
         [webView _synchronouslyExecuteEditCommand:@"Paste" argument:nil];
@@ -1036,12 +1036,12 @@
 
 TEST(WKAttachmentTests, InsertPastedAttributedStringContainingMultipleAttachments)
 {
+    auto webView = webViewForTestingAttachments();
     platformCopyRichTextWithMultipleAttachments();
 
     RetainPtr<_WKAttachment> imageAttachment;
     RetainPtr<_WKAttachment> zipAttachment;
     RetainPtr<_WKAttachment> pdfAttachment;
-    auto webView = webViewForTestingAttachments();
     {
         ObserveAttachmentUpdatesForScope observer(webView.get());
         [webView _synchronouslyExecuteEditCommand:@"Paste" argument:nil];

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm (246197 => 246198)


--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2019-06-07 14:17:49 UTC (rev 246197)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2019-06-07 14:42:56 UTC (rev 246198)
@@ -45,6 +45,7 @@
 
 #if PLATFORM(IOS_FAMILY)
 #import "UIKitSPI.h"
+#import <MobileCoreServices/MobileCoreServices.h>
 #import <wtf/SoftLinking.h>
 SOFT_LINK_FRAMEWORK(UIKit)
 SOFT_LINK_CLASS(UIKit, UIWindow)
@@ -272,6 +273,25 @@
 
 #if PLATFORM(IOS_FAMILY)
 
+static NSArray<NSString *> *writableTypeIdentifiersForItemProviderWithoutPublicRTFD()
+{
+    return @[
+        @"com.apple.uikit.attributedstring",
+        (__bridge NSString *)kUTTypeFlatRTFD,
+        (__bridge NSString *)kUTTypeUTF8PlainText,
+    ];
+}
+
+static void applyWorkaroundToAllowWritingAttributedStringsToItemProviders()
+{
+    // FIXME: Remove this once <rdar://problem/51510554> is fixed.
+    static std::unique_ptr<ClassMethodSwizzler> swizzler;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        swizzler = std::make_unique<ClassMethodSwizzler>(NSAttributedString.class, @selector(writableTypeIdentifiersForItemProvider), reinterpret_cast<IMP>(writableTypeIdentifiersForItemProviderWithoutPublicRTFD));
+    });
+}
+
 using InputSessionChangeCount = NSUInteger;
 static InputSessionChangeCount nextInputSessionChangeCount()
 {
@@ -323,6 +343,7 @@
     // FIXME: Remove this workaround once <https://webkit.org/b/175204> is fixed.
     _sharedCalloutBarSwizzler = std::make_unique<ClassMethodSwizzler>([UICalloutBar class], @selector(sharedCalloutBar), reinterpret_cast<IMP>(suppressUICalloutBar));
     _inputSessionChangeCount = 0;
+    applyWorkaroundToAllowWritingAttributedStringsToItemProviders();
 #endif
 
     return self;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to