[iOS] WKAttachmentTests.DropFolderAsAttachmentAndMoveByDragging encounters an excepti...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Aug 2018 18:04:54 +0000 (18:04 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Aug 2018 18:04:54 +0000 (18:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189049

Reviewed by Tim Horton.

Wrap an NSURL in a RetainPtr to prevent it from being freed prematurely. It seems this broke when I changed the
load handler from an Objective-C block that captured `folderURL` to a C++ lambda that didn't retain `folderURL`.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(simulateFolderDragWithURL):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235431 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm

index f750911..ccb23f4 100644 (file)
@@ -1,3 +1,16 @@
+2018-08-28  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] WKAttachmentTests.DropFolderAsAttachmentAndMoveByDragging encounters an exception on iOS simulator
+        https://bugs.webkit.org/show_bug.cgi?id=189049
+
+        Reviewed by Tim Horton.
+
+        Wrap an NSURL in a RetainPtr to prevent it from being freed prematurely. It seems this broke when I changed the
+        load handler from an Objective-C block that captured `folderURL` to a C++ lambda that didn't retain `folderURL`.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (simulateFolderDragWithURL):
+
 2018-08-27  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Attachment Support] Remove WebCore::AttachmentDisplayOptions and friends
index 70d2270..68d19ad 100644 (file)
@@ -416,8 +416,8 @@ static void simulateFolderDragWithURL(DragAndDropSimulator *simulator, NSURL *fo
     auto folderProvider = adoptNS([[NSItemProvider alloc] init]);
     [folderProvider setSuggestedName:folderURL.lastPathComponent];
     [folderProvider setPreferredPresentationStyle:UIPreferredPresentationStyleAttachment];
-    [folderProvider registerFileRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypeFolder fileOptions:0 visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[&] (void(^completion)(NSURL *, BOOL, NSError *)) -> NSProgress * {
-        completion(folderURL, NO, nil);
+    [folderProvider registerFileRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypeFolder fileOptions:0 visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[protectedFolderURL = retainPtr(folderURL)] (void(^completion)(NSURL *, BOOL, NSError *)) -> NSProgress * {
+        completion(protectedFolderURL.get(), NO, nil);
         return nil;
     }];
     simulator.externalItemProviders = @[ folderProvider.get() ];