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

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: Comments 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 fill_data_.basic_data.action = GURL(origin); 333 fill_data_.basic_data.action = GURL(origin);
334 334
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 is marked as readonly, neither field is autofilled
344 // field is autofilled on page load. 344 // 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 // Can still fill a password field if the username is set to a value that
357 // matches.
358 TEST_F(PasswordAutofillAgentTest,
359 AutocompletePasswordForReadonlyUsernameMatched) {
360 username_element_.setValue(username3_);
361 username_element_.setAttribute(WebString::fromUTF8("readonly"),
362 WebString::fromUTF8("true"));
363
364 // Filled even though username is not the preferred match.
365 SimulateOnFillPasswordForm(fill_data_);
366 CheckTextFieldsState(UTF16ToUTF8(username3_), true,
367 UTF16ToUTF8(password3_), true);
368 }
369
370 // If a username field is empty and readonly, don't autofill.
371 TEST_F(PasswordAutofillAgentTest,
372 NoAutocompletePasswordForReadonlyUsernameUnmatched) {
373 username_element_.setValue(WebString::fromUTF8(""));
374 username_element_.setAttribute(WebString::fromUTF8("readonly"),
375 WebString::fromUTF8("true"));
376
377 SimulateOnFillPasswordForm(fill_data_);
378 CheckTextFieldsState(std::string(), false, std::string(), false);
379 }
380
356 // Tests that having a non-matching username precludes the autocomplete. 381 // Tests that having a non-matching username precludes the autocomplete.
357 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForFilledField) { 382 TEST_F(PasswordAutofillAgentTest, NoAutocompleteForFilledFieldUnmatched) {
358 username_element_.setValue(WebString::fromUTF8("bogus")); 383 username_element_.setValue(WebString::fromUTF8("bogus"));
359 384
360 // Simulate the browser sending back the login info, it triggers the 385 // Simulate the browser sending back the login info, it triggers the
361 // autocomplete. 386 // autocomplete.
362 SimulateOnFillPasswordForm(fill_data_); 387 SimulateOnFillPasswordForm(fill_data_);
363 388
364 // Neither field should be autocompleted. 389 // Neither field should be autocompleted.
365 CheckTextFieldsState("bogus", false, std::string(), false); 390 CheckTextFieldsState("bogus", false, std::string(), false);
366 } 391 }
367 392
393 // Don't try and complete a prefilled value even if it's a partial match
Ilya Sherman 2013/11/05 01:25:12 nit: "try and" -> "try to".
Garrett Casto 2013/11/05 01:56:39 Done.
394 // to a username.
395 TEST_F(PasswordAutofillAgentTest, NoPartialMatchForPrefilledUsername) {
396 username_element_.setValue(WebString::fromUTF8("ali"));
397
398 SimulateOnFillPasswordForm(fill_data_);
399
400 CheckTextFieldsState("ali", false, std::string(), false);
401 }
402
368 // Tests that we do not autofill username/passwords if marked as 403 // Tests that we do not autofill username/passwords if marked as
369 // autocomplete="off". 404 // autocomplete="off".
370 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForAutocompleteOff) { 405 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForAutocompleteOff) {
371 username_element_.setAttribute(WebString::fromUTF8("autocomplete"), 406 username_element_.setAttribute(WebString::fromUTF8("autocomplete"),
372 WebString::fromUTF8("off")); 407 WebString::fromUTF8("off"));
373 408
374 // Simulate the browser sending back the login info, it triggers the 409 // Simulate the browser sending back the login info, it triggers the
375 // autocomplete. 410 // autocomplete.
376 SimulateOnFillPasswordForm(fill_data_); 411 SimulateOnFillPasswordForm(fill_data_);
377 412
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( 680 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
646 AutofillHostMsg_PasswordFormsRendered::ID)); 681 AutofillHostMsg_PasswordFormsRendered::ID));
647 682
648 render_thread_->sink().ClearMessages(); 683 render_thread_->sink().ClearMessages();
649 LoadHTML(kWebpageWithDynamicContent); 684 LoadHTML(kWebpageWithDynamicContent);
650 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( 685 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
651 AutofillHostMsg_PasswordFormsRendered::ID)); 686 AutofillHostMsg_PasswordFormsRendered::ID));
652 } 687 }
653 688
654 } // namespace autofill 689 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698