@@ -66,16 +66,14 @@ - (AutoFillInputView *)_autofillInputView
6666 return (AutoFillInputView *)self.textInputContentView ;
6767}
6868
69- - (BOOL )acceptsAutoFillLoginCredentials
69+ - (BOOL )textInputHasAutoFillContext
7070{
71- auto context = self._autofillInputView ._autofillContext ;
72- if (!context )
71+ NSURL *url = [ self ._autofillInputView._autofillContext objectForKey: @" _WebViewURL " ] ;
72+ if (![url isKindOfClass: [ NSURL class ]] )
7373 return NO ;
7474
75- NSURL *url = context[@" _WebViewURL" ];
76- EXPECT_TRUE ([url isKindOfClass: NSURL .class ]);
7775 EXPECT_WK_STREQ ([self stringByEvaluatingJavaScript: @" document.URL" ], url.absoluteString );
78- return [context[ @" _acceptsLoginCredentials " ] boolValue ] ;
76+ return YES ;
7977}
8078
8179@end
@@ -87,29 +85,29 @@ - (BOOL)acceptsAutoFillLoginCredentials
8785 auto webView = adoptNS ([[AutoFillTestView alloc ] initWithFrame: CGRectMake (0 , 0 , 320 , 500 )]);
8886 [webView synchronouslyLoadHTMLString: @" <input id='user' type='email'><input id='password' type='password'>" ];
8987 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" user.focus()" ];
90- EXPECT_TRUE ([webView acceptsAutoFillLoginCredentials ]);
88+ EXPECT_TRUE ([webView textInputHasAutoFillContext ]);
9189
9290 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" password.focus()" ];
93- EXPECT_TRUE ([webView acceptsAutoFillLoginCredentials ]);
91+ EXPECT_TRUE ([webView textInputHasAutoFillContext ]);
9492
9593 auto credentialSuggestion = [UITextAutofillSuggestion autofillSuggestionWithUsername: @" frederik" password: @" famos" ];
9694 [[webView _autofillInputView ] insertTextSuggestion: credentialSuggestion];
9795
9896 EXPECT_WK_STREQ (" famos" , [webView stringByEvaluatingJavaScript: @" password.value" ]);
9997
10098 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" document.activeElement.blur()" ];
101- EXPECT_FALSE ([webView acceptsAutoFillLoginCredentials ]);
99+ EXPECT_FALSE ([webView textInputHasAutoFillContext ]);
102100}
103101
104102TEST (WKWebViewAutoFillTests, UsernameAndPasswordFieldSeparatedByRadioButton)
105103{
106104 auto webView = adoptNS ([[AutoFillTestView alloc ] initWithFrame: CGRectMake (0 , 0 , 320 , 500 )]);
107105 [webView synchronouslyLoadHTMLString: @" <input id='user' type='email'><input type='radio' name='radio_button' value='radio'><input id='password' type='password'>" ];
108106 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" user.focus()" ];
109- EXPECT_TRUE ([webView acceptsAutoFillLoginCredentials ]);
107+ EXPECT_TRUE ([webView textInputHasAutoFillContext ]);
110108
111109 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" password.focus()" ];
112- EXPECT_TRUE ([webView acceptsAutoFillLoginCredentials ]);
110+ EXPECT_TRUE ([webView textInputHasAutoFillContext ]);
113111
114112 auto credentialSuggestion = [UITextAutofillSuggestion autofillSuggestionWithUsername: @" frederik" password: @" famos" ];
115113 [[webView _autofillInputView ] insertTextSuggestion: credentialSuggestion];
@@ -118,56 +116,56 @@ - (BOOL)acceptsAutoFillLoginCredentials
118116 EXPECT_WK_STREQ (" famos" , [webView stringByEvaluatingJavaScript: @" password.value" ]);
119117
120118 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" document.activeElement.blur()" ];
121- EXPECT_FALSE ([webView acceptsAutoFillLoginCredentials ]);
119+ EXPECT_FALSE ([webView textInputHasAutoFillContext ]);
122120}
123121
124122TEST (WKWebViewAutoFillTests, TwoTextFields)
125123{
126124 auto webView = adoptNS ([[AutoFillTestView alloc ] initWithFrame: CGRectMake (0 , 0 , 320 , 500 )]);
127125 [webView synchronouslyLoadHTMLString: @" <input id='text1' type='email'><input id='text2' type='text'>" ];
128126 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" text1.focus()" ];
129- EXPECT_FALSE ([webView acceptsAutoFillLoginCredentials ]);
127+ EXPECT_FALSE ([webView textInputHasAutoFillContext ]);
130128
131129 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" text2.focus()" ];
132- EXPECT_FALSE ([webView acceptsAutoFillLoginCredentials ]);
130+ EXPECT_FALSE ([webView textInputHasAutoFillContext ]);
133131}
134132
135133TEST (WKWebViewAutoFillTests, StandalonePasswordField)
136134{
137135 auto webView = adoptNS ([[AutoFillTestView alloc ] initWithFrame: CGRectMake (0 , 0 , 320 , 500 )]);
138136 [webView synchronouslyLoadHTMLString: @" <input id='password' type='password'>" ];
139137 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" password.focus()" ];
140- EXPECT_TRUE ([webView acceptsAutoFillLoginCredentials ]);
138+ EXPECT_TRUE ([webView textInputHasAutoFillContext ]);
141139
142140 auto credentialSuggestion = [UITextAutofillSuggestion autofillSuggestionWithUsername: @" frederik" password: @" famos" ];
143141 [[webView _autofillInputView ] insertTextSuggestion: credentialSuggestion];
144142
145143 EXPECT_WK_STREQ (" famos" , [webView stringByEvaluatingJavaScript: @" password.value" ]);
146144
147145 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" document.activeElement.blur()" ];
148- EXPECT_FALSE ([webView acceptsAutoFillLoginCredentials ]);
146+ EXPECT_FALSE ([webView textInputHasAutoFillContext ]);
149147}
150148
151149TEST (WKWebViewAutoFillTests, StandaloneTextField)
152150{
153151 auto webView = adoptNS ([[AutoFillTestView alloc ] initWithFrame: CGRectMake (0 , 0 , 320 , 500 )]);
154152 [webView synchronouslyLoadHTMLString: @" <input id='textfield' type='text'>" ];
155153 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" textfield.focus()" ];
156- EXPECT_FALSE ([webView acceptsAutoFillLoginCredentials ]);
154+ EXPECT_FALSE ([webView textInputHasAutoFillContext ]);
157155}
158156
159157TEST (WKWebViewAutoFillTests, AccountCreationPage)
160158{
161159 auto webView = adoptNS ([[AutoFillTestView alloc ] initWithFrame: CGRectMake (0 , 0 , 320 , 500 )]);
162160 [webView synchronouslyLoadHTMLString: @" <input id='user' type='email'><input id='password' type='password'><input id='confirm_password' type='password'>" ];
163161 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" user.focus()" ];
164- EXPECT_TRUE ([webView acceptsAutoFillLoginCredentials ]);
162+ EXPECT_TRUE ([webView textInputHasAutoFillContext ]);
165163
166164 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" password.focus()" ];
167- EXPECT_TRUE ([webView acceptsAutoFillLoginCredentials ]);
165+ EXPECT_TRUE ([webView textInputHasAutoFillContext ]);
168166
169167 [webView evaluateJavaScriptAndWaitForInputSessionToChange: @" confirm_password.focus()" ];
170- EXPECT_TRUE ([webView acceptsAutoFillLoginCredentials ]);
168+ EXPECT_TRUE ([webView textInputHasAutoFillContext ]);
171169}
172170
173171static BOOL overrideIsInHardwareKeyboardMode ()
@@ -189,7 +187,7 @@ static BOOL overrideIsInHardwareKeyboardMode()
189187 [webView stringByEvaluatingJavaScript: @" user.focus()" ];
190188 Util::run (&done);
191189
192- EXPECT_FALSE ([webView acceptsAutoFillLoginCredentials ]);
190+ EXPECT_FALSE ([webView textInputHasAutoFillContext ]);
193191}
194192
195193#if PLATFORM(WATCHOS)
0 commit comments