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/chromeos/login/parallel_authenticator.h" | 5 #include "chrome/browser/chromeos/login/parallel_authenticator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "chrome/browser/chromeos/cros/cros_library.h" | 15 #include "chrome/browser/chromeos/cros/cros_library.h" |
16 #include "chrome/browser/chromeos/cros/mock_cert_library.h" | 16 #include "chrome/browser/chromeos/cros/mock_cert_library.h" |
17 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" | |
18 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h" | 17 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h" |
19 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" | 18 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
20 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 19 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
21 #include "chrome/browser/chromeos/login/test_attempt_state.h" | 20 #include "chrome/browser/chromeos/login/test_attempt_state.h" |
22 #include "chrome/browser/chromeos/login/user.h" | 21 #include "chrome/browser/chromeos/login/user.h" |
23 #include "chrome/browser/chromeos/settings/cros_settings.h" | 22 #include "chrome/browser/chromeos/settings/cros_settings.h" |
24 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 23 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
25 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
26 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
27 #include "chromeos/cryptohome/mock_async_method_caller.h" | 26 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 27 #include "chromeos/cryptohome/mock_cryptohome_library.h" |
28 #include "chromeos/dbus/mock_cryptohome_client.h" | 28 #include "chromeos/dbus/mock_cryptohome_client.h" |
29 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 29 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
30 #include "content/public/test/test_browser_thread.h" | 30 #include "content/public/test/test_browser_thread.h" |
31 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 31 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
32 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
33 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
34 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
35 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
37 #include "third_party/cros_system_api/dbus/service_constants.h" | 37 #include "third_party/cros_system_api/dbus/service_constants.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 DCHECK(!mock_caller_); | 71 DCHECK(!mock_caller_); |
72 } | 72 } |
73 | 73 |
74 virtual void SetUp() { | 74 virtual void SetUp() { |
75 mock_caller_ = new cryptohome::MockAsyncMethodCaller; | 75 mock_caller_ = new cryptohome::MockAsyncMethodCaller; |
76 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); | 76 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); |
77 | 77 |
78 chromeos::CrosLibrary::TestApi* test_api = | 78 chromeos::CrosLibrary::TestApi* test_api = |
79 chromeos::CrosLibrary::Get()->GetTestApi(); | 79 chromeos::CrosLibrary::Get()->GetTestApi(); |
80 | 80 |
81 mock_cryptohome_library_ = new MockCryptohomeLibrary(); | 81 mock_cryptohome_library_ .reset(new MockCryptohomeLibrary()); |
82 test_api->SetCryptohomeLibrary(mock_cryptohome_library_, true); | 82 CryptohomeLibrary::SetForTest(mock_cryptohome_library_.get()); |
83 | 83 |
84 mock_cert_library_ = new MockCertLibrary(); | 84 mock_cert_library_ = new MockCertLibrary(); |
85 EXPECT_CALL(*mock_cert_library_, LoadKeyStore()).Times(AnyNumber()); | 85 EXPECT_CALL(*mock_cert_library_, LoadKeyStore()).Times(AnyNumber()); |
86 test_api->SetCertLibrary(mock_cert_library_, true); | 86 test_api->SetCertLibrary(mock_cert_library_, true); |
87 | 87 |
88 io_thread_.Start(); | 88 io_thread_.Start(); |
89 | 89 |
90 auth_ = new ParallelAuthenticator(&consumer_); | 90 auth_ = new ParallelAuthenticator(&consumer_); |
91 auth_->set_using_oauth(false); | 91 auth_->set_using_oauth(false); |
92 state_.reset(new TestAttemptState(UserContext(username_, | 92 state_.reset(new TestAttemptState(UserContext(username_, |
93 password_, | 93 password_, |
94 std::string()), | 94 std::string()), |
95 hash_ascii_, | 95 hash_ascii_, |
96 "", | 96 "", |
97 "", | 97 "", |
98 User::USER_TYPE_REGULAR, | 98 User::USER_TYPE_REGULAR, |
99 false)); | 99 false)); |
100 } | 100 } |
101 | 101 |
102 // Tears down the test fixture. | 102 // Tears down the test fixture. |
103 virtual void TearDown() { | 103 virtual void TearDown() { |
104 // Prevent bogus gMock leak check from firing. | 104 CryptohomeLibrary::SetForTest(NULL); |
105 chromeos::CrosLibrary::TestApi* test_api = | |
106 chromeos::CrosLibrary::Get()->GetTestApi(); | |
107 test_api->SetCryptohomeLibrary(NULL, false); | |
108 | 105 |
109 cryptohome::AsyncMethodCaller::Shutdown(); | 106 cryptohome::AsyncMethodCaller::Shutdown(); |
110 mock_caller_ = NULL; | 107 mock_caller_ = NULL; |
111 } | 108 } |
112 | 109 |
113 base::FilePath PopulateTempFile(const char* data, int data_len) { | 110 base::FilePath PopulateTempFile(const char* data, int data_len) { |
114 base::FilePath out; | 111 base::FilePath out; |
115 FILE* tmp_file = file_util::CreateAndOpenTemporaryFile(&out); | 112 FILE* tmp_file = file_util::CreateAndOpenTemporaryFile(&out); |
116 EXPECT_NE(tmp_file, static_cast<FILE*>(NULL)); | 113 EXPECT_NE(tmp_file, static_cast<FILE*>(NULL)); |
117 EXPECT_EQ(file_util::WriteFile(out, data, data_len), data_len); | 114 EXPECT_EQ(file_util::WriteFile(out, data, data_len), data_len); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 std::string password_; | 214 std::string password_; |
218 std::string username_hash_; | 215 std::string username_hash_; |
219 std::string hash_ascii_; | 216 std::string hash_ascii_; |
220 | 217 |
221 ScopedStubCrosEnabler stub_cros_enabler_; | 218 ScopedStubCrosEnabler stub_cros_enabler_; |
222 ScopedDeviceSettingsTestHelper device_settings_test_helper_; | 219 ScopedDeviceSettingsTestHelper device_settings_test_helper_; |
223 ScopedTestCrosSettings test_cros_settings_; | 220 ScopedTestCrosSettings test_cros_settings_; |
224 | 221 |
225 // Mocks, destroyed by CrosLibrary class. | 222 // Mocks, destroyed by CrosLibrary class. |
226 MockCertLibrary* mock_cert_library_; | 223 MockCertLibrary* mock_cert_library_; |
227 MockCryptohomeLibrary* mock_cryptohome_library_; | |
228 ScopedMockUserManagerEnabler mock_user_manager_; | 224 ScopedMockUserManagerEnabler mock_user_manager_; |
229 | 225 |
| 226 scoped_ptr<MockCryptohomeLibrary> mock_cryptohome_library_; |
| 227 |
230 cryptohome::MockAsyncMethodCaller* mock_caller_; | 228 cryptohome::MockAsyncMethodCaller* mock_caller_; |
231 | 229 |
232 MockConsumer consumer_; | 230 MockConsumer consumer_; |
233 scoped_refptr<ParallelAuthenticator> auth_; | 231 scoped_refptr<ParallelAuthenticator> auth_; |
234 scoped_ptr<TestAttemptState> state_; | 232 scoped_ptr<TestAttemptState> state_; |
235 }; | 233 }; |
236 | 234 |
237 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { | 235 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { |
238 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username_, | 236 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username_, |
239 password_, | 237 password_, |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 .WillOnce(Return(std::string())) | 793 .WillOnce(Return(std::string())) |
796 .RetiresOnSaturation(); | 794 .RetiresOnSaturation(); |
797 | 795 |
798 auth_->AuthenticateToUnlock(UserContext(username_, | 796 auth_->AuthenticateToUnlock(UserContext(username_, |
799 std::string(), | 797 std::string(), |
800 std::string())); | 798 std::string())); |
801 message_loop_.Run(); | 799 message_loop_.Run(); |
802 } | 800 } |
803 | 801 |
804 } // namespace chromeos | 802 } // namespace chromeos |
OLD | NEW |