Title: [235792] branches/safari-606-branch
Revision
235792
Author
[email protected]
Date
2018-09-07 13:07:39 -0700 (Fri, 07 Sep 2018)

Log Message

Cherry-pick r234504. rdar://problem/44209851

    [iOS] Keyboard becomes unresponsive after pressing delete while pressing down on a character key with accents
    https://bugs.webkit.org/show_bug.cgi?id=188251
    <rdar://problem/37842108>

    Reviewed by Tim Horton.

    Source/WebKit:

    Fixes a bug in key event handling where invoking -handleKeyWebEvent:withCompletionHandler: from within the
    completion callback of a previous call to -handleKeyWebEvent:withCompletionHandler: would cause the completion
    callback to be cleared out prematurely. In some cases (as described in the title of this bug), UIKit exercises
    this codepath and subsequently hangs due to their completion block never getting invoked by WebKit.

    Test: KeyboardInputTests.CanHandleKeyEventInCompletionHandler

    * UIProcess/ios/WKContentViewInteraction.h:
    * UIProcess/ios/WKContentViewInteraction.mm:
    (-[WKContentView handleKeyWebEvent:withCompletionHandler:]):
    (-[WKContentView _didHandleKeyEvent:eventWasHandled:]):

    Tools:

    Adds a new API test to verify that clients (in this case, UIKit) is allowed to invoke
    -handleKeyWebEvent:withCompletionHandler: within the completion block of a prior invocation.

    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
    * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm: Added.
    (TestWebKitAPI::TEST):
    * TestWebKitAPI/Tests/ios/TestInputDelegate.h: Added.

    Pull some logic used to force an input session to start out from an existing API test file
    (WKWebViewAutofillTests) and into a separate helper class that is used by both the existing API tests and the
    new keyboard input test.

    * TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm:
    (-[AutofillTestView initWithFrame:]):
    (TestWebKitAPI::TEST):
    (-[TestInputDelegate init]): Deleted.
    (-[TestInputDelegate _webView:focusShouldStartInputSession:]): Deleted.
    * TestWebKitAPI/ios/UIKitSPI.h:

    Add some UIKit SPI utilized by the new API test.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-606-branch/Source/WebKit/ChangeLog (235791 => 235792)


--- branches/safari-606-branch/Source/WebKit/ChangeLog	2018-09-07 19:50:41 UTC (rev 235791)
+++ branches/safari-606-branch/Source/WebKit/ChangeLog	2018-09-07 20:07:39 UTC (rev 235792)
@@ -1,3 +1,73 @@
+2018-09-06  Babak Shafiei  <[email protected]>
+
+        Cherry-pick r234504. rdar://problem/44209851
+
+    [iOS] Keyboard becomes unresponsive after pressing delete while pressing down on a character key with accents
+    https://bugs.webkit.org/show_bug.cgi?id=188251
+    <rdar://problem/37842108>
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebKit:
+    
+    Fixes a bug in key event handling where invoking -handleKeyWebEvent:withCompletionHandler: from within the
+    completion callback of a previous call to -handleKeyWebEvent:withCompletionHandler: would cause the completion
+    callback to be cleared out prematurely. In some cases (as described in the title of this bug), UIKit exercises
+    this codepath and subsequently hangs due to their completion block never getting invoked by WebKit.
+    
+    Test: KeyboardInputTests.CanHandleKeyEventInCompletionHandler
+    
+    * UIProcess/ios/WKContentViewInteraction.h:
+    * UIProcess/ios/WKContentViewInteraction.mm:
+    (-[WKContentView handleKeyWebEvent:withCompletionHandler:]):
+    (-[WKContentView _didHandleKeyEvent:eventWasHandled:]):
+    
+    Tools:
+    
+    Adds a new API test to verify that clients (in this case, UIKit) is allowed to invoke
+    -handleKeyWebEvent:withCompletionHandler: within the completion block of a prior invocation.
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm: Added.
+    (TestWebKitAPI::TEST):
+    * TestWebKitAPI/Tests/ios/TestInputDelegate.h: Added.
+    
+    Pull some logic used to force an input session to start out from an existing API test file
+    (WKWebViewAutofillTests) and into a separate helper class that is used by both the existing API tests and the
+    new keyboard input test.
+    
+    * TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm:
+    (-[AutofillTestView initWithFrame:]):
+    (TestWebKitAPI::TEST):
+    (-[TestInputDelegate init]): Deleted.
+    (-[TestInputDelegate _webView:focusShouldStartInputSession:]): Deleted.
+    * TestWebKitAPI/ios/UIKitSPI.h:
+    
+    Add some UIKit SPI utilized by the new API test.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234504 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-08-02  Wenson Hsieh  <[email protected]>
+
+            [iOS] Keyboard becomes unresponsive after pressing delete while pressing down on a character key with accents
+            https://bugs.webkit.org/show_bug.cgi?id=188251
+            <rdar://problem/37842108>
+
+            Reviewed by Tim Horton.
+
+            Fixes a bug in key event handling where invoking -handleKeyWebEvent:withCompletionHandler: from within the
+            completion callback of a previous call to -handleKeyWebEvent:withCompletionHandler: would cause the completion
+            callback to be cleared out prematurely. In some cases (as described in the title of this bug), UIKit exercises
+            this codepath and subsequently hangs due to their completion block never getting invoked by WebKit.
+
+            Test: KeyboardInputTests.CanHandleKeyEventInCompletionHandler
+
+            * UIProcess/ios/WKContentViewInteraction.h:
+            * UIProcess/ios/WKContentViewInteraction.mm:
+            (-[WKContentView handleKeyWebEvent:withCompletionHandler:]):
+            (-[WKContentView _didHandleKeyEvent:eventWasHandled:]):
+
 2018-09-05  Babak Shafiei  <[email protected]>
 
         Cherry-pick r235133. rdar://problem/44144065

