OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" |
8 #include "components/autofill/common/autofill_messages.h" | 8 #include "components/autofill/common/autofill_messages.h" |
9 #include "components/autofill/common/form_data.h" | 9 #include "components/autofill/common/form_data.h" |
10 #include "components/autofill/common/form_field_data.h" | 10 #include "components/autofill/common/form_field_data.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForReadOnly) { | 244 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForReadOnly) { |
245 password_element_.setAttribute(WebString::fromUTF8("readonly"), | 245 password_element_.setAttribute(WebString::fromUTF8("readonly"), |
246 WebString::fromUTF8("true")); | 246 WebString::fromUTF8("true")); |
247 | 247 |
248 // Simulate the browser sending back the login info, it triggers the | 248 // Simulate the browser sending back the login info, it triggers the |
249 // autocomplete. | 249 // autocomplete. |
250 SimulateOnFillPasswordForm(fill_data_); | 250 SimulateOnFillPasswordForm(fill_data_); |
251 | 251 |
252 // Only the username should have been autocompleted. | 252 // Only the username should have been autocompleted. |
253 // TODO(jcivelli): may be we should not event fill the username? | 253 // TODO(jcivelli): may be we should not event fill the username? |
254 CheckTextFieldsState(kAliceUsername, true, "", false); | 254 CheckTextFieldsState(kAliceUsername, true, std::string(), false); |
255 } | 255 } |
256 | 256 |
257 // Tests that having a non-matching username precludes the autocomplete. | 257 // Tests that having a non-matching username precludes the autocomplete. |
258 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForFilledField) { | 258 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForFilledField) { |
259 username_element_.setValue(WebString::fromUTF8("bogus")); | 259 username_element_.setValue(WebString::fromUTF8("bogus")); |
260 | 260 |
261 // Simulate the browser sending back the login info, it triggers the | 261 // Simulate the browser sending back the login info, it triggers the |
262 // autocomplete. | 262 // autocomplete. |
263 SimulateOnFillPasswordForm(fill_data_); | 263 SimulateOnFillPasswordForm(fill_data_); |
264 | 264 |
265 // Neither field should be autocompleted. | 265 // Neither field should be autocompleted. |
266 CheckTextFieldsState("bogus", false, "", false); | 266 CheckTextFieldsState("bogus", false, std::string(), false); |
267 } | 267 } |
268 | 268 |
269 // Tests that having a matching username does not preclude the autocomplete. | 269 // Tests that having a matching username does not preclude the autocomplete. |
270 TEST_F(PasswordAutofillAgentTest, InitialAutocompleteForMatchingFilledField) { | 270 TEST_F(PasswordAutofillAgentTest, InitialAutocompleteForMatchingFilledField) { |
271 username_element_.setValue(WebString::fromUTF8(kAliceUsername)); | 271 username_element_.setValue(WebString::fromUTF8(kAliceUsername)); |
272 | 272 |
273 // Simulate the browser sending back the login info, it triggers the | 273 // Simulate the browser sending back the login info, it triggers the |
274 // autocomplete. | 274 // autocomplete. |
275 SimulateOnFillPasswordForm(fill_data_); | 275 SimulateOnFillPasswordForm(fill_data_); |
276 | 276 |
277 // The username and password should have been autocompleted. | 277 // The username and password should have been autocompleted. |
278 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 278 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
279 } | 279 } |
280 | 280 |
281 // Tests that editing the password clears the autocompleted password field. | 281 // Tests that editing the password clears the autocompleted password field. |
282 TEST_F(PasswordAutofillAgentTest, PasswordClearOnEdit) { | 282 TEST_F(PasswordAutofillAgentTest, PasswordClearOnEdit) { |
283 // Simulate the browser sending back the login info, it triggers the | 283 // Simulate the browser sending back the login info, it triggers the |
284 // autocomplete. | 284 // autocomplete. |
285 SimulateOnFillPasswordForm(fill_data_); | 285 SimulateOnFillPasswordForm(fill_data_); |
286 | 286 |
287 // Simulate the user changing the username to some unknown username. | 287 // Simulate the user changing the username to some unknown username. |
288 SimulateUsernameChange("alicia", true); | 288 SimulateUsernameChange("alicia", true); |
289 | 289 |
290 // The password should have been cleared. | 290 // The password should have been cleared. |
291 CheckTextFieldsState("alicia", false, "", false); | 291 CheckTextFieldsState("alicia", false, std::string(), false); |
292 } | 292 } |
293 | 293 |
294 // Tests that we only autocomplete on focus lost and with a full username match | 294 // Tests that we only autocomplete on focus lost and with a full username match |
295 // when |wait_for_username| is true. | 295 // when |wait_for_username| is true. |
296 TEST_F(PasswordAutofillAgentTest, WaitUsername) { | 296 TEST_F(PasswordAutofillAgentTest, WaitUsername) { |
297 // Simulate the browser sending back the login info. | 297 // Simulate the browser sending back the login info. |
298 fill_data_.wait_for_username = true; | 298 fill_data_.wait_for_username = true; |
299 SimulateOnFillPasswordForm(fill_data_); | 299 SimulateOnFillPasswordForm(fill_data_); |
300 | 300 |
301 // No auto-fill should have taken place. | 301 // No auto-fill should have taken place. |
302 CheckTextFieldsState("", false, "", false); | 302 CheckTextFieldsState(std::string(), false, std::string(), false); |
303 | 303 |
304 // No autocomplete should happen when text is entered in the username. | 304 // No autocomplete should happen when text is entered in the username. |
305 SimulateUsernameChange("a", true); | 305 SimulateUsernameChange("a", true); |
306 CheckTextFieldsState("a", false, "", false); | 306 CheckTextFieldsState("a", false, std::string(), false); |
307 SimulateUsernameChange("al", true); | 307 SimulateUsernameChange("al", true); |
308 CheckTextFieldsState("al", false, "", false); | 308 CheckTextFieldsState("al", false, std::string(), false); |
309 SimulateUsernameChange(kAliceUsername, true); | 309 SimulateUsernameChange(kAliceUsername, true); |
310 CheckTextFieldsState(kAliceUsername, false, "", false); | 310 CheckTextFieldsState(kAliceUsername, false, std::string(), false); |
311 | 311 |
312 // Autocomplete should happen only when the username textfield is blurred with | 312 // Autocomplete should happen only when the username textfield is blurred with |
313 // a full match. | 313 // a full match. |
314 username_element_.setValue("a"); | 314 username_element_.setValue("a"); |
315 autofill_agent_->textFieldDidEndEditing(username_element_); | 315 autofill_agent_->textFieldDidEndEditing(username_element_); |
316 CheckTextFieldsState("a", false, "", false); | 316 CheckTextFieldsState("a", false, std::string(), false); |
317 username_element_.setValue("al"); | 317 username_element_.setValue("al"); |
318 autofill_agent_->textFieldDidEndEditing(username_element_); | 318 autofill_agent_->textFieldDidEndEditing(username_element_); |
319 CheckTextFieldsState("al", false, "", false); | 319 CheckTextFieldsState("al", false, std::string(), false); |
320 username_element_.setValue("alices"); | 320 username_element_.setValue("alices"); |
321 autofill_agent_->textFieldDidEndEditing(username_element_); | 321 autofill_agent_->textFieldDidEndEditing(username_element_); |
322 CheckTextFieldsState("alices", false, "", false); | 322 CheckTextFieldsState("alices", false, std::string(), false); |
323 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); | 323 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); |
324 autofill_agent_->textFieldDidEndEditing(username_element_); | 324 autofill_agent_->textFieldDidEndEditing(username_element_); |
325 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 325 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
326 } | 326 } |
327 | 327 |
328 // Tests that inline autocompletion works properly. | 328 // Tests that inline autocompletion works properly. |
329 TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) { | 329 TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) { |
330 // Simulate the browser sending back the login info. | 330 // Simulate the browser sending back the login info. |
331 SimulateOnFillPasswordForm(fill_data_); | 331 SimulateOnFillPasswordForm(fill_data_); |
332 | 332 |
(...skipping 11 matching lines...) Expand all Loading... |
344 // Now the user types the next letter of the same username, 'l'. | 344 // Now the user types the next letter of the same username, 'l'. |
345 SimulateUsernameChange("al", true); | 345 SimulateUsernameChange("al", true); |
346 // Now the fields should have the same value, but the selection should have a | 346 // Now the fields should have the same value, but the selection should have a |
347 // different start value. | 347 // different start value. |
348 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 348 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
349 CheckUsernameSelection(2, 5); | 349 CheckUsernameSelection(2, 5); |
350 | 350 |
351 // Test that deleting does not trigger autocomplete. | 351 // Test that deleting does not trigger autocomplete. |
352 SimulateKeyDownEvent(username_element_, ui::VKEY_BACK); | 352 SimulateKeyDownEvent(username_element_, ui::VKEY_BACK); |
353 SimulateUsernameChange("alic", true); | 353 SimulateUsernameChange("alic", true); |
354 CheckTextFieldsState("alic", false, "", false); | 354 CheckTextFieldsState("alic", false, std::string(), false); |
355 CheckUsernameSelection(4, 4); // No selection. | 355 CheckUsernameSelection(4, 4); // No selection. |
356 // Reset the last pressed key to something other than backspace. | 356 // Reset the last pressed key to something other than backspace. |
357 SimulateKeyDownEvent(username_element_, ui::VKEY_A); | 357 SimulateKeyDownEvent(username_element_, ui::VKEY_A); |
358 | 358 |
359 // Now lets say the user goes astray from the stored username and types the | 359 // Now lets say the user goes astray from the stored username and types the |
360 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in | 360 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in |
361 // practice the username should no longer be 'alice' and the selected range | 361 // practice the username should no longer be 'alice' and the selected range |
362 // should be empty. | 362 // should be empty. |
363 SimulateUsernameChange("alf", true); | 363 SimulateUsernameChange("alf", true); |
364 CheckTextFieldsState("alf", false, "", false); | 364 CheckTextFieldsState("alf", false, std::string(), false); |
365 CheckUsernameSelection(3, 3); // No selection. | 365 CheckUsernameSelection(3, 3); // No selection. |
366 | 366 |
367 // Ok, so now the user removes all the text and enters the letter 'b'. | 367 // Ok, so now the user removes all the text and enters the letter 'b'. |
368 SimulateUsernameChange("b", true); | 368 SimulateUsernameChange("b", true); |
369 // The username and password fields should match the 'bob' entry. | 369 // The username and password fields should match the 'bob' entry. |
370 CheckTextFieldsState(kBobUsername, true, kBobPassword, true); | 370 CheckTextFieldsState(kBobUsername, true, kBobPassword, true); |
371 CheckUsernameSelection(1, 3); | 371 CheckUsernameSelection(1, 3); |
372 | 372 |
373 // Then, the user again removes all the text and types an uppercase 'C'. | 373 // Then, the user again removes all the text and types an uppercase 'C'. |
374 SimulateUsernameChange("C", true); | 374 SimulateUsernameChange("C", true); |
375 // The username and password fields should match the 'Carol' entry. | 375 // The username and password fields should match the 'Carol' entry. |
376 CheckTextFieldsState(kCarolUsername, true, kCarolPassword, true); | 376 CheckTextFieldsState(kCarolUsername, true, kCarolPassword, true); |
377 CheckUsernameSelection(1, 5); | 377 CheckUsernameSelection(1, 5); |
378 // Finally, the user removes all the text and types a lowercase 'c'. We only | 378 // Finally, the user removes all the text and types a lowercase 'c'. We only |
379 // want case-sensitive autocompletion, so the username and the selected range | 379 // want case-sensitive autocompletion, so the username and the selected range |
380 // should be empty. | 380 // should be empty. |
381 SimulateUsernameChange("c", true); | 381 SimulateUsernameChange("c", true); |
382 CheckTextFieldsState("c", false, "", false); | 382 CheckTextFieldsState("c", false, std::string(), false); |
383 CheckUsernameSelection(1, 1); | 383 CheckUsernameSelection(1, 1); |
384 } | 384 } |
385 | 385 |
386 // Tests that accepting an item in the suggestion drop-down works. | 386 // Tests that accepting an item in the suggestion drop-down works. |
387 TEST_F(PasswordAutofillAgentTest, SuggestionAccept) { | 387 TEST_F(PasswordAutofillAgentTest, SuggestionAccept) { |
388 // Simulate the browser sending back the login info. | 388 // Simulate the browser sending back the login info. |
389 SimulateOnFillPasswordForm(fill_data_); | 389 SimulateOnFillPasswordForm(fill_data_); |
390 | 390 |
391 // Clear the text fields to start fresh. | 391 // Clear the text fields to start fresh. |
392 ClearUsernameAndPasswordFields(); | 392 ClearUsernameAndPasswordFields(); |
(...skipping 19 matching lines...) Expand all Loading... |
412 ClearUsernameAndPasswordFields(); | 412 ClearUsernameAndPasswordFields(); |
413 | 413 |
414 // To simulate accepting an item in the suggestion drop-down we just mimic | 414 // To simulate accepting an item in the suggestion drop-down we just mimic |
415 // what the WebView does: it sets the element value then calls | 415 // what the WebView does: it sets the element value then calls |
416 // didSelectAutofillSuggestion on the renderer. | 416 // didSelectAutofillSuggestion on the renderer. |
417 autofill_agent_->didSelectAutofillSuggestion(username_element_, | 417 autofill_agent_->didSelectAutofillSuggestion(username_element_, |
418 ASCIIToUTF16(kAliceUsername), | 418 ASCIIToUTF16(kAliceUsername), |
419 WebKit::WebString(), | 419 WebKit::WebString(), |
420 0); | 420 0); |
421 // Autocomplete should not have kicked in. | 421 // Autocomplete should not have kicked in. |
422 CheckTextFieldsState("", false, "", false); | 422 CheckTextFieldsState(std::string(), false, std::string(), false); |
423 } | 423 } |
424 | 424 |
425 } // namespace autofill | 425 } // namespace autofill |
OLD | NEW |