Title: [258457] trunk
Revision
258457
Author
wenson_hs...@apple.com
Date
2020-03-13 19:01:28 -0700 (Fri, 13 Mar 2020)

Log Message

[watchOS] Don’t display empty text suggestions in Quickboard when editing input fields
https://bugs.webkit.org/show_bug.cgi?id=209089

Reviewed by Tim Horton.

Source/WebKit:

Handle text suggestions that lack `displayText` gracefully in Quickboard by not showing them as AutoFill
candidates. Currently, they are presented as blank collection view cells in Quickboard, which leads to a
confusing user experience.

Test: WKWebViewAutoFillTests.DoNotShowBlankTextSuggestions

* UIProcess/ios/forms/WKFocusedFormControlView.mm:
(-[WKFocusedFormControlView setSuggestions:]):

Tools:

Add an API test for watchOS. Also rename a few occurrences of "Autofill" to "AutoFill", to reflect the official
marketing name for the feature.

* TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
(runUntilReceivesAutoplayEvent):

Additionally fix the watchOS engineering build for arm64_32, which was failing due to comparisons between 64-bit
and 32-bit integers. This is because this function took a `WKAutoplayEvent` (a 32-bit integer), but compared
against the `_WKAutoplayEvent` type (an NSInteger that is 64 bits on this architecture). There didn't seem to
be any compelling reason to compare against different types here (especially since we only set
`receivedAutoplayEvent` under the Objective-C delegate method that provides a `_WKAutoplayEvent`), so I changed
these all to be `_WKAutoplayEvent`.

* TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm:
(-[AutoFillTestView _autofillInputView]):
(-[AutoFillTestView textInputHasAutoFillContext]):
(TestWebKitAPI::TEST):
(-[AutofillTestView initWithFrame:]): Deleted.
(-[AutofillTestView _autofillInputView]): Deleted.
(-[AutofillTestView textInputHasAutofillContext]): Deleted.
* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (258456 => 258457)


--- trunk/Source/WebKit/ChangeLog	2020-03-14 01:43:54 UTC (rev 258456)
+++ trunk/Source/WebKit/ChangeLog	2020-03-14 02:01:28 UTC (rev 258457)
@@ -1,3 +1,19 @@
+2020-03-13  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [watchOS] Don’t display empty text suggestions in Quickboard when editing input fields
+        https://bugs.webkit.org/show_bug.cgi?id=209089
+
+        Reviewed by Tim Horton.
+
+        Handle text suggestions that lack `displayText` gracefully in Quickboard by not showing them as AutoFill
+        candidates. Currently, they are presented as blank collection view cells in Quickboard, which leads to a
+        confusing user experience.
+
+        Test: WKWebViewAutoFillTests.DoNotShowBlankTextSuggestions
+
+        * UIProcess/ios/forms/WKFocusedFormControlView.mm:
+        (-[WKFocusedFormControlView setSuggestions:]):
+
 2020-03-13  Brent Fulgham  <bfulg...@apple.com>
 
         Clean up sandbox violations found during testing

Modified: trunk/Source/WebKit/UIProcess/ios/forms/WKFocusedFormControlView.mm (258456 => 258457)


--- trunk/Source/WebKit/UIProcess/ios/forms/WKFocusedFormControlView.mm	2020-03-14 01:43:54 UTC (rev 258456)
+++ trunk/Source/WebKit/UIProcess/ios/forms/WKFocusedFormControlView.mm	2020-03-14 02:01:28 UTC (rev 258457)
@@ -462,10 +462,21 @@
 
 - (void)setSuggestions:(NSArray<UITextSuggestion *> *)suggestions
 {
-    if (_textSuggestions == suggestions || [_textSuggestions isEqualToArray:suggestions])
+    RetainPtr<NSMutableArray> displayableTextSuggestions;
+    if (suggestions) {
+        displayableTextSuggestions = adoptNS([[NSMutableArray alloc] initWithCapacity:suggestions.count]);
+        for (UITextSuggestion *suggestion in suggestions) {
+            if (!suggestion.displayText.length)
+                continue;
+
+            [displayableTextSuggestions addObject:suggestion];
+        }
+    }
+
+    if (_textSuggestions == displayableTextSuggestions.get() || [_textSuggestions isEqualToArray:displayableTextSuggestions.get()])
         return;
 
-    _textSuggestions = adoptNS(suggestions.copy);
+    _textSuggestions = WTFMove(displayableTextSuggestions);
     [_delegate focusedFormControllerDidUpdateSuggestions:self];
 }
 

