Title: [211906] trunk
Revision
211906
Author
wenson_hs...@apple.com
Date
2017-02-08 15:30:52 -0800 (Wed, 08 Feb 2017)

Log Message

Add kUTTypeUTF8PlainText and kUTTypeJPEG to the list of compatible content types in DragData
https://bugs.webkit.org/show_bug.cgi?id=167942
<rdar://problem/30315079>

Reviewed by Tim Horton.

Source/WebCore:

Adds UTI types for dragging UTF8 plain text and JPEG images to the list of supported types in DragDataMac.mm.
Also handles reading these types in PasteboardMac.mm. I verified manually with a test app that if a platform
NSView vends only UTF8 plaintext or JPEG images when dragging, WebKit is able to read the contents of the
pasteboard as text and an image, respectively.

New TestWebKitAPI tests in DragAndDropPasteboardTests.mm.

* platform/mac/DragDataMac.mm:
(WebCore::DragData::containsCompatibleContent):
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::read):

Tools:

Adds a new test case that simulates dragging from a source that only vends JPEG images or UTF8 plaintext into a
contenteditable area. An image element and the plain text content, respectively, should be inserted into the
contenteditable in these cases.

The DragSource and DragInfo are used to mock dragging into the WebView. There is no reliance on using mouse
events in this test, since we call the dragging delegate methods (draggingEntered:, draggingUpdated:, and
performDragOperation:) directly.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/DragAndDropPasteboardTests.mm: Added.
(+[FrameLoadCompletionListener listenerWithCompletionBlock:]):
(-[FrameLoadCompletionListener initWithCompletionBlock:]):
(-[FrameLoadCompletionListener webView:didFinishLoadForFrame:]):
(-[DragSource draggingSourceOperationMaskForLocal:]):
(-[DragInfo initWithImage:offset:pasteboard:source:destinationWindow:]):
(-[DragInfo lastMousePosition]):
(-[DragInfo setLastMousePosition:]):
(-[DragInfo draggingDestinationWindow]):
(-[DragInfo draggingSourceOperationMask]):
(-[DragInfo draggingLocation]):
(-[DragInfo draggedImageLocation]):
(-[DragInfo draggedImage]):
(-[DragInfo draggingPasteboard]):
(-[DragInfo draggingSource]):
(-[DragInfo draggingSequenceNumber]):
(-[DragInfo slideDraggedImageTo:]):
(-[DragInfo namesOfPromisedFilesDroppedAtDestination:]):
(-[DragInfo draggingFormation]):
(-[DragInfo setDraggingFormation:]):
(-[DragInfo animatesToDestination]):
(-[DragInfo setAnimatesToDestination:]):
(-[DragInfo numberOfValidItemsForDrop]):
(-[DragInfo setNumberOfValidItemsForDrop:]):
(-[DragInfo enumerateDraggingItemsWithOptions:forView:classes:searchOptions:usingBlock:]):
(-[DragInfo springLoadingHighlight]):
(-[DragInfo resetSpringLoading]):
(TestWebKitAPI::getTestImage):
(TestWebKitAPI::webViewAfterPerformingDragOperation):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/mac/full-page-contenteditable.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (211905 => 211906)


--- trunk/Source/WebCore/ChangeLog	2017-02-08 23:15:58 UTC (rev 211905)
+++ trunk/Source/WebCore/ChangeLog	2017-02-08 23:30:52 UTC (rev 211906)
@@ -1,3 +1,23 @@
+2017-02-08  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Add kUTTypeUTF8PlainText and kUTTypeJPEG to the list of compatible content types in DragData
+        https://bugs.webkit.org/show_bug.cgi?id=167942
+        <rdar://problem/30315079>
+
+        Reviewed by Tim Horton.
+
+        Adds UTI types for dragging UTF8 plain text and JPEG images to the list of supported types in DragDataMac.mm.
+        Also handles reading these types in PasteboardMac.mm. I verified manually with a test app that if a platform
+        NSView vends only UTF8 plaintext or JPEG images when dragging, WebKit is able to read the contents of the
+        pasteboard as text and an image, respectively.
+
+        New TestWebKitAPI tests in DragAndDropPasteboardTests.mm.
+
+        * platform/mac/DragDataMac.mm:
+        (WebCore::DragData::containsCompatibleContent):
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::read):
+
 2017-02-08  Said Abou-Hallawa  <sabouhall...@apple.com>
 
         getIntersectionList always returns empty NodeList until layout is complete

