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

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_provider_unittest.cc

Issue 14927015: Translate device-local account IDs to user IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed DeviceLocalAccountTest. Created 7 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 | 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/settings/device_settings_provider.h" 5 #include "chrome/browser/chromeos/settings/device_settings_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/test/scoped_path_override.h" 13 #include "base/test/scoped_path_override.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chromeos/cros/cros_library.h" 15 #include "chrome/browser/chromeos/cros/cros_library.h"
16 #include "chrome/browser/chromeos/policy/device_local_account.h"
16 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 17 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
17 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 18 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
18 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" 19 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
19 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" 20 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
20 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
21 #include "chrome/test/base/scoped_testing_local_state.h" 22 #include "chrome/test/base/scoped_testing_local_state.h"
22 #include "chrome/test/base/testing_browser_process.h" 23 #include "chrome/test/base/testing_browser_process.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
(...skipping 16 matching lines...) Expand all
42 user_data_dir_override_(chrome::DIR_USER_DATA) {} 43 user_data_dir_override_(chrome::DIR_USER_DATA) {}
43 44
44 virtual void SetUp() OVERRIDE { 45 virtual void SetUp() OVERRIDE {
45 DeviceSettingsTestBase::SetUp(); 46 DeviceSettingsTestBase::SetUp();
46 47
47 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); 48 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber());
48 provider_.reset( 49 provider_.reset(
49 new DeviceSettingsProvider( 50 new DeviceSettingsProvider(
50 base::Bind(&DeviceSettingsProviderTest::SettingChanged, 51 base::Bind(&DeviceSettingsProviderTest::SettingChanged,
51 base::Unretained(this)), 52 base::Unretained(this)),
52 &device_settings_service_)); 53 DeviceSettingsService::Get()));
53 Mock::VerifyAndClearExpectations(this); 54 Mock::VerifyAndClearExpectations(this);
54 } 55 }
55 56
56 virtual void TearDown() OVERRIDE { 57 virtual void TearDown() OVERRIDE {
57 DeviceSettingsTestBase::TearDown(); 58 DeviceSettingsTestBase::TearDown();
58 } 59 }
59 60
60 ScopedStubCrosEnabler stub_cros_enabler_; 61 ScopedStubCrosEnabler stub_cros_enabler_;
61 62
62 ScopedTestingLocalState local_state_; 63 ScopedTestingLocalState local_state_;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Verify the change has not been applied. 135 // Verify the change has not been applied.
135 const base::Value* saved_value = provider_->Get(kStatsReportingPref); 136 const base::Value* saved_value = provider_->Get(kStatsReportingPref);
136 ASSERT_TRUE(saved_value); 137 ASSERT_TRUE(saved_value);
137 bool bool_value; 138 bool bool_value;
138 EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value)); 139 EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value));
139 EXPECT_FALSE(bool_value); 140 EXPECT_FALSE(bool_value);
140 } 141 }
141 142
142 TEST_F(DeviceSettingsProviderTest, SetPrefSucceed) { 143 TEST_F(DeviceSettingsProviderTest, SetPrefSucceed) {
143 owner_key_util_->SetPrivateKey(device_policy_.signing_key()); 144 owner_key_util_->SetPrivateKey(device_policy_.signing_key());
144 device_settings_service_.SetUsername(device_policy_.policy_data().username()); 145 DeviceSettingsService::Get()->SetUsername(
146 device_policy_.policy_data().username());
145 FlushDeviceSettings(); 147 FlushDeviceSettings();
146 148
147 base::FundamentalValue value(true); 149 base::FundamentalValue value(true);
148 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); 150 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber());
149 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1); 151 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1);
150 provider_->Set(kStatsReportingPref, value); 152 provider_->Set(kStatsReportingPref, value);
151 Mock::VerifyAndClearExpectations(this); 153 Mock::VerifyAndClearExpectations(this);
152 154
153 // Process the store. 155 // Process the store.
154 device_settings_test_helper_.set_policy_blob(std::string()); 156 device_settings_test_helper_.set_policy_blob(std::string());
155 FlushDeviceSettings(); 157 FlushDeviceSettings();
156 158
157 // Verify that the device policy has been adjusted. 159 // Verify that the device policy has been adjusted.
158 ASSERT_TRUE(device_settings_service_.device_settings()); 160 ASSERT_TRUE(DeviceSettingsService::Get()->device_settings());
159 EXPECT_TRUE(device_settings_service_.device_settings()-> 161 EXPECT_TRUE(DeviceSettingsService::Get()->device_settings()->
160 metrics_enabled().metrics_enabled()); 162 metrics_enabled().metrics_enabled());
161 163
162 // Verify the change has been applied. 164 // Verify the change has been applied.
163 const base::Value* saved_value = provider_->Get(kStatsReportingPref); 165 const base::Value* saved_value = provider_->Get(kStatsReportingPref);
164 ASSERT_TRUE(saved_value); 166 ASSERT_TRUE(saved_value);
165 bool bool_value; 167 bool bool_value;
166 EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value)); 168 EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value));
167 EXPECT_TRUE(bool_value); 169 EXPECT_TRUE(bool_value);
168 } 170 }
169 171
170 TEST_F(DeviceSettingsProviderTest, SetPrefTwice) { 172 TEST_F(DeviceSettingsProviderTest, SetPrefTwice) {
171 owner_key_util_->SetPrivateKey(device_policy_.signing_key()); 173 owner_key_util_->SetPrivateKey(device_policy_.signing_key());
172 device_settings_service_.SetUsername(device_policy_.policy_data().username()); 174 DeviceSettingsService::Get()->SetUsername(
175 device_policy_.policy_data().username());
173 FlushDeviceSettings(); 176 FlushDeviceSettings();
174 177
175 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); 178 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber());
176 179
177 base::StringValue value1("beta"); 180 base::StringValue value1("beta");
178 provider_->Set(kReleaseChannel, value1); 181 provider_->Set(kReleaseChannel, value1);
179 base::StringValue value2("dev"); 182 base::StringValue value2("dev");
180 provider_->Set(kReleaseChannel, value2); 183 provider_->Set(kReleaseChannel, value2);
181 184
182 // Let the changes propagate through the system. 185 // Let the changes propagate through the system.
183 device_settings_test_helper_.set_policy_blob(std::string()); 186 device_settings_test_helper_.set_policy_blob(std::string());
184 FlushDeviceSettings(); 187 FlushDeviceSettings();
185 188
186 // Verify the second change has been applied. 189 // Verify the second change has been applied.
187 const base::Value* saved_value = provider_->Get(kReleaseChannel); 190 const base::Value* saved_value = provider_->Get(kReleaseChannel);
188 EXPECT_TRUE(value2.Equals(saved_value)); 191 EXPECT_TRUE(value2.Equals(saved_value));
189 192
190 Mock::VerifyAndClearExpectations(this); 193 Mock::VerifyAndClearExpectations(this);
191 } 194 }
192 195
193 TEST_F(DeviceSettingsProviderTest, PolicyRetrievalFailedBadSignature) { 196 TEST_F(DeviceSettingsProviderTest, PolicyRetrievalFailedBadSignature) {
194 owner_key_util_->SetPublicKeyFromPrivateKey(device_policy_.signing_key()); 197 owner_key_util_->SetPublicKeyFromPrivateKey(device_policy_.signing_key());
195 device_policy_.policy().set_policy_data_signature("bad signature"); 198 device_policy_.policy().set_policy_data_signature("bad signature");
196 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 199 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
197 ReloadDeviceSettings(); 200 ReloadDeviceSettings();
198 201
199 // Verify that the cached settings blob is not "trusted". 202 // Verify that the cached settings blob is not "trusted".
200 EXPECT_EQ(DeviceSettingsService::STORE_VALIDATION_ERROR, 203 EXPECT_EQ(DeviceSettingsService::STORE_VALIDATION_ERROR,
201 device_settings_service_.status()); 204 DeviceSettingsService::Get()->status());
202 EXPECT_EQ(CrosSettingsProvider::PERMANENTLY_UNTRUSTED, 205 EXPECT_EQ(CrosSettingsProvider::PERMANENTLY_UNTRUSTED,
203 provider_->PrepareTrustedValues(base::Closure())); 206 provider_->PrepareTrustedValues(base::Closure()));
204 } 207 }
205 208
206 TEST_F(DeviceSettingsProviderTest, PolicyRetrievalNoPolicy) { 209 TEST_F(DeviceSettingsProviderTest, PolicyRetrievalNoPolicy) {
207 owner_key_util_->SetPublicKeyFromPrivateKey(device_policy_.signing_key()); 210 owner_key_util_->SetPublicKeyFromPrivateKey(device_policy_.signing_key());
208 device_settings_test_helper_.set_policy_blob(std::string()); 211 device_settings_test_helper_.set_policy_blob(std::string());
209 ReloadDeviceSettings(); 212 ReloadDeviceSettings();
210 213
211 // Verify that the cached settings blob is not "trusted". 214 // Verify that the cached settings blob is not "trusted".
212 EXPECT_EQ(DeviceSettingsService::STORE_NO_POLICY, 215 EXPECT_EQ(DeviceSettingsService::STORE_NO_POLICY,
213 device_settings_service_.status()); 216 DeviceSettingsService::Get()->status());
214 EXPECT_EQ(CrosSettingsProvider::PERMANENTLY_UNTRUSTED, 217 EXPECT_EQ(CrosSettingsProvider::PERMANENTLY_UNTRUSTED,
215 provider_->PrepareTrustedValues(base::Closure())); 218 provider_->PrepareTrustedValues(base::Closure()));
216 } 219 }
217 220
218 TEST_F(DeviceSettingsProviderTest, PolicyFailedPermanentlyNotification) { 221 TEST_F(DeviceSettingsProviderTest, PolicyFailedPermanentlyNotification) {
219 device_settings_test_helper_.set_policy_blob(std::string()); 222 device_settings_test_helper_.set_policy_blob(std::string());
220 223
221 EXPECT_CALL(*this, GetTrustedCallback()); 224 EXPECT_CALL(*this, GetTrustedCallback());
222 EXPECT_EQ(CrosSettingsProvider::TEMPORARILY_UNTRUSTED, 225 EXPECT_EQ(CrosSettingsProvider::TEMPORARILY_UNTRUSTED,
223 provider_->PrepareTrustedValues( 226 provider_->PrepareTrustedValues(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 276 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
274 ReloadDeviceSettings(); 277 ReloadDeviceSettings();
275 Mock::VerifyAndClearExpectations(this); 278 Mock::VerifyAndClearExpectations(this);
276 279
277 // On load, the deprecated spec should have been converted to the new format. 280 // On load, the deprecated spec should have been converted to the new format.
278 base::ListValue expected_accounts; 281 base::ListValue expected_accounts;
279 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); 282 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue());
280 entry_dict->SetString(kAccountsPrefDeviceLocalAccountsKeyId, 283 entry_dict->SetString(kAccountsPrefDeviceLocalAccountsKeyId,
281 policy::PolicyBuilder::kFakeUsername); 284 policy::PolicyBuilder::kFakeUsername);
282 entry_dict->SetInteger(kAccountsPrefDeviceLocalAccountsKeyType, 285 entry_dict->SetInteger(kAccountsPrefDeviceLocalAccountsKeyType,
283 DEVICE_LOCAL_ACCOUNT_TYPE_PUBLIC_SESSION); 286 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION);
284 expected_accounts.Append(entry_dict.release()); 287 expected_accounts.Append(entry_dict.release());
285 const base::Value* actual_accounts = 288 const base::Value* actual_accounts =
286 provider_->Get(kAccountsPrefDeviceLocalAccounts); 289 provider_->Get(kAccountsPrefDeviceLocalAccounts);
287 EXPECT_TRUE(base::Value::Equals(&expected_accounts, actual_accounts)); 290 EXPECT_TRUE(base::Value::Equals(&expected_accounts, actual_accounts));
288 } 291 }
289 292
290 } // namespace chromeos 293 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698