| 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 "chrome/browser/password_manager/password_store_mac.h" | 5 #include "chrome/browser/password_manager/password_store_mac.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "chrome/browser/password_manager/password_store_mac_internal.h" | 14 #include "chrome/browser/password_manager/password_store_mac_internal.h" |
| 15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "components/password_manager/core/browser/login_database.h" | 16 #include "components/password_manager/core/browser/login_database.h" |
| 17 #include "components/password_manager/core/browser/password_form_data.h" | 17 #include "components/password_manager/core/browser/password_manager_test_utils.h
" |
| 18 #include "components/password_manager/core/browser/password_store_consumer.h" | 18 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 20 #include "crypto/mock_apple_keychain.h" | 20 #include "crypto/mock_apple_keychain.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 using autofill::PasswordForm; | 24 using autofill::PasswordForm; |
| 25 using base::ASCIIToUTF16; | 25 using base::ASCIIToUTF16; |
| 26 using base::WideToUTF16; | 26 using base::WideToUTF16; |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using crypto::MockAppleKeychain; | 28 using crypto::MockAppleKeychain; |
| 29 using internal_keychain_helpers::FormsMatchForMerge; | 29 using internal_keychain_helpers::FormsMatchForMerge; |
| 30 using internal_keychain_helpers::STRICT_FORM_MATCH; | 30 using internal_keychain_helpers::STRICT_FORM_MATCH; |
| 31 using password_manager::CreatePasswordFormFromDataForTesting; |
| 31 using password_manager::LoginDatabase; | 32 using password_manager::LoginDatabase; |
| 33 using password_manager::PasswordFormData; |
| 32 using password_manager::PasswordStore; | 34 using password_manager::PasswordStore; |
| 33 using password_manager::PasswordStoreConsumer; | 35 using password_manager::PasswordStoreConsumer; |
| 34 using testing::_; | 36 using testing::_; |
| 35 using testing::DoAll; | 37 using testing::DoAll; |
| 36 using testing::Invoke; | 38 using testing::Invoke; |
| 37 using testing::IsEmpty; | 39 using testing::IsEmpty; |
| 38 using testing::SizeIs; | 40 using testing::SizeIs; |
| 39 using testing::WithArg; | 41 using testing::WithArg; |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 using PasswordStoreMac::GetBackgroundTaskRunner; | 121 using PasswordStoreMac::GetBackgroundTaskRunner; |
| 120 | 122 |
| 121 private: | 123 private: |
| 122 ~TestPasswordStoreMac() override {} | 124 ~TestPasswordStoreMac() override {} |
| 123 | 125 |
| 124 DISALLOW_COPY_AND_ASSIGN(TestPasswordStoreMac); | 126 DISALLOW_COPY_AND_ASSIGN(TestPasswordStoreMac); |
| 125 }; | 127 }; |
| 126 | 128 |
| 127 #pragma mark - | 129 #pragma mark - |
| 128 | 130 |
| 129 // Struct used for creation of PasswordForms from static arrays of data. | |
| 130 struct PasswordFormData { | |
| 131 const PasswordForm::Scheme scheme; | |
| 132 const char* signon_realm; | |
| 133 const char* origin; | |
| 134 const char* action; | |
| 135 const wchar_t* submit_element; | |
| 136 const wchar_t* username_element; | |
| 137 const wchar_t* password_element; | |
| 138 const wchar_t* username_value; // Set to NULL for a blacklist entry. | |
| 139 const wchar_t* password_value; | |
| 140 const bool preferred; | |
| 141 const bool ssl_valid; | |
| 142 const double creation_time; | |
| 143 }; | |
| 144 | |
| 145 // Creates and returns a new PasswordForm built from form_data. | |
| 146 scoped_ptr<PasswordForm> CreatePasswordFormFromData( | |
| 147 const PasswordFormData& form_data) { | |
| 148 scoped_ptr<PasswordForm> form(new PasswordForm()); | |
| 149 form->scheme = form_data.scheme; | |
| 150 form->preferred = form_data.preferred; | |
| 151 form->ssl_valid = form_data.ssl_valid; | |
| 152 form->date_created = base::Time::FromDoubleT(form_data.creation_time); | |
| 153 form->date_synced = form->date_created + base::TimeDelta::FromDays(1); | |
| 154 if (form_data.signon_realm) | |
| 155 form->signon_realm = std::string(form_data.signon_realm); | |
| 156 if (form_data.origin) | |
| 157 form->origin = GURL(form_data.origin); | |
| 158 if (form_data.action) | |
| 159 form->action = GURL(form_data.action); | |
| 160 if (form_data.submit_element) | |
| 161 form->submit_element = WideToUTF16(form_data.submit_element); | |
| 162 if (form_data.username_element) | |
| 163 form->username_element = WideToUTF16(form_data.username_element); | |
| 164 if (form_data.password_element) | |
| 165 form->password_element = WideToUTF16(form_data.password_element); | |
| 166 if (form_data.username_value) { | |
| 167 form->username_value = WideToUTF16(form_data.username_value); | |
| 168 form->display_name = form->username_value; | |
| 169 form->skip_zero_click = true; | |
| 170 if (form_data.password_value) | |
| 171 form->password_value = WideToUTF16(form_data.password_value); | |
| 172 } else { | |
| 173 form->blacklisted_by_user = true; | |
| 174 } | |
| 175 form->avatar_url = GURL("https://accounts.google.com/Avatar"); | |
| 176 form->federation_url = GURL("https://accounts.google.com/login"); | |
| 177 return form.Pass(); | |
| 178 } | |
| 179 | |
| 180 // Macro to simplify calling CheckFormsAgainstExpectations with a useful label. | 131 // Macro to simplify calling CheckFormsAgainstExpectations with a useful label. |
| 181 #define CHECK_FORMS(forms, expectations, i) \ | 132 #define CHECK_FORMS(forms, expectations, i) \ |
| 182 CheckFormsAgainstExpectations(forms, expectations, #forms, i) | 133 CheckFormsAgainstExpectations(forms, expectations, #forms, i) |
| 183 | 134 |
| 184 // Ensures that the data in |forms| match |expectations|, causing test failures | 135 // Ensures that the data in |forms| match |expectations|, causing test failures |
| 185 // for any discrepencies. | 136 // for any discrepencies. |
| 186 // TODO(stuartmorgan): This is current order-dependent; ideally it shouldn't | 137 // TODO(stuartmorgan): This is current order-dependent; ideally it shouldn't |
| 187 // matter if |forms| and |expectations| are scrambled. | 138 // matter if |forms| and |expectations| are scrambled. |
| 188 void CheckFormsAgainstExpectations( | 139 void CheckFormsAgainstExpectations( |
| 189 const std::vector<PasswordForm*>& forms, | 140 const std::vector<PasswordForm*>& forms, |
| 190 const std::vector<PasswordFormData*>& expectations, | 141 const std::vector<PasswordFormData*>& expectations, |
| 191 const char* forms_label, | |
| 192 unsigned int test_number) { | |
| 193 const unsigned int kBufferSize = 128; | |
| 194 char test_label[kBufferSize]; | |
| 195 snprintf(test_label, kBufferSize, "%s in test %u", forms_label, test_number); | |
| 196 | 142 |
| 197 EXPECT_EQ(expectations.size(), forms.size()) << test_label; | 143 const char* forms_label, unsigned int test_number) { |
| 144 EXPECT_EQ(expectations.size(), forms.size()) << forms_label << " in test " |
| 145 << test_number; |
| 198 if (expectations.size() != forms.size()) | 146 if (expectations.size() != forms.size()) |
| 199 return; | 147 return; |
| 200 | 148 |
| 201 for (unsigned int i = 0; i < expectations.size(); ++i) { | 149 for (unsigned int i = 0; i < expectations.size(); ++i) { |
| 202 snprintf(test_label, kBufferSize, "%s in test %u, item %u", | 150 SCOPED_TRACE(testing::Message() << forms_label << " in test " << test_number |
| 203 forms_label, test_number, i); | 151 << ", item " << i); |
| 204 PasswordForm* form = forms[i]; | 152 PasswordForm* form = forms[i]; |
| 205 PasswordFormData* expectation = expectations[i]; | 153 PasswordFormData* expectation = expectations[i]; |
| 206 EXPECT_EQ(expectation->scheme, form->scheme) << test_label; | 154 EXPECT_EQ(expectation->scheme, form->scheme); |
| 207 EXPECT_EQ(std::string(expectation->signon_realm), form->signon_realm) | 155 EXPECT_EQ(std::string(expectation->signon_realm), form->signon_realm); |
| 208 << test_label; | 156 EXPECT_EQ(GURL(expectation->origin), form->origin); |
| 209 EXPECT_EQ(GURL(expectation->origin), form->origin) << test_label; | 157 EXPECT_EQ(GURL(expectation->action), form->action); |
| 210 EXPECT_EQ(GURL(expectation->action), form->action) << test_label; | 158 EXPECT_EQ(WideToUTF16(expectation->submit_element), form->submit_element); |
| 211 EXPECT_EQ(WideToUTF16(expectation->submit_element), form->submit_element) | |
| 212 << test_label; | |
| 213 EXPECT_EQ(WideToUTF16(expectation->username_element), | 159 EXPECT_EQ(WideToUTF16(expectation->username_element), |
| 214 form->username_element) << test_label; | 160 form->username_element); |
| 215 EXPECT_EQ(WideToUTF16(expectation->password_element), | 161 EXPECT_EQ(WideToUTF16(expectation->password_element), |
| 216 form->password_element) << test_label; | 162 form->password_element); |
| 217 if (expectation->username_value) { | 163 if (expectation->username_value) { |
| 218 EXPECT_EQ(WideToUTF16(expectation->username_value), | 164 EXPECT_EQ(WideToUTF16(expectation->username_value), form->username_value); |
| 219 form->username_value) << test_label; | 165 EXPECT_EQ(WideToUTF16(expectation->username_value), form->display_name); |
| 220 EXPECT_EQ(WideToUTF16(expectation->username_value), | 166 EXPECT_TRUE(form->skip_zero_click); |
| 221 form->display_name) << test_label; | 167 EXPECT_EQ(WideToUTF16(expectation->password_value), form->password_value); |
| 222 EXPECT_TRUE(form->skip_zero_click) << test_label; | |
| 223 EXPECT_EQ(WideToUTF16(expectation->password_value), | |
| 224 form->password_value) << test_label; | |
| 225 } else { | 168 } else { |
| 226 EXPECT_TRUE(form->blacklisted_by_user) << test_label; | 169 EXPECT_TRUE(form->blacklisted_by_user); |
| 227 } | 170 } |
| 228 EXPECT_EQ(expectation->preferred, form->preferred) << test_label; | 171 EXPECT_EQ(expectation->preferred, form->preferred); |
| 229 EXPECT_EQ(expectation->ssl_valid, form->ssl_valid) << test_label; | 172 EXPECT_EQ(expectation->ssl_valid, form->ssl_valid); |
| 230 EXPECT_DOUBLE_EQ(expectation->creation_time, | 173 EXPECT_DOUBLE_EQ(expectation->creation_time, |
| 231 form->date_created.ToDoubleT()) << test_label; | 174 form->date_created.ToDoubleT()); |
| 232 base::Time created = base::Time::FromDoubleT(expectation->creation_time); | 175 base::Time created = base::Time::FromDoubleT(expectation->creation_time); |
| 233 EXPECT_EQ(created + base::TimeDelta::FromDays(1), | 176 EXPECT_EQ( |
| 234 form->date_synced) << test_label; | 177 created + base::TimeDelta::FromDays( |
| 235 EXPECT_EQ(GURL("https://accounts.google.com/Avatar"), form->avatar_url); | 178 password_manager::kTestingDaysAfterPasswordsAreSynced), |
| 236 EXPECT_EQ(GURL("https://accounts.google.com/login"), form->federation_url); | 179 form->date_synced); |
| 180 EXPECT_EQ(GURL(password_manager::kTestingAvatarUrlSpec), form->avatar_url); |
| 181 EXPECT_EQ(GURL(password_manager::kTestingFederationUrlSpec), |
| 182 form->federation_url); |
| 237 } | 183 } |
| 238 } | 184 } |
| 239 | 185 |
| 240 } // namespace | 186 } // namespace |
| 241 | 187 |
| 242 #pragma mark - | 188 #pragma mark - |
| 243 | 189 |
| 244 class PasswordStoreMacInternalsTest : public testing::Test { | 190 class PasswordStoreMacInternalsTest : public testing::Test { |
| 245 public: | 191 public: |
| 246 void SetUp() override { | 192 void SetUp() override { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 // Garbage forms should have no matches. | 470 // Garbage forms should have no matches. |
| 525 { { PasswordForm::SCHEME_HTML, "foo/bar/baz", | 471 { { PasswordForm::SCHEME_HTML, "foo/bar/baz", |
| 526 NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, false, 0 }, 0, 0 }, | 472 NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, false, 0 }, 0, 0 }, |
| 527 }; | 473 }; |
| 528 | 474 |
| 529 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); | 475 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); |
| 530 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); | 476 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); |
| 531 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 477 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 532 for (unsigned int i = 0; i < arraysize(test_data); ++i) { | 478 for (unsigned int i = 0; i < arraysize(test_data); ++i) { |
| 533 scoped_ptr<PasswordForm> query_form = | 479 scoped_ptr<PasswordForm> query_form = |
| 534 CreatePasswordFormFromData(test_data[i].data); | 480 CreatePasswordFormFromDataForTesting(test_data[i].data); |
| 535 | 481 |
| 536 // Check matches treating the form as a fill target. | 482 // Check matches treating the form as a fill target. |
| 537 ScopedVector<autofill::PasswordForm> matching_items = | 483 ScopedVector<autofill::PasswordForm> matching_items = |
| 538 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, | 484 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, |
| 539 query_form->scheme); | 485 query_form->scheme); |
| 540 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size()); | 486 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size()); |
| 541 matching_items.clear(); | 487 matching_items.clear(); |
| 542 | 488 |
| 543 // Check matches treating the form as a merging target. | 489 // Check matches treating the form as a merging target. |
| 544 EXPECT_EQ(test_data[i].expected_merge_matches > 0, | 490 EXPECT_EQ(test_data[i].expected_merge_matches > 0, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 "http://some.domain.com:4567/insecure.html", | 550 "http://some.domain.com:4567/insecure.html", |
| 605 NULL, NULL, NULL, NULL, L"basic_auth_user", NULL, true, false, 0 }, | 551 NULL, NULL, NULL, NULL, L"basic_auth_user", NULL, true, false, 0 }, |
| 606 { PasswordForm::SCHEME_DIGEST, "https://some.domain.com/high_security", | 552 { PasswordForm::SCHEME_DIGEST, "https://some.domain.com/high_security", |
| 607 "https://some.domain.com", | 553 "https://some.domain.com", |
| 608 NULL, NULL, NULL, NULL, L"digest_auth_user", NULL, true, true, 0 }, | 554 NULL, NULL, NULL, NULL, L"digest_auth_user", NULL, true, true, 0 }, |
| 609 }; | 555 }; |
| 610 | 556 |
| 611 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) { | 557 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) { |
| 612 // Create a base form and make sure we find a match. | 558 // Create a base form and make sure we find a match. |
| 613 scoped_ptr<PasswordForm> base_form = | 559 scoped_ptr<PasswordForm> base_form = |
| 614 CreatePasswordFormFromData(base_form_data[i]); | 560 CreatePasswordFormFromDataForTesting(base_form_data[i]); |
| 615 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form)); | 561 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form)); |
| 616 EXPECT_TRUE(keychain_adapter.HasPasswordExactlyMatchingForm(*base_form)); | 562 EXPECT_TRUE(keychain_adapter.HasPasswordExactlyMatchingForm(*base_form)); |
| 617 | 563 |
| 618 // Make sure that the matching isn't looser than it should be by checking | 564 // Make sure that the matching isn't looser than it should be by checking |
| 619 // that slightly altered forms don't match. | 565 // that slightly altered forms don't match. |
| 620 ScopedVector<autofill::PasswordForm> modified_forms; | 566 ScopedVector<autofill::PasswordForm> modified_forms; |
| 621 | 567 |
| 622 modified_forms.push_back(new PasswordForm(*base_form)); | 568 modified_forms.push_back(new PasswordForm(*base_form)); |
| 623 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user"); | 569 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user"); |
| 624 | 570 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 { { PasswordForm::SCHEME_HTML, "http://some.domain.com", | 624 { { PasswordForm::SCHEME_HTML, "http://some.domain.com", |
| 679 "http://some.domain.com/insecure.html", NULL, NULL, NULL, NULL, | 625 "http://some.domain.com/insecure.html", NULL, NULL, NULL, NULL, |
| 680 L"joe_user", L"fail_me", false, false, 0 }, false }, | 626 L"joe_user", L"fail_me", false, false, 0 }, false }, |
| 681 }; | 627 }; |
| 682 | 628 |
| 683 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); | 629 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); |
| 684 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 630 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 685 | 631 |
| 686 for (unsigned int i = 0; i < arraysize(test_data); ++i) { | 632 for (unsigned int i = 0; i < arraysize(test_data); ++i) { |
| 687 scoped_ptr<PasswordForm> in_form = | 633 scoped_ptr<PasswordForm> in_form = |
| 688 CreatePasswordFormFromData(test_data[i].data); | 634 CreatePasswordFormFromDataForTesting(test_data[i].data); |
| 689 bool add_succeeded = owned_keychain_adapter.AddPassword(*in_form); | 635 bool add_succeeded = owned_keychain_adapter.AddPassword(*in_form); |
| 690 EXPECT_EQ(test_data[i].should_succeed, add_succeeded); | 636 EXPECT_EQ(test_data[i].should_succeed, add_succeeded); |
| 691 if (add_succeeded) { | 637 if (add_succeeded) { |
| 692 EXPECT_TRUE(owned_keychain_adapter.HasPasswordsMergeableWithForm( | 638 EXPECT_TRUE(owned_keychain_adapter.HasPasswordsMergeableWithForm( |
| 693 *in_form)); | 639 *in_form)); |
| 694 EXPECT_TRUE(owned_keychain_adapter.HasPasswordExactlyMatchingForm( | 640 EXPECT_TRUE(owned_keychain_adapter.HasPasswordExactlyMatchingForm( |
| 695 *in_form)); | 641 *in_form)); |
| 696 } | 642 } |
| 697 } | 643 } |
| 698 | 644 |
| 699 // Test that adding duplicate item updates the existing item. | 645 // Test that adding duplicate item updates the existing item. |
| 700 { | 646 { |
| 701 PasswordFormData data = { | 647 PasswordFormData data = { |
| 702 PasswordForm::SCHEME_HTML, "http://some.domain.com", | 648 PasswordForm::SCHEME_HTML, "http://some.domain.com", |
| 703 "http://some.domain.com/insecure.html", NULL, | 649 "http://some.domain.com/insecure.html", NULL, |
| 704 NULL, NULL, NULL, L"joe_user", L"updated_password", false, false, 0 | 650 NULL, NULL, NULL, L"joe_user", L"updated_password", false, false, 0 |
| 705 }; | 651 }; |
| 706 scoped_ptr<PasswordForm> update_form = CreatePasswordFormFromData(data); | 652 scoped_ptr<PasswordForm> update_form = |
| 653 CreatePasswordFormFromDataForTesting(data); |
| 707 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); | 654 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); |
| 708 EXPECT_TRUE(keychain_adapter.AddPassword(*update_form)); | 655 EXPECT_TRUE(keychain_adapter.AddPassword(*update_form)); |
| 709 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(2); | 656 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(2); |
| 710 PasswordForm stored_form; | 657 PasswordForm stored_form; |
| 711 internal_keychain_helpers::FillPasswordFormFromKeychainItem(*keychain_, | 658 internal_keychain_helpers::FillPasswordFormFromKeychainItem(*keychain_, |
| 712 keychain_item, | 659 keychain_item, |
| 713 &stored_form, | 660 &stored_form, |
| 714 true); | 661 true); |
| 715 EXPECT_EQ(update_form->password_value, stored_form.password_value); | 662 EXPECT_EQ(update_form->password_value, stored_form.password_value); |
| 716 } | 663 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 730 { { PasswordForm::SCHEME_HTML, "http://some.domain.com/", | 677 { { PasswordForm::SCHEME_HTML, "http://some.domain.com/", |
| 731 "http://some.domain.com/insecure.html", NULL, NULL, NULL, NULL, | 678 "http://some.domain.com/insecure.html", NULL, NULL, NULL, NULL, |
| 732 L"joe_user", NULL, true, false, 0 }, false }, | 679 L"joe_user", NULL, true, false, 0 }, false }, |
| 733 }; | 680 }; |
| 734 | 681 |
| 735 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); | 682 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); |
| 736 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 683 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 737 | 684 |
| 738 // Add our test item so that we can delete it. | 685 // Add our test item so that we can delete it. |
| 739 scoped_ptr<PasswordForm> add_form = | 686 scoped_ptr<PasswordForm> add_form = |
| 740 CreatePasswordFormFromData(test_data[0].data); | 687 CreatePasswordFormFromDataForTesting(test_data[0].data); |
| 741 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*add_form)); | 688 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*add_form)); |
| 742 | 689 |
| 743 for (unsigned int i = 0; i < arraysize(test_data); ++i) { | 690 for (unsigned int i = 0; i < arraysize(test_data); ++i) { |
| 744 scoped_ptr<PasswordForm> form = | 691 scoped_ptr<PasswordForm> form = |
| 745 CreatePasswordFormFromData(test_data[i].data); | 692 CreatePasswordFormFromDataForTesting(test_data[i].data); |
| 746 EXPECT_EQ(test_data[i].should_succeed, | 693 EXPECT_EQ(test_data[i].should_succeed, |
| 747 owned_keychain_adapter.RemovePassword(*form)); | 694 owned_keychain_adapter.RemovePassword(*form)); |
| 748 | 695 |
| 749 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); | 696 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); |
| 750 bool match = keychain_adapter.HasPasswordExactlyMatchingForm(*form); | 697 bool match = keychain_adapter.HasPasswordExactlyMatchingForm(*form); |
| 751 EXPECT_EQ(test_data[i].should_succeed, !match); | 698 EXPECT_EQ(test_data[i].should_succeed, !match); |
| 752 } | 699 } |
| 753 } | 700 } |
| 754 | 701 |
| 755 TEST_F(PasswordStoreMacInternalsTest, TestFormMatch) { | 702 TEST_F(PasswordStoreMacInternalsTest, TestFormMatch) { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 test_data[DATABASE_INPUT][current_test].push_back(&db_user_1_with_path); | 883 test_data[DATABASE_INPUT][current_test].push_back(&db_user_1_with_path); |
| 937 test_data[MERGE_OUTPUT][current_test].push_back(&merged_user_1); | 884 test_data[MERGE_OUTPUT][current_test].push_back(&merged_user_1); |
| 938 test_data[MERGE_OUTPUT][current_test].push_back( | 885 test_data[MERGE_OUTPUT][current_test].push_back( |
| 939 &merged_user_1_with_both_paths); | 886 &merged_user_1_with_both_paths); |
| 940 | 887 |
| 941 for (unsigned int test_case = 0; test_case <= current_test; ++test_case) { | 888 for (unsigned int test_case = 0; test_case <= current_test; ++test_case) { |
| 942 ScopedVector<autofill::PasswordForm> keychain_forms; | 889 ScopedVector<autofill::PasswordForm> keychain_forms; |
| 943 for (std::vector<PasswordFormData*>::iterator i = | 890 for (std::vector<PasswordFormData*>::iterator i = |
| 944 test_data[KEYCHAIN_INPUT][test_case].begin(); | 891 test_data[KEYCHAIN_INPUT][test_case].begin(); |
| 945 i != test_data[KEYCHAIN_INPUT][test_case].end(); ++i) { | 892 i != test_data[KEYCHAIN_INPUT][test_case].end(); ++i) { |
| 946 keychain_forms.push_back(CreatePasswordFormFromData(*(*i)).release()); | 893 keychain_forms.push_back( |
| 894 CreatePasswordFormFromDataForTesting(*(*i)).release()); |
| 947 } | 895 } |
| 948 ScopedVector<autofill::PasswordForm> database_forms; | 896 ScopedVector<autofill::PasswordForm> database_forms; |
| 949 for (std::vector<PasswordFormData*>::iterator i = | 897 for (std::vector<PasswordFormData*>::iterator i = |
| 950 test_data[DATABASE_INPUT][test_case].begin(); | 898 test_data[DATABASE_INPUT][test_case].begin(); |
| 951 i != test_data[DATABASE_INPUT][test_case].end(); ++i) { | 899 i != test_data[DATABASE_INPUT][test_case].end(); ++i) { |
| 952 database_forms.push_back(CreatePasswordFormFromData(*(*i)).release()); | 900 database_forms.push_back( |
| 901 CreatePasswordFormFromDataForTesting(*(*i)).release()); |
| 953 } | 902 } |
| 954 | 903 |
| 955 ScopedVector<autofill::PasswordForm> merged_forms; | 904 ScopedVector<autofill::PasswordForm> merged_forms; |
| 956 internal_keychain_helpers::MergePasswordForms(&keychain_forms, | 905 internal_keychain_helpers::MergePasswordForms(&keychain_forms, |
| 957 &database_forms, | 906 &database_forms, |
| 958 &merged_forms); | 907 &merged_forms); |
| 959 | 908 |
| 960 CHECK_FORMS(keychain_forms.get(), test_data[KEYCHAIN_OUTPUT][test_case], | 909 CHECK_FORMS(keychain_forms.get(), test_data[KEYCHAIN_OUTPUT][test_case], |
| 961 test_case); | 910 test_case); |
| 962 CHECK_FORMS(database_forms.get(), test_data[DATABASE_OUTPUT][test_case], | 911 CHECK_FORMS(database_forms.get(), test_data[DATABASE_OUTPUT][test_case], |
| (...skipping 24 matching lines...) Expand all Loading... |
| 987 "http://dont.remember.com/handlepage.cgi", | 936 "http://dont.remember.com/handlepage.cgi", |
| 988 L"submit", L"username", L"password", L"joe_user", L"", | 937 L"submit", L"username", L"password", L"joe_user", L"", |
| 989 true, false, 1240000000 }, | 938 true, false, 1240000000 }, |
| 990 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", | 939 { PasswordForm::SCHEME_HTML, "http://some.domain.com/", |
| 991 "http://some.domain.com/path.html", "http://some.domain.com/action.cgi", | 940 "http://some.domain.com/path.html", "http://some.domain.com/action.cgi", |
| 992 L"submit", L"username", L"password", NULL, NULL, | 941 L"submit", L"username", L"password", NULL, NULL, |
| 993 true, false, 1212121212 }, | 942 true, false, 1212121212 }, |
| 994 }; | 943 }; |
| 995 ScopedVector<autofill::PasswordForm> database_forms; | 944 ScopedVector<autofill::PasswordForm> database_forms; |
| 996 for (unsigned int i = 0; i < arraysize(db_data); ++i) { | 945 for (unsigned int i = 0; i < arraysize(db_data); ++i) { |
| 997 database_forms.push_back(CreatePasswordFormFromData(db_data[i]).release()); | 946 database_forms.push_back( |
| 947 CreatePasswordFormFromDataForTesting(db_data[i]).release()); |
| 998 } | 948 } |
| 999 ScopedVector<autofill::PasswordForm> merged_forms; | 949 ScopedVector<autofill::PasswordForm> merged_forms; |
| 1000 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, | 950 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, |
| 1001 &merged_forms); | 951 &merged_forms); |
| 1002 EXPECT_EQ(2U, database_forms.size()); | 952 EXPECT_EQ(2U, database_forms.size()); |
| 1003 ASSERT_EQ(3U, merged_forms.size()); | 953 ASSERT_EQ(3U, merged_forms.size()); |
| 1004 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[0]->password_value); | 954 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[0]->password_value); |
| 1005 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[1]->password_value); | 955 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[1]->password_value); |
| 1006 EXPECT_TRUE(merged_forms[2]->blacklisted_by_user); | 956 EXPECT_TRUE(merged_forms[2]->blacklisted_by_user); |
| 1007 } | 957 } |
| 1008 | 958 |
| 1009 TEST_F(PasswordStoreMacInternalsTest, TestBlacklistedFiltering) { | 959 TEST_F(PasswordStoreMacInternalsTest, TestBlacklistedFiltering) { |
| 1010 PasswordFormData db_data[] = { | 960 PasswordFormData db_data[] = { |
| 1011 { PasswordForm::SCHEME_HTML, "http://dont.remember.com/", | 961 { PasswordForm::SCHEME_HTML, "http://dont.remember.com/", |
| 1012 "http://dont.remember.com/", | 962 "http://dont.remember.com/", |
| 1013 "http://dont.remember.com/handlepage.cgi", | 963 "http://dont.remember.com/handlepage.cgi", |
| 1014 L"submit", L"username", L"password", L"joe_user", L"non_empty_password", | 964 L"submit", L"username", L"password", L"joe_user", L"non_empty_password", |
| 1015 true, false, 1240000000 }, | 965 true, false, 1240000000 }, |
| 1016 { PasswordForm::SCHEME_HTML, "https://dont.remember.com/", | 966 { PasswordForm::SCHEME_HTML, "https://dont.remember.com/", |
| 1017 "https://dont.remember.com/", | 967 "https://dont.remember.com/", |
| 1018 "https://dont.remember.com/handlepage_secure.cgi", | 968 "https://dont.remember.com/handlepage_secure.cgi", |
| 1019 L"submit", L"username", L"password", L"joe_user", L"non_empty_password", | 969 L"submit", L"username", L"password", L"joe_user", L"non_empty_password", |
| 1020 true, false, 1240000000 }, | 970 true, false, 1240000000 }, |
| 1021 }; | 971 }; |
| 1022 ScopedVector<autofill::PasswordForm> database_forms; | 972 ScopedVector<autofill::PasswordForm> database_forms; |
| 1023 for (unsigned int i = 0; i < arraysize(db_data); ++i) { | 973 for (unsigned int i = 0; i < arraysize(db_data); ++i) { |
| 1024 database_forms.push_back(CreatePasswordFormFromData(db_data[i]).release()); | 974 database_forms.push_back( |
| 975 CreatePasswordFormFromDataForTesting(db_data[i]).release()); |
| 1025 } | 976 } |
| 1026 ScopedVector<autofill::PasswordForm> merged_forms; | 977 ScopedVector<autofill::PasswordForm> merged_forms; |
| 1027 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, | 978 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, |
| 1028 &merged_forms); | 979 &merged_forms); |
| 1029 EXPECT_EQ(2U, database_forms.size()); | 980 EXPECT_EQ(2U, database_forms.size()); |
| 1030 ASSERT_EQ(0U, merged_forms.size()); | 981 ASSERT_EQ(0U, merged_forms.size()); |
| 1031 } | 982 } |
| 1032 | 983 |
| 1033 TEST_F(PasswordStoreMacInternalsTest, TestFillPasswordFormFromKeychainItem) { | 984 TEST_F(PasswordStoreMacInternalsTest, TestFillPasswordFormFromKeychainItem) { |
| 1034 // When |extract_password_data| is false, the password field must be empty, | 985 // When |extract_password_data| is false, the password field must be empty, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 L"anonymous", L"knock-knock", false, false, 0 }, | 1067 L"anonymous", L"knock-knock", false, false, 0 }, |
| 1117 { PasswordForm::SCHEME_BASIC, "http://a.site.com:2222/therealm", | 1068 { PasswordForm::SCHEME_BASIC, "http://a.site.com:2222/therealm", |
| 1118 "http://a.site.com:2222/", NULL, NULL, NULL, NULL, | 1069 "http://a.site.com:2222/", NULL, NULL, NULL, NULL, |
| 1119 L"username", L"password", false, false, 0 }, | 1070 L"username", L"password", false, false, 0 }, |
| 1120 { PasswordForm::SCHEME_DIGEST, "https://digest.site.com/differentrealm", | 1071 { PasswordForm::SCHEME_DIGEST, "https://digest.site.com/differentrealm", |
| 1121 "https://digest.site.com/secure.html", NULL, NULL, NULL, NULL, | 1072 "https://digest.site.com/secure.html", NULL, NULL, NULL, NULL, |
| 1122 L"testname", L"testpass", false, false, 0 }, | 1073 L"testname", L"testpass", false, false, 0 }, |
| 1123 }; | 1074 }; |
| 1124 for (unsigned int i = 0; i < arraysize(owned_password_data); ++i) { | 1075 for (unsigned int i = 0; i < arraysize(owned_password_data); ++i) { |
| 1125 scoped_ptr<PasswordForm> form = | 1076 scoped_ptr<PasswordForm> form = |
| 1126 CreatePasswordFormFromData(owned_password_data[i]); | 1077 CreatePasswordFormFromDataForTesting(owned_password_data[i]); |
| 1127 owned_keychain_adapter.AddPassword(*form); | 1078 owned_keychain_adapter.AddPassword(*form); |
| 1128 } | 1079 } |
| 1129 | 1080 |
| 1130 ScopedVector<autofill::PasswordForm> all_passwords = | 1081 ScopedVector<autofill::PasswordForm> all_passwords = |
| 1131 keychain_adapter.GetAllPasswordFormPasswords(); | 1082 keychain_adapter.GetAllPasswordFormPasswords(); |
| 1132 EXPECT_EQ(8 + arraysize(owned_password_data), all_passwords.size()); | 1083 EXPECT_EQ(8 + arraysize(owned_password_data), all_passwords.size()); |
| 1133 | 1084 |
| 1134 ScopedVector<autofill::PasswordForm> owned_passwords = | 1085 ScopedVector<autofill::PasswordForm> owned_passwords = |
| 1135 owned_keychain_adapter.GetAllPasswordFormPasswords(); | 1086 owned_keychain_adapter.GetAllPasswordFormPasswords(); |
| 1136 EXPECT_EQ(arraysize(owned_password_data), owned_passwords.size()); | 1087 EXPECT_EQ(arraysize(owned_password_data), owned_passwords.size()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 // Insert a password into both the database and the keychain. | 1160 // Insert a password into both the database and the keychain. |
| 1210 // This is done manually, rather than through store_->AddLogin, because the | 1161 // This is done manually, rather than through store_->AddLogin, because the |
| 1211 // Mock Keychain isn't smart enough to be able to support update generically, | 1162 // Mock Keychain isn't smart enough to be able to support update generically, |
| 1212 // so some.domain.com triggers special handling to test it that make inserting | 1163 // so some.domain.com triggers special handling to test it that make inserting |
| 1213 // fail. | 1164 // fail. |
| 1214 PasswordFormData joint_data = { | 1165 PasswordFormData joint_data = { |
| 1215 PasswordForm::SCHEME_HTML, "http://some.domain.com/", | 1166 PasswordForm::SCHEME_HTML, "http://some.domain.com/", |
| 1216 "http://some.domain.com/insecure.html", "login.cgi", | 1167 "http://some.domain.com/insecure.html", "login.cgi", |
| 1217 L"username", L"password", L"submit", L"joe_user", L"sekrit", true, false, 1 | 1168 L"username", L"password", L"submit", L"joe_user", L"sekrit", true, false, 1 |
| 1218 }; | 1169 }; |
| 1219 scoped_ptr<PasswordForm> joint_form = CreatePasswordFormFromData(joint_data); | 1170 scoped_ptr<PasswordForm> joint_form = |
| 1171 CreatePasswordFormFromDataForTesting(joint_data); |
| 1220 login_db()->AddLogin(*joint_form); | 1172 login_db()->AddLogin(*joint_form); |
| 1221 MockAppleKeychain::KeychainTestData joint_keychain_data = { | 1173 MockAppleKeychain::KeychainTestData joint_keychain_data = { |
| 1222 kSecAuthenticationTypeHTMLForm, "some.domain.com", | 1174 kSecAuthenticationTypeHTMLForm, "some.domain.com", |
| 1223 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z", | 1175 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z", |
| 1224 "joe_user", "sekrit", false }; | 1176 "joe_user", "sekrit", false }; |
| 1225 keychain()->AddTestItem(joint_keychain_data); | 1177 keychain()->AddTestItem(joint_keychain_data); |
| 1226 | 1178 |
| 1227 // Insert a password into the keychain only. | 1179 // Insert a password into the keychain only. |
| 1228 MockAppleKeychain::KeychainTestData keychain_only_data = { | 1180 MockAppleKeychain::KeychainTestData keychain_only_data = { |
| 1229 kSecAuthenticationTypeHTMLForm, "keychain.only.com", | 1181 kSecAuthenticationTypeHTMLForm, "keychain.only.com", |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1259 // form is submitted. | 1211 // form is submitted. |
| 1260 { { PasswordForm::SCHEME_HTML, "http://different.com/", | 1212 { { PasswordForm::SCHEME_HTML, "http://different.com/", |
| 1261 "http://different.com/index.html", "login.cgi", | 1213 "http://different.com/index.html", "login.cgi", |
| 1262 L"username", L"password", L"submit", L"abc", L"123", | 1214 L"username", L"password", L"submit", L"abc", L"123", |
| 1263 true, false, 2 }, | 1215 true, false, 2 }, |
| 1264 NULL, | 1216 NULL, |
| 1265 }, | 1217 }, |
| 1266 }; | 1218 }; |
| 1267 for (unsigned int i = 0; i < arraysize(updates); ++i) { | 1219 for (unsigned int i = 0; i < arraysize(updates); ++i) { |
| 1268 scoped_ptr<PasswordForm> form = | 1220 scoped_ptr<PasswordForm> form = |
| 1269 CreatePasswordFormFromData(updates[i].form_data); | 1221 CreatePasswordFormFromDataForTesting(updates[i].form_data); |
| 1270 store_->UpdateLogin(*form); | 1222 store_->UpdateLogin(*form); |
| 1271 } | 1223 } |
| 1272 | 1224 |
| 1273 FinishAsyncProcessing(); | 1225 FinishAsyncProcessing(); |
| 1274 | 1226 |
| 1275 MacKeychainPasswordFormAdapter keychain_adapter(keychain()); | 1227 MacKeychainPasswordFormAdapter keychain_adapter(keychain()); |
| 1276 for (unsigned int i = 0; i < arraysize(updates); ++i) { | 1228 for (unsigned int i = 0; i < arraysize(updates); ++i) { |
| 1277 scoped_ptr<PasswordForm> query_form = | 1229 scoped_ptr<PasswordForm> query_form = |
| 1278 CreatePasswordFormFromData(updates[i].form_data); | 1230 CreatePasswordFormFromDataForTesting(updates[i].form_data); |
| 1279 | 1231 |
| 1280 ScopedVector<autofill::PasswordForm> matching_items = | 1232 ScopedVector<autofill::PasswordForm> matching_items = |
| 1281 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, | 1233 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, |
| 1282 query_form->scheme); | 1234 query_form->scheme); |
| 1283 if (updates[i].password) { | 1235 if (updates[i].password) { |
| 1284 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; | 1236 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; |
| 1285 if (matching_items.size() >= 1) | 1237 if (matching_items.size() >= 1) |
| 1286 EXPECT_EQ(ASCIIToUTF16(updates[i].password), | 1238 EXPECT_EQ(ASCIIToUTF16(updates[i].password), |
| 1287 matching_items[0]->password_value) << "iteration " << i; | 1239 matching_items[0]->password_value) << "iteration " << i; |
| 1288 } else { | 1240 } else { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1311 // www.facebook.com password from the login database, we should not be blocked | 1263 // www.facebook.com password from the login database, we should not be blocked |
| 1312 // from deleting it from the keystore just becaus the m.facebook.com password | 1264 // from deleting it from the keystore just becaus the m.facebook.com password |
| 1313 // fuzzy-matches the www.facebook.com one.) | 1265 // fuzzy-matches the www.facebook.com one.) |
| 1314 | 1266 |
| 1315 // 1. Add a password for www.facebook.com | 1267 // 1. Add a password for www.facebook.com |
| 1316 PasswordFormData www_form_data = { | 1268 PasswordFormData www_form_data = { |
| 1317 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1269 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1318 "http://www.facebook.com/index.html", "login", | 1270 "http://www.facebook.com/index.html", "login", |
| 1319 L"username", L"password", L"submit", L"joe_user", L"sekrit", true, false, 1 | 1271 L"username", L"password", L"submit", L"joe_user", L"sekrit", true, false, 1 |
| 1320 }; | 1272 }; |
| 1321 scoped_ptr<PasswordForm> www_form = CreatePasswordFormFromData(www_form_data); | 1273 scoped_ptr<PasswordForm> www_form = |
| 1274 CreatePasswordFormFromDataForTesting(www_form_data); |
| 1322 login_db()->AddLogin(*www_form); | 1275 login_db()->AddLogin(*www_form); |
| 1323 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain()); | 1276 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain()); |
| 1324 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1277 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 1325 owned_keychain_adapter.AddPassword(*www_form); | 1278 owned_keychain_adapter.AddPassword(*www_form); |
| 1326 | 1279 |
| 1327 // 2. Get a password for m.facebook.com. | 1280 // 2. Get a password for m.facebook.com. |
| 1328 PasswordForm m_form(*www_form); | 1281 PasswordForm m_form(*www_form); |
| 1329 m_form.signon_realm = "http://m.facebook.com"; | 1282 m_form.signon_realm = "http://m.facebook.com"; |
| 1330 m_form.origin = GURL("http://m.facebook.com/index.html"); | 1283 m_form.origin = GURL("http://m.facebook.com/index.html"); |
| 1331 | 1284 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 // The old form doesn't have elements names. | 1354 // The old form doesn't have elements names. |
| 1402 PasswordFormData www_form_data_facebook_old = { | 1355 PasswordFormData www_form_data_facebook_old = { |
| 1403 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1356 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1404 "http://www.facebook.com/index.html", "login", L"", L"", | 1357 "http://www.facebook.com/index.html", "login", L"", L"", |
| 1405 L"", L"joe_user", L"oldsekrit", true, false, 0 }; | 1358 L"", L"joe_user", L"oldsekrit", true, false, 0 }; |
| 1406 PasswordFormData www_form_data_other = { | 1359 PasswordFormData www_form_data_other = { |
| 1407 PasswordForm::SCHEME_HTML, "http://different.com/", | 1360 PasswordForm::SCHEME_HTML, "http://different.com/", |
| 1408 "http://different.com/index.html", "login", L"submit", L"username", | 1361 "http://different.com/index.html", "login", L"submit", L"username", |
| 1409 L"password", L"different_joe_user", L"sekrit", true, false, 0 }; | 1362 L"password", L"different_joe_user", L"sekrit", true, false, 0 }; |
| 1410 scoped_ptr<PasswordForm> form_facebook = | 1363 scoped_ptr<PasswordForm> form_facebook = |
| 1411 CreatePasswordFormFromData(www_form_data_facebook); | 1364 CreatePasswordFormFromDataForTesting(www_form_data_facebook); |
| 1412 scoped_ptr<PasswordForm> form_facebook_old = | 1365 scoped_ptr<PasswordForm> form_facebook_old = |
| 1413 CreatePasswordFormFromData(www_form_data_facebook_old); | 1366 CreatePasswordFormFromDataForTesting(www_form_data_facebook_old); |
| 1414 scoped_ptr<PasswordForm> form_other = | 1367 scoped_ptr<PasswordForm> form_other = |
| 1415 CreatePasswordFormFromData(www_form_data_other); | 1368 CreatePasswordFormFromDataForTesting(www_form_data_other); |
| 1416 base::Time now = base::Time::Now(); | 1369 base::Time now = base::Time::Now(); |
| 1417 // TODO(vasilii): remove the next line once crbug/374132 is fixed. | 1370 // TODO(vasilii): remove the next line once crbug/374132 is fixed. |
| 1418 now = base::Time::FromTimeT(now.ToTimeT()); | 1371 now = base::Time::FromTimeT(now.ToTimeT()); |
| 1419 base::Time next_day = now + base::TimeDelta::FromDays(1); | 1372 base::Time next_day = now + base::TimeDelta::FromDays(1); |
| 1420 if (check_created) { | 1373 if (check_created) { |
| 1421 form_facebook_old->date_created = now; | 1374 form_facebook_old->date_created = now; |
| 1422 form_facebook->date_created = next_day; | 1375 form_facebook->date_created = next_day; |
| 1423 form_other->date_created = next_day; | 1376 form_other->date_created = next_day; |
| 1424 } else { | 1377 } else { |
| 1425 form_facebook_old->date_synced = now; | 1378 form_facebook_old->date_synced = now; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1505 | 1458 |
| 1506 // Add a password through the adapter. It has the "Chrome" creator tag. | 1459 // Add a password through the adapter. It has the "Chrome" creator tag. |
| 1507 // However, it's not referenced by the password database. | 1460 // However, it's not referenced by the password database. |
| 1508 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain()); | 1461 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain()); |
| 1509 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1462 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 1510 PasswordFormData www_form_data1 = { | 1463 PasswordFormData www_form_data1 = { |
| 1511 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1464 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1512 "http://www.facebook.com/index.html", "login", L"username", L"password", | 1465 "http://www.facebook.com/index.html", "login", L"username", L"password", |
| 1513 L"submit", L"joe_user", L"sekrit", true, false, 1 }; | 1466 L"submit", L"joe_user", L"sekrit", true, false, 1 }; |
| 1514 scoped_ptr<PasswordForm> www_form = | 1467 scoped_ptr<PasswordForm> www_form = |
| 1515 CreatePasswordFormFromData(www_form_data1); | 1468 CreatePasswordFormFromDataForTesting(www_form_data1); |
| 1516 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*www_form)); | 1469 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*www_form)); |
| 1517 | 1470 |
| 1518 // Add a password from the current profile. | 1471 // Add a password from the current profile. |
| 1519 PasswordFormData www_form_data2 = { | 1472 PasswordFormData www_form_data2 = { |
| 1520 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1473 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1521 "http://www.facebook.com/index.html", "login", L"username", L"password", | 1474 "http://www.facebook.com/index.html", "login", L"username", L"password", |
| 1522 L"submit", L"not_joe_user", L"12345", true, false, 1 }; | 1475 L"submit", L"not_joe_user", L"12345", true, false, 1 }; |
| 1523 www_form = CreatePasswordFormFromData(www_form_data2); | 1476 www_form = CreatePasswordFormFromDataForTesting(www_form_data2); |
| 1524 store_->AddLogin(*www_form); | 1477 store_->AddLogin(*www_form); |
| 1525 FinishAsyncProcessing(); | 1478 FinishAsyncProcessing(); |
| 1526 | 1479 |
| 1527 ScopedVector<PasswordForm> matching_items; | 1480 ScopedVector<PasswordForm> matching_items; |
| 1528 login_db()->GetLogins(*www_form, &matching_items); | 1481 login_db()->GetLogins(*www_form, &matching_items); |
| 1529 EXPECT_EQ(1u, matching_items.size()); | 1482 EXPECT_EQ(1u, matching_items.size()); |
| 1530 matching_items.clear(); | 1483 matching_items.clear(); |
| 1531 | 1484 |
| 1532 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); | 1485 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); |
| 1533 FinishAsyncProcessing(); | 1486 FinishAsyncProcessing(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1558 ClosePasswordStore(); | 1511 ClosePasswordStore(); |
| 1559 | 1512 |
| 1560 base::WaitableEvent event(false, false); | 1513 base::WaitableEvent event(false, false); |
| 1561 CreateAndInitPasswordStore(make_scoped_ptr<password_manager::LoginDatabase>( | 1514 CreateAndInitPasswordStore(make_scoped_ptr<password_manager::LoginDatabase>( |
| 1562 new SlowToInitLoginDatabase(test_login_db_file_path(), &event))); | 1515 new SlowToInitLoginDatabase(test_login_db_file_path(), &event))); |
| 1563 | 1516 |
| 1564 PasswordFormData www_form_data = { | 1517 PasswordFormData www_form_data = { |
| 1565 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1518 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1566 "http://www.facebook.com/index.html", "login", L"username", L"password", | 1519 "http://www.facebook.com/index.html", "login", L"username", L"password", |
| 1567 L"submit", L"not_joe_user", L"12345", true, false, 1}; | 1520 L"submit", L"not_joe_user", L"12345", true, false, 1}; |
| 1568 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(www_form_data); | 1521 scoped_ptr<PasswordForm> form = |
| 1522 CreatePasswordFormFromDataForTesting(www_form_data); |
| 1569 store()->AddLogin(*form); | 1523 store()->AddLogin(*form); |
| 1570 | 1524 |
| 1571 MockPasswordStoreConsumer mock_consumer; | 1525 MockPasswordStoreConsumer mock_consumer; |
| 1572 store()->GetLogins(*form, PasswordStore::ALLOW_PROMPT, &mock_consumer); | 1526 store()->GetLogins(*form, PasswordStore::ALLOW_PROMPT, &mock_consumer); |
| 1573 | 1527 |
| 1574 // Now the read/write tasks are scheduled, let the DB initialization proceed. | 1528 // Now the read/write tasks are scheduled, let the DB initialization proceed. |
| 1575 event.Signal(); | 1529 event.Signal(); |
| 1576 | 1530 |
| 1577 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u))) | 1531 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u))) |
| 1578 .WillOnce(QuitUIMessageLoop()); | 1532 .WillOnce(QuitUIMessageLoop()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1591 EXPECT_FALSE(login_db()); | 1545 EXPECT_FALSE(login_db()); |
| 1592 | 1546 |
| 1593 testing::StrictMock<MockPasswordStoreObserver> mock_observer; | 1547 testing::StrictMock<MockPasswordStoreObserver> mock_observer; |
| 1594 store()->AddObserver(&mock_observer); | 1548 store()->AddObserver(&mock_observer); |
| 1595 | 1549 |
| 1596 // Add a new autofillable login + a blacklisted login. | 1550 // Add a new autofillable login + a blacklisted login. |
| 1597 PasswordFormData www_form_data = { | 1551 PasswordFormData www_form_data = { |
| 1598 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | 1552 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| 1599 "http://www.facebook.com/index.html", "login", L"username", L"password", | 1553 "http://www.facebook.com/index.html", "login", L"username", L"password", |
| 1600 L"submit", L"not_joe_user", L"12345", true, false, 1}; | 1554 L"submit", L"not_joe_user", L"12345", true, false, 1}; |
| 1601 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(www_form_data); | 1555 scoped_ptr<PasswordForm> form = |
| 1556 CreatePasswordFormFromDataForTesting(www_form_data); |
| 1602 scoped_ptr<PasswordForm> blacklisted_form(new PasswordForm(*form)); | 1557 scoped_ptr<PasswordForm> blacklisted_form(new PasswordForm(*form)); |
| 1603 blacklisted_form->signon_realm = "http://foo.example.com"; | 1558 blacklisted_form->signon_realm = "http://foo.example.com"; |
| 1604 blacklisted_form->origin = GURL("http://foo.example.com/origin"); | 1559 blacklisted_form->origin = GURL("http://foo.example.com/origin"); |
| 1605 blacklisted_form->action = GURL("http://foo.example.com/action"); | 1560 blacklisted_form->action = GURL("http://foo.example.com/action"); |
| 1606 blacklisted_form->blacklisted_by_user = true; | 1561 blacklisted_form->blacklisted_by_user = true; |
| 1607 store()->AddLogin(*form); | 1562 store()->AddLogin(*form); |
| 1608 store()->AddLogin(*blacklisted_form); | 1563 store()->AddLogin(*blacklisted_form); |
| 1609 FinishAsyncProcessing(); | 1564 FinishAsyncProcessing(); |
| 1610 | 1565 |
| 1611 // Get all logins; autofillable logins; blacklisted logins. | 1566 // Get all logins; autofillable logins; blacklisted logins. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1635 | 1590 |
| 1636 // Delete one login; a range of logins. | 1591 // Delete one login; a range of logins. |
| 1637 store()->RemoveLogin(*form); | 1592 store()->RemoveLogin(*form); |
| 1638 store()->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max()); | 1593 store()->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max()); |
| 1639 store()->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max()); | 1594 store()->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max()); |
| 1640 FinishAsyncProcessing(); | 1595 FinishAsyncProcessing(); |
| 1641 | 1596 |
| 1642 // Verify no notifications are fired during shutdown either. | 1597 // Verify no notifications are fired during shutdown either. |
| 1643 ClosePasswordStore(); | 1598 ClosePasswordStore(); |
| 1644 } | 1599 } |
| OLD | NEW |