Title: [252309] trunk
Revision
252309
Author
[email protected]
Date
2019-11-09 12:14:37 -0800 (Sat, 09 Nov 2019)

Log Message

Clicky Orbing support.apple.com categories shows a PNG instead of the web page preview, tapping loads image asset only instead of web page
https://bugs.webkit.org/show_bug.cgi?id=204037
<rdar://55614939>

Reviewed by Simon Fraser.

Source/WebKit:

When Safari adopted the ContextMenu API they began providing a PreviewViewController that
showed the image rather than the link, for the case of <a><img></a>.

This could be fixed in Safari, but I noticed that we actually tell the delegate that the
type of the activated element is an image, which is why they treat it as such. It's not
clear that because the image also has a link attached, a client should defer to the link.

Instead, I think it makes more sense to identify this as a link, because that is the more
important information in this API.

While here I also changed the logic to make sure we call the API if both the API and SPI
are available.

New ContextMenus and WKRequestActivatedElementInfo API tests.

* UIProcess/API/Cocoa/_WKActivatedElementInfo.mm: Identify as a link if you have a link.
(-[_WKActivatedElementInfo _initWithInteractionInformationAtPosition:userInfo:]):
* UIProcess/ios/WKContentViewInteraction.mm: Look for the API before the SPI.
(-[WKContentView continueContextMenuInteraction:]):

Tools:

New tests for a link wrapping an image, and the ordering of API and SPI.

Rename these tests so that they are much easier to filter on the command line.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
(TEST):
(-[TestContextMenuAPIBeforeSPIUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
(-[TestContextMenuAPIBeforeSPIUIDelegate _webView:contextMenuConfigurationForElement:completionHandler:]):
(-[TestContextMenuAPIBeforeSPIUIDelegate webView:contextMenuWillPresentForElement:]):
* TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/image.html: Added.
* TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (252308 => 252309)


--- trunk/Source/WebKit/ChangeLog	2019-11-09 17:09:02 UTC (rev 252308)
+++ trunk/Source/WebKit/ChangeLog	2019-11-09 20:14:37 UTC (rev 252309)
@@ -1,3 +1,31 @@
+2019-11-09  Dean Jackson  <[email protected]>
+
+        Clicky Orbing support.apple.com categories shows a PNG instead of the web page preview, tapping loads image asset only instead of web page
+        https://bugs.webkit.org/show_bug.cgi?id=204037
+        <rdar://55614939>
+
+        Reviewed by Simon Fraser.
+
+        When Safari adopted the ContextMenu API they began providing a PreviewViewController that
+        showed the image rather than the link, for the case of <a><img></a>.
+
+        This could be fixed in Safari, but I noticed that we actually tell the delegate that the
+        type of the activated element is an image, which is why they treat it as such. It's not
+        clear that because the image also has a link attached, a client should defer to the link.
+
+        Instead, I think it makes more sense to identify this as a link, because that is the more
+        important information in this API.
+
+        While here I also changed the logic to make sure we call the API if both the API and SPI
+        are available.
+
+        New ContextMenus and WKRequestActivatedElementInfo API tests.
+
+        * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm: Identify as a link if you have a link.
+        (-[_WKActivatedElementInfo _initWithInteractionInformationAtPosition:userInfo:]):
+        * UIProcess/ios/WKContentViewInteraction.mm: Look for the API before the SPI.
+        (-[WKContentView continueContextMenuInteraction:]):
+
 2019-11-08  Brady Eidson  <[email protected]>
 
         WKWebView Find-in-page API.

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm (252308 => 252309)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm	2019-11-09 17:09:02 UTC (rev 252308)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm	2019-11-09 20:14:37 UTC (rev 252309)
@@ -73,10 +73,10 @@
     
     if (information.isAttachment)
         _type = _WKActivatedElementTypeAttachment;
+    else if (information.isLink)
+        _type = _WKActivatedElementTypeLink;
     else if (information.isImage)
         _type = _WKActivatedElementTypeImage;
-    else if (information.isLink)
-        _type = _WKActivatedElementTypeLink;
     else
         _type = _WKActivatedElementTypeUnspecified;
     

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (252308 => 252309)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-11-09 17:09:02 UTC (rev 252308)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-11-09 20:14:37 UTC (rev 252309)
@@ -8382,25 +8382,26 @@
 
     _contextMenuActionProviderDelegateNeedsOverride = NO;
     _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation, nil));
