Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: chrome/browser/chromeos/login/login_utils_browsertest.cc

Issue 14200028: Make CrosSettings and DeviceSettingsService non Lazy instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 20 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
21 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" 21 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
22 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" 22 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
23 #include "chrome/browser/chromeos/login/authenticator.h" 23 #include "chrome/browser/chromeos/login/authenticator.h"
24 #include "chrome/browser/chromeos/login/login_status_consumer.h" 24 #include "chrome/browser/chromeos/login/login_status_consumer.h"
25 #include "chrome/browser/chromeos/login/user_manager.h" 25 #include "chrome/browser/chromeos/login/user_manager.h"
26 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" 26 #include "chrome/browser/chromeos/net/connectivity_state_helper.h"
27 #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h" 27 #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h"
28 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 28 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
29 #include "chrome/browser/chromeos/settings/cros_settings.h"
29 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 30 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
30 #include "chrome/browser/io_thread.h" 31 #include "chrome/browser/io_thread.h"
31 #include "chrome/browser/net/predictor.h" 32 #include "chrome/browser/net/predictor.h"
32 #include "chrome/browser/policy/browser_policy_connector.h" 33 #include "chrome/browser/policy/browser_policy_connector.h"
33 #include "chrome/browser/policy/cloud/device_management_service.h" 34 #include "chrome/browser/policy/cloud/device_management_service.h"
34 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" 35 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h"
35 #include "chrome/browser/policy/policy_service.h" 36 #include "chrome/browser/policy/policy_service.h"
36 #include "chrome/browser/profiles/profile_manager.h" 37 #include "chrome/browser/profiles/profile_manager.h"
37 #include "chrome/browser/rlz/rlz.h" 38 #include "chrome/browser/rlz/rlz.h"
38 #include "chrome/common/chrome_notification_types.h" 39 #include "chrome/common/chrome_notification_types.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 .WillRepeatedly(DoAll(SetArgPointee<1>(kMode), 284 .WillRepeatedly(DoAll(SetArgPointee<1>(kMode),
284 Return(true))); 285 Return(true)));
285 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _)) 286 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _))
286 .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId), 287 .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId),
287 Return(true))); 288 Return(true)));
288 test_api->SetCryptohomeLibrary(cryptohome_, true); 289 test_api->SetCryptohomeLibrary(cryptohome_, true);
289 290
290 cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client(); 291 cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client();
291 EXPECT_CALL(*cryptohome_client_, IsMounted(_)); 292 EXPECT_CALL(*cryptohome_client_, IsMounted(_));
292 293
294 test_cros_settings_.reset(new ScopedTestCrosSettings);
295
293 browser_process_->SetProfileManager( 296 browser_process_->SetProfileManager(
294 new ProfileManagerWithoutInit(scoped_temp_dir_.path())); 297 new ProfileManagerWithoutInit(scoped_temp_dir_.path()));
295 connector_ = browser_process_->browser_policy_connector(); 298 connector_ = browser_process_->browser_policy_connector();
296 connector_->Init(local_state_.Get(), 299 connector_->Init(local_state_.Get(),
297 browser_process_->system_request_context()); 300 browser_process_->system_request_context());
298 301
299 io_thread_state_.reset(new IOThread(local_state_.Get(), 302 io_thread_state_.reset(new IOThread(local_state_.Get(),
300 browser_process_->policy_service(), 303 browser_process_->policy_service(),
301 NULL, NULL)); 304 NULL, NULL));
302 browser_process_->SetIOThread(io_thread_state_.get()); 305 browser_process_->SetIOThread(io_thread_state_.get());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 policy::EnterpriseInstallAttributes::LockResult result; 415 policy::EnterpriseInstallAttributes::LockResult result;
413 connector_->GetInstallAttributes()->LockDevice( 416 connector_->GetInstallAttributes()->LockDevice(
414 username, policy::DEVICE_MODE_ENTERPRISE, kDeviceId, 417 username, policy::DEVICE_MODE_ENTERPRISE, kDeviceId,
415 base::Bind(&CopyLockResult, &loop, &result)); 418 base::Bind(&CopyLockResult, &loop, &result));
416 loop.Run(); 419 loop.Run();
417 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS, result); 420 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS, result);
418 RunUntilIdle(); 421 RunUntilIdle();
419 } 422 }
420 423
421 void PrepareProfile(const std::string& username) { 424 void PrepareProfile(const std::string& username) {
422 ScopedDeviceSettingsTestHelper device_settings_test_helper; 425 DeviceSettingsTestHelper device_settings_test_helper;
426 DeviceSettingsService::Get()->SetSessionManager(
bartfab (slow) 2013/04/17 11:14:10 Nit: #include "chrome/browser/chromeos/settings/de
stevenjb 2013/04/17 16:27:12 Done.
427 &device_settings_test_helper, new MockOwnerKeyUtil());
bartfab (slow) 2013/04/17 11:14:10 Nit: #include "chrome/browser/chromeos/settings/mo
stevenjb 2013/04/17 16:27:12 Done.
428
423 MockSessionManagerClient* session_manager_client = 429 MockSessionManagerClient* session_manager_client =
424 mock_dbus_thread_manager_.mock_session_manager_client(); 430 mock_dbus_thread_manager_.mock_session_manager_client();
425 EXPECT_CALL(*session_manager_client, StartSession(_)); 431 EXPECT_CALL(*session_manager_client, StartSession(_));
426 EXPECT_CALL(*cryptohome_, GetSystemSalt()) 432 EXPECT_CALL(*cryptohome_, GetSystemSalt())
427 .WillRepeatedly(Return(std::string("stub_system_salt"))); 433 .WillRepeatedly(Return(std::string("stub_system_salt")));
428 EXPECT_CALL(*mock_async_method_caller_, AsyncMount(_, _, _, _)) 434 EXPECT_CALL(*mock_async_method_caller_, AsyncMount(_, _, _, _))
429 .WillRepeatedly(Return()); 435 .WillRepeatedly(Return());
430 EXPECT_CALL(*mock_async_method_caller_, AsyncGetSanitizedUsername(_, _)) 436 EXPECT_CALL(*mock_async_method_caller_, AsyncGetSanitizedUsername(_, _))
431 .WillRepeatedly(Return()); 437 .WillRepeatedly(Return());
432 438
433 scoped_refptr<Authenticator> authenticator = 439 scoped_refptr<Authenticator> authenticator =
434 LoginUtils::Get()->CreateAuthenticator(this); 440 LoginUtils::Get()->CreateAuthenticator(this);
435 authenticator->CompleteLogin(ProfileManager::GetDefaultProfile(), 441 authenticator->CompleteLogin(ProfileManager::GetDefaultProfile(),
436 UserContext(username, 442 UserContext(username,
437 "password", 443 "password",
438 std::string(), 444 std::string(),
439 username)); // username_hash 445 username)); // username_hash
440 446
441 const bool kUsingOAuth = true; 447 const bool kUsingOAuth = true;
442 // Setting |kHasCookies| to false prevents ProfileAuthData::Transfer from 448 // Setting |kHasCookies| to false prevents ProfileAuthData::Transfer from
443 // waiting for an IO task before proceeding. 449 // waiting for an IO task before proceeding.
444 const bool kHasCookies = false; 450 const bool kHasCookies = false;
445 LoginUtils::Get()->PrepareProfile( 451 LoginUtils::Get()->PrepareProfile(
446 UserContext(username, "password", std::string(), username), 452 UserContext(username, "password", std::string(), username),
447 std::string(), kUsingOAuth, kHasCookies, this); 453 std::string(), kUsingOAuth, kHasCookies, this);
448 device_settings_test_helper.Flush(); 454 device_settings_test_helper.Flush();
449 RunUntilIdle(); 455 RunUntilIdle();
456
457 DeviceSettingsService::Get()->UnsetSessionManager();
450 } 458 }
451 459
452 net::TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) { 460 net::TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) {
453 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); 461 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0);
454 EXPECT_TRUE(fetcher); 462 EXPECT_TRUE(fetcher);
455 if (!fetcher) 463 if (!fetcher)
456 return NULL; 464 return NULL;
457 EXPECT_TRUE(fetcher->delegate()); 465 EXPECT_TRUE(fetcher->delegate());
458 EXPECT_TRUE(StartsWithASCII(fetcher->GetOriginalURL().spec(), 466 EXPECT_TRUE(StartsWithASCII(fetcher->GetOriginalURL().spec(),
459 expected_url, 467 expected_url,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 input_method::MockInputMethodManager mock_input_method_manager_; 530 input_method::MockInputMethodManager mock_input_method_manager_;
523 disks::MockDiskMountManager mock_disk_mount_manager_; 531 disks::MockDiskMountManager mock_disk_mount_manager_;
524 net::TestURLFetcherFactory test_url_fetcher_factory_; 532 net::TestURLFetcherFactory test_url_fetcher_factory_;
525 MockConnectivityStateHelper mock_connectivity_state_helper_; 533 MockConnectivityStateHelper mock_connectivity_state_helper_;
526 534
527 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; 535 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_;
528 536
529 policy::BrowserPolicyConnector* connector_; 537 policy::BrowserPolicyConnector* connector_;
530 MockCryptohomeLibrary* cryptohome_; 538 MockCryptohomeLibrary* cryptohome_;
531 MockCryptohomeClient* cryptohome_client_; 539 MockCryptohomeClient* cryptohome_client_;
540
541 // Initialized after |mock_dbus_thread_manager_| and |cryptohome_| are set up.
542 scoped_ptr<ScopedTestCrosSettings> test_cros_settings_;
543
532 Profile* prepared_profile_; 544 Profile* prepared_profile_;
533 545
534 base::Closure rlz_initialized_cb_; 546 base::Closure rlz_initialized_cb_;
535 547
536 private: 548 private:
537 base::ScopedTempDir scoped_temp_dir_; 549 base::ScopedTempDir scoped_temp_dir_;
538 550
539 std::string device_policy_; 551 std::string device_policy_;
540 std::string user_policy_; 552 std::string user_policy_;
541 553
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 733 }
722 734
723 INSTANTIATE_TEST_CASE_P( 735 INSTANTIATE_TEST_CASE_P(
724 LoginUtilsBlockingLoginTestInstance, 736 LoginUtilsBlockingLoginTestInstance,
725 LoginUtilsBlockingLoginTest, 737 LoginUtilsBlockingLoginTest,
726 testing::Values(0, 1, 2, 3, 4, 5)); 738 testing::Values(0, 1, 2, 3, 4, 5));
727 739
728 } // namespace 740 } // namespace
729 741
730 } 742 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698