Modified: trunk/Source/WebCore/platform/mac/DragDataMac.mm (211905 => 211906)


--- trunk/Source/WebCore/platform/mac/DragDataMac.mm	2017-02-08 23:15:58 UTC (rev 211905)
+++ trunk/Source/WebCore/platform/mac/DragDataMac.mm	2017-02-08 23:30:52 UTC (rev 211906)
@@ -204,8 +204,10 @@
         || types.contains(urlPasteboardType())
         || types.contains(rtfdPasteboardType())
         || types.contains(rtfPasteboardType())
+        || types.contains(String(kUTTypeUTF8PlainText))
         || types.contains(stringPasteboardType())
         || types.contains(colorPasteboardType())
+        || types.contains(String(kUTTypeJPEG))
         || types.contains(String(kUTTypePNG));
 }
 

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (211905 => 211906)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2017-02-08 23:15:58 UTC (rev 211905)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2017-02-08 23:30:52 UTC (rev 211906)
@@ -414,6 +414,13 @@
         }
     }
 
+    if (types.contains(String(kUTTypeJPEG))) {
+        if (RefPtr<SharedBuffer> buffer = strategy.bufferForType(kUTTypeJPEG, m_pasteboardName)) {
+            if (reader.readImage(buffer.releaseNonNull(), ASCIILiteral("image/jpeg")))
+                return;
+        }
+    }
+
     if (types.contains(String(NSURLPboardType))) {
         URL url = ""
         String title = strategy.stringForType(WebURLNamePboardType, m_pasteboardName);
@@ -426,6 +433,12 @@
         if (!string.isNull() && reader.readPlainText(string))
             return;
     }
+
+    if (types.contains(String(kUTTypeUTF8PlainText))) {
+        String string = strategy.stringForType(kUTTypeUTF8PlainText, m_pasteboardName);
+        if (!string.isNull() && reader.readPlainText(string))
+            return;
+    }
 }
 
 bool Pasteboard::hasData()

Modified: trunk/Tools/ChangeLog (211905 => 211906)


--- trunk/Tools/ChangeLog	2017-02-08 23:15:58 UTC (rev 211905)
+++ trunk/Tools/ChangeLog	2017-02-08 23:30:52 UTC (rev 211906)
@@ -1,3 +1,52 @@
+2017-02-08  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Add kUTTypeUTF8PlainText and kUTTypeJPEG to the list of compatible content types in DragData
+        https://bugs.webkit.org/show_bug.cgi?id=167942
+        <rdar://problem/30315079>
+
+        Reviewed by Tim Horton.
+
+        Adds a new test case that simulates dragging from a source that only vends JPEG images or UTF8 plaintext into a
+        contenteditable area. An image element and the plain text content, respectively, should be inserted into the
+        contenteditable in these cases.
+
+        The DragSource and DragInfo are used to mock dragging into the WebView. There is no reliance on using mouse
+        events in this test, since we call the dragging delegate methods (draggingEntered:, draggingUpdated:, and
+        performDragOperation:) directly.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/DragAndDropPasteboardTests.mm: Added.
+        (+[FrameLoadCompletionListener listenerWithCompletionBlock:]):
+        (-[FrameLoadCompletionListener initWithCompletionBlock:]):
+        (-[FrameLoadCompletionListener webView:didFinishLoadForFrame:]):
+        (-[DragSource draggingSourceOperationMaskForLocal:]):
+        (-[DragInfo initWithImage:offset:pasteboard:source:destinationWindow:]):
+        (-[DragInfo lastMousePosition]):
+        (-[DragInfo setLastMousePosition:]):
+        (-[DragInfo draggingDestinationWindow]):
+        (-[DragInfo draggingSourceOperationMask]):
+        (-[DragInfo draggingLocation]):
+        (-[DragInfo draggedImageLocation]):
+        (-[DragInfo draggedImage]):
+        (-[DragInfo draggingPasteboard]):
+        (-[DragInfo draggingSource]):
+        (-[DragInfo draggingSequenceNumber]):
+        (-[DragInfo slideDraggedImageTo:]):
+        (-[DragInfo namesOfPromisedFilesDroppedAtDestination:]):
+        (-[DragInfo draggingFormation]):
+        (-[DragInfo setDraggingFormation:]):
+        (-[DragInfo animatesToDestination]):
+        (-[DragInfo setAnimatesToDestination:]):
+        (-[DragInfo numberOfValidItemsForDrop]):
+        (-[DragInfo setNumberOfValidItemsForDrop:]):
+        (-[DragInfo enumerateDraggingItemsWithOptions:forView:classes:searchOptions:usingBlock:]):
+        (-[DragInfo springLoadingHighlight]):
+        (-[DragInfo resetSpringLoading]):
+        (TestWebKitAPI::getTestImage):
+        (TestWebKitAPI::webViewAfterPerformingDragOperation):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/mac/full-page-contenteditable.html: Added.
+
 2017-02-08  Jer Noble  <jer.no...@apple.com>
 
         Move FullscreenClient creation into WebViewImpl, for use in (deprecated) WKView.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (211905 => 211906)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-02-08 23:15:58 UTC (rev 211905)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-02-08 23:30:52 UTC (rev 211906)
