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/settings/device_settings_provider.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 device_policy_.payload().mutable_login_screen_domain_auto_complete(); | 184 device_policy_.payload().mutable_login_screen_domain_auto_complete(); |
185 proto->set_login_screen_domain_auto_complete(domain); | 185 proto->set_login_screen_domain_auto_complete(domain); |
186 device_policy_.Build(); | 186 device_policy_.Build(); |
187 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 187 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
188 ReloadDeviceSettings(); | 188 ReloadDeviceSettings(); |
189 Mock::VerifyAndClearExpectations(this); | 189 Mock::VerifyAndClearExpectations(this); |
190 } | 190 } |
191 | 191 |
192 // Helper routine to check value of the LoginScreenDomainAutoComplete policy. | 192 // Helper routine to check value of the LoginScreenDomainAutoComplete policy. |
193 void VerifyDomainAutoComplete( | 193 void VerifyDomainAutoComplete( |
194 const base::StringValue* const ptr_to_expected_value) { | 194 const base::Value* const ptr_to_expected_value) { |
195 EXPECT_TRUE(base::Value::Equals( | 195 EXPECT_TRUE(base::Value::Equals( |
196 provider_->Get(kAccountsPrefLoginScreenDomainAutoComplete), | 196 provider_->Get(kAccountsPrefLoginScreenDomainAutoComplete), |
197 ptr_to_expected_value)); | 197 ptr_to_expected_value)); |
198 } | 198 } |
199 | 199 |
200 ScopedTestingLocalState local_state_; | 200 ScopedTestingLocalState local_state_; |
201 | 201 |
202 std::unique_ptr<DeviceSettingsProvider> provider_; | 202 std::unique_ptr<DeviceSettingsProvider> provider_; |
203 | 203 |
204 base::ScopedPathOverride user_data_dir_override_; | 204 base::ScopedPathOverride user_data_dir_override_; |
(...skipping 29 matching lines...) Expand all Loading... |
234 provider_->PrepareTrustedValues(base::Closure())); | 234 provider_->PrepareTrustedValues(base::Closure())); |
235 const base::Value* value = provider_->Get(kReleaseChannel); | 235 const base::Value* value = provider_->Get(kReleaseChannel); |
236 ASSERT_TRUE(value); | 236 ASSERT_TRUE(value); |
237 std::string string_value; | 237 std::string string_value; |
238 EXPECT_TRUE(value->GetAsString(&string_value)); | 238 EXPECT_TRUE(value->GetAsString(&string_value)); |
239 EXPECT_TRUE(string_value.empty()); | 239 EXPECT_TRUE(string_value.empty()); |
240 | 240 |
241 // Sets should succeed though and be readable from the cache. | 241 // Sets should succeed though and be readable from the cache. |
242 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); | 242 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); |
243 EXPECT_CALL(*this, SettingChanged(kReleaseChannel)).Times(1); | 243 EXPECT_CALL(*this, SettingChanged(kReleaseChannel)).Times(1); |
244 base::StringValue new_value("stable-channel"); | 244 base::Value new_value("stable-channel"); |
245 provider_->Set(kReleaseChannel, new_value); | 245 provider_->Set(kReleaseChannel, new_value); |
246 Mock::VerifyAndClearExpectations(this); | 246 Mock::VerifyAndClearExpectations(this); |
247 | 247 |
248 // This shouldn't trigger a write. | 248 // This shouldn't trigger a write. |
249 device_settings_test_helper_.set_policy_blob(std::string()); | 249 device_settings_test_helper_.set_policy_blob(std::string()); |
250 FlushDeviceSettings(); | 250 FlushDeviceSettings(); |
251 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); | 251 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); |
252 | 252 |
253 // Verify the change has been applied. | 253 // Verify the change has been applied. |
254 const base::Value* saved_value = provider_->Get(kReleaseChannel); | 254 const base::Value* saved_value = provider_->Get(kReleaseChannel); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 309 } |
310 | 310 |
311 TEST_F(DeviceSettingsProviderTest, SetPrefTwice) { | 311 TEST_F(DeviceSettingsProviderTest, SetPrefTwice) { |
312 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); | 312 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); |
313 InitOwner(AccountId::FromUserEmail(device_policy_.policy_data().username()), | 313 InitOwner(AccountId::FromUserEmail(device_policy_.policy_data().username()), |
314 true); | 314 true); |
315 FlushDeviceSettings(); | 315 FlushDeviceSettings(); |
316 | 316 |
317 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); | 317 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); |
318 | 318 |
319 base::StringValue value1("beta"); | 319 base::Value value1("beta"); |
320 provider_->Set(kReleaseChannel, value1); | 320 provider_->Set(kReleaseChannel, value1); |
321 base::StringValue value2("dev"); | 321 base::Value value2("dev"); |
322 provider_->Set(kReleaseChannel, value2); | 322 provider_->Set(kReleaseChannel, value2); |
323 | 323 |
324 // Let the changes propagate through the system. | 324 // Let the changes propagate through the system. |
325 device_settings_test_helper_.set_policy_blob(std::string()); | 325 device_settings_test_helper_.set_policy_blob(std::string()); |
326 FlushDeviceSettings(); | 326 FlushDeviceSettings(); |
327 | 327 |
328 // Verify the second change has been applied. | 328 // Verify the second change has been applied. |
329 const base::Value* saved_value = provider_->Get(kReleaseChannel); | 329 const base::Value* saved_value = provider_->Get(kReleaseChannel); |
330 EXPECT_TRUE(value2.Equals(saved_value)); | 330 EXPECT_TRUE(value2.Equals(saved_value)); |
331 | 331 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 mutable_disabled_state()->set_message(kDisabledMessage); | 418 mutable_disabled_state()->set_message(kDisabledMessage); |
419 device_policy_.Build(); | 419 device_policy_.Build(); |
420 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 420 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
421 ReloadDeviceSettings(); | 421 ReloadDeviceSettings(); |
422 Mock::VerifyAndClearExpectations(this); | 422 Mock::VerifyAndClearExpectations(this); |
423 | 423 |
424 // Verify that the device state has been decoded correctly. | 424 // Verify that the device state has been decoded correctly. |
425 const base::Value expected_disabled_value(true); | 425 const base::Value expected_disabled_value(true); |
426 EXPECT_TRUE(base::Value::Equals(provider_->Get(kDeviceDisabled), | 426 EXPECT_TRUE(base::Value::Equals(provider_->Get(kDeviceDisabled), |
427 &expected_disabled_value)); | 427 &expected_disabled_value)); |
428 const base::StringValue expected_disabled_message_value(kDisabledMessage); | 428 const base::Value expected_disabled_message_value(kDisabledMessage); |
429 EXPECT_TRUE(base::Value::Equals(provider_->Get(kDeviceDisabledMessage), | 429 EXPECT_TRUE(base::Value::Equals(provider_->Get(kDeviceDisabledMessage), |
430 &expected_disabled_message_value)); | 430 &expected_disabled_message_value)); |
431 | 431 |
432 // Verify that a change to the device state triggers a notification. | 432 // Verify that a change to the device state triggers a notification. |
433 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); | 433 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); |
434 device_policy_.policy_data().mutable_device_state()->clear_device_mode(); | 434 device_policy_.policy_data().mutable_device_state()->clear_device_mode(); |
435 device_policy_.Build(); | 435 device_policy_.Build(); |
436 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 436 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
437 ReloadDeviceSettings(); | 437 ReloadDeviceSettings(); |
438 Mock::VerifyAndClearExpectations(this); | 438 Mock::VerifyAndClearExpectations(this); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 TEST_F(DeviceSettingsProviderTest, DecodeDomainAutoComplete) { | 470 TEST_F(DeviceSettingsProviderTest, DecodeDomainAutoComplete) { |
471 // By default LoginScreenDomainAutoComplete policy should not be set. | 471 // By default LoginScreenDomainAutoComplete policy should not be set. |
472 VerifyDomainAutoComplete(nullptr); | 472 VerifyDomainAutoComplete(nullptr); |
473 | 473 |
474 // Empty string means that the policy is not set. | 474 // Empty string means that the policy is not set. |
475 SetDomainAutoComplete(""); | 475 SetDomainAutoComplete(""); |
476 VerifyDomainAutoComplete(nullptr); | 476 VerifyDomainAutoComplete(nullptr); |
477 | 477 |
478 // Check some meaningful value. Policy should be set. | 478 // Check some meaningful value. Policy should be set. |
479 const std::string domain = "domain.test"; | 479 const std::string domain = "domain.test"; |
480 const base::StringValue domain_value(domain); | 480 const base::Value domain_value(domain); |
481 SetDomainAutoComplete(domain); | 481 SetDomainAutoComplete(domain); |
482 VerifyDomainAutoComplete(&domain_value); | 482 VerifyDomainAutoComplete(&domain_value); |
483 } | 483 } |
484 | 484 |
485 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { | 485 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { |
486 SetLogUploadSettings(true); | 486 SetLogUploadSettings(true); |
487 VerifyLogUploadSettings(true); | 487 VerifyLogUploadSettings(true); |
488 | 488 |
489 SetLogUploadSettings(false); | 489 SetLogUploadSettings(false); |
490 VerifyLogUploadSettings(false); | 490 VerifyLogUploadSettings(false); |
491 } | 491 } |
492 } // namespace chromeos | 492 } // namespace chromeos |
OLD | NEW |