| 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/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/scoped_observer.h" | 10 #include "base/scoped_observer.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(TestPasswordStoreMac); | 81 DISALLOW_COPY_AND_ASSIGN(TestPasswordStoreMac); |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 } // namespace | 84 } // namespace |
| 85 | 85 |
| 86 #pragma mark - | 86 #pragma mark - |
| 87 | 87 |
| 88 class PasswordStoreMacInternalsTest : public testing::Test { | 88 class PasswordStoreMacInternalsTest : public testing::Test { |
| 89 public: | 89 public: |
| 90 virtual void SetUp() { | 90 void SetUp() override { |
| 91 MockAppleKeychain::KeychainTestData test_data[] = { | 91 MockAppleKeychain::KeychainTestData test_data[] = { |
| 92 // Basic HTML form. | 92 // Basic HTML form. |
| 93 { kSecAuthenticationTypeHTMLForm, "some.domain.com", | 93 { kSecAuthenticationTypeHTMLForm, "some.domain.com", |
| 94 kSecProtocolTypeHTTP, NULL, 0, NULL, "20020601171500Z", | 94 kSecProtocolTypeHTTP, NULL, 0, NULL, "20020601171500Z", |
| 95 "joe_user", "sekrit", false }, | 95 "joe_user", "sekrit", false }, |
| 96 // HTML form with path. | 96 // HTML form with path. |
| 97 { kSecAuthenticationTypeHTMLForm, "some.domain.com", | 97 { kSecAuthenticationTypeHTMLForm, "some.domain.com", |
| 98 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "19991231235959Z", | 98 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "19991231235959Z", |
| 99 "joe_user", "sekrit", false }, | 99 "joe_user", "sekrit", false }, |
| 100 // Secure HTML form with path. | 100 // Secure HTML form with path. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 128 "abc", "123", false }, | 128 "abc", "123", false }, |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 keychain_ = new MockAppleKeychain(); | 131 keychain_ = new MockAppleKeychain(); |
| 132 | 132 |
| 133 for (unsigned int i = 0; i < arraysize(test_data); ++i) { | 133 for (unsigned int i = 0; i < arraysize(test_data); ++i) { |
| 134 keychain_->AddTestItem(test_data[i]); | 134 keychain_->AddTestItem(test_data[i]); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 virtual void TearDown() { | 138 void TearDown() override { |
| 139 ExpectCreatesAndFreesBalanced(); | 139 ExpectCreatesAndFreesBalanced(); |
| 140 ExpectCreatorCodesSet(); | 140 ExpectCreatorCodesSet(); |
| 141 delete keychain_; | 141 delete keychain_; |
| 142 } | 142 } |
| 143 | 143 |
| 144 protected: | 144 protected: |
| 145 // Causes a test failure unless everything returned from keychain_'s | 145 // Causes a test failure unless everything returned from keychain_'s |
| 146 // ItemCopyAttributesAndData, SearchCreateFromAttributes, and SearchCopyNext | 146 // ItemCopyAttributesAndData, SearchCreateFromAttributes, and SearchCopyNext |
| 147 // was correctly freed. | 147 // was correctly freed. |
| 148 void ExpectCreatesAndFreesBalanced() { | 148 void ExpectCreatesAndFreesBalanced() { |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 EXPECT_EQ(arraysize(owned_password_data), owned_passwords.size()); | 1044 EXPECT_EQ(arraysize(owned_password_data), owned_passwords.size()); |
| 1045 STLDeleteElements(&owned_passwords); | 1045 STLDeleteElements(&owned_passwords); |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 #pragma mark - | 1048 #pragma mark - |
| 1049 | 1049 |
| 1050 class PasswordStoreMacTest : public testing::Test { | 1050 class PasswordStoreMacTest : public testing::Test { |
| 1051 public: | 1051 public: |
| 1052 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} | 1052 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 1053 | 1053 |
| 1054 virtual void SetUp() { | 1054 void SetUp() override { |
| 1055 login_db_ = new LoginDatabase(); | 1055 login_db_ = new LoginDatabase(); |
| 1056 ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); | 1056 ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); |
| 1057 base::FilePath db_file = db_dir_.path().AppendASCII("login.db"); | 1057 base::FilePath db_file = db_dir_.path().AppendASCII("login.db"); |
| 1058 ASSERT_TRUE(login_db_->Init(db_file)); | 1058 ASSERT_TRUE(login_db_->Init(db_file)); |
| 1059 | 1059 |
| 1060 keychain_ = new MockAppleKeychain(); | 1060 keychain_ = new MockAppleKeychain(); |
| 1061 | 1061 |
| 1062 store_ = new TestPasswordStoreMac( | 1062 store_ = new TestPasswordStoreMac( |
| 1063 base::MessageLoopProxy::current(), | 1063 base::MessageLoopProxy::current(), |
| 1064 base::MessageLoopProxy::current(), | 1064 base::MessageLoopProxy::current(), |
| 1065 keychain_, | 1065 keychain_, |
| 1066 login_db_); | 1066 login_db_); |
| 1067 ASSERT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 1067 ASSERT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
| 1068 } | 1068 } |
| 1069 | 1069 |
| 1070 virtual void TearDown() { | 1070 void TearDown() override { |
| 1071 store_->Shutdown(); | 1071 store_->Shutdown(); |
| 1072 EXPECT_FALSE(store_->GetBackgroundTaskRunner().get()); | 1072 EXPECT_FALSE(store_->GetBackgroundTaskRunner().get()); |
| 1073 } | 1073 } |
| 1074 | 1074 |
| 1075 void WaitForStoreUpdate() { | 1075 void WaitForStoreUpdate() { |
| 1076 // Do a store-level query to wait for all the operations above to be done. | 1076 // Do a store-level query to wait for all the operations above to be done. |
| 1077 MockPasswordStoreConsumer consumer; | 1077 MockPasswordStoreConsumer consumer; |
| 1078 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)) | 1078 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)) |
| 1079 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | 1079 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); |
| 1080 store_->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer); | 1080 store_->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1435 ASSERT_EQ(1u, matching_items.size()); | 1435 ASSERT_EQ(1u, matching_items.size()); |
| 1436 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); | 1436 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); |
| 1437 matching_items.clear(); | 1437 matching_items.clear(); |
| 1438 | 1438 |
| 1439 // Check the third-party password is still there. | 1439 // Check the third-party password is still there. |
| 1440 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); | 1440 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); |
| 1441 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | 1441 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( |
| 1442 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); | 1442 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); |
| 1443 ASSERT_EQ(1u, matching_items.size()); | 1443 ASSERT_EQ(1u, matching_items.size()); |
| 1444 } | 1444 } |
| OLD | NEW |