Modified: branches/safari-606-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (235791 => 235792)


--- branches/safari-606-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-09-07 19:50:41 UTC (rev 235791)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-09-07 20:07:39 UTC (rev 235792)
@@ -92,7 +92,6 @@
 typedef void (^UIWKDictationContextHandler)(NSString *selectedText, NSString *beforeText, NSString *afterText);
 typedef void (^UIWKSelectionCompletionHandler)(void);
 typedef void (^UIWKSelectionWithDirectionCompletionHandler)(BOOL selectionEndIsMoving);
-typedef void (^UIWKKeyWebEventCompletionHandler)(::WebEvent *theEvent, BOOL wasHandled);
 
 typedef BlockPtr<void(WebKit::InteractionInformationAtPosition)> InteractionInformationCallback;
 typedef std::pair<WebKit::InteractionInformationRequest, InteractionInformationCallback> InteractionInformationRequestAndCallback;
@@ -201,7 +200,7 @@
     WebKit::AssistedNodeInformation _assistedNodeInformation;
     RetainPtr<NSObject<WKFormPeripheral>> _inputPeripheral;
     RetainPtr<UIEvent> _uiEventBeingResent;
-    UIWKKeyWebEventCompletionHandler _keyWebEventHandler;
+    BlockPtr<void(::WebEvent *, BOOL)> _keyWebEventHandler;
 
     CGPoint _lastInteractionLocation;
     uint64_t _layerTreeTransactionIdAtLastTouchStart;

Modified: branches/safari-606-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (235791 => 235792)