-    if ([uiDelegate respondsToSelector:@selector(_webView:contextMenuConfigurationForElement:completionHandler:)]) {
-        if (_positionInformation.isImage && _positionInformation.url.isNull() && [uiDelegate respondsToSelector:@selector(_webView:alternateURLFromImage:userInfo:)]) {
-            UIImage *uiImage = [[_contextMenuElementInfo _activatedElementInfo] image];
-            NSDictionary *userInfo = nil;
-            NSURL *nsURL = [uiDelegate _webView:_webView alternateURLFromImage:uiImage userInfo:&userInfo];
-            _positionInformation.url = ""
-            _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation, userInfo));
-        }
 
-        auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(_webView:contextMenuConfigurationForElement:completionHandler:));
-        [uiDelegate _webView:_webView contextMenuConfigurationForElement:_contextMenuElementInfo.get() completionHandler:makeBlockPtr([completionBlock = WTFMove(completionBlock), checker = WTFMove(checker)] (UIContextMenuConfiguration *configuration) {
+    if (_positionInformation.isImage && _positionInformation.url.isNull() && [uiDelegate respondsToSelector:@selector(_webView:alternateURLFromImage:userInfo:)]) {
+        UIImage *uiImage = [[_contextMenuElementInfo _activatedElementInfo] image];
+        NSDictionary *userInfo = nil;
+        NSURL *nsURL = [uiDelegate _webView:_webView alternateURLFromImage:uiImage userInfo:&userInfo];
+        _positionInformation.url = ""
+        _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation, userInfo));
+    }
+
+    if (_positionInformation.isLink && [uiDelegate respondsToSelector:@selector(webView:contextMenuConfigurationForElement:completionHandler:)]) {
+        auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(webView:contextMenuConfigurationForElement:completionHandler:));
+        [uiDelegate webView:_webView contextMenuConfigurationForElement:_contextMenuElementInfo.get() completionHandler:makeBlockPtr([completionBlock = WTFMove(completionBlock), checker = WTFMove(checker)] (UIContextMenuConfiguration *configuration) {
             if (checker->completionHandlerHasBeenCalled())
                 return;
             checker->didCallCompletionHandler();
             completionBlock(configuration);
         }).get()];
-    } else if (_positionInformation.isLink && [uiDelegate respondsToSelector:@selector(webView:contextMenuConfigurationForElement:completionHandler:)]) {
-        auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(webView:contextMenuConfigurationForElement:completionHandler:));
-        [uiDelegate webView:_webView contextMenuConfigurationForElement:_contextMenuElementInfo.get() completionHandler:makeBlockPtr([completionBlock = WTFMove(completionBlock), checker = WTFMove(checker)] (UIContextMenuConfiguration *configuration) {
+    } else if ([uiDelegate respondsToSelector:@selector(_webView:contextMenuConfigurationForElement:completionHandler:)]) {
+        auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(_webView:contextMenuConfigurationForElement:completionHandler:));
+        [uiDelegate _webView:_webView contextMenuConfigurationForElement:_contextMenuElementInfo.get() completionHandler:makeBlockPtr([completionBlock = WTFMove(completionBlock), checker = WTFMove(checker)] (UIContextMenuConfiguration *configuration) {
             if (checker->completionHandlerHasBeenCalled())
                 return;
             checker->didCallCompletionHandler();

Modified: trunk/Tools/ChangeLog (252308 => 252309)


--- trunk/Tools/ChangeLog	2019-11-09 17:09:02 UTC (rev 252308)
+++ trunk/Tools/ChangeLog	2019-11-09 20:14:37 UTC (rev 252309)
@@ -1,3 +1,26 @@
+2019-11-09  Dean Jackson  <[email protected]>
+
+        Clicky Orbing support.apple.com categories shows a PNG instead of the web page preview, tapping loads image asset only instead of web page
+        https://bugs.webkit.org/show_bug.cgi?id=204037
+        <rdar://55614939>
+
+        Reviewed by Simon Fraser.
+
+        New tests for a link wrapping an image, and the ordering of API and SPI.
+
+        Rename these tests so that they are much easier to filter on the command line.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
+        (TEST):
+        (-[TestContextMenuAPIBeforeSPIUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
+        (-[TestContextMenuAPIBeforeSPIUIDelegate _webView:contextMenuConfigurationForElement:completionHandler:]):
+        (-[TestContextMenuAPIBeforeSPIUIDelegate webView:contextMenuWillPresentForElement:]):
+        * TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/image.html: Added.
+        * TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html: Added.
+
 2019-11-08  Brady Eidson  <[email protected]>
 
         WKWebView Find-in-page API.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (252308 => 252309)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-11-09 17:09:02 UTC (rev 252308)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-11-09 20:14:37 UTC (rev 252309)
@@ -177,6 +177,8 @@
 		2EFF06C71D886A580004BB30 /* change-video-source-on-end.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */; };
 		2EFF06CD1D8A429A0004BB30 /* input-field-in-scrollable-document.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06CC1D8A42910004BB30 /* input-field-in-scrollable-document.html */; };
 		2EFF06D71D8AF34A0004BB30 /* WKWebViewCandidateTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */; };
+		3128A81323763FAC00D90D40 /* link-with-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 3128A81223763F0B00D90D40 /* link-with-image.html */; };
+		3128A8152376413300D90D40 /* image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 3128A814237640FD00D90D40 /* image.html */; };
 		313C3A0221E567C300DBA86E /* SystemPreviewBlobNaming.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 313C3A0121E5677A00DBA86E /* SystemPreviewBlobNaming.html */; };
 		315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */; };
 		31B76E4323298E2C007FED2C /* SystemPreview.mm in Sources */ = {isa = PBXBuildFile; fileRef = 31B76E4223298E2B007FED2C /* SystemPreview.mm */; };
