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

Side by Side Diff: chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc

Issue 1118773004: [chrome/browser/chromeos/policy] Replace MessageLoopProxy usage with ThreadTaskRunnerHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Review Comments Created 5 years, 7 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
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/policy/device_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/prefs/pref_registry_simple.h" 14 #include "base/prefs/pref_registry_simple.h"
16 #include "base/prefs/testing_pref_service.h" 15 #include "base/prefs/testing_pref_service.h"
17 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/thread_task_runner_handle.h"
18 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 18 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
19 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 19 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h"
21 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 21 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
22 #include "chrome/browser/chromeos/policy/enrollment_config.h" 22 #include "chrome/browser/chromeos/policy/enrollment_config.h"
23 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 23 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
24 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 24 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
25 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 25 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
26 #include "chrome/browser/chromeos/settings/cros_settings.h" 26 #include "chrome/browser/chromeos/settings/cros_settings.h"
27 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 27 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 ~TestingDeviceCloudPolicyManagerChromeOS() override {} 85 ~TestingDeviceCloudPolicyManagerChromeOS() override {}
86 }; 86 };
87 87
88 class DeviceCloudPolicyManagerChromeOSTest 88 class DeviceCloudPolicyManagerChromeOSTest
89 : public chromeos::DeviceSettingsTestBase, 89 : public chromeos::DeviceSettingsTestBase,
90 public DeviceCloudPolicyManagerChromeOS::Observer { 90 public DeviceCloudPolicyManagerChromeOS::Observer {
91 protected: 91 protected:
92 DeviceCloudPolicyManagerChromeOSTest() 92 DeviceCloudPolicyManagerChromeOSTest()
93 : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), 93 : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()),
94 state_keys_broker_(&fake_session_manager_client_, 94 state_keys_broker_(&fake_session_manager_client_,
95 base::MessageLoopProxy::current()), 95 base::ThreadTaskRunnerHandle::Get()),
96 store_(NULL) { 96 store_(NULL) {
97 fake_statistics_provider_.SetMachineStatistic("serial_numer", "test_sn"); 97 fake_statistics_provider_.SetMachineStatistic("serial_numer", "test_sn");
98 std::vector<std::string> state_keys; 98 std::vector<std::string> state_keys;
99 state_keys.push_back("1"); 99 state_keys.push_back("1");
100 state_keys.push_back("2"); 100 state_keys.push_back("2");
101 state_keys.push_back("3"); 101 state_keys.push_back("3");
102 fake_session_manager_client_.set_server_backed_state_keys(state_keys); 102 fake_session_manager_client_.set_server_backed_state_keys(state_keys);
103 } 103 }
104 104
105 ~DeviceCloudPolicyManagerChromeOSTest() override { 105 ~DeviceCloudPolicyManagerChromeOSTest() override {
106 chromeos::system::StatisticsProvider::SetTestProvider(NULL); 106 chromeos::system::StatisticsProvider::SetTestProvider(NULL);
107 } 107 }
108 108
109 void SetUp() override { 109 void SetUp() override {
110 DeviceSettingsTestBase::SetUp(); 110 DeviceSettingsTestBase::SetUp();
111 111
112 dbus_setter_->SetCryptohomeClient( 112 dbus_setter_->SetCryptohomeClient(
113 scoped_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_)); 113 scoped_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_));
114 114
115 install_attributes_.reset( 115 install_attributes_.reset(
116 new EnterpriseInstallAttributes(fake_cryptohome_client_)); 116 new EnterpriseInstallAttributes(fake_cryptohome_client_));
117 store_ = 117 store_ = new DeviceCloudPolicyStoreChromeOS(
118 new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, 118 &device_settings_service_, install_attributes_.get(),
119 install_attributes_.get(), 119 base::ThreadTaskRunnerHandle::Get());
120 base::MessageLoopProxy::current());
121 manager_.reset(new TestingDeviceCloudPolicyManagerChromeOS( 120 manager_.reset(new TestingDeviceCloudPolicyManagerChromeOS(
122 make_scoped_ptr(store_), 121 make_scoped_ptr(store_), base::ThreadTaskRunnerHandle::Get(),
123 base::MessageLoopProxy::current(),
124 &state_keys_broker_)); 122 &state_keys_broker_));
125 123
126 chrome::RegisterLocalState(local_state_.registry()); 124 chrome::RegisterLocalState(local_state_.registry());
127 manager_->Init(&schema_registry_); 125 manager_->Init(&schema_registry_);
128 126
129 // DeviceOAuth2TokenService uses the system request context to fetch 127 // DeviceOAuth2TokenService uses the system request context to fetch
130 // OAuth tokens, then writes the token to local state, encrypting it 128 // OAuth tokens, then writes the token to local state, encrypting it
131 // first with methods in CryptohomeTokenEncryptor. 129 // first with methods in CryptohomeTokenEncryptor.
132 request_context_getter_ = new net::TestURLRequestContextGetter( 130 request_context_getter_ = new net::TestURLRequestContextGetter(
133 base::MessageLoopProxy::current()); 131 base::ThreadTaskRunnerHandle::Get());
134 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext( 132 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext(
135 request_context_getter_.get()); 133 request_context_getter_.get());
136 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); 134 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
137 // SystemSaltGetter is used in DeviceOAuth2TokenService. 135 // SystemSaltGetter is used in DeviceOAuth2TokenService.
138 chromeos::SystemSaltGetter::Initialize(); 136 chromeos::SystemSaltGetter::Initialize();
139 chromeos::DeviceOAuth2TokenServiceFactory::Initialize(); 137 chromeos::DeviceOAuth2TokenServiceFactory::Initialize();
140 url_fetcher_response_code_ = 200; 138 url_fetcher_response_code_ = 200;
141 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\"," 139 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\","
142 "\"expires_in\":1234," 140 "\"expires_in\":1234,"
143 "\"refresh_token\":\"refreshToken4Test\"}"; 141 "\"refresh_token\":\"refreshToken4Test\"}";
(...skipping 22 matching lines...) Expand all
166 PolicyBuilder::kFakeDeviceId, 164 PolicyBuilder::kFakeDeviceId,
167 base::Bind(&CopyLockResult, &loop, &result)); 165 base::Bind(&CopyLockResult, &loop, &result));
168 loop.Run(); 166 loop.Run();
169 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result); 167 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result);
170 } 168 }
171 169
172 void ConnectManager() { 170 void ConnectManager() {
173 manager_->Initialize(&local_state_); 171 manager_->Initialize(&local_state_);
174 manager_->AddDeviceCloudPolicyManagerObserver(this); 172 manager_->AddDeviceCloudPolicyManagerObserver(this);
175 initializer_.reset(new DeviceCloudPolicyInitializer( 173 initializer_.reset(new DeviceCloudPolicyInitializer(
176 &local_state_, 174 &local_state_, &device_management_service_,
177 &device_management_service_,
178 &consumer_device_management_service_, 175 &consumer_device_management_service_,
179 base::MessageLoopProxy::current(), 176 base::ThreadTaskRunnerHandle::Get(), install_attributes_.get(),
180 install_attributes_.get(), 177 &state_keys_broker_, store_, manager_.get()));
181 &state_keys_broker_,
182 store_,
183 manager_.get()));
184 initializer_->Init(); 178 initializer_->Init();
185 } 179 }
186 180
187 void VerifyPolicyPopulated() { 181 void VerifyPolicyPopulated() {
188 PolicyBundle bundle; 182 PolicyBundle bundle;
189 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 183 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
190 .Set(key::kDeviceMetricsReportingEnabled, 184 .Set(key::kDeviceMetricsReportingEnabled,
191 POLICY_LEVEL_MANDATORY, 185 POLICY_LEVEL_MANDATORY,
192 POLICY_SCOPE_MACHINE, 186 POLICY_SCOPE_MACHINE,
193 new base::FundamentalValue(false), 187 new base::FundamentalValue(false),
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 740
747 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, 741 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest,
748 RobotRefreshSaveFailed) { 742 RobotRefreshSaveFailed) {
749 // Without the system salt, the robot token can't be stored. 743 // Without the system salt, the robot token can't be stored.
750 RunTest(); 744 RunTest();
751 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); 745 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED);
752 } 746 }
753 747
754 } // namespace 748 } // namespace
755 } // namespace policy 749 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698