--- branches/safari-606-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-09-07 19:50:41 UTC (rev 235791)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-09-07 20:07:39 UTC (rev 235792)
@@ -3616,16 +3616,14 @@
 
 - (void)handleKeyWebEvent:(::WebEvent *)theEvent withCompletionHandler:(void (^)(::WebEvent *theEvent, BOOL wasHandled))completionHandler
 {
-    _keyWebEventHandler = [completionHandler copy];
+    _keyWebEventHandler = makeBlockPtr(completionHandler);
     _page->handleKeyboardEvent(NativeWebKeyboardEvent(theEvent));
 }
 
 - (void)_didHandleKeyEvent:(::WebEvent *)event eventWasHandled:(BOOL)eventWasHandled
 {
-    if (_keyWebEventHandler) {
-        _keyWebEventHandler(event, eventWasHandled);
-        [_keyWebEventHandler release];
-        _keyWebEventHandler = nil;
+    if (auto handler = WTFMove(_keyWebEventHandler)) {
+        handler(event, eventWasHandled);
         return;
     }
         

Modified: branches/safari-606-branch/Tools/ChangeLog (235791 => 235792)


--- branches/safari-606-branch/Tools/ChangeLog	2018-09-07 19:50:41 UTC (rev 235791)
+++ branches/safari-606-branch/Tools/ChangeLog	2018-09-07 20:07:39 UTC (rev 235792)
@@ -1,3 +1,82 @@
+2018-09-06  Babak Shafiei  <[email protected]>
+
+        Cherry-pick r234504. rdar://problem/44209851
+
+    [iOS] Keyboard becomes unresponsive after pressing delete while pressing down on a character key with accents
+    https://bugs.webkit.org/show_bug.cgi?id=188251
+    <rdar://problem/37842108>
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebKit:
+    
+    Fixes a bug in key event handling where invoking -handleKeyWebEvent:withCompletionHandler: from within the
+    completion callback of a previous call to -handleKeyWebEvent:withCompletionHandler: would cause the completion
+    callback to be cleared out prematurely. In some cases (as described in the title of this bug), UIKit exercises
+    this codepath and subsequently hangs due to their completion block never getting invoked by WebKit.
+    
+    Test: KeyboardInputTests.CanHandleKeyEventInCompletionHandler
+    
+    * UIProcess/ios/WKContentViewInteraction.h:
+    * UIProcess/ios/WKContentViewInteraction.mm:
+    (-[WKContentView handleKeyWebEvent:withCompletionHandler:]):
+    (-[WKContentView _didHandleKeyEvent:eventWasHandled:]):
+    
+    Tools:
+    
+    Adds a new API test to verify that clients (in this case, UIKit) is allowed to invoke
+    -handleKeyWebEvent:withCompletionHandler: within the completion block of a prior invocation.
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm: Added.
+    (TestWebKitAPI::TEST):
+    * TestWebKitAPI/Tests/ios/TestInputDelegate.h: Added.
+    
+    Pull some logic used to force an input session to start out from an existing API test file
+    (WKWebViewAutofillTests) and into a separate helper class that is used by both the existing API tests and the
+    new keyboard input test.
+    
+    * TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm:
+    (-[AutofillTestView initWithFrame:]):
+    (TestWebKitAPI::TEST):
+    (-[TestInputDelegate init]): Deleted.
+    (-[TestInputDelegate _webView:focusShouldStartInputSession:]): Deleted.
+    * TestWebKitAPI/ios/UIKitSPI.h:
+    
+    Add some UIKit SPI utilized by the new API test.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234504 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-08-02  Wenson Hsieh  <[email protected]>
+
+            [iOS] Keyboard becomes unresponsive after pressing delete while pressing down on a character key with accents
+            https://bugs.webkit.org/show_bug.cgi?id=188251
+            <rdar://problem/37842108>
+
+            Reviewed by Tim Horton.
+
+            Adds a new API test to verify that clients (in this case, UIKit) is allowed to invoke
+            -handleKeyWebEvent:withCompletionHandler: within the completion block of a prior invocation.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm: Added.
+            (TestWebKitAPI::TEST):
+            * TestWebKitAPI/Tests/ios/TestInputDelegate.h: Added.
+
+            Pull some logic used to force an input session to start out from an existing API test file
+            (WKWebViewAutofillTests) and into a separate helper class that is used by both the existing API tests and the
+            new keyboard input test.
+
+            * TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm:
+            (-[AutofillTestView initWithFrame:]):
+            (TestWebKitAPI::TEST):
+            (-[TestInputDelegate init]): Deleted.
+            (-[TestInputDelegate _webView:focusShouldStartInputSession:]): Deleted.
+            * TestWebKitAPI/ios/UIKitSPI.h:
+
+            Add some UIKit SPI utilized by the new API test.
+
 2018-09-05  Babak Shafiei  <[email protected]>
 
         Cherry-pick r234873. rdar://problem/44144063

Modified: branches/safari-606-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (235791 => 235792)


--- branches/safari-606-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-09-07 19:50:41 UTC (rev 235791)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-09-07 20:07:39 UTC (rev 235792)
@@ -797,6 +797,8 @@
 		F457A9D6202D68AF00F7E9D5 /* DataTransfer.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F457A9B3202D535300F7E9D5 /* DataTransfer.html */; };
 		F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F45B63FA1F197F33009D38B9 /* image-map.html */; };
 		F45B63FE1F19D410009D38B9 /* ActionSheetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F45B63FC1F19D410009D38B9 /* ActionSheetTests.mm */; };
