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/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
19 #include "chrome/browser/chromeos/cros/cros_library.h" | 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
20 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" | |
21 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 20 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
22 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" | 21 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" |
23 #include "chrome/browser/chromeos/login/authenticator.h" | 22 #include "chrome/browser/chromeos/login/authenticator.h" |
24 #include "chrome/browser/chromeos/login/login_status_consumer.h" | 23 #include "chrome/browser/chromeos/login/login_status_consumer.h" |
25 #include "chrome/browser/chromeos/login/user_manager.h" | 24 #include "chrome/browser/chromeos/login/user_manager.h" |
26 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" | 25 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" |
27 #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h" | 26 #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h" |
28 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 27 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
29 #include "chrome/browser/chromeos/settings/cros_settings.h" | 28 #include "chrome/browser/chromeos/settings/cros_settings.h" |
30 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 29 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
31 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 30 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
32 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" | 31 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" |
33 #include "chrome/browser/io_thread.h" | 32 #include "chrome/browser/io_thread.h" |
34 #include "chrome/browser/net/predictor.h" | 33 #include "chrome/browser/net/predictor.h" |
35 #include "chrome/browser/policy/browser_policy_connector.h" | 34 #include "chrome/browser/policy/browser_policy_connector.h" |
36 #include "chrome/browser/policy/cloud/device_management_service.h" | 35 #include "chrome/browser/policy/cloud/device_management_service.h" |
37 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" | 36 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" |
38 #include "chrome/browser/policy/policy_service.h" | 37 #include "chrome/browser/policy/policy_service.h" |
39 #include "chrome/browser/profiles/profile_manager.h" | 38 #include "chrome/browser/profiles/profile_manager.h" |
40 #include "chrome/browser/rlz/rlz.h" | 39 #include "chrome/browser/rlz/rlz.h" |
41 #include "chrome/common/chrome_notification_types.h" | 40 #include "chrome/common/chrome_notification_types.h" |
42 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
43 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
44 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
45 #include "chrome/test/base/scoped_testing_local_state.h" | 44 #include "chrome/test/base/scoped_testing_local_state.h" |
46 #include "chrome/test/base/testing_browser_process.h" | 45 #include "chrome/test/base/testing_browser_process.h" |
47 #include "chromeos/chromeos_switches.h" | 46 #include "chromeos/chromeos_switches.h" |
48 #include "chromeos/cryptohome/mock_async_method_caller.h" | 47 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 48 #include "chromeos/cryptohome/mock_cryptohome_library.h" |
49 #include "chromeos/dbus/mock_cryptohome_client.h" | 49 #include "chromeos/dbus/mock_cryptohome_client.h" |
50 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 50 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
51 #include "chromeos/dbus/mock_session_manager_client.h" | 51 #include "chromeos/dbus/mock_session_manager_client.h" |
52 #include "chromeos/disks/disk_mount_manager.h" | 52 #include "chromeos/disks/disk_mount_manager.h" |
53 #include "chromeos/disks/mock_disk_mount_manager.h" | 53 #include "chromeos/disks/mock_disk_mount_manager.h" |
54 #include "chromeos/login/login_state.h" | 54 #include "chromeos/login/login_state.h" |
55 #include "content/public/browser/browser_thread.h" | 55 #include "content/public/browser/browser_thread.h" |
56 #include "content/public/test/test_browser_thread.h" | 56 #include "content/public/test/test_browser_thread.h" |
57 #include "content/public/test/test_utils.h" | 57 #include "content/public/test/test_utils.h" |
58 #include "google_apis/gaia/gaia_auth_consumer.h" | 58 #include "google_apis/gaia/gaia_auth_consumer.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // loop for the IO thread. | 167 // loop for the IO thread. |
168 LoginUtilsTest() | 168 LoginUtilsTest() |
169 : fake_io_thread_completion_(false, false), | 169 : fake_io_thread_completion_(false, false), |
170 fake_io_thread_("fake_io_thread"), | 170 fake_io_thread_("fake_io_thread"), |
171 loop_(MessageLoop::TYPE_IO), | 171 loop_(MessageLoop::TYPE_IO), |
172 browser_process_(TestingBrowserProcess::GetGlobal()), | 172 browser_process_(TestingBrowserProcess::GetGlobal()), |
173 local_state_(browser_process_), | 173 local_state_(browser_process_), |
174 ui_thread_(BrowserThread::UI, &loop_), | 174 ui_thread_(BrowserThread::UI, &loop_), |
175 db_thread_(BrowserThread::DB, &loop_), | 175 db_thread_(BrowserThread::DB, &loop_), |
176 file_thread_(BrowserThread::FILE, &loop_), | 176 file_thread_(BrowserThread::FILE, &loop_), |
| 177 mock_input_method_manager_(NULL), |
177 mock_async_method_caller_(NULL), | 178 mock_async_method_caller_(NULL), |
178 connector_(NULL), | 179 connector_(NULL), |
179 cryptohome_(NULL), | 180 cryptohome_(NULL), |
180 cryptohome_client_(NULL), | 181 cryptohome_client_(NULL), |
181 prepared_profile_(NULL) {} | 182 prepared_profile_(NULL) {} |
182 | 183 |
183 virtual void SetUp() OVERRIDE { | 184 virtual void SetUp() OVERRIDE { |
184 // This test is not a full blown InProcessBrowserTest, and doesn't have | 185 // This test is not a full blown InProcessBrowserTest, and doesn't have |
185 // all the usual threads running. However a lot of subsystems pulled from | 186 // all the usual threads running. However a lot of subsystems pulled from |
186 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that | 187 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that |
(...skipping 28 matching lines...) Expand all Loading... |
215 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 216 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
216 command_line->AppendSwitchASCII( | 217 command_line->AppendSwitchASCII( |
217 ::switches::kDeviceManagementUrl, kDMServer); | 218 ::switches::kDeviceManagementUrl, kDMServer); |
218 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 219 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
219 | 220 |
220 // DBusThreadManager should be initialized before io_thread_state_, as | 221 // DBusThreadManager should be initialized before io_thread_state_, as |
221 // DBusThreadManager is used from chromeos::ProxyConfigServiceImpl, | 222 // DBusThreadManager is used from chromeos::ProxyConfigServiceImpl, |
222 // which is part of io_thread_state_. | 223 // which is part of io_thread_state_. |
223 DBusThreadManager::InitializeForTesting(&mock_dbus_thread_manager_); | 224 DBusThreadManager::InitializeForTesting(&mock_dbus_thread_manager_); |
224 | 225 |
| 226 CryptohomeLibrary::Initialize(); |
225 LoginState::Initialize(); | 227 LoginState::Initialize(); |
226 ConnectivityStateHelper::InitializeForTesting( | 228 ConnectivityStateHelper::SetForTest(&mock_connectivity_state_helper_); |
227 &mock_connectivity_state_helper_); | |
228 | 229 |
229 input_method::InitializeForTesting(&mock_input_method_manager_); | 230 mock_input_method_manager_ = new input_method::MockInputMethodManager(); |
| 231 input_method::InitializeForTesting(mock_input_method_manager_); |
230 disks::DiskMountManager::InitializeForTesting(&mock_disk_mount_manager_); | 232 disks::DiskMountManager::InitializeForTesting(&mock_disk_mount_manager_); |
231 mock_disk_mount_manager_.SetupDefaultReplies(); | 233 mock_disk_mount_manager_.SetupDefaultReplies(); |
232 | 234 |
233 // Likewise, SessionManagerClient should also be initialized before | 235 // Likewise, SessionManagerClient should also be initialized before |
234 // io_thread_state_. | 236 // io_thread_state_. |
235 MockSessionManagerClient* session_managed_client = | 237 MockSessionManagerClient* session_managed_client = |
236 mock_dbus_thread_manager_.mock_session_manager_client(); | 238 mock_dbus_thread_manager_.mock_session_manager_client(); |
237 EXPECT_CALL(*session_managed_client, RetrieveDevicePolicy(_)) | 239 EXPECT_CALL(*session_managed_client, RetrieveDevicePolicy(_)) |
238 .WillRepeatedly( | 240 .WillRepeatedly( |
239 MockSessionManagerClientRetrievePolicyCallback(&device_policy_)); | 241 MockSessionManagerClientRetrievePolicyCallback(&device_policy_)); |
240 EXPECT_CALL(*session_managed_client, RetrieveUserPolicy(_)) | 242 EXPECT_CALL(*session_managed_client, RetrieveUserPolicy(_)) |
241 .WillRepeatedly( | 243 .WillRepeatedly( |
242 MockSessionManagerClientRetrievePolicyCallback(&user_policy_)); | 244 MockSessionManagerClientRetrievePolicyCallback(&user_policy_)); |
243 EXPECT_CALL(*session_managed_client, StoreUserPolicy(_, _)) | 245 EXPECT_CALL(*session_managed_client, StoreUserPolicy(_, _)) |
244 .WillRepeatedly( | 246 .WillRepeatedly( |
245 DoAll(SaveArg<0>(&user_policy_), | 247 DoAll(SaveArg<0>(&user_policy_), |
246 MockSessionManagerClientStorePolicyCallback(true))); | 248 MockSessionManagerClientStorePolicyCallback(true))); |
247 | 249 |
248 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller; | 250 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller; |
249 cryptohome::AsyncMethodCaller::InitializeForTesting( | 251 cryptohome::AsyncMethodCaller::InitializeForTesting( |
250 mock_async_method_caller_); | 252 mock_async_method_caller_); |
251 | 253 |
252 CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi(); | 254 cryptohome_.reset(new MockCryptohomeLibrary()); |
253 ASSERT_TRUE(test_api); | |
254 | |
255 cryptohome_ = new MockCryptohomeLibrary(); | |
256 EXPECT_CALL(*cryptohome_, InstallAttributesIsInvalid()) | 255 EXPECT_CALL(*cryptohome_, InstallAttributesIsInvalid()) |
257 .WillRepeatedly(Return(false)); | 256 .WillRepeatedly(Return(false)); |
258 EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall()) | 257 EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall()) |
259 .WillRepeatedly(Return(true)); | 258 .WillRepeatedly(Return(true)); |
260 EXPECT_CALL(*cryptohome_, TpmIsEnabled()) | 259 EXPECT_CALL(*cryptohome_, TpmIsEnabled()) |
261 .WillRepeatedly(Return(false)); | 260 .WillRepeatedly(Return(false)); |
262 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwned, kTrue)) | 261 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwned, kTrue)) |
263 .WillRepeatedly(Return(true)); | 262 .WillRepeatedly(Return(true)); |
264 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwner, | 263 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwner, |
265 kUsername)) | 264 kUsername)) |
(...skipping 17 matching lines...) Expand all Loading... |
283 Return(true))); | 282 Return(true))); |
284 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDomain, _)) | 283 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDomain, _)) |
285 .WillRepeatedly(DoAll(SetArgPointee<1>(kDomain), | 284 .WillRepeatedly(DoAll(SetArgPointee<1>(kDomain), |
286 Return(true))); | 285 Return(true))); |
287 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseMode, _)) | 286 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseMode, _)) |
288 .WillRepeatedly(DoAll(SetArgPointee<1>(kMode), | 287 .WillRepeatedly(DoAll(SetArgPointee<1>(kMode), |
289 Return(true))); | 288 Return(true))); |
290 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _)) | 289 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _)) |
291 .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId), | 290 .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId), |
292 Return(true))); | 291 Return(true))); |
293 test_api->SetCryptohomeLibrary(cryptohome_, true); | 292 CryptohomeLibrary::SetForTest(cryptohome_.get()); |
294 | 293 |
295 cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client(); | 294 cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client(); |
296 EXPECT_CALL(*cryptohome_client_, IsMounted(_)); | 295 EXPECT_CALL(*cryptohome_client_, IsMounted(_)); |
297 | 296 |
298 test_cros_settings_.reset(new ScopedTestCrosSettings); | 297 test_cros_settings_.reset(new ScopedTestCrosSettings); |
299 | 298 |
300 browser_process_->SetProfileManager( | 299 browser_process_->SetProfileManager( |
301 new ProfileManagerWithoutInit(scoped_temp_dir_.path())); | 300 new ProfileManagerWithoutInit(scoped_temp_dir_.path())); |
302 connector_ = browser_process_->browser_policy_connector(); | 301 connector_ = browser_process_->browser_policy_connector(); |
303 connector_->Init(local_state_.Get(), | 302 connector_->Init(local_state_.Get(), |
(...skipping 18 matching lines...) Expand all Loading... |
322 mock_async_method_caller_ = NULL; | 321 mock_async_method_caller_ = NULL; |
323 | 322 |
324 UserManager::Get()->Shutdown(); | 323 UserManager::Get()->Shutdown(); |
325 | 324 |
326 InvokeOnIO( | 325 InvokeOnIO( |
327 base::Bind(&LoginUtilsTest::TearDownOnIO, base::Unretained(this))); | 326 base::Bind(&LoginUtilsTest::TearDownOnIO, base::Unretained(this))); |
328 | 327 |
329 // LoginUtils instance must not outlive Profile instances. | 328 // LoginUtils instance must not outlive Profile instances. |
330 LoginUtils::Set(NULL); | 329 LoginUtils::Set(NULL); |
331 | 330 |
| 331 input_method::Shutdown(); |
| 332 ConnectivityStateHelper::SetForTest(NULL); |
332 LoginState::Shutdown(); | 333 LoginState::Shutdown(); |
| 334 CryptohomeLibrary::Shutdown(); |
333 | 335 |
334 // These trigger some tasks that have to run while BrowserThread::UI | 336 // These trigger some tasks that have to run while BrowserThread::UI |
335 // exists. Delete all the profiles before deleting the connector. | 337 // exists. Delete all the profiles before deleting the connector. |
336 browser_process_->SetProfileManager(NULL); | 338 browser_process_->SetProfileManager(NULL); |
337 connector_ = NULL; | 339 connector_ = NULL; |
338 browser_process_->SetBrowserPolicyConnector(NULL); | 340 browser_process_->SetBrowserPolicyConnector(NULL); |
339 QuitIOLoop(); | 341 QuitIOLoop(); |
340 RunUntilIdle(); | 342 RunUntilIdle(); |
| 343 |
| 344 CryptohomeLibrary::SetForTest(NULL); |
341 } | 345 } |
342 | 346 |
343 void TearDownOnIO() { | 347 void TearDownOnIO() { |
344 // chrome_browser_net::Predictor usually skips its shutdown routines on | 348 // chrome_browser_net::Predictor usually skips its shutdown routines on |
345 // unit_tests, but does the full thing when | 349 // unit_tests, but does the full thing when |
346 // g_browser_process->profile_manager() is valid during initialization. | 350 // g_browser_process->profile_manager() is valid during initialization. |
347 // That includes a WaitableEvent on UI waiting for a task on IO, so that | 351 // That includes a WaitableEvent on UI waiting for a task on IO, so that |
348 // task must execute. Do it directly from here now. | 352 // task must execute. Do it directly from here now. |
349 std::vector<Profile*> profiles = | 353 std::vector<Profile*> profiles = |
350 browser_process_->profile_manager()->GetLoadedProfiles(); | 354 browser_process_->profile_manager()->GetLoadedProfiles(); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 TestingBrowserProcess* browser_process_; | 530 TestingBrowserProcess* browser_process_; |
527 ScopedTestingLocalState local_state_; | 531 ScopedTestingLocalState local_state_; |
528 | 532 |
529 content::TestBrowserThread ui_thread_; | 533 content::TestBrowserThread ui_thread_; |
530 content::TestBrowserThread db_thread_; | 534 content::TestBrowserThread db_thread_; |
531 content::TestBrowserThread file_thread_; | 535 content::TestBrowserThread file_thread_; |
532 scoped_ptr<content::TestBrowserThread> io_thread_; | 536 scoped_ptr<content::TestBrowserThread> io_thread_; |
533 scoped_ptr<IOThread> io_thread_state_; | 537 scoped_ptr<IOThread> io_thread_state_; |
534 | 538 |
535 MockDBusThreadManager mock_dbus_thread_manager_; | 539 MockDBusThreadManager mock_dbus_thread_manager_; |
536 input_method::MockInputMethodManager mock_input_method_manager_; | 540 input_method::MockInputMethodManager* mock_input_method_manager_; |
537 disks::MockDiskMountManager mock_disk_mount_manager_; | 541 disks::MockDiskMountManager mock_disk_mount_manager_; |
538 net::TestURLFetcherFactory test_url_fetcher_factory_; | 542 net::TestURLFetcherFactory test_url_fetcher_factory_; |
539 MockConnectivityStateHelper mock_connectivity_state_helper_; | 543 MockConnectivityStateHelper mock_connectivity_state_helper_; |
540 | 544 |
541 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; | 545 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; |
542 | 546 |
543 policy::BrowserPolicyConnector* connector_; | 547 policy::BrowserPolicyConnector* connector_; |
544 MockCryptohomeLibrary* cryptohome_; | 548 scoped_ptr<MockCryptohomeLibrary> cryptohome_; |
545 MockCryptohomeClient* cryptohome_client_; | 549 MockCryptohomeClient* cryptohome_client_; |
546 | 550 |
547 // Initialized after |mock_dbus_thread_manager_| and |cryptohome_| are set up. | 551 // Initialized after |mock_dbus_thread_manager_| and |cryptohome_| are set up. |
548 scoped_ptr<ScopedTestCrosSettings> test_cros_settings_; | 552 scoped_ptr<ScopedTestCrosSettings> test_cros_settings_; |
549 | 553 |
550 Profile* prepared_profile_; | 554 Profile* prepared_profile_; |
551 | 555 |
552 base::Closure rlz_initialized_cb_; | 556 base::Closure rlz_initialized_cb_; |
553 | 557 |
554 private: | 558 private: |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 } | 743 } |
740 | 744 |
741 INSTANTIATE_TEST_CASE_P( | 745 INSTANTIATE_TEST_CASE_P( |
742 LoginUtilsBlockingLoginTestInstance, | 746 LoginUtilsBlockingLoginTestInstance, |
743 LoginUtilsBlockingLoginTest, | 747 LoginUtilsBlockingLoginTest, |
744 testing::Values(0, 1, 2, 3, 4, 5)); | 748 testing::Values(0, 1, 2, 3, 4, 5)); |
745 | 749 |
746 } // namespace | 750 } // namespace |
747 | 751 |
748 } | 752 } |
OLD | NEW |