@@ -549,6 +549,8 @@
 		E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
 		F415086D1DA040C50044BE9B /* play-audio-on-click.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F415086C1DA040C10044BE9B /* play-audio-on-click.html */; };
 		F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
+		F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */; };
+		F4BFA68E1E4AD08000154298 /* DragAndDropPasteboardTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */; };
 		F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */; };
 		F4F137921D9B683E002BEC57 /* large-video-test-now-playing.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */; };
 		F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; };
@@ -622,6 +624,7 @@
 			dstPath = TestWebKitAPI.resources;
 			dstSubfolderSpec = 7;
 			files = (
+				F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */,
 				C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */,
 				C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */,
 				C99B675C1E39721A00FC6C80 /* autoplay-with-controls.html in Copy Resources */,
@@ -1360,6 +1363,8 @@
 		F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		F415086C1DA040C10044BE9B /* play-audio-on-click.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "play-audio-on-click.html"; sourceTree = "<group>"; };
 		F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "large-input-field-focus-onload.html"; path = "Tests/WebKit2Cocoa/large-input-field-focus-onload.html"; sourceTree = SOURCE_ROOT; };
+		F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-page-contenteditable.html"; sourceTree = "<group>"; };
+		F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropPasteboardTests.mm; sourceTree = "<group>"; };
 		F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "enormous-video-with-sound.html"; sourceTree = "<group>"; };
 		F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-test-now-playing.html"; sourceTree = "<group>"; };
 		F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-size-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
@@ -2118,6 +2123,7 @@
 				37FB72951DB2E82F00E41BE4 /* ContextMenuDefaultItemsHaveTags.mm */,
 				3776BC62150946BC0043A66D /* DeviceScaleFactorInDashboardRegions.mm */,
 				939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */,
+				F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */,
 				37E1064A1697676400B78BD0 /* DOMHTMLTableCellCellAbove.mm */,
 				2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */,
 				46397B941DC2C850009A78AE /* DOMNode.mm */,
@@ -2180,6 +2186,7 @@
 				37E1064B169767F700B78BD0 /* DOMHTMLTableCellElementCellAbove.html */,
 				37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */,
 				1A7E8B351812093600AEB74A /* FragmentNavigation.html */,
+				F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */,
 				CDBFCC421A9FF44800A7B691 /* FullscreenZoomInitialFrame.html */,
 				9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */,
 				9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */,
@@ -2783,6 +2790,7 @@
 				7C89D2AC1A69B80D003A5FDE /* WKPageConfiguration.cpp in Sources */,
 				52D673EE1AFB127300FA19FE /* WKPageCopySessionStateWithFiltering.cpp in Sources */,
 				7CCE7F1F1A411AE600447C4C /* WKPageGetScaleFactorNotZero.cpp in Sources */,
+				F4BFA68E1E4AD08000154298 /* DragAndDropPasteboardTests.mm in Sources */,
 				7CCE7F201A411AE600447C4C /* WKPageIsPlayingAudio.cpp in Sources */,
 				2D00065F1C1F589A0088E6A7 /* WKPDFViewResizeCrash.mm in Sources */,
 				7CCE7F211A411AE600447C4C /* WKPreferences.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/mac/DragAndDropPasteboardTests.mm (0 => 211906)


--- trunk/Tools/TestWebKitAPI/Tests/mac/DragAndDropPasteboardTests.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/DragAndDropPasteboardTests.mm	2017-02-08 23:30:52 UTC (rev 211906)
@@ -0,0 +1,260 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if PLATFORM(MAC)
+
+#import "PlatformUtilities.h"
+#import <AppKit/NSDragging.h>
+#import <WebKit/WebView.h>
+#import <wtf/BlockPtr.h>
+#import <wtf/RetainPtr.h>
+
+@interface FrameLoadCompletionListener : NSObject<WebFrameLoadDelegate> {
+    BlockPtr<void (void)> _completionBlock;
+}
++ (instancetype)listenerWithCompletionBlock:(dispatch_block_t)completionBlock;
+@end
+
+@implementation FrameLoadCompletionListener
+
++ (instancetype)listenerWithCompletionBlock:(dispatch_block_t)completionBlock
+{
+    return [[[FrameLoadCompletionListener alloc] initWithCompletionBlock:completionBlock] autorelease];
+}
+
+- (instancetype)initWithCompletionBlock:(dispatch_block_t)completionBlock
+{
+    if (self = [super init])
+        _completionBlock = completionBlock;
+
+    return self;
+}
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    if (_completionBlock)
+        _completionBlock();
+}
+@end
+
+@interface DragSource : NSObject
+- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag;
+@end
+
+@implementation DragSource
+
+- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag
+{
+    return NSDragOperationCopy;
+}
+
+@end
+
+@interface DragInfo : NSObject<NSDraggingInfo> {
+    NSPoint _lastMousePosition;
+    RetainPtr<NSImage> _image;
+    RetainPtr<NSPasteboard> _pasteboard;
+    RetainPtr<DragSource> _source;
+    RetainPtr<NSWindow> _window;
+    NSSize _offset;
+}
+@property (nonatomic) NSPoint lastMousePosition;
+@end
+
+@implementation DragInfo
+
+- (id)initWithImage:(NSImage *)image offset:(NSSize)offset pasteboard:(NSPasteboard *)pasteboard source:(DragSource *)source destinationWindow:(NSWindow *)destinationWindow
+{
+    if (self = [super init]) {
+        _image = image;
+        _pasteboard = pasteboard;
+        _source = source;
+        _window = destinationWindow;
+        _offset = offset;
+    }
+    return self;
+}
+
+- (NSPoint)lastMousePosition
+{
+    return _lastMousePosition;
+}
+
+- (void)setLastMousePosition:(NSPoint)lastMousePosition
+{
+    _lastMousePosition = lastMousePosition;
+}
+
+- (NSWindow *)draggingDestinationWindow
+{
+    return _window.get();
+}
+
+- (NSDragOperation)draggingSourceOperationMask
+{
+    return NSDragOperationCopy;
+}
+
+- (NSPoint)draggingLocation
+{
+    return _lastMousePosition;
+}
+
+- (NSPoint)draggedImageLocation
+{
+    return NSMakePoint(_lastMousePosition.x + _offset.width, _lastMousePosition.y + _offset.height);
+}
+
+- (NSImage *)draggedImage
+{
+    return _image.get();
+}
+
+- (NSPasteboard *)draggingPasteboard
+{
+    return _pasteboard.get();
+}
+
+- (id)draggingSource
+{
+    return _source.get();
+}
+
+- (NSInteger)draggingSequenceNumber
+{
+    return 0;
+}
+
+- (void)slideDraggedImageTo:(NSPoint)screenPoint
+{
+}
+
+- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
+{
+    return nil;
+}
+
+- (NSDraggingFormation)draggingFormation
+{
+    return NSDraggingFormationDefault;
+}
+
+- (void)setDraggingFormation:(NSDraggingFormation)formation
+{
+}
+
+- (BOOL)animatesToDestination
+{
+    return NO;
+}
+
+- (void)setAnimatesToDestination:(BOOL)flag
+{
+}
+
+- (NSInteger)numberOfValidItemsForDrop
+{
+    return 1;
+}
+
+- (void)setNumberOfValidItemsForDrop:(NSInteger)number
+{
+}
+
+- (void)enumerateDraggingItemsWithOptions:(NSEnumerationOptions)enumOpts forView:(NSView *)view classes:(NSArray *)classArray searchOptions:(NSDictionary *)searchOptions usingBlock:(void (^)(NSDraggingItem *draggingItem, NSInteger idx, BOOL *stop))block
+{
+}
+
+#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
+
+- (NSSpringLoadingHighlight)springLoadingHighlight
+{
+    return NSSpringLoadingHighlightNone;
+}
+
+- (void)resetSpringLoading
+{
+}
+
+#endif
+
+@end
+
+namespace TestWebKitAPI {
+
+static NSImage *getTestImage()
+{
+    return [[[NSImage alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]] autorelease];
+}
+
+static WebView *webViewAfterPerformingDragOperation(NSPasteboard *pasteboard)
+{
+    RetainPtr<WebView> destination = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    RetainPtr<NSWindow> hostWindow = adoptNS([[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 400) styleMask:0 backing:NSBackingStoreBuffered defer:NO]);
+    [hostWindow setFrameOrigin:NSMakePoint(0, 0)];
+    [[hostWindow contentView] addSubview:destination.get()];
+    __block bool isDone = false;
+    [destination setFrameLoadDelegate:[FrameLoadCompletionListener listenerWithCompletionBlock:^() {
+        RetainPtr<DragSource> source = adoptNS([[DragSource alloc] init]);
+        RetainPtr<DragInfo> info = adoptNS([[DragInfo alloc] initWithImage:getTestImage() offset:NSMakeSize(0, 0) pasteboard:pasteboard source:source.get() destinationWindow:hostWindow.get()]);
+        [info setLastMousePosition:NSMakePoint(0, 200)];
+        [destination draggingEntered:info.get()];
+        [info setLastMousePosition:NSMakePoint(200, 200)];
+        [destination draggingUpdated:info.get()];
+
+        EXPECT_TRUE([destination performDragOperation:info.get()]);
+        isDone = true;
+    }]];
+    [[destination mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"full-page-contenteditable" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+
+    TestWebKitAPI::Util::run(&isDone);
+    return destination.get();
+}
+
+TEST(DragAndDropPasteboardTests, DropUTF8PlainText)
+{
+    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithUniqueName];
+    [pasteboard setData:[@"I am a WebKit." dataUsingEncoding:NSUTF8StringEncoding] forType:(__bridge NSString *)kUTTypeUTF8PlainText];
+
+    RetainPtr<WebView> resultingWebView = webViewAfterPerformingDragOperation(pasteboard);
+    EXPECT_TRUE([[resultingWebView stringByEvaluatingJavaScriptFromString:@"document.body.textContent"] containsString:@"I am a WebKit."]);
+}
+
+TEST(DragAndDropPasteboardTests, DropJPEG)
+{
+    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithUniqueName];
+    NSImage *icon = getTestImage();
+    NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:icon.TIFFRepresentation];
+    [pasteboard setData:[imageRep representationUsingType:NSJPEGFileType properties:@{ NSImageCompressionFactor: @(0.9) }] forType:(__bridge NSString *)kUTTypeJPEG];
+
+    RetainPtr<WebView> resultingWebView = webViewAfterPerformingDragOperation(pasteboard);
+    EXPECT_TRUE([[resultingWebView stringByEvaluatingJavaScriptFromString:@"document.querySelector('img').tagName === 'IMG'"] isEqualToString:@"true"]);
+}
+
+} // namespace TestWebKitAPI
+
+#endif

Added: trunk/Tools/TestWebKitAPI/Tests/mac/full-page-contenteditable.html (0 => 211906)


--- trunk/Tools/TestWebKitAPI/Tests/mac/full-page-contenteditable.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/full-page-contenteditable.html	2017-02-08 23:30:52 UTC (rev 211906)
@@ -0,0 +1 @@
+<body contenteditable style="width: 100%; height: 100%; margin: 0;">
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to