OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/password_manager/core/browser/password_autofill_manager.h" | 5 #include "components/password_manager/core/browser/password_autofill_manager.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/browser/popup_item_ids.h" | 11 #include "components/autofill/core/browser/popup_item_ids.h" |
11 #include "components/autofill/core/browser/suggestion_test_helpers.h" | 12 #include "components/autofill/core/browser/suggestion_test_helpers.h" |
12 #include "components/autofill/core/browser/test_autofill_client.h" | 13 #include "components/autofill/core/browser/test_autofill_client.h" |
13 #include "components/autofill/core/browser/test_autofill_driver.h" | 14 #include "components/autofill/core/browser/test_autofill_driver.h" |
14 #include "components/autofill/core/common/autofill_constants.h" | 15 #include "components/autofill/core/common/autofill_constants.h" |
| 16 #include "components/autofill/core/common/autofill_switches.h" |
15 #include "components/autofill/core/common/form_field_data.h" | 17 #include "components/autofill/core/common/form_field_data.h" |
16 #include "components/autofill/core/common/password_form_fill_data.h" | 18 #include "components/autofill/core/common/password_form_fill_data.h" |
17 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 19 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
18 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 20 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
19 #include "components/strings/grit/components_strings.h" | 21 #include "components/strings/grit/components_strings.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/gfx/geometry/rect_f.h" | 25 #include "ui/gfx/geometry/rect_f.h" |
24 | 26 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 element_bounds, _, | 349 element_bounds, _, |
348 SuggestionVectorValuesAre(testing::UnorderedElementsAre( | 350 SuggestionVectorValuesAre(testing::UnorderedElementsAre( |
349 title, | 351 title, |
350 test_username_)), | 352 test_username_)), |
351 _)); | 353 _)); |
352 password_autofill_manager_->OnShowPasswordSuggestions( | 354 password_autofill_manager_->OnShowPasswordSuggestions( |
353 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_, | 355 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_, |
354 autofill::IS_PASSWORD_FIELD, element_bounds); | 356 autofill::IS_PASSWORD_FIELD, element_bounds); |
355 } | 357 } |
356 | 358 |
| 359 // Verify that typing "foo" into the username field will match usernames |
| 360 // "foo.bar@example.com", "bar.foo@example.com" and "example@foo.com". |
| 361 TEST_F(PasswordAutofillManagerTest, DisplaySuggestionsWithMatchingTokens) { |
| 362 // Token matching is currently behind a flag. |
| 363 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 364 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 365 |
| 366 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| 367 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| 368 InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| 369 |
| 370 gfx::RectF element_bounds; |
| 371 autofill::PasswordFormFillData data; |
| 372 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); |
| 373 data.username_field.value = username; |
| 374 data.password_field.value = base::ASCIIToUTF16("foobar"); |
| 375 data.preferred_realm = "http://foo.com/"; |
| 376 |
| 377 autofill::PasswordAndRealm additional; |
| 378 additional.realm = "https://foobarrealm.org"; |
| 379 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); |
| 380 data.additional_logins[additional_username] = additional; |
| 381 |
| 382 autofill::UsernamesCollectionKey usernames_key; |
| 383 usernames_key.realm = "http://yetanother.net"; |
| 384 std::vector<base::string16> other_names; |
| 385 base::string16 other_username(base::ASCIIToUTF16("example@foo.com")); |
| 386 other_names.push_back(other_username); |
| 387 data.other_possible_usernames[usernames_key] = other_names; |
| 388 |
| 389 int dummy_key = 0; |
| 390 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| 391 |
| 392 EXPECT_CALL( |
| 393 *autofill_client, |
| 394 ShowAutofillPopup(element_bounds, _, |
| 395 SuggestionVectorValuesAre(testing::UnorderedElementsAre( |
| 396 username, additional_username, other_username)), |
| 397 _)); |
| 398 password_autofill_manager_->OnShowPasswordSuggestions( |
| 399 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo"), false, |
| 400 element_bounds); |
| 401 } |
| 402 |
| 403 // Verify that typing "oo" into the username field will not match any usernames |
| 404 // "foo.bar@example.com", "bar.foo@example.com" or "example@foo.com". |
| 405 TEST_F(PasswordAutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) { |
| 406 // Token matching is currently behind a flag. |
| 407 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 408 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 409 |
| 410 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| 411 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| 412 InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| 413 |
| 414 gfx::RectF element_bounds; |
| 415 autofill::PasswordFormFillData data; |
| 416 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); |
| 417 data.username_field.value = username; |
| 418 data.password_field.value = base::ASCIIToUTF16("foobar"); |
| 419 data.preferred_realm = "http://foo.com/"; |
| 420 |
| 421 autofill::PasswordAndRealm additional; |
| 422 additional.realm = "https://foobarrealm.org"; |
| 423 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); |
| 424 data.additional_logins[additional_username] = additional; |
| 425 |
| 426 autofill::UsernamesCollectionKey usernames_key; |
| 427 usernames_key.realm = "http://yetanother.net"; |
| 428 std::vector<base::string16> other_names; |
| 429 base::string16 other_username(base::ASCIIToUTF16("example@foo.com")); |
| 430 other_names.push_back(other_username); |
| 431 data.other_possible_usernames[usernames_key] = other_names; |
| 432 |
| 433 int dummy_key = 0; |
| 434 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| 435 |
| 436 EXPECT_CALL(*autofill_client, ShowAutofillPopup(_, _, _, _)).Times(0); |
| 437 |
| 438 password_autofill_manager_->OnShowPasswordSuggestions( |
| 439 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("oo"), false, |
| 440 element_bounds); |
| 441 } |
| 442 |
| 443 // Verify that typing "foo@exam" into the username field will match username |
| 444 // "bar.foo@example.com" even if the field contents span accross multiple |
| 445 // tokens. |
| 446 TEST_F(PasswordAutofillManagerTest, |
| 447 MatchingContentsWithSuggestionTokenSeparator) { |
| 448 // Token matching is currently behind a flag. |
| 449 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 450 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 451 |
| 452 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| 453 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| 454 InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| 455 |
| 456 gfx::RectF element_bounds; |
| 457 autofill::PasswordFormFillData data; |
| 458 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); |
| 459 data.username_field.value = username; |
| 460 data.password_field.value = base::ASCIIToUTF16("foobar"); |
| 461 data.preferred_realm = "http://foo.com/"; |
| 462 |
| 463 autofill::PasswordAndRealm additional; |
| 464 additional.realm = "https://foobarrealm.org"; |
| 465 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); |
| 466 data.additional_logins[additional_username] = additional; |
| 467 |
| 468 autofill::UsernamesCollectionKey usernames_key; |
| 469 usernames_key.realm = "http://yetanother.net"; |
| 470 std::vector<base::string16> other_names; |
| 471 base::string16 other_username(base::ASCIIToUTF16("example@foo.com")); |
| 472 other_names.push_back(other_username); |
| 473 data.other_possible_usernames[usernames_key] = other_names; |
| 474 |
| 475 int dummy_key = 0; |
| 476 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| 477 |
| 478 EXPECT_CALL( |
| 479 *autofill_client, |
| 480 ShowAutofillPopup(element_bounds, _, |
| 481 SuggestionVectorValuesAre( |
| 482 testing::UnorderedElementsAre(additional_username)), |
| 483 _)); |
| 484 password_autofill_manager_->OnShowPasswordSuggestions( |
| 485 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo@exam"), |
| 486 false, element_bounds); |
| 487 } |
| 488 |
| 489 // Verify that typing "example" into the username field will match and order |
| 490 // usernames "example@foo.com", "foo.bar@example.com" and "bar.foo@example.com" |
| 491 // i.e. prefix matched followed by substring matched. |
| 492 TEST_F(PasswordAutofillManagerTest, |
| 493 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) { |
| 494 // Token matching is currently behind a flag. |
| 495 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 496 autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| 497 |
| 498 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| 499 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| 500 InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| 501 |
| 502 gfx::RectF element_bounds; |
| 503 autofill::PasswordFormFillData data; |
| 504 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); |
| 505 data.username_field.value = username; |
| 506 data.password_field.value = base::ASCIIToUTF16("foobar"); |
| 507 data.preferred_realm = "http://foo.com/"; |
| 508 |
| 509 autofill::PasswordAndRealm additional; |
| 510 additional.realm = "https://foobarrealm.org"; |
| 511 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); |
| 512 data.additional_logins[additional_username] = additional; |
| 513 |
| 514 autofill::UsernamesCollectionKey usernames_key; |
| 515 usernames_key.realm = "http://yetanother.net"; |
| 516 std::vector<base::string16> other_names; |
| 517 base::string16 other_username(base::ASCIIToUTF16("example@foo.com")); |
| 518 other_names.push_back(other_username); |
| 519 data.other_possible_usernames[usernames_key] = other_names; |
| 520 |
| 521 int dummy_key = 0; |
| 522 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| 523 |
| 524 EXPECT_CALL( |
| 525 *autofill_client, |
| 526 ShowAutofillPopup(element_bounds, _, |
| 527 SuggestionVectorValuesAre(testing::UnorderedElementsAre( |
| 528 other_username, username, additional_username)), |
| 529 _)); |
| 530 password_autofill_manager_->OnShowPasswordSuggestions( |
| 531 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo"), false, |
| 532 element_bounds); |
| 533 } |
| 534 |
357 } // namespace password_manager | 535 } // namespace password_manager |
OLD | NEW |