OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "app/keyboard_codes.h" | 5 #include "app/keyboard_codes.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/renderer/password_autocomplete_manager.h" | 8 #include "chrome/renderer/password_autocomplete_manager.h" |
9 #include "chrome/test/render_view_test.h" | 9 #include "chrome/test/render_view_test.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 string16 password2_; | 145 string16 password2_; |
146 PasswordFormFillData fill_data_; | 146 PasswordFormFillData fill_data_; |
147 | 147 |
148 WebInputElement username_element_; | 148 WebInputElement username_element_; |
149 WebInputElement password_element_; | 149 WebInputElement password_element_; |
150 | 150 |
151 private: | 151 private: |
152 DISALLOW_COPY_AND_ASSIGN(PasswordAutocompleteManagerTest); | 152 DISALLOW_COPY_AND_ASSIGN(PasswordAutocompleteManagerTest); |
153 }; | 153 }; |
154 | 154 |
155 #if defined(WEBKIT_BUG_41283_IS_FIXED) | |
156 #define MAYBE_InitialAutocomplete InitialAutocomplete | |
157 #define MAYBE_NoInitialAutocompleteForReadOnly NoInitialAutocompleteForReadOnly | |
158 #define MAYBE_PasswordClearOnEdit PasswordClearOnEdit | |
159 #define MAYBE_WaitUsername WaitUsername | |
160 #define MAYBE_InlineAutocomplete InlineAutocomplete | |
161 #define MAYBE_SuggestionSelect SuggestionSelect | |
162 #else | |
163 #define MAYBE_InitialAutocomplete DISABLED_InitialAutocomplete | |
164 #define MAYBE_NoInitialAutocompleteForReadOnly \ | |
165 DISABLED_NoInitialAutocompleteForReadOnly | |
166 #define MAYBE_PasswordClearOnEdit DISABLED_PasswordClearOnEdit | |
167 #define MAYBE_WaitUsername DISABLED_WaitUsername | |
168 #define MAYBE_InlineAutocomplete DISABLED_InlineAutocomplete | |
169 #define MAYBE_SuggestionSelect DISABLED_SuggestionSelect | |
170 #endif | |
171 | |
172 // Tests that the password login is autocompleted as expected when the browser | 155 // Tests that the password login is autocompleted as expected when the browser |
173 // sends back the password info. | 156 // sends back the password info. |
174 TEST_F(PasswordAutocompleteManagerTest, MAYBE_InitialAutocomplete) { | 157 TEST_F(PasswordAutocompleteManagerTest, InitialAutocomplete) { |
175 /* | 158 /* |
176 * Right now we are not sending the message to the browser because we are | 159 * Right now we are not sending the message to the browser because we are |
177 * loading a data URL and the security origin canAccessPasswordManager() | 160 * loading a data URL and the security origin canAccessPasswordManager() |
178 * returns false. May be we should mock URL loading to cirmcuvent this? | 161 * returns false. May be we should mock URL loading to cirmcuvent this? |
179 TODO(jcivelli): find a way to make the security origin not deny access to the | 162 TODO(jcivelli): find a way to make the security origin not deny access to the |
180 password manager and then reenable this code. | 163 password manager and then reenable this code. |
181 | 164 |
182 // The form has been loaded, we should have sent the browser a message about | 165 // The form has been loaded, we should have sent the browser a message about |
183 // the form. | 166 // the form. |
184 const IPC::Message* msg = render_thread_.sink().GetFirstMessageMatching( | 167 const IPC::Message* msg = render_thread_.sink().GetFirstMessageMatching( |
(...skipping 11 matching lines...) Expand all Loading... |
196 | 179 |
197 // Simulate the browser sending back the login info, it triggers the | 180 // Simulate the browser sending back the login info, it triggers the |
198 // autocomplete. | 181 // autocomplete. |
199 SimulateOnFillPasswordForm(fill_data_); | 182 SimulateOnFillPasswordForm(fill_data_); |
200 | 183 |
201 // The username and password should have been autocompleted. | 184 // The username and password should have been autocompleted. |
202 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 185 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
203 } | 186 } |
204 | 187 |
205 // Tests that changing the username does not fill a read-only password field. | 188 // Tests that changing the username does not fill a read-only password field. |
206 TEST_F(PasswordAutocompleteManagerTest, | 189 TEST_F(PasswordAutocompleteManagerTest, NoInitialAutocompleteForReadOnly) { |
207 MAYBE_NoInitialAutocompleteForReadOnly) { | |
208 password_element_.setAttribute(WebString::fromUTF8("readonly"), | 190 password_element_.setAttribute(WebString::fromUTF8("readonly"), |
209 WebString::fromUTF8("true")); | 191 WebString::fromUTF8("true")); |
210 | 192 |
211 // Simulate the browser sending back the login info, it triggers the | 193 // Simulate the browser sending back the login info, it triggers the |
212 // autocompleted. | 194 // autocompleted. |
213 SimulateOnFillPasswordForm(fill_data_); | 195 SimulateOnFillPasswordForm(fill_data_); |
214 | 196 |
215 // Only the username should have been autocompleted. | 197 // Only the username should have been autocompleted. |
216 // TODO(jcivelli): may be we should not event fill the username? | 198 // TODO(jcivelli): may be we should not event fill the username? |
217 CheckTextFieldsState(kAliceUsername, true, "", false); | 199 CheckTextFieldsState(kAliceUsername, true, "", false); |
218 } | 200 } |
219 | 201 |
220 // Tests that editing the password clears the autocompleted password field. | 202 // Tests that editing the password clears the autocompleted password field. |
221 TEST_F(PasswordAutocompleteManagerTest, MAYBE_PasswordClearOnEdit) { | 203 TEST_F(PasswordAutocompleteManagerTest, PasswordClearOnEdit) { |
222 // Simulate the browser sending back the login info, it triggers the | 204 // Simulate the browser sending back the login info, it triggers the |
223 // autocomplete. | 205 // autocomplete. |
224 SimulateOnFillPasswordForm(fill_data_); | 206 SimulateOnFillPasswordForm(fill_data_); |
225 | 207 |
226 // Simulate the user changing the username to some unknown username. | 208 // Simulate the user changing the username to some unknown username. |
227 SimulateUsernameChange("alicia", true); | 209 SimulateUsernameChange("alicia", true); |
228 | 210 |
229 // The password should have been cleared. | 211 // The password should have been cleared. |
230 CheckTextFieldsState("alicia", false, "", false); | 212 CheckTextFieldsState("alicia", false, "", false); |
231 } | 213 } |
232 | 214 |
233 // Tests that we only autocomplete on focus lost and with a full username match | 215 // Tests that we only autocomplete on focus lost and with a full username match |
234 // when |wait_for_username| is true. | 216 // when |wait_for_username| is true. |
235 TEST_F(PasswordAutocompleteManagerTest, MAYBE_WaitUsername) { | 217 TEST_F(PasswordAutocompleteManagerTest, WaitUsername) { |
236 // Simulate the browser sending back the login info. | 218 // Simulate the browser sending back the login info. |
237 fill_data_.wait_for_username = true; | 219 fill_data_.wait_for_username = true; |
238 SimulateOnFillPasswordForm(fill_data_); | 220 SimulateOnFillPasswordForm(fill_data_); |
239 | 221 |
240 // No auto-fill should have taken place. | 222 // No auto-fill should have taken place. |
241 CheckTextFieldsState("", false, "", false); | 223 CheckTextFieldsState("", false, "", false); |
242 | 224 |
243 // No autocomplete should happen when text is entered in the username. | 225 // No autocomplete should happen when text is entered in the username. |
244 SimulateUsernameChange("a", true); | 226 SimulateUsernameChange("a", true); |
245 CheckTextFieldsState("a", false, "", false); | 227 CheckTextFieldsState("a", false, "", false); |
(...skipping 12 matching lines...) Expand all Loading... |
258 CheckTextFieldsState("al", false, "", false); | 240 CheckTextFieldsState("al", false, "", false); |
259 username_element_.setValue("alices"); | 241 username_element_.setValue("alices"); |
260 view_->textFieldDidEndEditing(username_element_); | 242 view_->textFieldDidEndEditing(username_element_); |
261 CheckTextFieldsState("alices", false, "", false); | 243 CheckTextFieldsState("alices", false, "", false); |
262 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); | 244 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); |
263 view_->textFieldDidEndEditing(username_element_); | 245 view_->textFieldDidEndEditing(username_element_); |
264 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 246 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
265 } | 247 } |
266 | 248 |
267 // Tests that inline autocompletion works properly. | 249 // Tests that inline autocompletion works properly. |
268 TEST_F(PasswordAutocompleteManagerTest, MAYBE_InlineAutocomplete) { | 250 TEST_F(PasswordAutocompleteManagerTest, InlineAutocomplete) { |
269 // Simulate the browser sending back the login info. | 251 // Simulate the browser sending back the login info. |
270 SimulateOnFillPasswordForm(fill_data_); | 252 SimulateOnFillPasswordForm(fill_data_); |
271 | 253 |
272 // Clear the textfields to start fresh. | 254 // Clear the textfields to start fresh. |
273 ClearUsernameAndPasswordFields(); | 255 ClearUsernameAndPasswordFields(); |
274 | 256 |
275 // Simulate the user typing in the first letter of 'alice', a stored username. | 257 // Simulate the user typing in the first letter of 'alice', a stored username. |
276 SimulateUsernameChange("a", true); | 258 SimulateUsernameChange("a", true); |
277 // Both the username and password textfields should reflect selection of the | 259 // Both the username and password textfields should reflect selection of the |
278 // stored login. | 260 // stored login. |
(...skipping 25 matching lines...) Expand all Loading... |
304 CheckUsernameSelection(3, 3); // No selection. | 286 CheckUsernameSelection(3, 3); // No selection. |
305 | 287 |
306 // Ok, so now the user removes all the text and enters the letter 'b'. | 288 // Ok, so now the user removes all the text and enters the letter 'b'. |
307 SimulateUsernameChange("b", true); | 289 SimulateUsernameChange("b", true); |
308 // The username and password fields should match the 'bob' entry. | 290 // The username and password fields should match the 'bob' entry. |
309 CheckTextFieldsState(kBobUsername, true, kBobPassword, true); | 291 CheckTextFieldsState(kBobUsername, true, kBobPassword, true); |
310 CheckUsernameSelection(1, 3); | 292 CheckUsernameSelection(1, 3); |
311 } | 293 } |
312 | 294 |
313 // Tests that selecting and item in the suggestion drop-down works. | 295 // Tests that selecting and item in the suggestion drop-down works. |
314 TEST_F(PasswordAutocompleteManagerTest, MAYBE_SuggestionSelect) { | 296 TEST_F(PasswordAutocompleteManagerTest, SuggestionSelect) { |
315 // Simulate the browser sending back the login info. | 297 // Simulate the browser sending back the login info. |
316 SimulateOnFillPasswordForm(fill_data_); | 298 SimulateOnFillPasswordForm(fill_data_); |
317 | 299 |
318 // Clear the textfields to start fresh. | 300 // Clear the textfields to start fresh. |
319 ClearUsernameAndPasswordFields(); | 301 ClearUsernameAndPasswordFields(); |
320 | 302 |
321 // To simulate a selection in the suggestion drop-down we just mimick what the | 303 // To simulate a selection in the suggestion drop-down we just mimick what the |
322 // WebView does: it sets the element value then calls | 304 // WebView does: it sets the element value then calls |
323 // didAcceptAutocompleteSuggestion on the renderer. | 305 // didAcceptAutocompleteSuggestion on the renderer. |
324 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); | 306 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); |
325 view_->didAcceptAutocompleteSuggestion(username_element_); | 307 view_->didAcceptAutocompleteSuggestion(username_element_); |
326 | 308 |
327 // Autocomplete should have kicked in. | 309 // Autocomplete should have kicked in. |
328 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 310 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
329 } | 311 } |
330 | 312 |
331 } // namespace | 313 } // namespace |
OLD | NEW |