| 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/location.h" | 8 #include "base/location.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 PasswordForm m_facebook_lookup; | 457 PasswordForm m_facebook_lookup; |
| 458 m_facebook_lookup.origin = kMobileURL; | 458 m_facebook_lookup.origin = kMobileURL; |
| 459 m_facebook_lookup.signon_realm = kMobileURL.spec(); | 459 m_facebook_lookup.signon_realm = kMobileURL.spec(); |
| 460 ScopedVector<autofill::PasswordForm> form_list; | 460 ScopedVector<autofill::PasswordForm> form_list; |
| 461 EXPECT_TRUE(backend.GetLogins(m_facebook_lookup, &form_list)); | 461 EXPECT_TRUE(backend.GetLogins(m_facebook_lookup, &form_list)); |
| 462 | 462 |
| 463 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 463 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 464 EXPECT_EQ(1u, form_list.size()); | 464 EXPECT_EQ(1u, form_list.size()); |
| 465 PasswordForm m_facebook = *form_list[0]; | 465 PasswordForm m_facebook = *form_list[0]; |
| 466 form_list.clear(); | 466 form_list.clear(); |
| 467 EXPECT_EQ(kMobileURL, m_facebook.origin); | 467 m_facebook.origin = kMobileURL; |
| 468 EXPECT_EQ(kMobileURL.spec(), m_facebook.signon_realm); | 468 m_facebook.signon_realm = kMobileURL.spec(); |
| 469 | 469 |
| 470 // Add the PSL-matched copy to saved logins. | 470 // Add the PSL-matched copy to saved logins. |
| 471 VerifiedAdd(&backend, m_facebook); | 471 VerifiedAdd(&backend, m_facebook); |
| 472 EXPECT_EQ(2u, global_mock_libsecret_items->size()); | 472 EXPECT_EQ(2u, global_mock_libsecret_items->size()); |
| 473 | 473 |
| 474 // Update www.facebook.com login. | 474 // Update www.facebook.com login. |
| 475 PasswordForm new_facebook(form_facebook_); | 475 PasswordForm new_facebook(form_facebook_); |
| 476 const base::string16 kOldPassword(form_facebook_.password_value); | 476 const base::string16 kOldPassword(form_facebook_.password_value); |
| 477 const base::string16 kNewPassword(UTF8ToUTF16("new_b")); | 477 const base::string16 kNewPassword(UTF8ToUTF16("new_b")); |
| 478 EXPECT_NE(kOldPassword, kNewPassword); | 478 EXPECT_NE(kOldPassword, kNewPassword); |
| 479 new_facebook.password_value = kNewPassword; | 479 new_facebook.password_value = kNewPassword; |
| 480 switch (update_type) { | 480 switch (update_type) { |
| 481 case UPDATE_BY_UPDATELOGIN: | 481 case UPDATE_BY_UPDATELOGIN: |
| 482 VerifiedUpdate(&backend, new_facebook); | 482 VerifiedUpdate(&backend, new_facebook); |
| 483 break; | 483 break; |
| 484 case UPDATE_BY_ADDLOGIN: | 484 case UPDATE_BY_ADDLOGIN: |
| 485 // This is an overwrite call. | 485 // This is an overwrite call. |
| 486 backend.AddLogin(new_facebook); | 486 backend.AddLogin(new_facebook); |
| 487 break; | 487 break; |
| 488 } | 488 } |
| 489 | 489 |
| 490 EXPECT_EQ(2u, global_mock_libsecret_items->size()); | 490 EXPECT_EQ(2u, global_mock_libsecret_items->size()); |
| 491 | 491 |
| 492 // Check that m.facebook.com login was not modified by the update. | 492 // Check that m.facebook.com login was not modified by the update. |
| 493 EXPECT_TRUE(backend.GetLogins(m_facebook_lookup, &form_list)); | 493 EXPECT_TRUE(backend.GetLogins(m_facebook_lookup, &form_list)); |
| 494 | 494 |
| 495 // There should be two results -- the exact one, and the PSL-matched one. | 495 // There should be two results -- the exact one, and the PSL-matched one. |
| 496 EXPECT_EQ(2u, form_list.size()); | 496 EXPECT_EQ(2u, form_list.size()); |
| 497 size_t index_non_psl = 0; | 497 size_t index_non_psl = 0; |
| 498 if (!form_list[index_non_psl]->original_signon_realm.empty()) | 498 if (form_list[index_non_psl]->is_public_suffix_match) |
| 499 index_non_psl = 1; | 499 index_non_psl = 1; |
| 500 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin); | 500 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin); |
| 501 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm); | 501 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm); |
| 502 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value); | 502 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value); |
| 503 form_list.clear(); | 503 form_list.clear(); |
| 504 | 504 |
| 505 // Check that www.facebook.com login was modified by the update. | 505 // Check that www.facebook.com login was modified by the update. |
| 506 EXPECT_TRUE(backend.GetLogins(form_facebook_, &form_list)); | 506 EXPECT_TRUE(backend.GetLogins(form_facebook_, &form_list)); |
| 507 // There should be two results -- the exact one, and the PSL-matched one. | 507 // There should be two results -- the exact one, and the PSL-matched one. |
| 508 EXPECT_EQ(2u, form_list.size()); | 508 EXPECT_EQ(2u, form_list.size()); |
| 509 index_non_psl = 0; | 509 index_non_psl = 0; |
| 510 if (!form_list[index_non_psl]->original_signon_realm.empty()) | 510 if (form_list[index_non_psl]->is_public_suffix_match) |
| 511 index_non_psl = 1; | 511 index_non_psl = 1; |
| 512 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin); | 512 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin); |
| 513 EXPECT_EQ(form_facebook_.signon_realm, | 513 EXPECT_EQ(form_facebook_.signon_realm, |
| 514 form_list[index_non_psl]->signon_realm); | 514 form_list[index_non_psl]->signon_realm); |
| 515 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value); | 515 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value); |
| 516 form_list.clear(); | 516 form_list.clear(); |
| 517 } | 517 } |
| 518 | 518 |
| 519 // Checks various types of matching for forms with a non-HTML |scheme|. | 519 // Checks various types of matching for forms with a non-HTML |scheme|. |
| 520 void CheckMatchingWithScheme(const PasswordForm::Scheme& scheme) { | 520 void CheckMatchingWithScheme(const PasswordForm::Scheme& scheme) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 625 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, |
| 626 "chrome-42"); | 626 "chrome-42"); |
| 627 } | 627 } |
| 628 | 628 |
| 629 // Save a password for www.facebook.com and see it suggested for m.facebook.com. | 629 // Save a password for www.facebook.com and see it suggested for m.facebook.com. |
| 630 TEST_F(NativeBackendLibsecretTest, PSLMatchingPositive) { | 630 TEST_F(NativeBackendLibsecretTest, PSLMatchingPositive) { |
| 631 PasswordForm result; | 631 PasswordForm result; |
| 632 const GURL kMobileURL("http://m.facebook.com/"); | 632 const GURL kMobileURL("http://m.facebook.com/"); |
| 633 EXPECT_TRUE(CheckCredentialAvailability(form_facebook_, kMobileURL, | 633 EXPECT_TRUE(CheckCredentialAvailability(form_facebook_, kMobileURL, |
| 634 PasswordForm::SCHEME_HTML, &result)); | 634 PasswordForm::SCHEME_HTML, &result)); |
| 635 EXPECT_EQ(kMobileURL, result.origin); | 635 EXPECT_EQ(form_facebook_.origin, result.origin); |
| 636 EXPECT_EQ(kMobileURL.spec(), result.signon_realm); | 636 EXPECT_EQ(form_facebook_.signon_realm, result.signon_realm); |
| 637 } | 637 } |
| 638 | 638 |
| 639 // Save a password for www.facebook.com and see it not suggested for | 639 // Save a password for www.facebook.com and see it not suggested for |
| 640 // m-facebook.com. | 640 // m-facebook.com. |
| 641 TEST_F(NativeBackendLibsecretTest, PSLMatchingNegativeDomainMismatch) { | 641 TEST_F(NativeBackendLibsecretTest, PSLMatchingNegativeDomainMismatch) { |
| 642 EXPECT_FALSE(CheckCredentialAvailability(form_facebook_, | 642 EXPECT_FALSE(CheckCredentialAvailability(form_facebook_, |
| 643 GURL("http://m-facebook.com/"), | 643 GURL("http://m-facebook.com/"), |
| 644 PasswordForm::SCHEME_HTML, nullptr)); | 644 PasswordForm::SCHEME_HTML, nullptr)); |
| 645 } | 645 } |
| 646 | 646 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 EXPECT_EQ(form_google_, *form_list[0]); | 905 EXPECT_EQ(form_google_, *form_list[0]); |
| 906 | 906 |
| 907 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 907 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 908 if (!global_mock_libsecret_items->empty()) { | 908 if (!global_mock_libsecret_items->empty()) { |
| 909 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 909 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, |
| 910 "chrome-42"); | 910 "chrome-42"); |
| 911 } | 911 } |
| 912 } | 912 } |
| 913 | 913 |
| 914 // TODO(mdm): add more basic tests here at some point. | 914 // TODO(mdm): add more basic tests here at some point. |
| OLD | NEW |