2 * Copyright (C) 2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(DATA_INTERACTION)
30 #import "PlatformUtilities.h"
31 #import "TestWKWebView.h"
32 #import <WebKit/WKWebViewPrivate.h>
33 #import <WebKit/_WKDraggableElementInfo.h>
35 @implementation _WKDraggableElementInfo (PositionInformationTests)
37 - (void)expectToBeLink:(BOOL)isLink image:(BOOL)isImage atPoint:(CGPoint)point
39 EXPECT_EQ(isLink, self.isLink);
40 EXPECT_EQ(isImage, self.isImage);
41 EXPECT_EQ(point.x, self.point.x);
42 EXPECT_EQ(point.y, self.point.y);
47 namespace TestWebKitAPI {
49 TEST(PositionInformationTests, FindDraggableLinkAtPosition)
51 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
52 [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
54 _WKDraggableElementInfo *information = [webView _draggableElementAtPosition:CGPointMake(100, 50)];
55 [information expectToBeLink:YES image:NO atPoint:CGPointMake(100, 50)];
58 TEST(PositionInformationTests, RequestDraggableLinkAtPosition)
60 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
61 [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
63 __block bool isDone = false;
64 [webView _requestDraggableElementAtPosition:CGPointMake(100, 50) completionBlock:^(_WKDraggableElementInfo *information) {
65 [information expectToBeLink:YES image:NO atPoint:CGPointMake(100, 50)];
69 TestWebKitAPI::Util::run(&isDone);
72 TEST(PositionInformationTests, FindDraggableLinkAtDifferentPositionWithinRequestBlock)
74 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
75 [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
77 __block bool isDone = false;
78 [webView _requestDraggableElementAtPosition:CGPointMake(100, 50) completionBlock:^(_WKDraggableElementInfo *information) {
79 _WKDraggableElementInfo *synchronousInformation = [webView _draggableElementAtPosition:CGPointMake(100, 300)];
80 [synchronousInformation expectToBeLink:NO image:NO atPoint:CGPointMake(100, 300)];
81 [information expectToBeLink:YES image:NO atPoint:CGPointMake(100, 50)];
85 TestWebKitAPI::Util::run(&isDone);
88 TEST(PositionInformationTests, FindDraggableLinkAtSamePositionWithinRequestBlock)
90 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
91 [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
93 __block bool isDone = false;
94 [webView _requestDraggableElementAtPosition:CGPointMake(100, 50) completionBlock:^(_WKDraggableElementInfo *information) {
95 _WKDraggableElementInfo *synchronousInformation = [webView _draggableElementAtPosition:CGPointMake(100, 50)];
96 [synchronousInformation expectToBeLink:YES image:NO atPoint:CGPointMake(100, 50)];
97 [information expectToBeLink:YES image:NO atPoint:CGPointMake(100, 50)];
101 TestWebKitAPI::Util::run(&isDone);
104 TEST(PositionInformationTests, RequestDraggableLinkAtSamePositionWithinRequestBlock)
106 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
107 [webView synchronouslyLoadTestPageNamed:@"image-and-contenteditable"];
109 __block bool isDoneWithInner = false;
110 __block bool isDoneWithOuter = false;
112 [webView _requestDraggableElementAtPosition:CGPointMake(100, 50) completionBlock:^(_WKDraggableElementInfo *outerInformation) {
113 [webView _requestDraggableElementAtPosition:CGPointMake(100, 50) completionBlock:^(_WKDraggableElementInfo *innerInformation) {
114 [innerInformation expectToBeLink:NO image:YES atPoint:CGPointMake(100, 50)];
115 isDoneWithInner = true;
117 [outerInformation expectToBeLink:NO image:YES atPoint:CGPointMake(100, 50)];
118 isDoneWithOuter = true;
121 TestWebKitAPI::Util::run(&isDoneWithOuter);
122 TestWebKitAPI::Util::run(&isDoneWithInner);
125 TEST(PositionInformationTests, RequestDraggableLinkAtDifferentPositionWithinRequestBlock)
127 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
128 [webView synchronouslyLoadTestPageNamed:@"image-and-contenteditable"];
130 __block bool isDoneWithInner = false;
131 __block bool isDoneWithOuter = false;
133 [webView _requestDraggableElementAtPosition:CGPointMake(100, 50) completionBlock:^(_WKDraggableElementInfo *outerInformation) {
134 [webView _requestDraggableElementAtPosition:CGPointMake(100, 300) completionBlock:^(_WKDraggableElementInfo *innerInformation) {
135 [innerInformation expectToBeLink:NO image:NO atPoint:CGPointMake(100, 300)];
136 isDoneWithInner = true;
138 [outerInformation expectToBeLink:NO image:YES atPoint:CGPointMake(100, 50)];
139 isDoneWithOuter = true;
142 TestWebKitAPI::Util::run(&isDoneWithOuter);
143 TestWebKitAPI::Util::run(&isDoneWithInner);
146 } // namespace TestWebKitAPI