<!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>[212507] 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/212507">212507</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2017-02-16 17:01:36 -0800 (Thu, 16 Feb 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>[WK2] Add additional test infrastructure and unit tests for data interaction
https://bugs.webkit.org/show_bug.cgi?id=168439
<rdar://problem/30557942>
Reviewed by Tim Horton.
Source/WebKit2:
Adds two new _WKTestingDelegate protocol methods that are fired when a 'start data interaction' request has been
sent to the web process, and when a response has been received. See Tools/ChangeLog for more details.
* UIProcess/API/Cocoa/_WKTestingDelegate.h:
Tools:
Adds test support for additional data interaction scenarios that we currently cannot test, and also adds 7 new
test cases to DataInteractionTests. Most of the changes here refactor and augment DataInteractionSimulator to
support data interaction from See per-method descriptions below for more details.
* Configurations/TestWebKitAPI.xcconfig:
Add MobileCoreServices to the list of additional frameworks to link against on iOS.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
Add a new build phase that copies additional resources from WebKitAdditions/Resources/TestWebKitAPI and dumps
them into TestWebKitAPI.resources/ in the build directory, if the WebKitAdditions folder exists.
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(-[TestWKWebView editorContainsImageElement]):
(-[TestWKWebView editorValue]):
New helper methods for querying information from the "editor" element in a test page.
(TestWebKitAPI::TEST):
(TestWebKitAPI::runTestsExpectingToObserveEvents): Deleted.
Moves logic for capturing events during a simulated data interaction run from the test file to
DataInteractionSimulator. See -[DataInteractionSimulator observedEventNames].
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[TestMessageHandler removeMessage:]):
(-[TestWKWebView clearMessageHandlers:]):
Add the ability to clear message handlers from the TestWKWebView.
* TestWebKitAPI/ios/DataInteractionSimulator.h:
* TestWebKitAPI/ios/DataInteractionSimulator.mm:
(dataInteractionEventNames):
(-[DataInteractionSimulator initWithWebView:]):
(-[DataInteractionSimulator _resetSimulatedState]):
Moves logic to clear test harness state from any previous runs into a helper. Called at the beginning when
simulating data interaction.
(-[DataInteractionSimulator observedEventNames]):
Returns a list of the names of events relevant to data interaction that were observed over the course of the
most recent run.
(-[DataInteractionSimulator runFrom:to:]):
Changes -run to -runFrom:to:, which takes window-relative start and end locations. This allows the test harness
to run the same data interaction for multiple simulated gestures.
(-[DataInteractionSimulator _advanceProgress]):
(-[DataInteractionSimulator _finishDataInteraction]):
(-[DataInteractionSimulator externalItemProvider]):
(-[DataInteractionSimulator setExternalItemProvider:]):
Adds the -externalItemProvider property to DataInteractionSimulator. Setting this skips the gesture recognition
phase of a test run.
(-[DataInteractionSimulator webViewDidPerformDataInteractionControllerOperation:]):
(-[DataInteractionSimulator webView:beginDataInteractionWithSourceIndex:gestureRecognizer:]):
(-[DataInteractionSimulator webViewDidSendDataInteractionStartRequest:]):
(-[DataInteractionSimulator webView:didReceiveDataInteractionStartResponse:]):
While a request to start data interaction is in flight, put the remainder of the test on hold until the web
process returns. Then continue the test by scheduling a progress advance call. This addresses a race condition
wherein the the web process might take longer than usual to process the request to start data interaction, and
in the meantime, DataInteractionSimulator would end up completing the rest of the test before a response from
the web process is received, which then causes no simulated delegate methods to be fired.
(-[DataInteractionSimulator initWithWebView:startLocation:endLocation:]): Deleted.
(-[DataInteractionSimulator run]): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoa_WKTestingDelegateh">trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKTestingDelegate.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPIConfigurationsTestWebKitAPIxcconfig">trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsiosDataInteractionTestsmm">trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPIcocoaTestWKWebViewh">trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h</a></li>
<li><a href="#trunkToolsTestWebKitAPIcocoaTestWKWebViewmm">trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.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 (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Source/WebKit2/ChangeLog        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2017-02-16 Wenson Hsieh <wenson_hsieh@apple.com>
+
+ [WK2] Add additional test infrastructure and unit tests for data interaction
+ https://bugs.webkit.org/show_bug.cgi?id=168439
+ <rdar://problem/30557942>
+
+ Reviewed by Tim Horton.
+
+ Adds two new _WKTestingDelegate protocol methods that are fired when a 'start data interaction' request has been
+ sent to the web process, and when a response has been received. See Tools/ChangeLog for more details.
+
+ * UIProcess/API/Cocoa/_WKTestingDelegate.h:
+
</ins><span class="cx"> 2017-02-16 Aakash Jain <aakash_jain@apple.com>
</span><span class="cx">
</span><span class="cx"> Remove unused method WKBundlePageCopyContextMenuItemTitle
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoa_WKTestingDelegateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKTestingDelegate.h (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKTestingDelegate.h        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKTestingDelegate.h        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -43,6 +43,8 @@
</span><span class="cx">
</span><span class="cx"> #if TARGET_OS_IPHONE
</span><span class="cx"> @property (nonatomic, readonly) UILongPressGestureRecognizer *dataInteractionGestureRecognizer;
</span><ins>+- (void)webViewDidSendDataInteractionStartRequest:(WKWebView *)webView;
+- (void)webView:(WKWebView *)webView didReceiveDataInteractionStartResponse:(BOOL)started;
</ins><span class="cx"> - (void)webViewDidPerformDataInteractionControllerOperation:(WKWebView *)webView;
</span><span class="cx"> - (void)webView:(WKWebView *)webView beginDataInteractionWithSourceIndex:(NSInteger)sourceIndex gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
</span><span class="cx"> #endif // TARGET_OS_PHONE
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Tools/ChangeLog        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -1,5 +1,86 @@
</span><span class="cx"> 2017-02-16 Wenson Hsieh <wenson_hsieh@apple.com>
</span><span class="cx">
</span><ins>+ [WK2] Add additional test infrastructure and unit tests for data interaction
+ https://bugs.webkit.org/show_bug.cgi?id=168439
+ <rdar://problem/30557942>
+
+ Reviewed by Tim Horton.
+
+ Adds test support for additional data interaction scenarios that we currently cannot test, and also adds 7 new
+ test cases to DataInteractionTests. Most of the changes here refactor and augment DataInteractionSimulator to
+ support data interaction from See per-method descriptions below for more details.
+
+ * Configurations/TestWebKitAPI.xcconfig:
+
+ Add MobileCoreServices to the list of additional frameworks to link against on iOS.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+
+ Add a new build phase that copies additional resources from WebKitAdditions/Resources/TestWebKitAPI and dumps
+ them into TestWebKitAPI.resources/ in the build directory, if the WebKitAdditions folder exists.
+
+ * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+ (-[TestWKWebView editorContainsImageElement]):
+ (-[TestWKWebView editorValue]):
+
+ New helper methods for querying information from the "editor" element in a test page.
+
+ (TestWebKitAPI::TEST):
+ (TestWebKitAPI::runTestsExpectingToObserveEvents): Deleted.
+
+ Moves logic for capturing events during a simulated data interaction run from the test file to
+ DataInteractionSimulator. See -[DataInteractionSimulator observedEventNames].
+
+ * TestWebKitAPI/cocoa/TestWKWebView.h:
+ * TestWebKitAPI/cocoa/TestWKWebView.mm:
+ (-[TestMessageHandler removeMessage:]):
+ (-[TestWKWebView clearMessageHandlers:]):
+
+ Add the ability to clear message handlers from the TestWKWebView.
+
+ * TestWebKitAPI/ios/DataInteractionSimulator.h:
+ * TestWebKitAPI/ios/DataInteractionSimulator.mm:
+ (dataInteractionEventNames):
+ (-[DataInteractionSimulator initWithWebView:]):
+ (-[DataInteractionSimulator _resetSimulatedState]):
+
+ Moves logic to clear test harness state from any previous runs into a helper. Called at the beginning when
+ simulating data interaction.
+
+ (-[DataInteractionSimulator observedEventNames]):
+
+ Returns a list of the names of events relevant to data interaction that were observed over the course of the
+ most recent run.
+
+ (-[DataInteractionSimulator runFrom:to:]):
+
+ Changes -run to -runFrom:to:, which takes window-relative start and end locations. This allows the test harness
+ to run the same data interaction for multiple simulated gestures.
+
+ (-[DataInteractionSimulator _advanceProgress]):
+ (-[DataInteractionSimulator _finishDataInteraction]):
+ (-[DataInteractionSimulator externalItemProvider]):
+ (-[DataInteractionSimulator setExternalItemProvider:]):
+
+ Adds the -externalItemProvider property to DataInteractionSimulator. Setting this skips the gesture recognition
+ phase of a test run.
+
+ (-[DataInteractionSimulator webViewDidPerformDataInteractionControllerOperation:]):
+ (-[DataInteractionSimulator webView:beginDataInteractionWithSourceIndex:gestureRecognizer:]):
+ (-[DataInteractionSimulator webViewDidSendDataInteractionStartRequest:]):
+ (-[DataInteractionSimulator webView:didReceiveDataInteractionStartResponse:]):
+
+ While a request to start data interaction is in flight, put the remainder of the test on hold until the web
+ process returns. Then continue the test by scheduling a progress advance call. This addresses a race condition
+ wherein the the web process might take longer than usual to process the request to start data interaction, and
+ in the meantime, DataInteractionSimulator would end up completing the rest of the test before a response from
+ the web process is received, which then causes no simulated delegate methods to be fired.
+
+ (-[DataInteractionSimulator initWithWebView:startLocation:endLocation:]): Deleted.
+ (-[DataInteractionSimulator run]): Deleted.
+
+2017-02-16 Wenson Hsieh <wenson_hsieh@apple.com>
+
</ins><span class="cx"> Remove unused test pages in TestWebKitAPI
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=168462
</span><span class="cx">
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPIConfigurationsTestWebKitAPIxcconfig"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -32,6 +32,6 @@
</span><span class="cx"> OTHER_LDFLAGS_PLATFORM[sdk=macosx*] = -framework Cocoa -framework Carbon;
</span><span class="cx">
</span><span class="cx"> // FIXME: This should not be built on iOS. Instead we should create and use a TestWebKitAPI application.
</span><del>-OTHER_LDFLAGS_PLATFORM[sdk=iphone*] = -framework WebCore -framework CoreGraphics -framework UIKit;
</del><ins>+OTHER_LDFLAGS_PLATFORM[sdk=iphone*] = -framework WebCore -framework CoreGraphics -framework UIKit -framework MobileCoreServices;
</ins><span class="cx">
</span><span class="cx"> LD_RUNPATH_SEARCH_PATHS = "@loader_path";
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -2391,6 +2391,7 @@
</span><span class="cx">                                 8DD76F9B0486AA7600D96B5E /* Frameworks */,
</span><span class="cx">                                 8DD76F9E0486AA7600D96B5E /* CopyFiles */,
</span><span class="cx">                                 BCB9F4FB112384C000A137E0 /* Copy Resources */,
</span><ins>+                                F471CB8B1E565C0F0028055C /* ShellScript */,
</ins><span class="cx">                         );
</span><span class="cx">                         buildRules = (
</span><span class="cx">                         );
</span><span class="lines">@@ -2501,6 +2502,23 @@
</span><span class="cx">                 };
</span><span class="cx"> /* End PBXResourcesBuildPhase section */
</span><span class="cx">
</span><ins>+/* Begin PBXShellScriptBuildPhase section */
+                F471CB8B1E565C0F0028055C /* ShellScript */ = {
+                        isa = PBXShellScriptBuildPhase;
+                        buildActionMask = 2147483647;
+                        files = (
+                        );
+                        inputPaths = (
+                        );
+                        outputPaths = (
+                        );
+                        name = "Copy additional resources";
+                        runOnlyForDeploymentPostprocessing = 0;
+                        shellPath = /bin/sh;
+                        shellScript = "ADDITIONAL_RESOURCES_PATH=\"usr/local/include/WebKitAdditions/Resources/TestWebKitAPI\"\nDESTINATION_PATH=\"$TARGET_BUILD_DIR/TestWebKitAPI.resources\"\nif [ -d $TARGET_BUILD_DIR/$ADDITIONAL_RESOURCES_PATH ]; then\n cp $TARGET_BUILD_DIR/$ADDITIONAL_RESOURCES_PATH/* $DESTINATION_PATH\nelif [ -d $SDKROOT/$ADDITIONAL_RESOURCES_PATH ]; then\n cp $SDKROOT/$ADDITIONAL_RESOURCES_PATH/* $DESTINATION_PATH\nfi";
+                };
+/* End PBXShellScriptBuildPhase section */
+
</ins><span class="cx"> /* Begin PBXSourcesBuildPhase section */
</span><span class="cx">                 7C83DE961D0A590C00FEBCF3 /* Sources */ = {
</span><span class="cx">                         isa = PBXSourcesBuildPhase;
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsiosDataInteractionTestsmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -30,91 +30,231 @@
</span><span class="cx"> #import "DataInteractionSimulator.h"
</span><span class="cx"> #import "PlatformUtilities.h"
</span><span class="cx"> #import "TestWKWebView.h"
</span><ins>+#import <MobileCoreServices/MobileCoreServices.h>
+#import <UIKit/UIItemProvider_Private.h>
</ins><span class="cx">
</span><del>-namespace TestWebKitAPI {
</del><ins>+@implementation TestWKWebView (DataInteractionTests)
</ins><span class="cx">
</span><del>-static void runTestsExpectingToObserveEvents(TestWKWebView *webView, NSArray *eventNamesToObserve, dispatch_block_t test)
</del><ins>+- (BOOL)editorContainsImageElement
</ins><span class="cx"> {
</span><del>- NSMutableSet *observedEvents = [NSMutableSet set];
- for (NSString *eventName in eventNamesToObserve) {
- [webView performAfterReceivingMessage:eventName action:^() {
- [observedEvents addObject:eventName];
- }];
- }
</del><ins>+ return [self stringByEvaluatingJavaScript:@"!!editor.querySelector('img')"].boolValue;
+}
</ins><span class="cx">
</span><del>- test();
-
- for (NSString *eventName in eventNamesToObserve)
- EXPECT_TRUE([observedEvents containsObject:eventName]);
</del><ins>+- (NSString *)editorValue
+{
+ return [self stringByEvaluatingJavaScript:@"editor.value"];
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+@end
+
+namespace TestWebKitAPI {
+
</ins><span class="cx"> TEST(DataInteractionTests, ImageToContentEditable)
</span><span class="cx"> {
</span><span class="cx"> RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
</span><del>- runTestsExpectingToObserveEvents(webView.get(), @[ DataInteractionEnterEventName, DataInteractionOverEventName, DataInteractionPerformOperationEventName ], ^() {
- [webView synchronouslyLoadTestPageNamed:@"image-and-contenteditable"];
</del><ins>+ [webView synchronouslyLoadTestPageNamed:@"image-and-contenteditable"];
</ins><span class="cx">
</span><del>- RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get() startLocation:CGPointMake(100, 100) endLocation:CGPointMake(100, 300)]);
- [dataInteractionSimulator run];
</del><ins>+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
</ins><span class="cx">
</span><del>- EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!!editor.querySelector('img')"].boolValue);
- });
</del><ins>+ EXPECT_TRUE([webView editorContainsImageElement]);
+
+ NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, ImageToTextarea)
</span><span class="cx"> {
</span><span class="cx"> RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
</span><del>- runTestsExpectingToObserveEvents(webView.get(), @[ DataInteractionEnterEventName, DataInteractionOverEventName, DataInteractionPerformOperationEventName ], ^() {
- [webView synchronouslyLoadTestPageNamed:@"image-and-textarea"];
</del><ins>+ [webView synchronouslyLoadTestPageNamed:@"image-and-textarea"];
</ins><span class="cx">
</span><del>- RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get() startLocation:CGPointMake(100, 100) endLocation:CGPointMake(100, 300)]);
- [dataInteractionSimulator run];
</del><ins>+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
</ins><span class="cx">
</span><del>- NSURL *imageURL = [NSURL fileURLWithPath:[webView stringByEvaluatingJavaScript:@"editor.value"]];
- EXPECT_WK_STREQ("icon.png", imageURL.lastPathComponent);
- });
</del><ins>+ NSURL *imageURL = [NSURL fileURLWithPath:[webView editorValue]];
+ EXPECT_WK_STREQ("icon.png", imageURL.lastPathComponent);
+ EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
+
+ NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, ContentEditableToContentEditable)
</span><span class="cx"> {
</span><span class="cx"> RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
</span><del>- runTestsExpectingToObserveEvents(webView.get(), @[ DataInteractionEnterEventName, DataInteractionOverEventName, DataInteractionPerformOperationEventName ], ^() {
- [webView synchronouslyLoadTestPageNamed:@"autofocus-contenteditable"];
</del><ins>+ [webView synchronouslyLoadTestPageNamed:@"autofocus-contenteditable"];
</ins><span class="cx">
</span><del>- RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get() startLocation:CGPointMake(100, 100) endLocation:CGPointMake(100, 300)]);
- [dataInteractionSimulator run];
</del><ins>+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
</ins><span class="cx">
</span><del>- EXPECT_EQ([webView stringByEvaluatingJavaScript:@"source.textContent"].length, 0UL);
- EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"editor.textContent"].UTF8String);
- });
</del><ins>+ EXPECT_EQ([webView stringByEvaluatingJavaScript:@"source.textContent"].length, 0UL);
+ EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"editor.textContent"].UTF8String);
+ EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
+
+ NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+TEST(DataInteractionTests, ContentEditableToTextarea)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ [webView synchronouslyLoadTestPageNamed:@"contenteditable-and-textarea"];
+
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
+
+ EXPECT_EQ([webView stringByEvaluatingJavaScript:@"source.textContent"].length, 0UL);
+ EXPECT_WK_STREQ("Hello world", [webView editorValue].UTF8String);
+ EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
+
+ NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
+}
+
</ins><span class="cx"> TEST(DataInteractionTests, LinkToInput)
</span><span class="cx"> {
</span><span class="cx"> RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
</span><del>- runTestsExpectingToObserveEvents(webView.get(), @[ DataInteractionEnterEventName, DataInteractionOverEventName, DataInteractionPerformOperationEventName ], ^() {
- [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
</del><ins>+ [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
</ins><span class="cx">
</span><del>- RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get() startLocation:CGPointMake(100, 100) endLocation:CGPointMake(100, 300)]);
- [dataInteractionSimulator run];
</del><ins>+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
</ins><span class="cx">
</span><del>- EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView stringByEvaluatingJavaScript:@"editor.value"].UTF8String);
- });
</del><ins>+ EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView editorValue].UTF8String);
+ EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
+
+ NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(DataInteractionTests, BackgroundImageLinkToInput)
</span><span class="cx"> {
</span><span class="cx"> RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
</span><del>- runTestsExpectingToObserveEvents(webView.get(), @[ DataInteractionEnterEventName, DataInteractionOverEventName, DataInteractionPerformOperationEventName ], ^() {
- [webView synchronouslyLoadTestPageNamed:@"background-image-link-and-input"];
</del><ins>+ [webView synchronouslyLoadTestPageNamed:@"background-image-link-and-input"];
</ins><span class="cx">
</span><del>- RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get() startLocation:CGPointMake(100, 100) endLocation:CGPointMake(100, 300)]);
- [dataInteractionSimulator run];
</del><ins>+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
</ins><span class="cx">
</span><del>- EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView stringByEvaluatingJavaScript:@"editor.value"].UTF8String);
- });
</del><ins>+ EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView editorValue].UTF8String);
+ EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
+
+ NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+TEST(DataInteractionTests, CanPreventStart)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ [webView synchronouslyLoadTestPageNamed:@"prevent-start"];
+
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
+
+ EXPECT_FALSE([webView editorContainsImageElement]);
+ EXPECT_FALSE([dataInteractionSimulator didTryToBeginDataInteraction]);
+
+ NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
+ EXPECT_FALSE([observedEventNames containsObject:DataInteractionEnterEventName]);
+ EXPECT_FALSE([observedEventNames containsObject:DataInteractionOverEventName]);
+}
+
+TEST(DataInteractionTests, CanPreventOperation)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ [webView synchronouslyLoadTestPageNamed:@"prevent-operation"];
+
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
+
+ EXPECT_FALSE([webView editorContainsImageElement]);
+ EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
+
+ NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
+}
+
+TEST(DataInteractionTests, EnterAndLeaveEvents)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
+
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 450)];
+
+ EXPECT_WK_STREQ("", [webView editorValue].UTF8String);
+ EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
+
+ NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
+ EXPECT_TRUE([observedEventNames containsObject:DataInteractionLeaveEventName]);
+ EXPECT_FALSE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
+}
+
+TEST(DataInteractionTests, HandlesDataInteractionFailureGracefully)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
+
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ [dataInteractionSimulator setForceRequestToFail:YES];
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
+ EXPECT_WK_STREQ("", [webView editorValue].UTF8String);
+
+ // Before r212266, starting a subsequent gesture would have caused a debug assertion in the web process.
+ [dataInteractionSimulator setForceRequestToFail:NO];
+ [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
+ EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView editorValue].UTF8String);
+}
+
+TEST(DataInteractionTests, ExternalSourceUTF8PlainTextOnly)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ [webView synchronouslyLoadTestPageNamed:@"autofocus-contenteditable"];
+
+ NSString *textPayload = @"Ceci n'est pas une string";
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ RetainPtr<UIItemProvider> simulatedItemProvider = adoptNS([[UIItemProvider alloc] init]);
+ [simulatedItemProvider registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypeUTF8PlainText options:nil loadHandler:^NSProgress *(UIItemProviderDataLoadCompletionBlock completionBlock)
+ {
+ completionBlock([textPayload dataUsingEncoding:NSUTF8StringEncoding], nil);
+ return [NSProgress discreteProgressWithTotalUnitCount:100];
+ }];
+ [dataInteractionSimulator setExternalItemProvider:simulatedItemProvider.get()];
+ [dataInteractionSimulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)];
+ EXPECT_WK_STREQ(textPayload.UTF8String, [webView stringByEvaluatingJavaScript:@"editor.textContent"].UTF8String);
+}
+
+TEST(DataInteractionTests, ExternalSourceJPEGOnly)
+{
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ [webView synchronouslyLoadTestPageNamed:@"autofocus-contenteditable"];
+
+ UIImage *testImage = [UIImage imageNamed:@"TestWebKitAPI.resources/icon.png"];
+ RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+ RetainPtr<UIItemProvider> simulatedItemProvider = adoptNS([[UIItemProvider alloc] init]);
+ [simulatedItemProvider registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypeJPEG options:nil loadHandler:^NSProgress *(UIItemProviderDataLoadCompletionBlock completionBlock)
+ {
+ completionBlock(UIImageJPEGRepresentation(testImage, 0.5), nil);
+ return [NSProgress discreteProgressWithTotalUnitCount:100];
+ }];
+ [dataInteractionSimulator setExternalItemProvider:simulatedItemProvider.get()];
+ [dataInteractionSimulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)];
+ EXPECT_TRUE([webView editorContainsImageElement]);
+}
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(DATA_INTERACTION)
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPIcocoaTestWKWebViewh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> @interface TestWKWebView : WKWebView
</span><ins>+- (void)clearMessageHandlers:(NSArray *)messageNames;
</ins><span class="cx"> - (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action;
</span><span class="cx"> - (void)loadTestPageNamed:(NSString *)pageName;
</span><span class="cx"> - (void)synchronouslyLoadTestPageNamed:(NSString *)pageName;
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPIcocoaTestWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -59,6 +59,11 @@
</span><span class="cx"> _messageHandlers[message] = [handler copy];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (void)removeMessage:(NSString *)message
+{
+ [_messageHandlers removeObjectForKey:message];
+}
+
</ins><span class="cx"> - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
</span><span class="cx"> {
</span><span class="cx"> dispatch_block_t handler = _messageHandlers[message.body];
</span><span class="lines">@@ -187,6 +192,12 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (void)clearMessageHandlers:(NSArray *)messageNames
+{
+ for (NSString *messageName in messageNames)
+ [_testHandler removeMessage:messageName];
+}
+
</ins><span class="cx"> - (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action
</span><span class="cx"> {
</span><span class="cx"> if (!_testHandler) {
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPIiosDataInteractionSimulatorh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -25,9 +25,9 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx">
</span><ins>+#import "TestWKWebView.h"
</ins><span class="cx"> #import <UIKit/UIItemProvider.h>
</span><span class="cx"> #import <UIKit/UIKit.h>
</span><del>-#import <WebKit/WebKit.h>
</del><span class="cx"> #import <WebKit/_WKTestingDelegate.h>
</span><span class="cx"> #import <wtf/BlockPtr.h>
</span><span class="cx">
</span><span class="lines">@@ -37,6 +37,8 @@
</span><span class="cx"> extern NSString * const DataInteractionEnterEventName;
</span><span class="cx"> extern NSString * const DataInteractionOverEventName;
</span><span class="cx"> extern NSString * const DataInteractionPerformOperationEventName;
</span><ins>+extern NSString * const DataInteractionLeaveEventName;
+extern NSString * const DataInteractionStartEventName;
</ins><span class="cx">
</span><span class="cx"> typedef NS_ENUM(NSInteger, DataInteractionPhase) {
</span><span class="cx"> DataInteractionUnrecognized = 1,
</span><span class="lines">@@ -46,20 +48,27 @@
</span><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> @interface DataInteractionSimulator : NSObject<_WKTestingDelegate> {
</span><del>- RetainPtr<WKWebView> _webView;
</del><ins>+ RetainPtr<TestWKWebView> _webView;
</ins><span class="cx"> RetainPtr<MockLongPressGestureRecognizer> _gestureRecognizer;
</span><span class="cx"> RetainPtr<MockDataInteractionInfo> _dataInteractionInfo;
</span><ins>+ RetainPtr<NSMutableArray> _observedEventNames;
+ RetainPtr<UIItemProvider> _externalItemProvider;
</ins><span class="cx"> CGPoint _startLocation;
</span><span class="cx"> CGPoint _endLocation;
</span><span class="cx">
</span><span class="cx"> double _gestureProgress;
</span><del>- bool _isDoneWithDataInteraction;
</del><ins>+ bool _isDoneWithCurrentRun;
</ins><span class="cx"> DataInteractionPhase _phase;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (instancetype)initWithWebView:(WKWebView *)webView startLocation:(CGPoint)startLocation endLocation:(CGPoint)endLocation;
-- (void)run;
</del><ins>+- (instancetype)initWithWebView:(TestWKWebView *)webView;
+- (void)runFrom:(CGPoint)startLocation to:(CGPoint)endLocation;
</ins><span class="cx">
</span><ins>+@property (nonatomic) BOOL forceRequestToFail;
+@property (nonatomic, strong) UIItemProvider *externalItemProvider;
+@property (nonatomic, readonly) BOOL didTryToBeginDataInteraction;
+@property (nonatomic, readonly) NSArray *observedEventNames;
+
</ins><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(DATA_INTERACTION)
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPIiosDataInteractionSimulatormm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm (212506 => 212507)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm        2017-02-17 00:57:05 UTC (rev 212506)
+++ trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm        2017-02-17 01:01:36 UTC (rev 212507)
</span><span class="lines">@@ -80,17 +80,25 @@
</span><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> static double progressIncrementStep = 0.033;
</span><del>-static double progressTimeStep = 0.03;
</del><ins>+static double progressTimeStep = 0.016;
</ins><span class="cx">
</span><ins>+static NSArray *dataInteractionEventNames()
+{
+ static NSArray *eventNames = nil;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^() {
+ eventNames = @[ DataInteractionEnterEventName, DataInteractionOverEventName, DataInteractionPerformOperationEventName, DataInteractionLeaveEventName, DataInteractionStartEventName ];
+ });
+ return eventNames;
+}
+
</ins><span class="cx"> @implementation DataInteractionSimulator
</span><span class="cx">
</span><del>-- (instancetype)initWithWebView:(WKWebView *)webView startLocation:(CGPoint)startLocation endLocation:(CGPoint)endLocation
</del><ins>+- (instancetype)initWithWebView:(TestWKWebView *)webView
</ins><span class="cx"> {
</span><span class="cx"> if (self = [super init]) {
</span><span class="cx"> _webView = webView;
</span><span class="cx"> _gestureRecognizer = adoptNS([[MockLongPressGestureRecognizer alloc] initWithWindow:webView.window]);
</span><del>- _startLocation = startLocation;
- _endLocation = endLocation;
</del><span class="cx">
</span><span class="cx"> [_gestureRecognizer setMockNumberOfTouches:0];
</span><span class="cx"> [_webView _setTestingDelegate:self];
</span><span class="lines">@@ -106,18 +114,47 @@
</span><span class="cx"> [super dealloc];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (void)run
</del><ins>+- (void)_resetSimulatedState
</ins><span class="cx"> {
</span><span class="cx"> _gestureProgress = 0;
</span><span class="cx"> _phase = DataInteractionUnrecognized;
</span><del>- _isDoneWithDataInteraction = NO;
</del><ins>+ _isDoneWithCurrentRun = false;
+ _didTryToBeginDataInteraction = NO;
+ _observedEventNames = adoptNS([[NSMutableArray alloc] init]);
+}
+
+- (NSArray *)observedEventNames
+{
+ return _observedEventNames.get();
+}
+
+- (void)runFrom:(CGPoint)startLocation to:(CGPoint)endLocation
+{
+ [self _resetSimulatedState];
+
+ RetainPtr<DataInteractionSimulator> strongSelf = self;
+ for (NSString *eventName in dataInteractionEventNames()) {
+ DataInteractionSimulator *weakSelf = strongSelf.get();
+ [weakSelf->_webView performAfterReceivingMessage:eventName action:^() {
+ [weakSelf->_observedEventNames addObject:eventName];
+ }];
+ }
+
+ _startLocation = startLocation;
+ _endLocation = endLocation;
</ins><span class="cx"> [_gestureRecognizer setMockNumberOfTouches:1];
</span><span class="cx">
</span><del>- [self _recognizeGestureAtLocation:_startLocation withState:UIGestureRecognizerStateBegan];
</del><ins>+ if (self.externalItemProvider) {
+ _phase = DataInteractionBegan;
+ _dataInteractionInfo = adoptNS([[MockDataInteractionInfo alloc] initWithProvider:self.externalItemProvider location:startLocation window:[_webView window]]);
+ } else
+ [self _recognizeGestureAtLocation:_startLocation withState:UIGestureRecognizerStateBegan];
+
</ins><span class="cx"> [self _scheduleAdvanceProgress];
</span><span class="cx">
</span><del>- TestWebKitAPI::Util::run(&_isDoneWithDataInteraction);
</del><ins>+ Util::run(&_isDoneWithCurrentRun);
</ins><span class="cx"> [_gestureRecognizer setMockNumberOfTouches:0];
</span><ins>+ [_webView clearMessageHandlers:dataInteractionEventNames()];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)_advanceProgress
</span><span class="lines">@@ -140,7 +177,6 @@
</span><span class="cx"> [self _scheduleAdvanceProgress];
</span><span class="cx"> break;
</span><span class="cx"> case DataInteractionEntered:
</span><del>- [_dataInteractionInfo setMockLocationInWindow:self._currentLocation];
</del><span class="cx"> [_webView _simulateDataInteractionUpdated:_dataInteractionInfo.get()];
</span><span class="cx"> [self _scheduleAdvanceProgress];
</span><span class="cx"> break;
</span><span class="lines">@@ -151,6 +187,12 @@
</span><span class="cx">
</span><span class="cx"> - (void)_finishDataInteraction
</span><span class="cx"> {
</span><ins>+ if (_phase == DataInteractionUnrecognized) {
+ [self _recognizeGestureAtLocation:self._currentLocation withState:UIGestureRecognizerStateEnded];
+ _isDoneWithCurrentRun = true;
+ return;
+ }
+
</ins><span class="cx"> _phase = DataInteractionPerforming;
</span><span class="cx"> [_webView _simulateDataInteractionPerformOperation:_dataInteractionInfo.get()];
</span><span class="cx"> [_webView _simulateDataInteractionEnded:_dataInteractionInfo.get()];
</span><span class="lines">@@ -177,6 +219,16 @@
</span><span class="cx"> [_webView _simulateDataInteractionGestureRecognized];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (UIItemProvider *)externalItemProvider
+{
+ return _externalItemProvider.get();
+}
+
+- (void)setExternalItemProvider:(UIItemProvider *)externalItemProvider
+{
+ _externalItemProvider = externalItemProvider;
+}
+
</ins><span class="cx"> #pragma mark - _WKTestingDelegate
</span><span class="cx">
</span><span class="cx"> - (UILongPressGestureRecognizer *)dataInteractionGestureRecognizer
</span><span class="lines">@@ -186,11 +238,18 @@
</span><span class="cx">
</span><span class="cx"> - (void)webViewDidPerformDataInteractionControllerOperation:(WKWebView *)webView
</span><span class="cx"> {
</span><del>- _isDoneWithDataInteraction = true;
</del><ins>+ _isDoneWithCurrentRun = true;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)webView:(WKWebView *)webView beginDataInteractionWithSourceIndex:(NSInteger)sourceIndex gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
</span><span class="cx"> {
</span><ins>+ _didTryToBeginDataInteraction = YES;
+
+ if (self.forceRequestToFail) {
+ [_webView _simulateFailedDataInteractionWithIndex:sourceIndex];
+ return;
+ }
+
</ins><span class="cx"> _phase = DataInteractionBegan;
</span><span class="cx">
</span><span class="cx"> // End the data interaction gesture recognizer.
</span><span class="lines">@@ -203,6 +262,20 @@
</span><span class="cx"> [_webView _simulateWillBeginDataInteractionWithIndex:sourceIndex withSession:nil];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (void)webViewDidSendDataInteractionStartRequest:(WKWebView *)webView
+{
+ // This addresses a race condition in the testing harness wherein the web process might take longer than usual to process the
+ // request to start data interaction, and in the meantime, DataInteractionSimulator would end up completing the rest of the test
+ // before a response from the web process is received. We instead defer test progress until after the web process has indicated
+ // whether or not data interaction should commence.
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_advanceProgress) object:nil];
+}
+
+- (void)webView:(WKWebView *)webView didReceiveDataInteractionStartResponse:(BOOL)started
+{
+ [self _scheduleAdvanceProgress];
+}
+
</ins><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(DATA_INTERACTION)
</span></span></pre>
</div>
</div>
</body>
</html>