| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); | 104 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); |
| 105 em::DeviceLogUploadSettingsProto* proto = | 105 em::DeviceLogUploadSettingsProto* proto = |
| 106 device_policy_.payload().mutable_device_log_upload_settings(); | 106 device_policy_.payload().mutable_device_log_upload_settings(); |
| 107 proto->set_system_log_upload_enabled(enable_system_log_upload); | 107 proto->set_system_log_upload_enabled(enable_system_log_upload); |
| 108 device_policy_.Build(); | 108 device_policy_.Build(); |
| 109 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 109 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 110 ReloadDeviceSettings(); | 110 ReloadDeviceSettings(); |
| 111 Mock::VerifyAndClearExpectations(this); | 111 Mock::VerifyAndClearExpectations(this); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Helper routine to enable/disable metrics report upload settings in policy. |
| 115 void SetMetricsReportingSettings(bool enable_metrics_reporting) { |
| 116 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); |
| 117 em::MetricsEnabledProto* proto = |
| 118 device_policy_.payload().mutable_metrics_enabled(); |
| 119 proto->set_metrics_enabled(enable_metrics_reporting); |
| 120 device_policy_.Build(); |
| 121 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 122 ReloadDeviceSettings(); |
| 123 Mock::VerifyAndClearExpectations(this); |
| 124 } |
| 125 |
| 114 // Helper routine to ensure all heartbeat policies have been correctly | 126 // Helper routine to ensure all heartbeat policies have been correctly |
| 115 // decoded. | 127 // decoded. |
| 116 void VerifyHeartbeatSettings(bool expected_enable_state, | 128 void VerifyHeartbeatSettings(bool expected_enable_state, |
| 117 int expected_frequency) { | 129 int expected_frequency) { |
| 118 | 130 |
| 119 const base::FundamentalValue expected_enabled_value(expected_enable_state); | 131 const base::FundamentalValue expected_enabled_value(expected_enable_state); |
| 120 EXPECT_TRUE(base::Value::Equals(provider_->Get(kHeartbeatEnabled), | 132 EXPECT_TRUE(base::Value::Equals(provider_->Get(kHeartbeatEnabled), |
| 121 &expected_enabled_value)); | 133 &expected_enabled_value)); |
| 122 | 134 |
| 123 const base::FundamentalValue expected_frequency_value(expected_frequency); | 135 const base::FundamentalValue expected_frequency_value(expected_frequency); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); | 246 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); |
| 235 | 247 |
| 236 // Verify the change has been applied. | 248 // Verify the change has been applied. |
| 237 const base::Value* saved_value = provider_->Get(kReleaseChannel); | 249 const base::Value* saved_value = provider_->Get(kReleaseChannel); |
| 238 ASSERT_TRUE(saved_value); | 250 ASSERT_TRUE(saved_value); |
| 239 EXPECT_TRUE(saved_value->GetAsString(&string_value)); | 251 EXPECT_TRUE(saved_value->GetAsString(&string_value)); |
| 240 ASSERT_EQ("stable-channel", string_value); | 252 ASSERT_EQ("stable-channel", string_value); |
| 241 } | 253 } |
| 242 | 254 |
| 243 TEST_F(DeviceSettingsProviderTest, SetPrefFailed) { | 255 TEST_F(DeviceSettingsProviderTest, SetPrefFailed) { |
| 256 SetMetricsReportingSettings(false); |
| 257 |
| 244 // If we are not the owner no sets should work. | 258 // If we are not the owner no sets should work. |
| 245 base::FundamentalValue value(true); | 259 base::FundamentalValue value(true); |
| 246 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1); | 260 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1); |
| 247 provider_->Set(kStatsReportingPref, value); | 261 provider_->Set(kStatsReportingPref, value); |
| 248 Mock::VerifyAndClearExpectations(this); | 262 Mock::VerifyAndClearExpectations(this); |
| 249 | 263 |
| 250 // This shouldn't trigger a write. | 264 // This shouldn't trigger a write. |
| 251 device_settings_test_helper_.set_policy_blob(std::string()); | 265 device_settings_test_helper_.set_policy_blob(std::string()); |
| 252 FlushDeviceSettings(); | 266 FlushDeviceSettings(); |
| 253 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); | 267 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 373 |
| 360 EXPECT_EQ(CrosSettingsProvider::TEMPORARILY_UNTRUSTED, | 374 EXPECT_EQ(CrosSettingsProvider::TEMPORARILY_UNTRUSTED, |
| 361 provider_->PrepareTrustedValues( | 375 provider_->PrepareTrustedValues( |
| 362 base::Bind(&DeviceSettingsProviderTest::GetTrustedCallback, | 376 base::Bind(&DeviceSettingsProviderTest::GetTrustedCallback, |
| 363 base::Unretained(this)))); | 377 base::Unretained(this)))); |
| 364 | 378 |
| 365 ReloadDeviceSettings(); | 379 ReloadDeviceSettings(); |
| 366 Mock::VerifyAndClearExpectations(this); | 380 Mock::VerifyAndClearExpectations(this); |
| 367 } | 381 } |
| 368 | 382 |
| 369 TEST_F(DeviceSettingsProviderTest, StatsReportingMigration) { | |
| 370 // Create the legacy consent file. | |
| 371 base::FilePath consent_file; | |
| 372 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &consent_file)); | |
| 373 consent_file = consent_file.AppendASCII("Consent To Send Stats"); | |
| 374 ASSERT_EQ(1, base::WriteFile(consent_file, "0", 1)); | |
| 375 | |
| 376 // This should trigger migration because the metrics policy isn't in the blob. | |
| 377 device_settings_test_helper_.set_policy_blob(std::string()); | |
| 378 FlushDeviceSettings(); | |
| 379 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); | |
| 380 | |
| 381 // Verify that migration has kicked in. | |
| 382 const base::Value* saved_value = provider_->Get(kStatsReportingPref); | |
| 383 ASSERT_TRUE(saved_value); | |
| 384 bool bool_value; | |
| 385 EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value)); | |
| 386 EXPECT_FALSE(bool_value); | |
| 387 } | |
| 388 | |
| 389 TEST_F(DeviceSettingsProviderTest, LegacyDeviceLocalAccounts) { | 383 TEST_F(DeviceSettingsProviderTest, LegacyDeviceLocalAccounts) { |
| 390 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); | 384 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); |
| 391 em::DeviceLocalAccountInfoProto* account = | 385 em::DeviceLocalAccountInfoProto* account = |
| 392 device_policy_.payload().mutable_device_local_accounts()->add_account(); | 386 device_policy_.payload().mutable_device_local_accounts()->add_account(); |
| 393 account->set_deprecated_public_session_id( | 387 account->set_deprecated_public_session_id( |
| 394 policy::PolicyBuilder::kFakeUsername); | 388 policy::PolicyBuilder::kFakeUsername); |
| 395 device_policy_.Build(); | 389 device_policy_.Build(); |
| 396 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 390 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 397 ReloadDeviceSettings(); | 391 ReloadDeviceSettings(); |
| 398 Mock::VerifyAndClearExpectations(this); | 392 Mock::VerifyAndClearExpectations(this); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 } | 496 } |
| 503 | 497 |
| 504 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { | 498 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { |
| 505 SetLogUploadSettings(true); | 499 SetLogUploadSettings(true); |
| 506 VerifyLogUploadSettings(true); | 500 VerifyLogUploadSettings(true); |
| 507 | 501 |
| 508 SetLogUploadSettings(false); | 502 SetLogUploadSettings(false); |
| 509 VerifyLogUploadSettings(false); | 503 VerifyLogUploadSettings(false); |
| 510 } | 504 } |
| 511 } // namespace chromeos | 505 } // namespace chromeos |
| OLD | NEW |