| 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/policy/user_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // a signin Profile to use its URLRequestContext. | 93 // a signin Profile to use its URLRequestContext. |
| 94 profile_manager_.reset( | 94 profile_manager_.reset( |
| 95 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 95 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 96 ASSERT_TRUE(profile_manager_->SetUp()); | 96 ASSERT_TRUE(profile_manager_->SetUp()); |
| 97 TestingProfile::TestingFactories factories; | 97 TestingProfile::TestingFactories factories; |
| 98 factories.push_back( | 98 factories.push_back( |
| 99 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), | 99 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 100 BuildFakeProfileOAuth2TokenService)); | 100 BuildFakeProfileOAuth2TokenService)); |
| 101 profile_ = profile_manager_->CreateTestingProfile( | 101 profile_ = profile_manager_->CreateTestingProfile( |
| 102 chrome::kInitialProfile, | 102 chrome::kInitialProfile, |
| 103 scoped_ptr<syncable_prefs::PrefServiceSyncable>(), | 103 std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), |
| 104 base::UTF8ToUTF16(""), 0, std::string(), factories); | 104 base::UTF8ToUTF16(""), 0, std::string(), factories); |
| 105 // Usually the signin Profile and the main Profile are separate, but since | 105 // Usually the signin Profile and the main Profile are separate, but since |
| 106 // the signin Profile is an OTR Profile then for this test it suffices to | 106 // the signin Profile is an OTR Profile then for this test it suffices to |
| 107 // attach it to the main Profile. | 107 // attach it to the main Profile. |
| 108 signin_profile_ = TestingProfile::Builder().BuildIncognito(profile_); | 108 signin_profile_ = TestingProfile::Builder().BuildIncognito(profile_); |
| 109 ASSERT_EQ(signin_profile_, chromeos::ProfileHelper::GetSigninProfile()); | 109 ASSERT_EQ(signin_profile_, chromeos::ProfileHelper::GetSigninProfile()); |
| 110 | 110 |
| 111 chrome::RegisterLocalState(prefs_.registry()); | 111 chrome::RegisterLocalState(prefs_.registry()); |
| 112 | 112 |
| 113 // Set up a policy map for testing. | 113 // Set up a policy map for testing. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 profile_ = NULL; | 163 profile_ = NULL; |
| 164 profile_manager_->DeleteTestingProfile(chrome::kInitialProfile); | 164 profile_manager_->DeleteTestingProfile(chrome::kInitialProfile); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void CreateManager(bool wait_for_fetch, int fetch_timeout) { | 167 void CreateManager(bool wait_for_fetch, int fetch_timeout) { |
| 168 store_ = new MockCloudPolicyStore(); | 168 store_ = new MockCloudPolicyStore(); |
| 169 external_data_manager_ = new MockCloudExternalDataManager; | 169 external_data_manager_ = new MockCloudExternalDataManager; |
| 170 external_data_manager_->SetPolicyStore(store_); | 170 external_data_manager_->SetPolicyStore(store_); |
| 171 EXPECT_CALL(*store_, Load()); | 171 EXPECT_CALL(*store_, Load()); |
| 172 manager_.reset(new UserCloudPolicyManagerChromeOS( | 172 manager_.reset(new UserCloudPolicyManagerChromeOS( |
| 173 scoped_ptr<CloudPolicyStore>(store_), | 173 std::unique_ptr<CloudPolicyStore>(store_), |
| 174 scoped_ptr<CloudExternalDataManager>(external_data_manager_), | 174 std::unique_ptr<CloudExternalDataManager>(external_data_manager_), |
| 175 base::FilePath(), | 175 base::FilePath(), wait_for_fetch, |
| 176 wait_for_fetch, | 176 base::TimeDelta::FromSeconds(fetch_timeout), task_runner_, task_runner_, |
| 177 base::TimeDelta::FromSeconds(fetch_timeout), | |
| 178 task_runner_, | |
| 179 task_runner_, | |
| 180 task_runner_)); | 177 task_runner_)); |
| 181 manager_->Init(&schema_registry_); | 178 manager_->Init(&schema_registry_); |
| 182 manager_->AddObserver(&observer_); | 179 manager_->AddObserver(&observer_); |
| 183 manager_->Connect(&prefs_, &device_management_service_, NULL); | 180 manager_->Connect(&prefs_, &device_management_service_, NULL); |
| 184 Mock::VerifyAndClearExpectations(store_); | 181 Mock::VerifyAndClearExpectations(store_); |
| 185 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 182 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
| 186 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); | 183 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); |
| 187 | 184 |
| 188 if (!wait_for_fetch) { | 185 if (!wait_for_fetch) { |
| 189 // Create the UserCloudPolicyTokenForwarder, which fetches the access | 186 // Create the UserCloudPolicyTokenForwarder, which fetches the access |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 326 |
| 330 // Policy infrastructure. | 327 // Policy infrastructure. |
| 331 net::TestURLFetcherFactory test_url_fetcher_factory_; | 328 net::TestURLFetcherFactory test_url_fetcher_factory_; |
| 332 TestingPrefServiceSimple prefs_; | 329 TestingPrefServiceSimple prefs_; |
| 333 MockConfigurationPolicyObserver observer_; | 330 MockConfigurationPolicyObserver observer_; |
| 334 MockDeviceManagementService device_management_service_; | 331 MockDeviceManagementService device_management_service_; |
| 335 MockCloudPolicyStore* store_; // Not owned. | 332 MockCloudPolicyStore* store_; // Not owned. |
| 336 MockCloudExternalDataManager* external_data_manager_; // Not owned. | 333 MockCloudExternalDataManager* external_data_manager_; // Not owned. |
| 337 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 334 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 338 SchemaRegistry schema_registry_; | 335 SchemaRegistry schema_registry_; |
| 339 scoped_ptr<UserCloudPolicyManagerChromeOS> manager_; | 336 std::unique_ptr<UserCloudPolicyManagerChromeOS> manager_; |
| 340 scoped_ptr<UserCloudPolicyTokenForwarder> token_forwarder_; | 337 std::unique_ptr<UserCloudPolicyTokenForwarder> token_forwarder_; |
| 341 | 338 |
| 342 // Required by ProfileHelper to get the signin Profile context. | 339 // Required by ProfileHelper to get the signin Profile context. |
| 343 scoped_ptr<TestingProfileManager> profile_manager_; | 340 std::unique_ptr<TestingProfileManager> profile_manager_; |
| 344 TestingProfile* profile_; | 341 TestingProfile* profile_; |
| 345 TestingProfile* signin_profile_; | 342 TestingProfile* signin_profile_; |
| 346 | 343 |
| 347 user_manager::FakeUserManager* user_manager_; | 344 user_manager::FakeUserManager* user_manager_; |
| 348 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 345 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 349 | 346 |
| 350 private: | 347 private: |
| 351 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest); | 348 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest); |
| 352 }; | 349 }; |
| 353 | 350 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 594 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
| 598 EXPECT_TRUE(manager_->core()->client()->is_registered()); | 595 EXPECT_TRUE(manager_->core()->client()->is_registered()); |
| 599 | 596 |
| 600 // The refresh scheduler takes care of the initial fetch for unmanaged users. | 597 // The refresh scheduler takes care of the initial fetch for unmanaged users. |
| 601 // Running the task runner issues the initial fetch. | 598 // Running the task runner issues the initial fetch. |
| 602 FetchPolicy( | 599 FetchPolicy( |
| 603 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_)); | 600 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_)); |
| 604 } | 601 } |
| 605 | 602 |
| 606 } // namespace policy | 603 } // namespace policy |
| OLD | NEW |