Modified: trunk/Tools/ChangeLog (258456 => 258457)


--- trunk/Tools/ChangeLog	2020-03-14 01:43:54 UTC (rev 258456)
+++ trunk/Tools/ChangeLog	2020-03-14 02:01:28 UTC (rev 258457)
@@ -1,3 +1,32 @@
+2020-03-13  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [watchOS] Don’t display empty text suggestions in Quickboard when editing input fields
+        https://bugs.webkit.org/show_bug.cgi?id=209089
+
+        Reviewed by Tim Horton.
+
+        Add an API test for watchOS. Also rename a few occurrences of "Autofill" to "AutoFill", to reflect the official
+        marketing name for the feature.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
+        (runUntilReceivesAutoplayEvent):
+
+        Additionally fix the watchOS engineering build for arm64_32, which was failing due to comparisons between 64-bit
+        and 32-bit integers. This is because this function took a `WKAutoplayEvent` (a 32-bit integer), but compared
+        against the `_WKAutoplayEvent` type (an NSInteger that is 64 bits on this architecture). There didn't seem to
+        be any compelling reason to compare against different types here (especially since we only set
+        `receivedAutoplayEvent` under the Objective-C delegate method that provides a `_WKAutoplayEvent`), so I changed
+        these all to be `_WKAutoplayEvent`.
+
+        * TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm:
+        (-[AutoFillTestView _autofillInputView]):
+        (-[AutoFillTestView textInputHasAutoFillContext]):
+        (TestWebKitAPI::TEST):
+        (-[AutofillTestView initWithFrame:]): Deleted.
+        (-[AutofillTestView _autofillInputView]): Deleted.
+        (-[AutofillTestView textInputHasAutofillContext]): Deleted.
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2020-03-13  Chris Dumez  <cdu...@apple.com>
 
         Unreviewed, reverting r256232.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm (258456 => 258457)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm	2020-03-14 01:43:54 UTC (rev 258456)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm	2020-03-14 02:01:28 UTC (rev 258457)
@@ -349,7 +349,7 @@
     [webView waitForMessage:@"did-not-play"];
 }
 
-static void runUntilReceivesAutoplayEvent(WKAutoplayEvent event)
+static void runUntilReceivesAutoplayEvent(_WKAutoplayEvent event)
 {
     while (!receivedAutoplayEvent || *receivedAutoplayEvent != event)
         CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
@@ -374,13 +374,13 @@
     NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"js-play-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:jsPlayRequest];
     [webView waitForMessage:@"loaded"];
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidPreventFromAutoplaying);
 
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaWithUserGesture);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsPlaybackWasPrevented);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidPlayMediaWithUserGesture);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsPlaybackWasPrevented);
 
     receivedAutoplayEvent = WTF::nullopt;
     [webView loadHTMLString:@"" baseURL:nil];
@@ -388,14 +388,14 @@
     NSURLRequest *autoplayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:autoplayRequest];
     [webView waitForMessage:@"loaded"];
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidPreventFromAutoplaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
 
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaWithUserGesture);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsPlaybackWasPrevented);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidPlayMediaWithUserGesture);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsPlaybackWasPrevented);
 
     receivedAutoplayEvent = WTF::nullopt;
     [webView loadHTMLString:@"" baseURL:nil];
