Links with empty hrefs should not be drag sources
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Mar 2017 19:29:25 +0000 (19:29 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Mar 2017 19:29:25 +0000 (19:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170241
<rdar://problem/31305505>

Reviewed by Tim Horton.

Source/WebCore:

The m_dragSouceAction member of DragController represents the drag source actions that are available to the
document, rather than the available actions given the dragging element. Thus, it is not correct to only check
that (m_dragSourceAction & DragSourceActionAttachment) before proceeding down the attachment dragging codepath.
This should be additionally guarded with a check that the element being dragged is, in fact, an attachment
element.

New API test (see Tools/ChangeLog).

* page/DragController.cpp:
(WebCore::DragController::startDrag):

Tools:

Adds a new API test: DataInteractionTests.LinkWithEmptyHREF.

* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/ios/DataInteractionSimulator.h:

Expose the current phase of the data interaction simulator for verifying behaviors in unit tests.

* TestWebKitAPI/ios/DataInteractionSimulator.mm:
(-[DataInteractionSimulator phase]):

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

Source/WebCore/ChangeLog
Source/WebCore/page/DragController.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
Tools/TestWebKitAPI/ios/DataInteractionSimulator.h
Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm

index 5e34a0e..aa353e2 100644 (file)
@@ -1,3 +1,22 @@
+2017-03-29  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Links with empty hrefs should not be drag sources
+        https://bugs.webkit.org/show_bug.cgi?id=170241
+        <rdar://problem/31305505>
+
+        Reviewed by Tim Horton.
+
+        The m_dragSouceAction member of DragController represents the drag source actions that are available to the
+        document, rather than the available actions given the dragging element. Thus, it is not correct to only check
+        that (m_dragSourceAction & DragSourceActionAttachment) before proceeding down the attachment dragging codepath.
+        This should be additionally guarded with a check that the element being dragged is, in fact, an attachment
+        element.
+
+        New API test (see Tools/ChangeLog).
+
+        * page/DragController.cpp:
+        (WebCore::DragController::startDrag):
+
 2017-03-29  Jeremy Jones  <jeremyj@apple.com>
 
         WebVideoFullscreenInterfaceAVKit needs a strong self ref before dispatching to the main thread.
index 5fffddc..d5339a4 100644 (file)
@@ -1013,7 +1013,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, DragOperation
     }
 
 #if ENABLE(ATTACHMENT_ELEMENT)
-    if (m_dragSourceAction & DragSourceActionAttachment) {
+    if (is<HTMLAttachmentElement>(element) && m_dragSourceAction & DragSourceActionAttachment) {
         if (!dataTransfer.pasteboard().hasData()) {
             selectElement(element);
             if (!attachmentURL.isEmpty()) {
index 292b795..db85e3e 100644 (file)
@@ -1,3 +1,22 @@
+2017-03-29  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Links with empty hrefs should not be drag sources
+        https://bugs.webkit.org/show_bug.cgi?id=170241
+        <rdar://problem/31305505>
+
+        Reviewed by Tim Horton.
+
+        Adds a new API test: DataInteractionTests.LinkWithEmptyHREF.
+
+        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/ios/DataInteractionSimulator.h:
+
+        Expose the current phase of the data interaction simulator for verifying behaviors in unit tests.
+
+        * TestWebKitAPI/ios/DataInteractionSimulator.mm:
+        (-[DataInteractionSimulator phase]):
+
 2017-03-29  Jonathan Bedard  <jbedard@apple.com>
 
         Use TCP instead of FIFOs for Simulator/Device communication
index 9ef0dd7..cf9ebba 100644 (file)
@@ -172,6 +172,7 @@ TEST(DataInteractionTests, CanPreventStart)
     RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
     [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
 
+    EXPECT_EQ(DataInteractionCancelled, [dataInteractionSimulator phase]);
     EXPECT_FALSE([webView editorContainsImageElement]);
 
     NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
@@ -292,6 +293,19 @@ TEST(DataInteractionTests, LargeImageToTargetDiv)
     EXPECT_WK_STREQ("PASS", [webView stringByEvaluatingJavaScript:@"target.textContent"].UTF8String);
 }
 
+TEST(DataInteractionTests, LinkWithEmptyHREF)
+{
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
+    [webView stringByEvaluatingJavaScript:@"document.querySelector('a').href = ''"];
+
+    RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+    [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
+
+    EXPECT_EQ(DataInteractionCancelled, [dataInteractionSimulator phase]);
+    EXPECT_WK_STREQ("", [webView editorValue].UTF8String);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // ENABLE(DATA_INTERACTION)
index 9ea77b8..1d5d1b4 100644 (file)
@@ -71,6 +71,7 @@ typedef NS_ENUM(NSInteger, DataInteractionPhase) {
 @property (nonatomic, strong) UIItemProvider *externalItemProvider;
 @property (nonatomic, readonly) NSArray *observedEventNames;
 @property (nonatomic, readonly) NSArray *finalSelectionRects;
+@property (nonatomic, readonly) DataInteractionPhase phase;
 
 @end
 
index 2525762..97e1fdb 100644 (file)
@@ -209,6 +209,11 @@ static NSArray *dataInteractionEventNames()
     _externalItemProvider = externalItemProvider;
 }
 
+- (DataInteractionPhase)phase
+{
+    return _phase;
+}
+
 #pragma mark - _WKTestingDelegate
 
 - (void)webViewDidPerformDataInteractionControllerOperation:(WKWebView *)webView