Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 56653002: [Password Autofill] Make better use of prefilled usernames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/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/content/renderer/autofill_agent.h" 8 #include "components/autofill/content/renderer/autofill_agent.h"
9 #include "components/autofill/content/renderer/form_autofill_util.h" 9 #include "components/autofill/content/renderer/form_autofill_util.h"
10 #include "components/autofill/content/renderer/password_autofill_agent.h" 10 #include "components/autofill/content/renderer/password_autofill_agent.h"
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // Simulate the browser sending back the login info, it triggers the 335 // Simulate the browser sending back the login info, it triggers the
336 // autocomplete. 336 // autocomplete.
337 SimulateOnFillPasswordForm(fill_data_); 337 SimulateOnFillPasswordForm(fill_data_);
338 338
339 // The username and password should have been autocompleted. 339 // The username and password should have been autocompleted.
340 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 340 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
341 } 341 }
342 342
343 // Tests that if a password or input element is marked as readonly, neither 343 // Tests that if a password or input element is marked as readonly, neither
344 // field is autofilled on page load. 344 // field is autofilled on page load.
345 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForReadOnly) { 345 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForReadOnlyPassword) {
346 password_element_.setAttribute(WebString::fromUTF8("readonly"), 346 password_element_.setAttribute(WebString::fromUTF8("readonly"),
347 WebString::fromUTF8("true")); 347 WebString::fromUTF8("true"));
348 348
349 // Simulate the browser sending back the login info, it triggers the 349 // Simulate the browser sending back the login info, it triggers the
350 // autocomplete. 350 // autocomplete.
351 SimulateOnFillPasswordForm(fill_data_); 351 SimulateOnFillPasswordForm(fill_data_);
352 352
353 CheckTextFieldsState(std::string(), false, std::string(), false); 353 CheckTextFieldsState(std::string(), false, std::string(), false);
354 } 354 }
355 355
356 // Tests that having a non-matching username precludes the autocomplete. 356 // Can still fill a password field if the username is set to a value that
357 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForFilledField) { 357 // matches. If it's set to something that doesn't match any username that
358 // we know about, we leave the field untouched.
Ilya Sherman 2013/11/04 23:10:48 Please write separate tests cases for the two beha
Garrett Casto 2013/11/05 00:40:35 Done.
359 TEST_F(PasswordAutofillAgentTest, AutocompletePasswordForReadonlyUsername) {
360 username_element_.setValue(username3_);
361 username_element_.setAttribute(WebString::fromUTF8("readonly"),
362 WebString::fromUTF8("true"));
363
364 SimulateOnFillPasswordForm(fill_data_);
365 CheckTextFieldsState(UTF16ToUTF8(username3_), true,
366 UTF16ToUTF8(password3_), true);
367
368 ClearUsernameAndPasswordFields();
369
370 // If the name is empty, don't fill the password.
371 username_element_.setValue(WebString::fromUTF8(""));
372
373 SimulateOnFillPasswordForm(fill_data_);
374 CheckTextFieldsState(std::string(), false, std::string(), false);
375 }
376
377 // Tests that having a non-matching username precludes the autocomplete, but
378 // having a matching username will allow autofilling.
Ilya Sherman 2013/11/04 23:10:48 Please write a separate test case for having a mat
Garrett Casto 2013/11/05 00:40:35 The first is different in that the field is prefil
379 TEST_F(PasswordAutofillAgentTest, AutocompleteForFilledField) {
358 username_element_.setValue(WebString::fromUTF8("bogus")); 380 username_element_.setValue(WebString::fromUTF8("bogus"));
359 381
360 // Simulate the browser sending back the login info, it triggers the 382 // Simulate the browser sending back the login info, it triggers the
361 // autocomplete. 383 // autocomplete.
362 SimulateOnFillPasswordForm(fill_data_); 384 SimulateOnFillPasswordForm(fill_data_);
363 385
364 // Neither field should be autocompleted. 386 // Neither field should be autocompleted.
365 CheckTextFieldsState("bogus", false, std::string(), false); 387 CheckTextFieldsState("bogus", false, std::string(), false);
388
389 // Make sure that even if the username isn't preferred, we will fill the
390 // correct password if this preset.
391 ClearUsernameAndPasswordFields();
392 username_element_.setValue(username2_);
393
394 SimulateOnFillPasswordForm(fill_data_);
395 CheckTextFieldsState(UTF16ToUTF8(username2_), true,
396 UTF16ToUTF8(password2_), true);
366 } 397 }
367 398
368 // Tests that we do not autofill username/passwords if marked as 399 // Tests that we do not autofill username/passwords if marked as
369 // autocomplete="off". 400 // autocomplete="off".
370 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForAutocompleteOff) { 401 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForAutocompleteOff) {
371 username_element_.setAttribute(WebString::fromUTF8("autocomplete"), 402 username_element_.setAttribute(WebString::fromUTF8("autocomplete"),
372 WebString::fromUTF8("off")); 403 WebString::fromUTF8("off"));
373 404
374 // Simulate the browser sending back the login info, it triggers the 405 // Simulate the browser sending back the login info, it triggers the
375 // autocomplete. 406 // autocomplete.
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( 676 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
646 AutofillHostMsg_PasswordFormsRendered::ID)); 677 AutofillHostMsg_PasswordFormsRendered::ID));
647 678
648 render_thread_->sink().ClearMessages(); 679 render_thread_->sink().ClearMessages();
649 LoadHTML(kWebpageWithDynamicContent); 680 LoadHTML(kWebpageWithDynamicContent);
650 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( 681 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
651 AutofillHostMsg_PasswordFormsRendered::ID)); 682 AutofillHostMsg_PasswordFormsRendered::ID));
652 } 683 }
653 684
654 } // namespace autofill 685 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698