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