@@ -418,13 +418,13 @@
     NSURLRequest *autoplayMutedRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-muted-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:autoplayMutedRequest];
     [webView waitForMessage:@"loaded"];
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidPreventFromAutoplaying);
 
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaWithUserGesture);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsPlaybackWasPrevented);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidPlayMediaWithUserGesture);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsPlaybackWasPrevented);
 }
 #endif
 
@@ -462,9 +462,9 @@
     [webView clickOnElementID:@"playButton"];
 #endif
 
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaWithUserGesture);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
-    ASSERT_FALSE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsMediaIsMainContent);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidPlayMediaWithUserGesture);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
+    ASSERT_FALSE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsMediaIsMainContent);
 
     receivedAutoplayEvent = WTF::nullopt;
 
@@ -479,9 +479,9 @@
     [webView clickOnElementID:@"playButton"];
 #endif
 
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaWithUserGesture);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsMediaIsMainContent);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidPlayMediaWithUserGesture);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsMediaIsMainContent);
 }
 
 TEST(WebpagePreferences, WebsitePoliciesPlayingWithoutInterference)
@@ -504,8 +504,8 @@
     receivedAutoplayEvent = WTF::nullopt;
     NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"js-autoplay-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:jsPlayRequest];
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
 }
 
 TEST(WebpagePreferences, WebsitePoliciesUserInterferenceWithPlaying)
@@ -531,9 +531,9 @@
     [webView waitForMessage:@"playing"];
     ASSERT_TRUE(receivedAutoplayEvent == WTF::nullopt);
 
-    WKPageSetMuted([webView _pageForTesting], kWKMediaAudioMuted);
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
+    WKPageSetMuted([webView _pageForTesting], _WKMediaAudioMuted);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventUserDidInterfereWithPlayback);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = WTF::nullopt;
     [webView loadRequest:jsPlayRequest];
@@ -548,8 +548,8 @@
     [webView clickOnElementID:@"muteButton"];
 #endif
 
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventUserDidInterfereWithPlayback);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = WTF::nullopt;
     [webView loadRequest:jsPlayRequest];
@@ -564,8 +564,8 @@
     [webView clickOnElementID:@"playButton"];
 #endif
 
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
-    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventUserDidInterfereWithPlayback);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & _WKAutoplayEventFlagsHasAudio);
 }
 
 #if PLATFORM(MAC)
@@ -787,7 +787,7 @@
     // A script should no longer be able to autoplay media.
     receivedAutoplayEvent = WTF::nullopt;
     [webView stringByEvaluatingJavaScript:@"playVideo()"];
-    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+    runUntilReceivesAutoplayEvent(_WKAutoplayEventDidPreventFromAutoplaying);
 }
 
 #if PLATFORM(MAC)

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm (258456 => 258457)


--- trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm	2020-03-14 01:43:54 UTC (rev 258456)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm	2020-03-14 02:01:28 UTC (rev 258457)
@@ -35,12 +35,16 @@
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/BlockPtr.h>
 
-typedef UIView <UITextInputPrivate> AutofillInputView;
+@protocol WKTextInputSuggestionDelegate <UITextInputSuggestionDelegate>
+- (NSArray<UITextSuggestion *> *)suggestions;
+@end
 
-@interface AutofillTestView : TestWKWebView
+typedef UIView <UITextInputPrivate> AutoFillInputView;
+
+@interface AutoFillTestView : TestWKWebView
 @end
 
-@implementation AutofillTestView {
+@implementation AutoFillTestView {
     RetainPtr<TestInputDelegate> _testDelegate;
 }
 
@@ -57,12 +61,12 @@
     return self;
 }
 
-- (AutofillInputView *)_autofillInputView
+- (AutoFillInputView *)_autofillInputView
 {
-    return (AutofillInputView *)self.textInputContentView;
+    return (AutoFillInputView *)self.textInputContentView;
 }
 
