Clicky Orbing support.apple.com categories shows a PNG instead of the web page previe...
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Nov 2019 20:14:37 +0000 (20:14 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Nov 2019 20:14:37 +0000 (20:14 +0000)
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.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/image.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html [new file with mode: 0644]

index be01b4c..c2607f7 100644 (file)
@@ -1,3 +1,31 @@
+2019-11-09  Dean Jackson  <dino@apple.com>
+
+        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  <beidson@apple.com>
 
         WKWebView Find-in-page API.
index 9f39054..a15bdb1 100644 (file)
     
     if (information.isAttachment)
         _type = _WKActivatedElementTypeAttachment;
-    else if (information.isImage)
-        _type = _WKActivatedElementTypeImage;
     else if (information.isLink)
         _type = _WKActivatedElementTypeLink;
+    else if (information.isImage)
+        _type = _WKActivatedElementTypeImage;
     else
         _type = _WKActivatedElementTypeUnspecified;
     
index f042b5f..1a0424f 100644 (file)
@@ -8382,25 +8382,26 @@ static UIMenu *menuFromLegacyPreviewOrDefaultActions(UIViewController *previewVi
 
     _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 = nsURL;
-            _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 = nsURL;
+        _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();
index 7210032..2836a10 100644 (file)
@@ -1,3 +1,26 @@
+2019-11-09  Dean Jackson  <dino@apple.com>
+
+        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  <beidson@apple.com>
 
         WKWebView Find-in-page API.
index 589c08b..e32b85e 100644 (file)
                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 */; };
                                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 */,
                                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 */,
                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>"; };
                                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 */,
                                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 */,
index d87cbc3..9876c86 100644 (file)
@@ -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 @@ static RetainPtr<TestContextMenuDriver> contextMenuWebViewDriver(Class delegateC
 
 @end
 
-TEST(WebKit, ContextMenuClick)
+TEST(ContextMenu, Click)
 {
     auto driver = contextMenuWebViewDriver([TestContextMenuUIDelegate class]);
     [driver begin:^(BOOL result) {
@@ -114,7 +115,7 @@ TEST(WebKit, ContextMenuClick)
     EXPECT_FALSE(didEndCalled);
 }
 
-TEST(WebKit, ContextMenuEnd)
+TEST(ContextMenu, End)
 {
     auto driver = contextMenuWebViewDriver([TestContextMenuUIDelegate class]);
     [driver begin:^(BOOL result) {
@@ -128,6 +129,51 @@ TEST(WebKit, ContextMenuEnd)
     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 @@ TEST(WebKit, ContextMenuEnd)
 
 @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='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAABGdBTUEAALGPC/xhBQAABBlpQ0NQa0NHQ29sb3JTcGFjZUdlbmVyaWNSR0IAADiNjVVdaBxVFD67c2cjJM5TbDSFdKg/DSUNk1Y0obS6f93dNm6WSTbaIuhk9u7OmMnOODO7/aFPRVB8MeqbFMS/t4AgKPUP2z60L5UKJdrUICg+tPiDUOiLpuuZOzOZabqx3mXufPOd75577rln7wXouapYlpEUARaari0XMuJzh4+IPSuQhIegFwahV1EdK12pTAI2Twt3tVvfQ8J7X9nV3f6frbdGHRUgcR9is+aoC4iPAfCnVct2AXr6kR8/6loe9mLotzFAxC96uOFj18NzPn6NaWbkLOLTiAVVU2qIlxCPzMX4Rgz7MbDWX6BNauuq6OWiYpt13aCxcO9h/p9twWiF823Dp8+Znz6E72Fc+ys1JefhUcRLqpKfRvwI4mttfbYc4NuWm5ERPwaQ3N6ar6YR70RcrNsHqr6fpK21iiF+54Q28yziLYjPN+fKU8HYq6qTxZzBdsS3NVry8jsEwIm6W5rxx3L7bVOe8ufl6jWay3t5RPz6vHlI9n1ynznt6Xzo84SWLQf8pZeUgxXEg4h/oUZB9ufi/rHcShADGWoa5Ul/LpKjDlsv411tpujPSwwXN9QfSxbr+oFSoP9Es4tygK9ZBqtRjI1P2i256uv5UcXOF3yffIU2q4F/vg2zCQUomDCHvQpNWAMRZChABt8W2Gipgw4GMhStFBmKX6FmFxvnwDzyOrSZzcG+wpT+yMhfg/m4zrQqZIc+ghayGvyOrBbTZfGrhVxjEz9+LDcCPyYZIBLZg89eMkn2kXEyASJ5ijxN9pMcshNk7/rYSmxFXjw31v28jDNSpptF3Tm0u6Bg/zMqTFxT16wsDraGI8sp+wVdvfzGX7Fc6Sw3UbbiGZ26V875X/nr/DL2K/xqpOB/5Ffxt3LHWsy7skzD7GxYc3dVGm0G4xbw0ZnFicUd83Hx5FcPRn6WyZnnr/RdPFlvLg5GrJcF+mr5VhlOjUSs9IP0h7QsvSd9KP3Gvc19yn3Nfc59wV0CkTvLneO+4S5wH3NfxvZq8xpa33sWeRi3Z+mWa6xKISNsFR4WcsI24VFhMvInDAhjQlHYgZat6/sWny+ePR0OYx/mp/tcvi5WAYn7sQL0Tf5VVVTpcJQpHVZvTTi+QROMJENkjJQ2VPe4V/OhIpVP5VJpEFM7UxOpsdRBD4ezpnagbQL7/B3VqW6yUurSY959AlnTOm7rDc0Vd0vSk2IarzYqlprq6IioGIbITI5oU4fabVobBe/e9I/0mzK7DxNbLkec+wzAvj/x7Psu4o60AJYcgIHHI24Yz8oH3gU484TastvBHZFIfAvg1Pfs9r/6Mnh+/dTp3MRzrOctgLU3O52/3+901j5A/6sAZ41/AaCffFUDXAvvAAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAB4ZVhJZk1NACoAAAAIAAUBEgADAAAAAQABAAABGgAFAAAAAQAAAEoBGwAFAAAAAQAAAFIBKAADAAAAAQACAACHaQAEAAAAAQAAAFoAAAAAAAAASAAAAAEAAABIAAAAAQACoAIABAAAAAEAAAAFoAMABAAAAAEAAAAFAAAAAMNY+UAAAAAJcEhZcwAACxMAAAsTAQCanBgAAAFZaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA1LjQuMCI+CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOnRpZmY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vdGlmZi8xLjAvIj4KICAgICAgICAgPHRpZmY6T3JpZW50YXRpb24+MTwvdGlmZjpPcmllbnRhdGlvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CkzCJ1kAAAAXSURBVAgdY2RgYPgPxCiACYUH5VAoCABnEQEJC5HbTwAAAABJRU5ErkJggg=='>");
@@ -231,7 +277,7 @@ TEST(WebKit, ContextMenuImage)
 
 @end
 
-TEST(WebKit, ContextMenuLegacy)
+TEST(ContextMenu, Legacy)
 {
     auto driver = contextMenuWebViewDriver([LegacyContextMenuUIDelegate class]);
     [driver begin:^(BOOL result) {
@@ -286,7 +332,7 @@ TEST(WebKit, ContextMenuLegacy)
 
 @end
 
-TEST(WebKit, ContextMenuSuggestedActions)
+TEST(ContextMenu, SuggestedActions)
 {
     auto driver = contextMenuWebViewDriver([TestContextMenuSuggestedActionsUIDelegate class]);
     [driver begin:^(BOOL result) {
index a463a83..f33b016 100644 (file)
@@ -49,10 +49,10 @@ static void checkElementTypeAndBoundingRect(_WKActivatedElementInfo *elementInfo
     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='testURL.test' 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='testURL.test' style='display: block; height: 100%;' title='HitTestLinkTitle' id='testID'></a></body></html>" baseURL:nil];
     [webView _test_waitForDidFinishNavigation];
     
     __block bool finished = false;
@@ -73,8 +73,28 @@ TEST(WebKit, RequestActivatedElementInfoForLink)
     
     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"]];
@@ -98,11 +118,37 @@ TEST(WebKit, RequestActivatedElementInfoForImage)
     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:@"img-with-rotated-image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    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 @@ TEST(WebKit, RequestActivatedElementInfoForRotatedImage)
     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 @@ TEST(WebKit, RequestActivatedElementInfoForBlank)
     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='missing.gif' 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='missing.gif' height='100' width='100'></body></html>" baseURL:nil];
     [webView _test_waitForDidFinishNavigation];
     
     __block bool finished = false;
@@ -193,7 +239,7 @@ TEST(WebKit, RequestActivatedElementInfoForBrokenImage)
     TestWebKitAPI::Util::run(&finished);
 }
 
-TEST(WebKit, RequestActivatedElementInfoForAttachment)
+TEST(_WKActivatedElementInfo, InfoForAttachment)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [configuration _setAttachmentElementEnabled:YES];
@@ -212,7 +258,7 @@ TEST(WebKit, RequestActivatedElementInfoForAttachment)
     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='https://www.apple.com'>FOO</a>"];
@@ -236,7 +282,7 @@ TEST(WebKit, RequestActivatedElementInfoWithNestedSynchronousUpdates)
     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"];
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/image.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/image.html
new file mode 100644 (file)
index 0000000..ae8ac1d
--- /dev/null
@@ -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="large-red-square.png">
+    </body>
+</html>
+
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/link-with-image.html
new file mode 100644 (file)
index 0000000..44d584c
--- /dev/null
@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <meta name='viewport' content='initial-scale=1'>
+    </head>
+    <body style='margin: 0px;'>
+        <a href='testURL.test'>
+            <img  id='testID' title='HitTestImageTitle' style='display: block; width: 100vw; height: 100vh;' src="large-red-square.png">
+        </a>
+    </body>
+</html>