| OLD | NEW |
| 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 <stdarg.h> | 5 #include <stdarg.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "components/password_manager/core/common/password_manager_pref_names.h" | 25 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 26 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 27 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 using autofill::PasswordForm; | 31 using autofill::PasswordForm; |
| 32 using base::UTF8ToUTF16; | 32 using base::UTF8ToUTF16; |
| 33 using base::UTF16ToUTF8; | 33 using base::UTF16ToUTF8; |
| 34 using content::BrowserThread; | 34 using content::BrowserThread; |
| 35 using password_manager::PasswordStore; |
| 35 using password_manager::PasswordStoreChange; | 36 using password_manager::PasswordStoreChange; |
| 36 using password_manager::PasswordStoreChangeList; | 37 using password_manager::PasswordStoreChangeList; |
| 37 using testing::Pointee; | 38 using testing::Pointee; |
| 38 using testing::UnorderedElementsAre; | 39 using testing::UnorderedElementsAre; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 // What follows is a very simple implementation of the subset of the GNOME | 43 // What follows is a very simple implementation of the subset of the GNOME |
| 43 // Keyring API that we actually use. It gets substituted for the real one by | 44 // Keyring API that we actually use. It gets substituted for the real one by |
| 44 // MockGnomeKeyringLoader, which hooks into the facility normally used to load | 45 // MockGnomeKeyringLoader, which hooks into the facility normally used to load |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 NativeBackendGnome backend(321); | 517 NativeBackendGnome backend(321); |
| 517 backend.Init(); | 518 backend.Init(); |
| 518 | 519 |
| 519 BrowserThread::PostTask( | 520 BrowserThread::PostTask( |
| 520 BrowserThread::DB, | 521 BrowserThread::DB, |
| 521 FROM_HERE, | 522 FROM_HERE, |
| 522 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 523 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 523 base::Unretained(&backend), | 524 base::Unretained(&backend), |
| 524 credentials)); | 525 credentials)); |
| 525 | 526 |
| 526 PasswordForm target_form; | 527 PasswordStore::FormDigest target_form = {scheme, url.spec(), url}; |
| 527 target_form.origin = url; | |
| 528 target_form.signon_realm = url.spec(); | |
| 529 if (scheme != PasswordForm::SCHEME_HTML) { | 528 if (scheme != PasswordForm::SCHEME_HTML) { |
| 530 // For non-HTML forms, the realm used for authentication | 529 // For non-HTML forms, the realm used for authentication |
| 531 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the | 530 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the |
| 532 // signon_realm. Just use a default value for now. | 531 // signon_realm. Just use a default value for now. |
| 533 target_form.signon_realm.append("Realm"); | 532 target_form.signon_realm.append("Realm"); |
| 534 target_form.scheme = scheme; | |
| 535 } | 533 } |
| 536 ScopedVector<autofill::PasswordForm> form_list; | 534 ScopedVector<autofill::PasswordForm> form_list; |
| 537 BrowserThread::PostTaskAndReplyWithResult( | 535 BrowserThread::PostTaskAndReplyWithResult( |
| 538 BrowserThread::DB, | 536 BrowserThread::DB, |
| 539 FROM_HERE, | 537 FROM_HERE, |
| 540 base::Bind(&NativeBackendGnome::GetLogins, | 538 base::Bind(&NativeBackendGnome::GetLogins, |
| 541 base::Unretained(&backend), | 539 base::Unretained(&backend), |
| 542 target_form, | 540 target_form, |
| 543 &form_list), | 541 &form_list), |
| 544 base::Bind(&CheckTrue)); | 542 base::Bind(&CheckTrue)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 573 FROM_HERE, | 571 FROM_HERE, |
| 574 base::Bind(&NativeBackendGnome::AddLogin, | 572 base::Bind(&NativeBackendGnome::AddLogin, |
| 575 base::Unretained(&backend), | 573 base::Unretained(&backend), |
| 576 form_facebook_), | 574 form_facebook_), |
| 577 base::Bind(&CheckPasswordChanges, | 575 base::Bind(&CheckPasswordChanges, |
| 578 PasswordStoreChangeList(1, PasswordStoreChange( | 576 PasswordStoreChangeList(1, PasswordStoreChange( |
| 579 PasswordStoreChange::ADD, form_facebook_)))); | 577 PasswordStoreChange::ADD, form_facebook_)))); |
| 580 | 578 |
| 581 // Get the PSL-matched copy of the saved login for m.facebook. | 579 // Get the PSL-matched copy of the saved login for m.facebook. |
| 582 const GURL kMobileURL("http://m.facebook.com/"); | 580 const GURL kMobileURL("http://m.facebook.com/"); |
| 583 PasswordForm m_facebook_lookup; | 581 PasswordStore::FormDigest m_facebook_lookup = { |
| 584 m_facebook_lookup.origin = kMobileURL; | 582 PasswordForm::SCHEME_HTML, kMobileURL.spec(), kMobileURL}; |
| 585 m_facebook_lookup.signon_realm = kMobileURL.spec(); | |
| 586 ScopedVector<autofill::PasswordForm> form_list; | 583 ScopedVector<autofill::PasswordForm> form_list; |
| 587 BrowserThread::PostTaskAndReplyWithResult( | 584 BrowserThread::PostTaskAndReplyWithResult( |
| 588 BrowserThread::DB, | 585 BrowserThread::DB, |
| 589 FROM_HERE, | 586 FROM_HERE, |
| 590 base::Bind(&NativeBackendGnome::GetLogins, | 587 base::Bind(&NativeBackendGnome::GetLogins, |
| 591 base::Unretained(&backend), | 588 base::Unretained(&backend), |
| 592 m_facebook_lookup, | 589 m_facebook_lookup, |
| 593 &form_list), | 590 &form_list), |
| 594 base::Bind(&CheckTrue)); | 591 base::Bind(&CheckTrue)); |
| 595 RunBothThreads(); | 592 RunBothThreads(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 size_t index_non_psl = 0; | 662 size_t index_non_psl = 0; |
| 666 if (form_list[index_non_psl]->is_public_suffix_match) | 663 if (form_list[index_non_psl]->is_public_suffix_match) |
| 667 index_non_psl = 1; | 664 index_non_psl = 1; |
| 668 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin); | 665 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin); |
| 669 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm); | 666 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm); |
| 670 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value); | 667 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value); |
| 671 form_list.clear(); | 668 form_list.clear(); |
| 672 | 669 |
| 673 // Check that www.facebook.com login was modified by the update. | 670 // Check that www.facebook.com login was modified by the update. |
| 674 BrowserThread::PostTaskAndReplyWithResult( | 671 BrowserThread::PostTaskAndReplyWithResult( |
| 675 BrowserThread::DB, | 672 BrowserThread::DB, FROM_HERE, |
| 676 FROM_HERE, | 673 base::Bind(&NativeBackendGnome::GetLogins, base::Unretained(&backend), |
| 677 base::Bind(&NativeBackendGnome::GetLogins, | 674 PasswordStore::FormDigest(form_facebook_), &form_list), |
| 678 base::Unretained(&backend), | |
| 679 form_facebook_, | |
| 680 &form_list), | |
| 681 base::Bind(&CheckTrue)); | 675 base::Bind(&CheckTrue)); |
| 682 RunBothThreads(); | 676 RunBothThreads(); |
| 683 // There should be two results -- the exact one, and the PSL-matched one. | 677 // There should be two results -- the exact one, and the PSL-matched one. |
| 684 EXPECT_EQ(2u, form_list.size()); | 678 EXPECT_EQ(2u, form_list.size()); |
| 685 index_non_psl = 0; | 679 index_non_psl = 0; |
| 686 if (form_list[index_non_psl]->is_public_suffix_match) | 680 if (form_list[index_non_psl]->is_public_suffix_match) |
| 687 index_non_psl = 1; | 681 index_non_psl = 1; |
| 688 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin); | 682 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin); |
| 689 EXPECT_EQ(form_facebook_.signon_realm, | 683 EXPECT_EQ(form_facebook_.signon_realm, |
| 690 form_list[index_non_psl]->signon_realm); | 684 form_list[index_non_psl]->signon_realm); |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 | 1123 |
| 1130 EXPECT_EQ(1u, mock_keyring_items.size()); | 1124 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 1131 if (mock_keyring_items.size() > 0) | 1125 if (mock_keyring_items.size() > 0) |
| 1132 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 1126 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
| 1133 } | 1127 } |
| 1134 | 1128 |
| 1135 TEST_F(NativeBackendGnomeTest, AndroidCredentials) { | 1129 TEST_F(NativeBackendGnomeTest, AndroidCredentials) { |
| 1136 NativeBackendGnome backend(42); | 1130 NativeBackendGnome backend(42); |
| 1137 backend.Init(); | 1131 backend.Init(); |
| 1138 | 1132 |
| 1139 PasswordForm observed_android_form; | 1133 PasswordForm saved_android_form; |
| 1140 observed_android_form.scheme = PasswordForm::SCHEME_HTML; | 1134 saved_android_form.scheme = PasswordForm::SCHEME_HTML; |
| 1141 observed_android_form.signon_realm = | 1135 saved_android_form.signon_realm = |
| 1142 "android://7x7IDboo8u9YKraUsbmVkuf1-@net.rateflix.app/"; | 1136 "android://7x7IDboo8u9YKraUsbmVkuf1-@net.rateflix.app/"; |
| 1143 PasswordForm saved_android_form = observed_android_form; | |
| 1144 saved_android_form.username_value = base::UTF8ToUTF16("randomusername"); | 1137 saved_android_form.username_value = base::UTF8ToUTF16("randomusername"); |
| 1145 saved_android_form.password_value = base::UTF8ToUTF16("password"); | 1138 saved_android_form.password_value = base::UTF8ToUTF16("password"); |
| 1146 saved_android_form.date_created = base::Time::Now(); | 1139 saved_android_form.date_created = base::Time::Now(); |
| 1147 | 1140 |
| 1141 PasswordStore::FormDigest observed_android_form(saved_android_form); |
| 1148 BrowserThread::PostTaskAndReplyWithResult( | 1142 BrowserThread::PostTaskAndReplyWithResult( |
| 1149 BrowserThread::DB, FROM_HERE, | 1143 BrowserThread::DB, FROM_HERE, |
| 1150 base::Bind(&NativeBackendGnome::AddLogin, | 1144 base::Bind(&NativeBackendGnome::AddLogin, |
| 1151 base::Unretained(&backend), saved_android_form), | 1145 base::Unretained(&backend), saved_android_form), |
| 1152 base::Bind(&CheckPasswordChanges, | 1146 base::Bind(&CheckPasswordChanges, |
| 1153 PasswordStoreChangeList(1, PasswordStoreChange( | 1147 PasswordStoreChangeList(1, PasswordStoreChange( |
| 1154 PasswordStoreChange::ADD, saved_android_form)))); | 1148 PasswordStoreChange::ADD, saved_android_form)))); |
| 1155 | 1149 |
| 1156 ScopedVector<autofill::PasswordForm> form_list; | 1150 ScopedVector<autofill::PasswordForm> form_list; |
| 1157 BrowserThread::PostTaskAndReplyWithResult( | 1151 BrowserThread::PostTaskAndReplyWithResult( |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 base::Bind(&CheckTrue)); | 1289 base::Bind(&CheckTrue)); |
| 1296 | 1290 |
| 1297 RunBothThreads(); | 1291 RunBothThreads(); |
| 1298 | 1292 |
| 1299 EXPECT_EQ(2u, form_list.size()); | 1293 EXPECT_EQ(2u, form_list.size()); |
| 1300 EXPECT_THAT(form_list, UnorderedElementsAre(Pointee(form_google_), | 1294 EXPECT_THAT(form_list, UnorderedElementsAre(Pointee(form_google_), |
| 1301 Pointee(form_facebook_))); | 1295 Pointee(form_facebook_))); |
| 1302 } | 1296 } |
| 1303 | 1297 |
| 1304 // TODO(mdm): add more basic tests here at some point. | 1298 // TODO(mdm): add more basic tests here at some point. |
| OLD | NEW |