+		F45E15732112CE2900307E82 /* KeyboardInputTestsIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F45E15722112CE2900307E82 /* KeyboardInputTestsIOS.mm */; };
+		F45E15762112CE6200307E82 /* TestInputDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = F45E15752112CE6200307E82 /* TestInputDelegate.mm */; };
 		F464AF9220BB66EA007F9B18 /* RenderingProgressTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F464AF9120BB66EA007F9B18 /* RenderingProgressTests.mm */; };
 		F46849BE1EEF58E400B937FE /* UIPasteboardTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F46849BD1EEF58E400B937FE /* UIPasteboardTests.mm */; };
 		F46849C01EEF5EF300B937FE /* rich-and-plain-text.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F46849BF1EEF5EDC00B937FE /* rich-and-plain-text.html */; };
@@ -2006,6 +2008,9 @@
 		F457A9B6202D5CDC00F7E9D5 /* PasteMixedContent.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteMixedContent.mm; sourceTree = "<group>"; };
 		F45B63FA1F197F33009D38B9 /* image-map.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "image-map.html"; sourceTree = "<group>"; };
 		F45B63FC1F19D410009D38B9 /* ActionSheetTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ActionSheetTests.mm; sourceTree = "<group>"; };
+		F45E15722112CE2900307E82 /* KeyboardInputTestsIOS.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyboardInputTestsIOS.mm; sourceTree = "<group>"; };
+		F45E15742112CE6200307E82 /* TestInputDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestInputDelegate.h; sourceTree = "<group>"; };
+		F45E15752112CE6200307E82 /* TestInputDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TestInputDelegate.mm; sourceTree = "<group>"; };
 		F464AF9120BB66EA007F9B18 /* RenderingProgressTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderingProgressTests.mm; sourceTree = "<group>"; };
 		F46849BD1EEF58E400B937FE /* UIPasteboardTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UIPasteboardTests.mm; sourceTree = "<group>"; };
 		F46849BF1EEF5EDC00B937FE /* rich-and-plain-text.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "rich-and-plain-text.html"; sourceTree = "<group>"; };
@@ -2465,6 +2470,7 @@
 				2E205BA31F527746005952DD /* AccessibilityTestsIOS.mm */,
 				F45B63FC1F19D410009D38B9 /* ActionSheetTests.mm */,
 				F4D4F3B71E4E36E400BB2767 /* DataInteractionTests.mm */,
+				F45E15722112CE2900307E82 /* KeyboardInputTestsIOS.mm */,
 				574F55CE204D3763002948C6 /* LocalAuthenticator.mm */,
 				7560917719259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm */,
 				F464AF9120BB66EA007F9B18 /* RenderingProgressTests.mm */,
@@ -2471,6 +2477,8 @@
 				F4C8797E2059D8D3009CD00B /* ScrollViewInsetTests.mm */,
 				CE6E819F20A6935F00E2C80F /* SetTimeoutFunction.mm */,
 				4433A395208044130091ED57 /* SynchronousTimeoutTests.mm */,
+				F45E15742112CE6200307E82 /* TestInputDelegate.h */,
+				F45E15752112CE6200307E82 /* TestInputDelegate.mm */,
 				F45033F4206BEC95009351CE /* TextAutosizingBoost.mm */,
 				F46849BD1EEF58E400B937FE /* UIPasteboardTests.mm */,
 				F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */,
@@ -3735,6 +3743,7 @@
 				7CCE7EAD1A411A3400447C4C /* _javascript_Test.cpp in Sources */,
 				7CCE7EA51A411A0800447C4C /* _javascript_TestMac.mm in Sources */,
 				7CCE7EC41A411A7E00447C4C /* JSWrapperForNodeInWebFrame.mm in Sources */,
+				F45E15732112CE2900307E82 /* KeyboardInputTestsIOS.mm in Sources */,
 				7CCE7F061A411AE600447C4C /* LayoutMilestonesWithAllContentInFrame.cpp in Sources */,
 				7CCE7EDF1A411A9200447C4C /* LayoutUnit.cpp in Sources */,
 				7A66BDB61EAF14EF00CCC924 /* LimitTitleSize.cpp in Sources */,
@@ -3871,6 +3880,7 @@
 				1C734B5320788C4800F430EA /* SystemColors.mm in Sources */,
 				7CCE7F161A411AE600447C4C /* TerminateTwice.cpp in Sources */,
 				7CCE7EA91A411A1D00447C4C /* TestBrowsingContextLoadDelegate.mm in Sources */,