-- (BOOL)textInputHasAutofillContext
+- (BOOL)textInputHasAutoFillContext
 {
     NSURL *url = "" objectForKey:@"_WebViewURL"];
     if (![url isKindOfClass:[NSURL class]])
@@ -76,15 +80,15 @@
 
 namespace TestWebKitAPI {
 
-TEST(WKWebViewAutofillTests, UsernameAndPasswordField)
+TEST(WKWebViewAutoFillTests, UsernameAndPasswordField)
 {
-    auto webView = adoptNS([[AutofillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto webView = adoptNS([[AutoFillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [webView synchronouslyLoadHTMLString:@"<input id='user' type='email'><input id='password' type='password'>"];
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"user.focus()"];
-    EXPECT_TRUE([webView textInputHasAutofillContext]);
+    EXPECT_TRUE([webView textInputHasAutoFillContext]);
 
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"password.focus()"];
-    EXPECT_TRUE([webView textInputHasAutofillContext]);
+    EXPECT_TRUE([webView textInputHasAutoFillContext]);
 
     auto credentialSuggestion = [UITextAutofillSuggestion autofillSuggestionWithUsername:@"frederik" password:@"famos"];
     [[webView _autofillInputView] insertTextSuggestion:credentialSuggestion];
@@ -92,18 +96,18 @@
     EXPECT_WK_STREQ("famos", [webView stringByEvaluatingJavaScript:@"password.value"]);
 
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.activeElement.blur()"];
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 }
 
-TEST(WKWebViewAutofillTests, UsernameAndPasswordFieldSeparatedByRadioButton)
+TEST(WKWebViewAutoFillTests, UsernameAndPasswordFieldSeparatedByRadioButton)
 {
-    auto webView = adoptNS([[AutofillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto webView = adoptNS([[AutoFillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [webView synchronouslyLoadHTMLString:@"<input id='user' type='email'><input type='radio' name='radio_button' value='radio'><input id='password' type='password'>"];
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"user.focus()"];
-    EXPECT_TRUE([webView textInputHasAutofillContext]);
+    EXPECT_TRUE([webView textInputHasAutoFillContext]);
 
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"password.focus()"];
-    EXPECT_TRUE([webView textInputHasAutofillContext]);
+    EXPECT_TRUE([webView textInputHasAutoFillContext]);
 
     auto credentialSuggestion = [UITextAutofillSuggestion autofillSuggestionWithUsername:@"frederik" password:@"famos"];
     [[webView _autofillInputView] insertTextSuggestion:credentialSuggestion];
@@ -112,26 +116,26 @@
     EXPECT_WK_STREQ("famos", [webView stringByEvaluatingJavaScript:@"password.value"]);
 
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.activeElement.blur()"];
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 }
 
-TEST(WKWebViewAutofillTests, TwoTextFields)
+TEST(WKWebViewAutoFillTests, TwoTextFields)
 {
-    auto webView = adoptNS([[AutofillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto webView = adoptNS([[AutoFillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [webView synchronouslyLoadHTMLString:@"<input id='text1' type='email'><input id='text2' type='text'>"];
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"text1.focus()"];
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"text2.focus()"];
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 }
 
-TEST(WKWebViewAutofillTests, StandalonePasswordField)
+TEST(WKWebViewAutoFillTests, StandalonePasswordField)
 {
-    auto webView = adoptNS([[AutofillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto webView = adoptNS([[AutoFillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [webView synchronouslyLoadHTMLString:@"<input id='password' type='password'>"];
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"password.focus()"];
-    EXPECT_TRUE([webView textInputHasAutofillContext]);
+    EXPECT_TRUE([webView textInputHasAutoFillContext]);
 
     auto credentialSuggestion = [UITextAutofillSuggestion autofillSuggestionWithUsername:@"frederik" password:@"famos"];
     [[webView _autofillInputView] insertTextSuggestion:credentialSuggestion];
@@ -139,29 +143,29 @@
     EXPECT_WK_STREQ("famos", [webView stringByEvaluatingJavaScript:@"password.value"]);
 
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.activeElement.blur()"];
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 }
 
-TEST(WKWebViewAutofillTests, StandaloneTextField)
+TEST(WKWebViewAutoFillTests, StandaloneTextField)
 {
-    auto webView = adoptNS([[AutofillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto webView = adoptNS([[AutoFillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [webView synchronouslyLoadHTMLString:@"<input id='textfield' type='text'>"];
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"textfield.focus()"];
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 }
 
-TEST(WKWebViewAutofillTests, AccountCreationPage)
+TEST(WKWebViewAutoFillTests, AccountCreationPage)
 {
-    auto webView = adoptNS([[AutofillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto webView = adoptNS([[AutoFillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [webView synchronouslyLoadHTMLString:@"<input id='user' type='email'><input id='password' type='password'><input id='confirm_password' type='password'>"];
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"user.focus()"];
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"password.focus()"];
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 
     [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"confirm_password.focus()"];
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 }
 
 static BOOL overrideIsInHardwareKeyboardMode()
@@ -169,12 +173,12 @@
     return NO;
 }
 
-TEST(WKWebViewAutofillTests, AutofillRequiresInputSession)
+TEST(WKWebViewAutoFillTests, AutoFillRequiresInputSession)
 {
     ClassMethodSwizzler swizzler([UIKeyboard class], @selector(isInHardwareKeyboardMode), reinterpret_cast<IMP>(overrideIsInHardwareKeyboardMode));
 
     bool done = false;
-    auto webView = adoptNS([[AutofillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto webView = adoptNS([[AutoFillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [(TestInputDelegate *)[webView _inputDelegate] setFocusStartsInputSessionPolicyHandler:[&done] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
         done = true;
         return _WKFocusStartsInputSessionPolicyAuto;
@@ -183,9 +187,28 @@
     [webView stringByEvaluatingJavaScript:@"user.focus()"];
     Util::run(&done);
 
-    EXPECT_FALSE([webView textInputHasAutofillContext]);
+    EXPECT_FALSE([webView textInputHasAutoFillContext]);
 }
 
+#if PLATFORM(WATCHOS)
+
+TEST(WKWebViewAutoFillTests, DoNotShowBlankTextSuggestions)
+{
+    auto webView = adoptNS([[AutoFillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [(TestInputDelegate *)[webView _inputDelegate] setWillStartInputSessionHandler:[](WKWebView *, id <_WKFormInputSession> session) {
+        auto emptySuggestion = adoptNS([[UITextSuggestion alloc] init]);
+        [emptySuggestion setDisplayText:@""];
+        session.suggestions = @[ emptySuggestion.get() ];
+    }];
+    [webView synchronouslyLoadHTMLString:@"<input id='user' type='email'><input id='password' type='password'>"];
+    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"user.focus()"];
+
+    NSArray *suggestions = [(id <WKTextInputSuggestionDelegate>)[[webView textInputContentView] inputDelegate] suggestions];
+    EXPECT_EQ(0U, suggestions.count);
+}
+
+#endif
+
 } // namespace TestWebKitAPI
 
 #endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (258456 => 258457)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-03-14 01:43:54 UTC (rev 258456)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-03-14 02:01:28 UTC (rev 258457)
@@ -67,7 +67,7 @@
 WTF_EXTERN_C_END
 
 @interface UITextSuggestion : NSObject
-
+@property (nonatomic, copy) NSString *displayText;
 @end
 
 @interface UITextInputTraits : NSObject <UITextInputTraits>
@@ -210,6 +210,10 @@
 + (instancetype)sharedInstance;
 @end
 
+@protocol UITextInputSuggestionDelegate <UITextInputDelegate>
+- (void)setSuggestions:(NSArray <UITextSuggestion*> *)suggestions;
+@end
+
 #endif // USE(APPLE_INTERNAL_SDK)
 
 #define UIWKDocumentRequestMarkedTextRects (1 << 5)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to