@@ -1286,6 +1288,7 @@
 				F41AB9A51EF4696B0083FA08 /* image-and-textarea.html in Copy Resources */,
 				F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */,
 				F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */,
+				3128A8152376413300D90D40 /* image.html in Copy Resources */,
 				7283A9D022FA754900B21C7D /* img-with-rotated-image.html in Copy Resources */,
 				935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */,
 				935786CE20F6A2A10000CDFC /* IndexedDB.sqlite3-shm in Copy Resources */,
@@ -1344,6 +1347,7 @@
 				F46128D4211E40FD00D9FADB /* link-in-iframe-and-input.html in Copy Resources */,
 				8361F1781E610B4E00759B25 /* link-with-download-attribute-with-slashes.html in Copy Resources */,
 				8349D3C41DB9728E004A9F65 /* link-with-download-attribute.html in Copy Resources */,
+				3128A81323763FAC00D90D40 /* link-with-image.html in Copy Resources */,
 				378E64791632707400B6C676 /* link-with-title.html in Copy Resources */,
 				573255A622139BC700396AE8 /* load-web-archive-1.html in Copy Resources */,
 				573255A722139BC700396AE8 /* load-web-archive-2.html in Copy Resources */,
@@ -1677,6 +1681,8 @@
 		2EFF06D21D8AEDBB0004BB30 /* TestWKWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestWKWebView.h; path = cocoa/TestWKWebView.h; sourceTree = "<group>"; };
 		2EFF06D31D8AEDBB0004BB30 /* TestWKWebView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestWKWebView.mm; path = cocoa/TestWKWebView.mm; sourceTree = "<group>"; };
 		2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewCandidateTests.mm; sourceTree = "<group>"; };
+		3128A81223763F0B00D90D40 /* link-with-image.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "link-with-image.html"; sourceTree = "<group>"; };
+		3128A814237640FD00D90D40 /* image.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = image.html; sourceTree = "<group>"; };
 		313C3A0121E5677A00DBA86E /* SystemPreviewBlobNaming.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = SystemPreviewBlobNaming.html; sourceTree = "<group>"; };
 		3151180F1DB1ADD500176304 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; };
 		31B76E4223298E2B007FED2C /* SystemPreview.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemPreview.mm; sourceTree = "<group>"; };
@@ -3334,6 +3340,7 @@
 				F41AB9931EF4692C0083FA08 /* image-and-textarea.html */,
 				F4DEF6EC1E9B4D950048EF61 /* image-in-link-and-input.html */,
 				F45B63FA1F197F33009D38B9 /* image-map.html */,