+				F45E15762112CE6200307E82 /* TestInputDelegate.mm in Sources */,
 				2D1C04A71D76298B000A6816 /* TestNavigationDelegate.mm in Sources */,
 				A14FC5901B8AE36F00D107EB /* TestProtocol.mm in Sources */,
 				7CCE7EAE1A411A3400447C4C /* TestsController.cpp in Sources */,

Added: branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm (0 => 235792)


--- branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm	                        (rev 0)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm	2018-09-07 20:07:39 UTC (rev 235792)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_API_ENABLED && PLATFORM(IOS)
+
+#import "PlatformUtilities.h"
+#import "TestInputDelegate.h"
+#import "TestWKWebView.h"
+#import "UIKitSPI.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKitLegacy/WebEvent.h>
+
+namespace TestWebKitAPI {
+
+TEST(KeyboardInputTests, CanHandleKeyEventInCompletionHandler)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
+
+    bool doneWaiting = false;
+    [inputDelegate setFocusStartsInputSessionPolicyHandler:[&] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
+        doneWaiting = true;
+        return _WKFocusStartsInputSessionPolicyAllow;
+    }];
+    [webView _setInputDelegate:inputDelegate.get()];
+    [webView synchronouslyLoadHTMLString:@"<input autofocus>"];
+
+    TestWebKitAPI::Util::run(&doneWaiting);
+    doneWaiting = false;
+
+    id <UITextInputPrivate> contentView = (id <UITextInputPrivate>)[webView firstResponder];
+    auto firstWebEvent = adoptNS([[WebEvent alloc] initWithKeyEventType:WebEventKeyDown timeStamp:CFAbsoluteTimeGetCurrent() characters:@"a" charactersIgnoringModifiers:@"a" modifiers:0 isRepeating:NO withFlags:0 withInputManagerHint:nil keyCode:0 isTabKey:NO]);
+    auto secondWebEvent = adoptNS([[WebEvent alloc] initWithKeyEventType:WebEventKeyUp timeStamp:CFAbsoluteTimeGetCurrent() characters:@"a" charactersIgnoringModifiers:@"a" modifiers:0 isRepeating:NO withFlags:0 withInputManagerHint:nil keyCode:0 isTabKey:NO]);
+    [contentView handleKeyWebEvent:firstWebEvent.get() withCompletionHandler:[&] (WebEvent *event, BOOL) {
+        EXPECT_TRUE([event isEqual:firstWebEvent.get()]);
+        [contentView handleKeyWebEvent:secondWebEvent.get() withCompletionHandler:[&] (WebEvent *event, BOOL) {
+            EXPECT_TRUE([event isEqual:secondWebEvent.get()]);
+            [contentView insertText:@"a"];
+            doneWaiting = true;
+        }];
+    }];
+
+    TestWebKitAPI::Util::run(&doneWaiting);
+    EXPECT_WK_STREQ("a", [webView stringByEvaluatingJavaScript:@"document.querySelector('input').value"]);
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED && PLATFORM(IOS)

Added: branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h (0 => 235792)


--- branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h	                        (rev 0)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h	2018-09-07 20:07:39 UTC (rev 235792)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if WK_API_ENABLED && PLATFORM(IOS)
+
+#import <WebKit/_WKFocusedElementInfo.h>
+#import <WebKit/_WKInputDelegate.h>
+
+@class WKWebView;
+
+@interface TestInputDelegate : NSObject <_WKInputDelegate>
+@property (nonatomic, copy) _WKFocusStartsInputSessionPolicy (^focusStartsInputSessionPolicyHandler)(WKWebView *, id <_WKFocusedElementInfo>);
+@end
+
+#endif

Added: branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm (0 => 235792)


--- branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm	                        (rev 0)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm	2018-09-07 20:07:39 UTC (rev 235792)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TestInputDelegate.h"
+
+#if WK_API_ENABLED && PLATFORM(IOS)
+
+#import <wtf/BlockPtr.h>
+
+@implementation TestInputDelegate {
+    BlockPtr<_WKFocusStartsInputSessionPolicy(WKWebView *, id <_WKFocusedElementInfo>)> _focusStartsInputSessionPolicyHandler;
+}
+
+- (void)setFocusStartsInputSessionPolicyHandler:(_WKFocusStartsInputSessionPolicy (^)(WKWebView *, id <_WKFocusedElementInfo>))handler
+{
+    _focusStartsInputSessionPolicyHandler = makeBlockPtr(handler);
+}
+
+- (_WKFocusStartsInputSessionPolicy (^)(WKWebView *, id <_WKFocusedElementInfo>))focusStartsInputSessionPolicyHandler
+{
+    return _focusStartsInputSessionPolicyHandler.get();
+}
+
+- (_WKFocusStartsInputSessionPolicy)_webView:(WKWebView *)webView decidePolicyForFocusedElement:(id <_WKFocusedElementInfo>)info
+{
+    return self.focusStartsInputSessionPolicyHandler ? self.focusStartsInputSessionPolicyHandler(webView, info) : _WKFocusStartsInputSessionPolicyAuto;
+}
+
+@end
+
+#endif // WK_API_ENABLED && PLATFORM(IOS)

