Changeset 246198 in webkit


Ignore:
Timestamp:
Jun 7, 2019 7:42:56 AM (5 years ago)
Author:
Wenson Hsieh
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:]):

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r246189 r246198  
     12019-06-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] At least 6 API tests are failing due to an exception when writing NSAttributedString to the pasteboard
     4        https://bugs.webkit.org/show_bug.cgi?id=198641
     5        <rdar://problem/51266310>
     6
     7        Reviewed by Tim Horton.
     8
     9        Work around a bug in a lower-level framework, which currently prevents NSAttributedStrings from being written to
     10        UIPasteboard by way of -[NSItemProvider registerObject:visibility:]. This is because, when saving a
     11        representation of "public.rtfd" to disk, the default suggested filename (determined using CoreServices APIs
     12        _UTTypeCreateSuggestedFilename and UTTypeCopyDescription) ends up being nil; UIKit then subsequently tries to
     13        append nil as a path component using -URLByAppendingPathComponent:, which throws an exception. This only
     14        reproduces on iOS simulator.
     15
     16        To work around this for the time being, simply avoid writing a representation of "public.rtfd" to disk. This
     17        representation is actually ignored by most clients anyways (including WebKit), in favor of using
     18        "com.apple.flat-rtfd".
     19
     20        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
     21        (TestWebKitAPI::TEST):
     22        * TestWebKitAPI/cocoa/TestWKWebView.mm:
     23        (applyWorkaroundToAllowWritingAttributedStringsToItemProviders):
     24        (-[TestWKWebView initWithFrame:configuration:addToWindow:]):
     25
    1262019-06-06  Carlos Garcia Campos  <cgarcia@igalia.com>
    227
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm

    r245839 r246198  
    10111011TEST(WKAttachmentTests, InsertPastedAttributedStringContainingImage)
    10121012{
     1013    auto webView = webViewForTestingAttachments();
    10131014    platformCopyRichTextWithImage();
    10141015
    10151016    RetainPtr<_WKAttachment> attachment;
    1016     auto webView = webViewForTestingAttachments();
    10171017    {
    10181018        ObserveAttachmentUpdatesForScope observer(webView.get());
     
    10371037TEST(WKAttachmentTests, InsertPastedAttributedStringContainingMultipleAttachments)
    10381038{
     1039    auto webView = webViewForTestingAttachments();
    10391040    platformCopyRichTextWithMultipleAttachments();
    10401041
     
    10421043    RetainPtr<_WKAttachment> zipAttachment;
    10431044    RetainPtr<_WKAttachment> pdfAttachment;
    1044     auto webView = webViewForTestingAttachments();
    10451045    {
    10461046        ObserveAttachmentUpdatesForScope observer(webView.get());
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

    r244955 r246198  
    4646#if PLATFORM(IOS_FAMILY)
    4747#import "UIKitSPI.h"
     48#import <MobileCoreServices/MobileCoreServices.h>
    4849#import <wtf/SoftLinking.h>
    4950SOFT_LINK_FRAMEWORK(UIKit)
     
    273274#if PLATFORM(IOS_FAMILY)
    274275
     276static NSArray<NSString *> *writableTypeIdentifiersForItemProviderWithoutPublicRTFD()
     277{
     278    return @[
     279        @"com.apple.uikit.attributedstring",
     280        (__bridge NSString *)kUTTypeFlatRTFD,
     281        (__bridge NSString *)kUTTypeUTF8PlainText,
     282    ];
     283}
     284
     285static void applyWorkaroundToAllowWritingAttributedStringsToItemProviders()
     286{
     287    // FIXME: Remove this once <rdar://problem/51510554> is fixed.
     288    static std::unique_ptr<ClassMethodSwizzler> swizzler;
     289    static dispatch_once_t onceToken;
     290    dispatch_once(&onceToken, ^{
     291        swizzler = std::make_unique<ClassMethodSwizzler>(NSAttributedString.class, @selector(writableTypeIdentifiersForItemProvider), reinterpret_cast<IMP>(writableTypeIdentifiersForItemProviderWithoutPublicRTFD));
     292    });
     293}
     294
    275295using InputSessionChangeCount = NSUInteger;
    276296static InputSessionChangeCount nextInputSessionChangeCount()
     
    324344    _sharedCalloutBarSwizzler = std::make_unique<ClassMethodSwizzler>([UICalloutBar class], @selector(sharedCalloutBar), reinterpret_cast<IMP>(suppressUICalloutBar));
    325345    _inputSessionChangeCount = 0;
     346    applyWorkaroundToAllowWritingAttributedStringsToItemProviders();
    326347#endif
    327348
Note: See TracChangeset for help on using the changeset viewer.