+				3128A814237640FD00D90D40 /* image.html */,
 				7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */,
 				934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */,
 				934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */,
@@ -3382,6 +3389,7 @@
 				F41AB9961EF4692C0083FA08 /* link-and-input.html */,
 				F41AB99D1EF4692C0083FA08 /* link-and-target-div.html */,
 				F46128D1211E2D2500D9FADB /* link-in-iframe-and-input.html */,
+				3128A81223763F0B00D90D40 /* link-with-image.html */,
 				CA7787FE228CEFC700E50463 /* local-storage-process-crashes.html */,
 				9368A25D229EFB3A00A829CA /* local-storage-process-suspends-1.html */,
 				9368A25C229EFB3A00A829CA /* local-storage-process-suspends-2.html */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm (252308 => 252309)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm	2019-11-09 17:09:02 UTC (rev 252308)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm	2019-11-09 20:14:37 UTC (rev 252309)
@@ -35,6 +35,7 @@
 #import <WebKit/WebKit.h>
 
 static bool contextMenuRequested;
+static bool contextMenuSPIRequested;
 static bool willPresentCalled;
 static bool willCommitCalled;
 static bool previewingViewControllerCalled;
@@ -99,7 +100,7 @@
 
 @end
 
-TEST(WebKit, ContextMenuClick)
+TEST(ContextMenu, Click)
 {
     auto driver = contextMenuWebViewDriver([TestContextMenuUIDelegate class]);
     [driver begin:^(BOOL result) {
@@ -114,7 +115,7 @@
     EXPECT_FALSE(didEndCalled);
 }
 
-TEST(WebKit, ContextMenuEnd)
+TEST(ContextMenu, End)
 {
     auto driver = contextMenuWebViewDriver([TestContextMenuUIDelegate class]);
     [driver begin:^(BOOL result) {
@@ -128,6 +129,51 @@
     EXPECT_TRUE(didEndCalled);
 }
 
+@interface TestContextMenuAPIBeforeSPIUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation TestContextMenuAPIBeforeSPIUIDelegate
+
+- (void)webView:(WKWebView *)webView contextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo completionHandler:(void(^)(UIContextMenuConfiguration * _Nullable))completionHandler
+{
+    contextMenuRequested = true;
+    UIContextMenuContentPreviewProvider previewProvider = ^UIViewController * ()
+    {
+        return [[[UIViewController alloc] init] autorelease];
+    };
+    UIContextMenuActionProvider actionProvider = ^UIMenu *(NSArray<UIMenuElement *> *suggestedActions)
+    {
+        return [UIMenu menuWithTitle:@"" children:suggestedActions];
+    };
+    completionHandler([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:previewProvider actionProvider:actionProvider]);
+}
+
+- (void)_webView:(WKWebView *)webView contextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo completionHandler:(void(^)(UIContextMenuConfiguration * _Nullable))completionHandler
+{
+    contextMenuSPIRequested = true;
+    completionHandler(nil);
+}
+
+- (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo
+{
+    willPresentCalled = true;
+}
+
+@end
+
+TEST(ContextMenu, APIBeforeSPI)
+{
+    auto driver = contextMenuWebViewDriver([TestContextMenuAPIBeforeSPIUIDelegate class]);
+    [driver begin:^(BOOL result) {
+        EXPECT_TRUE(result);
+        [driver clickDown];
+        [driver clickUp];
+    }];
+    TestWebKitAPI::Util::run(&willPresentCalled);
+    EXPECT_TRUE(contextMenuRequested);
+    EXPECT_FALSE(contextMenuSPIRequested);
+}
+
 @interface TestContextMenuImageUIDelegate : NSObject <WKUIDelegate>
 @end
 
@@ -163,7 +209,7 @@
 
 @end
 
-TEST(WebKit, ContextMenuImage)
+TEST(ContextMenu, Image)
 {
     linkURL = [NSURL URLWithString:@"http://127.0.0.1/image"];
     auto driver = contextMenuWebViewDriver([TestContextMenuImageUIDelegate class], @"<img style='width:400px;height:400px' src=''>");
@@ -231,7 +277,7 @@
 
 @end
 
-TEST(WebKit, ContextMenuLegacy)
+TEST(ContextMenu, Legacy)
 {
     auto driver = contextMenuWebViewDriver([LegacyContextMenuUIDelegate class]);
     [driver begin:^(BOOL result) {
@@ -286,7 +332,7 @@
 
 @end
 
-TEST(WebKit, ContextMenuSuggestedActions)
+TEST(ContextMenu, SuggestedActions)
 {
     auto driver = contextMenuWebViewDriver([TestContextMenuSuggestedActionsUIDelegate class]);
     [driver begin:^(BOOL result) {

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm (252308 => 252309)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm	2019-11-09 17:09:02 UTC (rev 252308)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm	2019-11-09 20:14:37 UTC (rev 252309)
@@ -49,10 +49,10 @@
     EXPECT_EQ(expectedType, elementInfo.type);
 }
     
-TEST(WebKit, RequestActivatedElementInfoForLink)
+TEST(_WKActivatedElementInfo, InfoForLink)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
-    [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style = 'margin: 0px;'><a href='' style='display: block; height: 100%;' title='HitTestLinkTitle' id='testID'></a></body></html>" baseURL:nil];
+    [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style='margin: 0px;'><a href='' style='display: block; height: 100%;' title='HitTestLinkTitle' id='testID'></a></body></html>" baseURL:nil];
     [webView _test_waitForDidFinishNavigation];
     
     __block bool finished = false;
@@ -73,10 +73,30 @@
     
     TestWebKitAPI::Util::run(&finished);
 }
-    
-TEST(WebKit, RequestActivatedElementInfoForImage)
+
+TEST(_WKActivatedElementInfo, InfoForImage)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 215, 174)]);
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+    [webView _test_waitForDidFinishNavigation];
+
+    __block bool finished = false;
+    [webView _requestActivatedElementAtPosition:CGPointMake(50, 50) completionBlock: ^(_WKActivatedElementInfo *elementInfo) {
+
+        EXPECT_TRUE(elementInfo.type == _WKActivatedElementTypeImage);
+        EXPECT_WK_STREQ(elementInfo.imageURL.lastPathComponent, "large-red-square.png");
+        EXPECT_NOT_NULL(elementInfo.image);
+
+        finished = true;
+    }];
+
+    TestWebKitAPI::Util::run(&finished);
+}
+
+TEST(_WKActivatedElementInfo, InfoForMediaDocument)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 215, 174)]);
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
     [webView _test_waitForDidFinishNavigation];
@@ -98,11 +118,37 @@
     TestWebKitAPI::Util::run(&finished);
 }
 
-TEST(WebKit, RequestActivatedElementInfoForRotatedImage)
+TEST(_WKActivatedElementInfo, InfoForLinkAroundImage)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"link-with-image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+    [webView _test_waitForDidFinishNavigation];
+
+    __block bool finished = false;
+    [webView _requestActivatedElementAtPosition:CGPointMake(50, 50) completionBlock: ^(_WKActivatedElementInfo *elementInfo) {
+
+        EXPECT_TRUE(elementInfo.type == _WKActivatedElementTypeLink);
+        EXPECT_WK_STREQ(elementInfo.URL.lastPathComponent, "testURL.test");
+        EXPECT_WK_STREQ(elementInfo.title, "HitTestImageTitle");
+        EXPECT_WK_STREQ(elementInfo.ID, @"testID");
+        EXPECT_NOT_NULL(elementInfo.image);
+        EXPECT_EQ(elementInfo.boundingRect.size.width, 320);
+        EXPECT_EQ(elementInfo.boundingRect.size.height, 500);
+        EXPECT_EQ(elementInfo.image.size.width, 1668);
+        EXPECT_EQ(elementInfo.image.size.height, 1668);
+
+        finished = true;
+    }];
+
+    TestWebKitAPI::Util::run(&finished);
+}
+
+
+TEST(_WKActivatedElementInfo, InfoForRotatedImage)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"img-with-rotated-image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
-
     [webView loadRequest:request];
     [webView _test_waitForDidFinishNavigation];
 
@@ -155,10 +201,10 @@
     TestWebKitAPI::Util::run(&finished);
 }
 
-TEST(WebKit, RequestActivatedElementInfoForBlank)
+TEST(_WKActivatedElementInfo, InfoForBlank)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
-    [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style = 'margin: 0px;'></body></html>" baseURL:nil];
+    [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style='margin: 0px;'></body></html>" baseURL:nil];
     [webView _test_waitForDidFinishNavigation];
     
     __block bool finished = false;
@@ -174,10 +220,10 @@
     TestWebKitAPI::Util::run(&finished);
 }
 
-TEST(WebKit, RequestActivatedElementInfoForBrokenImage)
+TEST(_WKActivatedElementInfo, InfoForBrokenImage)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
-    [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style = 'margin: 0px;'><img  src='' height='100' width='100'></body></html>" baseURL:nil];
+    [webView loadHTMLString:@"<html><head><meta name='viewport' content='initial-scale=1'></head><body style='margin: 0px;'><img  src='' height='100' width='100'></body></html>" baseURL:nil];
     [webView _test_waitForDidFinishNavigation];
     
     __block bool finished = false;
@@ -193,7 +239,7 @@
     TestWebKitAPI::Util::run(&finished);
 }
 
-TEST(WebKit, RequestActivatedElementInfoForAttachment)
+TEST(_WKActivatedElementInfo, InfoForAttachment)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [configuration _setAttachmentElementEnabled:YES];
@@ -212,7 +258,7 @@
     TestWebKitAPI::Util::run(&finished);
 }
 
-TEST(WebKit, RequestActivatedElementInfoWithNestedSynchronousUpdates)
+TEST(_WKActivatedElementInfo, InfoWithNestedSynchronousUpdates)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [webView synchronouslyLoadHTMLString:@"<meta name='viewport' content='initial-scale=1'><style>body { margin:0 } a { display:block; width:200px; height:200px }</style><a href=''>FOO</a>"];
@@ -236,7 +282,7 @@
     TestWebKitAPI::Util::run(&finished);
 }
 
-TEST(WebKit, RequestActivatedElementInfoWithNestedRequests)
+TEST(_WKActivatedElementInfo, InfoWithNestedRequests)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [webView synchronouslyLoadTestPageNamed:@"image-and-contenteditable"];

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/image.html (0 => 252309)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/image.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/image.html	2019-11-09 20:14:37 UTC (rev 252309)
@@ -0,0 +1,9 @@
+<html>
+    <head>
+        <meta name='viewport' content='initial-scale=1'>
+    </head>
+    <body style='margin: 0px;'>
+        <img style='display: block; height: 100%;' src=""
+    </body>
+</html>
+
Property changes on: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/image.html
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html (0 => 252309)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html	2019-11-09 20:14:37 UTC (rev 252309)
@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <meta name='viewport' content='initial-scale=1'>
+    </head>
+    <body style='margin: 0px;'>
+        <a href=''>
+            <img  id='testID' title='HitTestImageTitle' style='display: block; width: 100vw; height: 100vh;' src=""
+        </a>
+    </body>
+</html>
Property changes on: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to