Modified: branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm (235791 => 235792)


--- branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm	2018-09-07 19:50:41 UTC (rev 235791)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm	2018-09-07 20:07:39 UTC (rev 235792)
@@ -28,36 +28,14 @@
 #if WK_API_ENABLED && PLATFORM(IOS)
 
 #import "PlatformUtilities.h"
+#import "TestInputDelegate.h"
 #import "TestWKWebView.h"
 #import "UIKitSPI.h"
 #import <WebKit/WKWebViewPrivate.h>
-#import <WebKit/_WKFocusedElementInfo.h>
-#import <WebKit/_WKInputDelegate.h>
 #import <wtf/BlockPtr.h>
 
 typedef UIView <UITextInputTraits_Private_Proposed_SPI_34583628> AutofillInputView;
 
-@interface TestInputDelegate : NSObject <_WKInputDelegate>
-@property (nonatomic) BOOL inputSessionRequiresUserInteraction;
-@end
-
-@implementation TestInputDelegate
-
-- (instancetype)init
-{
-    if (self = [super init])
-        _inputSessionRequiresUserInteraction = NO;
-
-    return self;
-}
-
-- (BOOL)_webView:(WKWebView *)webView focusShouldStartInputSession:(id <_WKFocusedElementInfo>)info
-{
-    return !self.inputSessionRequiresUserInteraction || info.userInitiated;
-}
-
-@end
-
 @interface AutofillTestView : TestWKWebView
 @end
 
@@ -71,6 +49,9 @@
         return nil;
 
     _testDelegate = adoptNS([[TestInputDelegate alloc] init]);
+    [_testDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
+        return _WKFocusStartsInputSessionPolicyAllow;
+    }];
     self._inputDelegate = _testDelegate.get();
     return self;
 }
@@ -186,7 +167,9 @@
 TEST(WKWebViewAutofillTests, AutofillRequiresInputSession)
 {
     auto webView = adoptNS([[AutofillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
-    [(TestInputDelegate *)[webView _inputDelegate] setInputSessionRequiresUserInteraction:YES];
+    [(TestInputDelegate *)[webView _inputDelegate] setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
+        return _WKFocusStartsInputSessionPolicyAuto;
+    }];
     [webView synchronouslyLoadHTMLString:@"<input id='user' type='email'><input id='password' type='password'>"];
     [webView stringByEvaluatingJavaScript:@"user.focus()"];
 

Modified: branches/safari-606-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h (235791 => 235792)


--- branches/safari-606-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h	2018-09-07 19:50:41 UTC (rev 235791)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h	2018-09-07 20:07:39 UTC (rev 235792)
@@ -30,6 +30,7 @@
 #if USE(APPLE_INTERNAL_SDK)
 
 #import <UIKit/UIApplication_Private.h>
+#import <UIKit/UIResponder_Private.h>
 #import <UIKit/UITextInputTraits_Private.h>
 #import <UIKit/UITextInput_Private.h>
 #import <UIKit/UIViewController_Private.h>
@@ -62,8 +63,11 @@
 @property (nonatomic, readonly) UIColor *insertionPointColor;
 @end
 
+@class WebEvent;
+
 @protocol UITextInputPrivate <UITextInput, UITextInputTraits_Private>
 - (void)insertTextSuggestion:(UITextSuggestion *)textSuggestion;
+- (void)handleKeyWebEvent:(WebEvent *)theEvent withCompletionHandler:(void (^)(WebEvent *, BOOL))completionHandler;
 @end
 
 #endif
@@ -100,4 +104,8 @@
 + (UIViewController *)_viewControllerForFullScreenPresentationFromView:(UIView *)view;
 @end
 
+@interface UIResponder (UIKitSPI)
+- (UIResponder *)firstResponder;
+@end
+
 #endif // PLATFORM(IOS)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to