| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 <stdarg.h> | 5 #include <stdarg.h> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 PasswordForm target_form; | 403 PasswordForm target_form; |
| 404 target_form.origin = url; | 404 target_form.origin = url; |
| 405 target_form.signon_realm = url.spec(); | 405 target_form.signon_realm = url.spec(); |
| 406 if (scheme != PasswordForm::SCHEME_HTML) { | 406 if (scheme != PasswordForm::SCHEME_HTML) { |
| 407 // For non-HTML forms, the realm used for authentication | 407 // For non-HTML forms, the realm used for authentication |
| 408 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the | 408 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the |
| 409 // signon_realm. Just use a default value for now. | 409 // signon_realm. Just use a default value for now. |
| 410 target_form.signon_realm.append("Realm"); | 410 target_form.signon_realm.append("Realm"); |
| 411 target_form.scheme = scheme; | 411 target_form.scheme = scheme; |
| 412 } | 412 } |
| 413 std::vector<PasswordForm*> form_list; | 413 ScopedVector<autofill::PasswordForm> form_list; |
| 414 backend.GetLogins(target_form, &form_list); | 414 backend.GetLogins(target_form, &form_list); |
| 415 | 415 |
| 416 EXPECT_EQ(1u, global_mock_libsecret_items.size()); | 416 EXPECT_EQ(1u, global_mock_libsecret_items.size()); |
| 417 if (global_mock_libsecret_items.size() > 0) | 417 if (global_mock_libsecret_items.size() > 0) |
| 418 CheckMockSecretItem(global_mock_libsecret_items[0], credentials, | 418 CheckMockSecretItem(global_mock_libsecret_items[0], credentials, |
| 419 "chrome-321"); | 419 "chrome-321"); |
| 420 ClearMockObjects(); | 420 ClearMockObjects(); |
| 421 | 421 |
| 422 if (form_list.empty()) | 422 if (form_list.empty()) |
| 423 return false; | 423 return false; |
| 424 EXPECT_EQ(1u, form_list.size()); | 424 EXPECT_EQ(1u, form_list.size()); |
| 425 if (result) | 425 if (result) |
| 426 *result = *form_list[0]; | 426 *result = *form_list[0]; |
| 427 STLDeleteElements(&form_list); | |
| 428 return true; | 427 return true; |
| 429 } | 428 } |
| 430 | 429 |
| 431 // Test that updating does not use PSL matching: Add a www.facebook.com | 430 // Test that updating does not use PSL matching: Add a www.facebook.com |
| 432 // password, then use PSL matching to get a copy of it for m.facebook.com, and | 431 // password, then use PSL matching to get a copy of it for m.facebook.com, and |
| 433 // add that copy as well. Now update the www.facebook.com password -- the | 432 // add that copy as well. Now update the www.facebook.com password -- the |
| 434 // m.facebook.com password should not get updated. Depending on the argument, | 433 // m.facebook.com password should not get updated. Depending on the argument, |
| 435 // the credential update is done via UpdateLogin or AddLogin. | 434 // the credential update is done via UpdateLogin or AddLogin. |
| 436 void CheckPSLUpdate(UpdateType update_type) { | 435 void CheckPSLUpdate(UpdateType update_type) { |
| 437 NativeBackendLibsecret backend(321); | 436 NativeBackendLibsecret backend(321); |
| 438 | 437 |
| 439 backend.AddLogin(form_facebook_); | 438 backend.AddLogin(form_facebook_); |
| 440 | 439 |
| 441 // Get the PSL-matched copy of the saved login for m.facebook. | 440 // Get the PSL-matched copy of the saved login for m.facebook. |
| 442 const GURL kMobileURL("http://m.facebook.com/"); | 441 const GURL kMobileURL("http://m.facebook.com/"); |
| 443 PasswordForm m_facebook_lookup; | 442 PasswordForm m_facebook_lookup; |
| 444 m_facebook_lookup.origin = kMobileURL; | 443 m_facebook_lookup.origin = kMobileURL; |
| 445 m_facebook_lookup.signon_realm = kMobileURL.spec(); | 444 m_facebook_lookup.signon_realm = kMobileURL.spec(); |
| 446 std::vector<PasswordForm*> form_list; | 445 ScopedVector<autofill::PasswordForm> form_list; |
| 447 backend.GetLogins(m_facebook_lookup, &form_list); | 446 backend.GetLogins(m_facebook_lookup, &form_list); |
| 448 | 447 |
| 449 EXPECT_EQ(1u, global_mock_libsecret_items.size()); | 448 EXPECT_EQ(1u, global_mock_libsecret_items.size()); |
| 450 EXPECT_EQ(1u, form_list.size()); | 449 EXPECT_EQ(1u, form_list.size()); |
| 451 PasswordForm m_facebook = *form_list[0]; | 450 PasswordForm m_facebook = *form_list[0]; |
| 452 STLDeleteElements(&form_list); | 451 form_list.clear(); |
| 453 EXPECT_EQ(kMobileURL, m_facebook.origin); | 452 EXPECT_EQ(kMobileURL, m_facebook.origin); |
| 454 EXPECT_EQ(kMobileURL.spec(), m_facebook.signon_realm); | 453 EXPECT_EQ(kMobileURL.spec(), m_facebook.signon_realm); |
| 455 | 454 |
| 456 // Add the PSL-matched copy to saved logins. | 455 // Add the PSL-matched copy to saved logins. |
| 457 backend.AddLogin(m_facebook); | 456 backend.AddLogin(m_facebook); |
| 458 EXPECT_EQ(2u, global_mock_libsecret_items.size()); | 457 EXPECT_EQ(2u, global_mock_libsecret_items.size()); |
| 459 | 458 |
| 460 // Update www.facebook.com login. | 459 // Update www.facebook.com login. |
| 461 PasswordForm new_facebook(form_facebook_); | 460 PasswordForm new_facebook(form_facebook_); |
| 462 const base::string16 kOldPassword(form_facebook_.password_value); | 461 const base::string16 kOldPassword(form_facebook_.password_value); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 479 backend.GetLogins(m_facebook_lookup, &form_list); | 478 backend.GetLogins(m_facebook_lookup, &form_list); |
| 480 | 479 |
| 481 // There should be two results -- the exact one, and the PSL-matched one. | 480 // There should be two results -- the exact one, and the PSL-matched one. |
| 482 EXPECT_EQ(2u, form_list.size()); | 481 EXPECT_EQ(2u, form_list.size()); |
| 483 size_t index_non_psl = 0; | 482 size_t index_non_psl = 0; |
| 484 if (!form_list[index_non_psl]->original_signon_realm.empty()) | 483 if (!form_list[index_non_psl]->original_signon_realm.empty()) |
| 485 index_non_psl = 1; | 484 index_non_psl = 1; |
| 486 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin); | 485 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin); |
| 487 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm); | 486 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm); |
| 488 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value); | 487 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value); |
| 489 STLDeleteElements(&form_list); | 488 form_list.clear(); |
| 490 | 489 |
| 491 // Check that www.facebook.com login was modified by the update. | 490 // Check that www.facebook.com login was modified by the update. |
| 492 backend.GetLogins(form_facebook_, &form_list); | 491 backend.GetLogins(form_facebook_, &form_list); |
| 493 // There should be two results -- the exact one, and the PSL-matched one. | 492 // There should be two results -- the exact one, and the PSL-matched one. |
| 494 EXPECT_EQ(2u, form_list.size()); | 493 EXPECT_EQ(2u, form_list.size()); |
| 495 index_non_psl = 0; | 494 index_non_psl = 0; |
| 496 if (!form_list[index_non_psl]->original_signon_realm.empty()) | 495 if (!form_list[index_non_psl]->original_signon_realm.empty()) |
| 497 index_non_psl = 1; | 496 index_non_psl = 1; |
| 498 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin); | 497 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin); |
| 499 EXPECT_EQ(form_facebook_.signon_realm, | 498 EXPECT_EQ(form_facebook_.signon_realm, |
| 500 form_list[index_non_psl]->signon_realm); | 499 form_list[index_non_psl]->signon_realm); |
| 501 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value); | 500 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value); |
| 502 STLDeleteElements(&form_list); | 501 form_list.clear(); |
| 503 } | 502 } |
| 504 | 503 |
| 505 // Checks various types of matching for forms with a non-HTML |scheme|. | 504 // Checks various types of matching for forms with a non-HTML |scheme|. |
| 506 void CheckMatchingWithScheme(const PasswordForm::Scheme& scheme) { | 505 void CheckMatchingWithScheme(const PasswordForm::Scheme& scheme) { |
| 507 ASSERT_NE(PasswordForm::SCHEME_HTML, scheme); | 506 ASSERT_NE(PasswordForm::SCHEME_HTML, scheme); |
| 508 other_auth_.scheme = scheme; | 507 other_auth_.scheme = scheme; |
| 509 | 508 |
| 510 // Don't match a non-HTML form with an HTML form. | 509 // Don't match a non-HTML form with an HTML form. |
| 511 EXPECT_FALSE( | 510 EXPECT_FALSE( |
| 512 CheckCredentialAvailability(other_auth_, GURL("http://www.example.com"), | 511 CheckCredentialAvailability(other_auth_, GURL("http://www.example.com"), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 if (global_mock_libsecret_items.size() > 0) | 592 if (global_mock_libsecret_items.size() > 0) |
| 594 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, | 593 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, |
| 595 "chrome-42"); | 594 "chrome-42"); |
| 596 } | 595 } |
| 597 | 596 |
| 598 TEST_F(NativeBackendLibsecretTest, BasicListLogins) { | 597 TEST_F(NativeBackendLibsecretTest, BasicListLogins) { |
| 599 NativeBackendLibsecret backend(42); | 598 NativeBackendLibsecret backend(42); |
| 600 | 599 |
| 601 backend.AddLogin(form_google_); | 600 backend.AddLogin(form_google_); |
| 602 | 601 |
| 603 std::vector<PasswordForm*> form_list; | 602 ScopedVector<autofill::PasswordForm> form_list; |
| 604 backend.GetAutofillableLogins(&form_list); | 603 backend.GetAutofillableLogins(&form_list); |
| 605 | 604 |
| 606 // Quick check that we got something back. | 605 // Quick check that we got something back. |
| 607 EXPECT_EQ(1u, form_list.size()); | 606 EXPECT_EQ(1u, form_list.size()); |
| 608 STLDeleteElements(&form_list); | 607 form_list.clear(); |
| 609 | 608 |
| 610 EXPECT_EQ(1u, global_mock_libsecret_items.size()); | 609 EXPECT_EQ(1u, global_mock_libsecret_items.size()); |
| 611 if (global_mock_libsecret_items.size() > 0) | 610 if (global_mock_libsecret_items.size() > 0) |
| 612 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, | 611 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, |
| 613 "chrome-42"); | 612 "chrome-42"); |
| 614 } | 613 } |
| 615 | 614 |
| 616 // Save a password for www.facebook.com and see it suggested for m.facebook.com. | 615 // Save a password for www.facebook.com and see it suggested for m.facebook.com. |
| 617 TEST_F(NativeBackendLibsecretTest, PSLMatchingPositive) { | 616 TEST_F(NativeBackendLibsecretTest, PSLMatchingPositive) { |
| 618 PasswordForm result; | 617 PasswordForm result; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 | 723 |
| 725 EXPECT_EQ(1u, global_mock_libsecret_items.size()); | 724 EXPECT_EQ(1u, global_mock_libsecret_items.size()); |
| 726 if (global_mock_libsecret_items.size() > 0) | 725 if (global_mock_libsecret_items.size() > 0) |
| 727 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, | 726 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, |
| 728 "chrome-42"); | 727 "chrome-42"); |
| 729 | 728 |
| 730 // Attempt to remove a login that doesn't exist. | 729 // Attempt to remove a login that doesn't exist. |
| 731 backend.RemoveLogin(form_isc_); | 730 backend.RemoveLogin(form_isc_); |
| 732 | 731 |
| 733 // Make sure we can still get the first form back. | 732 // Make sure we can still get the first form back. |
| 734 std::vector<PasswordForm*> form_list; | 733 ScopedVector<autofill::PasswordForm> form_list; |
| 735 backend.GetAutofillableLogins(&form_list); | 734 backend.GetAutofillableLogins(&form_list); |
| 736 | 735 |
| 737 // Quick check that we got something back. | 736 // Quick check that we got something back. |
| 738 EXPECT_EQ(1u, form_list.size()); | 737 EXPECT_EQ(1u, form_list.size()); |
| 739 STLDeleteElements(&form_list); | 738 form_list.clear(); |
| 740 | 739 |
| 741 EXPECT_EQ(1u, global_mock_libsecret_items.size()); | 740 EXPECT_EQ(1u, global_mock_libsecret_items.size()); |
| 742 if (global_mock_libsecret_items.size() > 0) | 741 if (global_mock_libsecret_items.size() > 0) |
| 743 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, | 742 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, |
| 744 "chrome-42"); | 743 "chrome-42"); |
| 745 } | 744 } |
| 746 | 745 |
| 747 TEST_F(NativeBackendLibsecretTest, UpdateNonexistentLogin) { | 746 TEST_F(NativeBackendLibsecretTest, UpdateNonexistentLogin) { |
| 748 NativeBackendLibsecret backend(42); | 747 NativeBackendLibsecret backend(42); |
| 749 | 748 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, | 789 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, |
| 791 "chrome-42"); | 790 "chrome-42"); |
| 792 } | 791 } |
| 793 | 792 |
| 794 TEST_F(NativeBackendLibsecretTest, ListLoginsAppends) { | 793 TEST_F(NativeBackendLibsecretTest, ListLoginsAppends) { |
| 795 NativeBackendLibsecret backend(42); | 794 NativeBackendLibsecret backend(42); |
| 796 | 795 |
| 797 backend.AddLogin(form_google_); | 796 backend.AddLogin(form_google_); |
| 798 | 797 |
| 799 // Send the same request twice with the same list both times. | 798 // Send the same request twice with the same list both times. |
| 800 std::vector<PasswordForm*> form_list; | 799 ScopedVector<autofill::PasswordForm> form_list; |
| 801 backend.GetAutofillableLogins(&form_list); | 800 backend.GetAutofillableLogins(&form_list); |
| 802 backend.GetAutofillableLogins(&form_list); | 801 backend.GetAutofillableLogins(&form_list); |
| 803 | 802 |
| 804 // Quick check that we got two results back. | 803 // Quick check that we got two results back. |
| 805 EXPECT_EQ(2u, form_list.size()); | 804 EXPECT_EQ(2u, form_list.size()); |
| 806 STLDeleteElements(&form_list); | 805 form_list.clear(); |
| 807 | 806 |
| 808 EXPECT_EQ(1u, global_mock_libsecret_items.size()); | 807 EXPECT_EQ(1u, global_mock_libsecret_items.size()); |
| 809 if (global_mock_libsecret_items.size() > 0) | 808 if (global_mock_libsecret_items.size() > 0) |
| 810 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, | 809 CheckMockSecretItem(global_mock_libsecret_items[0], form_google_, |
| 811 "chrome-42"); | 810 "chrome-42"); |
| 812 } | 811 } |
| 813 | 812 |
| 814 TEST_F(NativeBackendLibsecretTest, RemoveLoginsCreatedBetween) { | 813 TEST_F(NativeBackendLibsecretTest, RemoveLoginsCreatedBetween) { |
| 815 CheckRemoveLoginsBetween(CREATED); | 814 CheckRemoveLoginsBetween(CREATED); |
| 816 } | 815 } |
| 817 | 816 |
| 818 TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) { | 817 TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) { |
| 819 CheckRemoveLoginsBetween(SYNCED); | 818 CheckRemoveLoginsBetween(SYNCED); |
| 820 } | 819 } |
| 821 | 820 |
| 822 // TODO(mdm): add more basic tests here at some point. | 821 // TODO(mdm): add more basic tests here at some point. |
| OLD | NEW |