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)