<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[214625] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/214625">214625</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2017-03-30 14:33:08 -0700 (Thu, 30 Mar 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>[WK2] Touches should not cancel when showing a custom action sheet while data interaction is active
https://bugs.webkit.org/show_bug.cgi?id=170291
<rdar://problem/31301388>
Reviewed by Tim Horton.
Source/WebKit2:
Currently, when presenting a custom popover, we will cancel all touches in the application. This makes data
interaction when a custom popover is shown impossible -- to address this, we should only cancel touches when
the view is not an active data interaction source.
New API test: DataInteractionTests.CustomActionSheetPopover.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView actionSheetAssistant:showCustomSheetForElement:]):
Tools:
Adds support for testing how the custom action sheet presentation codepath interacts with data interaction, as
well as a new unit test. In this case, we force data interaction to fail if touches are canceled on the
shared UIApplication, and verify that data interaction completes successfully.
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/ios/DataInteractionSimulator.h:
* TestWebKitAPI/ios/DataInteractionSimulator.mm:
(-[DataInteractionSimulatorApplication _cancelAllTouches]):
(-[DataInteractionSimulator initWithWebView:]):
(-[DataInteractionSimulator simulateAllTouchesCanceled:]):
(-[DataInteractionSimulator runFrom:to:]):
(-[DataInteractionSimulator _advanceProgress]):
(-[DataInteractionSimulator _webView:showCustomSheetForElement:]):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsiosDataInteractionTestsmm">trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPIiosDataInteractionSimulatorh">trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h</a></li>
<li><a href="#trunkToolsTestWebKitAPIiosDataInteractionSimulatormm">trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (214624 => 214625)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-03-30 21:27:09 UTC (rev 214624)
+++ trunk/Source/WebKit2/ChangeLog        2017-03-30 21:33:08 UTC (rev 214625)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2017-03-30 Wenson Hsieh <wenson_hsieh@apple.com>
+
+ [WK2] Touches should not cancel when showing a custom action sheet while data interaction is active
+ https://bugs.webkit.org/show_bug.cgi?id=170291
+ <rdar://problem/31301388>
+
+ Reviewed by Tim Horton.
+
+ Currently, when presenting a custom popover, we will cancel all touches in the application. This makes data
+ interaction when a custom popover is shown impossible -- to address this, we should only cancel touches when
+ the view is not an active data interaction source.
+
+ New API test: DataInteractionTests.CustomActionSheetPopover.
+
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView actionSheetAssistant:showCustomSheetForElement:]):
+
</ins><span class="cx"> 2017-03-30 Youenn Fablet <youenn@apple.com>
</span><span class="cx">
</span><span class="cx"> NetworkConnectionToWebProcess should stop web sockets when being destroyed
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (214624 => 214625)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2017-03-30 21:27:09 UTC (rev 214624)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2017-03-30 21:33:08 UTC (rev 214625)
</span><span class="lines">@@ -4045,8 +4045,15 @@
</span><span class="cx">
</span><span class="cx"> if ([uiDelegate respondsToSelector:@selector(_webView:showCustomSheetForElement:)]) {
</span><span class="cx"> if ([uiDelegate _webView:_webView showCustomSheetForElement:element]) {
</span><del>- // Prevent tap-and-hold and drag.
- [UIApp _cancelAllTouches];
</del><ins>+#if ENABLE(DATA_INTERACTION)
+ BOOL shouldCancelAllTouches = !_dataInteractionState.sourceAction;
+#else
+ BOOL shouldCancelAllTouches = YES;
+#endif
+ // Prevent tap-and-hold and panning.
+ if (shouldCancelAllTouches)
+ [UIApp _cancelAllTouches];
+
</ins><span class="cx"> return YES;
</span><span class="cx"> }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (214624 => 214625)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-03-30 21:27:09 UTC (rev 214624)
+++ trunk/Tools/ChangeLog        2017-03-30 21:33:08 UTC (rev 214625)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2017-03-30 Wenson Hsieh <wenson_hsieh@apple.com>
+
+ [WK2] Touches should not cancel when showing a custom action sheet while data interaction is active
+ https://bugs.webkit.org/show_bug.cgi?id=170291
+ <rdar://problem/31301388>
+
+ Reviewed by Tim Horton.
+
+ Adds support for testing how the custom action sheet presentation codepath interacts with data interaction, as
+ well as a new unit test. In this case, we force data interaction to fail if touches are canceled on the
+ shared UIApplication, and verify that data interaction completes successfully.
+
+ * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/ios/DataInteractionSimulator.h:
+ * TestWebKitAPI/ios/DataInteractionSimulator.mm:
+ (-[DataInteractionSimulatorApplication _cancelAllTouches]):
+ (-[DataInteractionSimulator initWithWebView:]):
+ (-[DataInteractionSimulator simulateAllTouchesCanceled:]):
+ (-[DataInteractionSimulator runFrom:to:]):
+ (-[DataInteractionSimulator _advanceProgress]):
+ (-[DataInteractionSimulator _webView:showCustomSheetForElement:]):
+
</ins><span class="cx"> 2017-03-30 Per Arne Vollan <pvollan@apple.com>
</span><span class="cx">
</span><span class="cx"> [Win] Pass close_fds = True in Python popen call.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsiosDataInteractionTestsmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (214624 => 214625)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm        2017-03-30 21:27:09 UTC (rev 214624)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm        2017-03-30 21:33:08 UTC (rev 214625)
</span><span class="lines">@@ -55,6 +55,13 @@
</span><span class="cx"> return [NSValue valueWithCGRect:CGRectMake(x, y, width, height)];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static void checkSelectionRectsWithLogging(NSArray *expected, NSArray *observed)
+{
+ if (![expected isEqualToArray:observed])
+ NSLog(@"Expected selection rects: %@ but observed: %@", expected, observed);
+ EXPECT_TRUE([expected isEqualToArray:observed]);
+}
+
</ins><span class="cx"> namespace TestWebKitAPI {
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, ImageToContentEditable)
</span><span class="lines">@@ -71,7 +78,7 @@
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ makeCGRectValue(1, 201, 215, 174) ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 215, 174) ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, ImageToTextarea)
</span><span class="lines">@@ -91,7 +98,7 @@
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</span><span class="cx">
</span><span class="cx"> NSArray *expectedSelectionRects = [NSArray arrayWithObjects:makeCGRectValue(6, 203, 188, 14), makeCGRectValue(6, 217, 188, 14), makeCGRectValue(6, 231, 66, 14), nil];
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:expectedSelectionRects]);
</del><ins>+ checkSelectionRectsWithLogging(expectedSelectionRects, [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, ContentEditableToContentEditable)
</span><span class="lines">@@ -109,7 +116,7 @@
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ makeCGRectValue(1, 201, 961, 227) ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 961, 227) ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, ContentEditableToTextarea)
</span><span class="lines">@@ -127,7 +134,7 @@
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ makeCGRectValue(6, 203, 990, 232) ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ makeCGRectValue(6, 203, 990, 232) ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, LinkToInput)
</span><span class="lines">@@ -138,13 +145,13 @@
</span><span class="cx"> RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
</span><span class="cx"> [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
</span><span class="cx">
</span><del>- EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView editorValue].UTF8String);
</del><ins>+ EXPECT_WK_STREQ("https://www.apple.com/", [webView editorValue].UTF8String);
</ins><span class="cx">
</span><span class="cx"> NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ makeCGRectValue(101, 273, 2613, 232) ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ makeCGRectValue(101, 273, 2057, 232) ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, BackgroundImageLinkToInput)
</span><span class="lines">@@ -155,13 +162,13 @@
</span><span class="cx"> RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
</span><span class="cx"> [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
</span><span class="cx">
</span><del>- EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView editorValue].UTF8String);
</del><ins>+ EXPECT_WK_STREQ("https://www.apple.com/", [webView editorValue].UTF8String);
</ins><span class="cx">
</span><span class="cx"> NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ makeCGRectValue(101, 241, 2613, 232) ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ makeCGRectValue(101, 241, 2057, 232) ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, CanPreventStart)
</span><span class="lines">@@ -178,7 +185,7 @@
</span><span class="cx"> NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
</span><span class="cx"> EXPECT_FALSE([observedEventNames containsObject:DataInteractionEnterEventName]);
</span><span class="cx"> EXPECT_FALSE([observedEventNames containsObject:DataInteractionOverEventName]);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, CanPreventOperation)
</span><span class="lines">@@ -194,7 +201,7 @@
</span><span class="cx"> NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, EnterAndLeaveEvents)
</span><span class="lines">@@ -212,7 +219,7 @@
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
</span><span class="cx"> EXPECT_TRUE([observedEventNames containsObject:DataInteractionLeaveEventName]);
</span><span class="cx"> EXPECT_FALSE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, ExternalSourceUTF8PlainTextOnly)
</span><span class="lines">@@ -231,7 +238,7 @@
</span><span class="cx"> [dataInteractionSimulator setExternalItemProvider:simulatedItemProvider.get()];
</span><span class="cx"> [dataInteractionSimulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)];
</span><span class="cx"> EXPECT_WK_STREQ(textPayload.UTF8String, [webView stringByEvaluatingJavaScript:@"editor.textContent"].UTF8String);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ makeCGRectValue(1, 201, 1936, 227) ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 1936, 227) ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, ExternalSourceJPEGOnly)
</span><span class="lines">@@ -250,7 +257,7 @@
</span><span class="cx"> [dataInteractionSimulator setExternalItemProvider:simulatedItemProvider.get()];
</span><span class="cx"> [dataInteractionSimulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)];
</span><span class="cx"> EXPECT_TRUE([webView editorContainsImageElement]);
</span><del>- EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ makeCGRectValue(1, 201, 215, 174) ]]);
</del><ins>+ checkSelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 215, 174) ], [dataInteractionSimulator finalSelectionRects]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, AttachmentElementItemProviders)
</span><span class="lines">@@ -306,6 +313,27 @@
</span><span class="cx"> EXPECT_WK_STREQ("", [webView editorValue].UTF8String);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+TEST(DataInteractionTests, CustomActionSheetPopover)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ [webView synchronouslyLoadTestPageNamed:@"link-and-target-div"];
+
+ auto dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator setShouldEnsureUIApplication:YES];
+
+ __block BOOL didInvokeCustomActionSheet = NO;
+ [dataInteractionSimulator setShowCustomActionSheetBlock:^BOOL(_WKActivatedElementInfo *element)
+ {
+ EXPECT_EQ(_WKActivatedElementTypeLink, element.type);
+ EXPECT_WK_STREQ("Hello world", element.title.UTF8String);
+ didInvokeCustomActionSheet = YES;
+ return YES;
+ }];
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
+ EXPECT_TRUE(didInvokeCustomActionSheet);
+ EXPECT_WK_STREQ("PASS", [webView stringByEvaluatingJavaScript:@"target.textContent"].UTF8String);
+}
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(DATA_INTERACTION)
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPIiosDataInteractionSimulatorh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h (214624 => 214625)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h        2017-03-30 21:27:09 UTC (rev 214624)
+++ trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h        2017-03-30 21:33:08 UTC (rev 214625)
</span><span class="lines">@@ -67,6 +67,8 @@
</span><span class="cx"> - (instancetype)initWithWebView:(TestWKWebView *)webView;
</span><span class="cx"> - (void)runFrom:(CGPoint)startLocation to:(CGPoint)endLocation;
</span><span class="cx">
</span><ins>+@property (nonatomic) BOOL shouldEnsureUIApplication;
+@property (nonatomic) BlockPtr<BOOL(_WKActivatedElementInfo *)> showCustomActionSheetBlock;
</ins><span class="cx"> @property (nonatomic) BlockPtr<NSArray *(NSArray *)> convertItemProvidersBlock;
</span><span class="cx"> @property (nonatomic, strong) UIItemProvider *externalItemProvider;
</span><span class="cx"> @property (nonatomic, readonly) NSArray *observedEventNames;
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPIiosDataInteractionSimulatormm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm (214624 => 214625)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm        2017-03-30 21:27:09 UTC (rev 214624)
+++ trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm        2017-03-30 21:33:08 UTC (rev 214625)
</span><span class="lines">@@ -28,11 +28,16 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx">
</span><ins>+#import "InstanceMethodSwizzler.h"
</ins><span class="cx"> #import "PlatformUtilities.h"
</span><span class="cx"> #import <UIKit/UIItemProvider_Private.h>
</span><ins>+#import <WebCore/SoftLinking.h>
</ins><span class="cx"> #import <WebKit/WKWebViewPrivate.h>
</span><span class="cx"> #import <wtf/RetainPtr.h>
</span><span class="cx">
</span><ins>+SOFT_LINK_FRAMEWORK(UIKit)
+SOFT_LINK(UIKit, UIApplicationInstantiateSingleton, void, (Class singletonClass), (singletonClass))
+
</ins><span class="cx"> using namespace TestWebKitAPI;
</span><span class="cx">
</span><span class="cx"> #if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/DataInteractionSimulatorAdditions.mm>)
</span><span class="lines">@@ -41,6 +46,7 @@
</span><span class="cx">
</span><span class="cx"> static double progressIncrementStep = 0.033;
</span><span class="cx"> static double progressTimeStep = 0.016;
</span><ins>+static NSString *TestWebKitAPISimulateCancelAllTouchesNotificationName = @"TestWebKitAPISimulateCancelAllTouchesNotificationName";
</ins><span class="cx">
</span><span class="cx"> static NSArray *dataInteractionEventNames()
</span><span class="cx"> {
</span><span class="lines">@@ -52,6 +58,16 @@
</span><span class="cx"> return eventNames;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+@interface DataInteractionSimulatorApplication : UIApplication
+@end
+
+@implementation DataInteractionSimulatorApplication
+- (void)_cancelAllTouches
+{
+ [[NSNotificationCenter defaultCenter] postNotificationName:TestWebKitAPISimulateCancelAllTouchesNotificationName object:nil];
+}
+@end
+
</ins><span class="cx"> @implementation DataInteractionSimulator
</span><span class="cx">
</span><span class="cx"> - (instancetype)initWithWebView:(TestWKWebView *)webView
</span><span class="lines">@@ -58,6 +74,7 @@
</span><span class="cx"> {
</span><span class="cx"> if (self = [super init]) {
</span><span class="cx"> _webView = webView;
</span><ins>+ _shouldEnsureUIApplication = NO;
</ins><span class="cx"> [_webView _setTestingDelegate:self];
</span><span class="cx"> [_webView setUIDelegate:self];
</span><span class="cx"> }
</span><span class="lines">@@ -91,8 +108,24 @@
</span><span class="cx"> return _observedEventNames.get();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (void)simulateAllTouchesCanceled:(NSNotification *)notification
+{
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_advanceProgress) object:nil];
+ _phase = DataInteractionCancelled;
+ _currentProgress = 1;
+ _isDoneWithCurrentRun = true;
+ if (_dataInteractionSession)
+ [_webView _simulateDataInteractionSessionDidEnd:_dataInteractionSession.get()];
+}
+
</ins><span class="cx"> - (void)runFrom:(CGPoint)startLocation to:(CGPoint)endLocation
</span><span class="cx"> {
</span><ins>+ NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
+ [defaultCenter addObserver:self selector:@selector(simulateAllTouchesCanceled:) name:TestWebKitAPISimulateCancelAllTouchesNotificationName object:nil];
+
+ if (_shouldEnsureUIApplication)
+ UIApplicationInstantiateSingleton([DataInteractionSimulatorApplication class]);
+
</ins><span class="cx"> [self _resetSimulatedState];
</span><span class="cx">
</span><span class="cx"> RetainPtr<DataInteractionSimulator> strongSelf = self;
</span><span class="lines">@@ -115,6 +148,9 @@
</span><span class="cx"> [_dataInteractionSession setMockLocationInWindow:_startLocation];
</span><span class="cx"> [_webView _simulatePrepareForDataInteractionSession:_dataInteractionSession.get() completion:^() {
</span><span class="cx"> DataInteractionSimulator *weakSelf = strongSelf.get();
</span><ins>+ if (weakSelf->_phase == DataInteractionCancelled)
+ return;
+
</ins><span class="cx"> weakSelf->_phase = DataInteractionBeginning;
</span><span class="cx"> [weakSelf _advanceProgress];
</span><span class="cx"> }];
</span><span class="lines">@@ -123,6 +159,8 @@
</span><span class="cx"> Util::run(&_isDoneWithCurrentRun);
</span><span class="cx"> [_webView clearMessageHandlers:dataInteractionEventNames()];
</span><span class="cx"> _finalSelectionRects = [_webView selectionRectsAfterPresentationUpdate];
</span><ins>+
+ [defaultCenter removeObserver:self];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (NSArray *)finalSelectionRects
</span><span class="lines">@@ -159,17 +197,15 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#if HAS_DATA_INTERACTION_ITEMS
</del><span class="cx"> for (WKDataInteractionItem *item in items)
</span><span class="cx"> [itemProviders addObject:item.itemProvider];
</span><del>-#endif
</del><span class="cx">
</span><span class="cx"> _dataOperationSession = adoptNS([[MockDataOperationSession alloc] initWithProvider:itemProviders.firstObject location:self._currentLocation window:[_webView window]]);
</span><del>-#if HAS_DATA_INTERACTION_ITEMS
</del><span class="cx"> [_dataInteractionSession setItems:items];
</span><del>-#endif
- [_webView _simulateWillBeginDataInteractionWithSession:_dataInteractionSession.get()];
- _phase = DataInteractionBegan;
</del><ins>+ if (!self.showCustomActionSheetBlock) {
+ [_webView _simulateWillBeginDataInteractionWithSession:_dataInteractionSession.get()];
+ _phase = DataInteractionBegan;
+ }
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx"> case DataInteractionBegan:
</span><span class="lines">@@ -228,6 +264,21 @@
</span><span class="cx"> return self.convertItemProvidersBlock ? self.convertItemProvidersBlock(originalItemProviders) : originalItemProviders;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (BOOL)_webView:(WKWebView *)webView showCustomSheetForElement:(_WKActivatedElementInfo *)element
+{
+ if (!self.showCustomActionSheetBlock)
+ return NO;
+
+ RetainPtr<DataInteractionSimulator> strongSelf = self;
+ dispatch_async(dispatch_get_main_queue(), ^() {
+ DataInteractionSimulator *weakSelf = strongSelf.get();
+ [weakSelf->_webView _simulateWillBeginDataInteractionWithSession:weakSelf->_dataInteractionSession.get()];
+ weakSelf->_phase = DataInteractionBegan;
+ });
+
+ return self.showCustomActionSheetBlock(element);
+}
+
</ins><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(DATA_INTERACTION)
</span></span></pre>
</div>
</div>
</body>
</html>