REGRESSION: fast/events/touch/ios/long-press-on-image.html is failing
https://bugs.webkit.org/show_bug.cgi?id=202845
Source/WebKit:

Reviewed by Antoine Quint.

Update _contentsOfUserInterfaceItem so that it returns more information
on a context menu.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _contentsOfUserInterfaceItem:]):

LayoutTests:

<rdar://51717197>

Reviewed by Antoine Quint.

This test failed because images no longer pop up action sheets, but
instead use context menus.

We no longer need to test the actions in the context menu here, since
it is covered by the TestWebKitAPI/Tests/WebKitCocoa/ContextMenus test.

However, we can still use this test to ensure we are getting a
context menu on the correct element.

* fast/events/touch/ios/long-press-on-image-expected.txt:
* fast/events/touch/ios/long-press-on-image.html:
* platform/iphone-7/fast/events/touch/force-press-on-link.html: This
test currently fails and needs to be rewritten (rdar://problem/52699530),
but at least update it to use the new data from the Internal API.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251012 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 1d6d660..b10af16 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,26 @@
+2019-10-11  Dean Jackson  <dino@apple.com>
+
+        REGRESSION: fast/events/touch/ios/long-press-on-image.html is failing
+        https://bugs.webkit.org/show_bug.cgi?id=202845
+        <rdar://51717197>
+
+        Reviewed by Antoine Quint.
+
+        This test failed because images no longer pop up action sheets, but
+        instead use context menus.
+
+        We no longer need to test the actions in the context menu here, since
+        it is covered by the TestWebKitAPI/Tests/WebKitCocoa/ContextMenus test.
+
+        However, we can still use this test to ensure we are getting a
+        context menu on the correct element.
+
+        * fast/events/touch/ios/long-press-on-image-expected.txt:
+        * fast/events/touch/ios/long-press-on-image.html:
+        * platform/iphone-7/fast/events/touch/force-press-on-link.html: This
+        test currently fails and needs to be rewritten (rdar://problem/52699530),
+        but at least update it to use the new data from the Internal API.
+
 2019-10-11  Peng Liu  <peng.liu6@apple.com>
 
         Layout Test media/W3C/audio/events/event_progress.html is flaky
diff --git a/LayoutTests/fast/events/touch/ios/long-press-on-image-expected.txt b/LayoutTests/fast/events/touch/ios/long-press-on-image-expected.txt
index efed8a8..6746330 100644
--- a/LayoutTests/fast/events/touch/ios/long-press-on-image-expected.txt
+++ b/LayoutTests/fast/events/touch/ios/long-press-on-image-expected.txt
@@ -1,6 +1 @@
-Available Actions: 
-Share…
-Add to Photos
-Copy
-Cancel
-PASS
+PASS: context menu triggered on image
diff --git a/LayoutTests/fast/events/touch/ios/long-press-on-image.html b/LayoutTests/fast/events/touch/ios/long-press-on-image.html
index c88708c..6c03958 100644
--- a/LayoutTests/fast/events/touch/ios/long-press-on-image.html
+++ b/LayoutTests/fast/events/touch/ios/long-press-on-image.html
@@ -14,7 +14,7 @@
             return `
             (function() {
                 uiController.longPressAtPoint(30, 20, function() {
-                    uiController.uiScriptComplete(JSON.stringify(uiController.contentsOfUserInterfaceItem('actionSheet')));
+                    uiController.uiScriptComplete(JSON.stringify(uiController.contentsOfUserInterfaceItem('contextMenu')));
                 });
              })();`
         }
@@ -27,21 +27,12 @@
             var target = document.getElementById('target');
             if (testRunner.runUIScript) {
                 testRunner.runUIScript(getUIScript(), function(result) {
-                    var actionDictionary = JSON.parse(result);
-                    var actionStrings = actionDictionary.actionSheet;
+                    var results = JSON.parse(result).contextMenu;
                     var output = '';
-                    if (actionStrings[0] == 'Share…' && actionStrings[1] == 'Add to Photos' && actionStrings[2] == 'Copy' && actionStrings[3] == 'Cancel') {
-                        output += 'Available Actions: <br>';
-                        output +=  actionStrings.join('<br>');
-                        output += '<br>';
-                        output += 'PASS';
-                    }
-                    else {
-                        output += 'Available Actions: <br>';
-                        output += actionStrings.join('<br>');
-                        output += '<br>';
-                        output += 'FAIL'
-                    }
+                    if (results.imageURL.includes("dice.png") && results.isImage && !results.isLink)
+                        output += 'PASS: context menu triggered on image';
+                    else
+                        output += 'FAIL: context menu was not triggered on image';
 
                     document.getElementById('target').innerHTML = output;
                     testRunner.notifyDone();
diff --git a/LayoutTests/platform/iphone-7/fast/events/touch/force-press-on-link.html b/LayoutTests/platform/iphone-7/fast/events/touch/force-press-on-link.html
index eda45b1..29c3aa0 100644
--- a/LayoutTests/platform/iphone-7/fast/events/touch/force-press-on-link.html
+++ b/LayoutTests/platform/iphone-7/fast/events/touch/force-press-on-link.html
@@ -52,7 +52,7 @@
                 uiController.sendEventStream(JSON.stringify(eventStream), function() {});
              
                 uiController.didShowForcePressPreviewCallback = function() {
-                    uiController.uiScriptComplete(JSON.stringify(uiController.contentsOfUserInterfaceItem('linkPreviewPopoverContents')));
+                    uiController.uiScriptComplete(JSON.stringify(uiController.contentsOfUserInterfaceItem('contextMenu')));
                 };
              
             })();`
@@ -78,9 +78,8 @@
             
             if (testRunner.runUIScript) {
                 testRunner.runUIScript(getUIScript(), function(result) {
-                    var uiContentsDictionary = JSON.parse(result);
-                    var pageURL = uiContentsDictionary.linkPreviewPopoverContents.pageURL;
-                    if (pageURL = 'http://localhost:54321')
+                    var results = JSON.parse(result).contextMenu;
+                    if (results.url == 'http://localhost:54321' && results.isLink)
                         output += 'PASS: correct page loaded in popover';
                     document.getElementById('target').innerHTML = output;
                                        
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index 99dc572..31466cd 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,16 @@
+2019-10-11  Dean Jackson  <dino@apple.com>
+
+        REGRESSION: fast/events/touch/ios/long-press-on-image.html is failing
+        https://bugs.webkit.org/show_bug.cgi?id=202845
+
+        Reviewed by Antoine Quint.
+
+        Update _contentsOfUserInterfaceItem so that it returns more information
+        on a context menu.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _contentsOfUserInterfaceItem:]):
+
 2019-10-11  Alex Christensen  <achristensen@webkit.org>
 
         Use sendWithAsyncReply for cookie getting/clearing functions
diff --git a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
index 52cdfa5..7f9a05a 100644
--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
@@ -7895,12 +7895,22 @@
         return @{ userInterfaceItem: [_actionSheetAssistant currentAvailableActionTitles] };
 
 #if HAVE(LINK_PREVIEW)
-    if ([userInterfaceItem isEqualToString:@"linkPreviewPopoverContents"]) {
+    if ([userInterfaceItem isEqualToString:@"contextMenu"]) {
         if (self._shouldUseContextMenus)
-            return @{ userInterfaceItem: @{ @"pageURL": WTF::userVisibleString(_positionInformation.url) } };
+            return @{ userInterfaceItem: @{
+                @"url": _positionInformation.url.isValid() ? WTF::userVisibleString(_positionInformation.url) : @"",
+                @"isLink": [NSNumber numberWithBool:_positionInformation.isLink],
+                @"isImage": [NSNumber numberWithBool:_positionInformation.isImage],
+                @"imageURL": _positionInformation.imageURL.isValid() ? WTF::userVisibleString(_positionInformation.imageURL) : @""
+            } };
 
         NSString *url = [_previewItemController previewData][UIPreviewDataLink];
-        return @{ userInterfaceItem: @{ @"pageURL": url } };
+        return @{ userInterfaceItem: @{
+            @"url": url,
+            @"isLink": [NSNumber numberWithBool:_positionInformation.isLink],
+            @"isImage": [NSNumber numberWithBool:_positionInformation.isImage],
+            @"imageURL": _positionInformation.imageURL.isValid() ? WTF::userVisibleString(_positionInformation.imageURL) : @""
+        } };
     }
 #endif