| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 371 |
| 358 EXPECT_EQ(CrosSettingsProvider::TEMPORARILY_UNTRUSTED, | 372 EXPECT_EQ(CrosSettingsProvider::TEMPORARILY_UNTRUSTED, |
| 359 provider_->PrepareTrustedValues( | 373 provider_->PrepareTrustedValues( |
| 360 base::Bind(&DeviceSettingsProviderTest::GetTrustedCallback, | 374 base::Bind(&DeviceSettingsProviderTest::GetTrustedCallback, |
| 361 base::Unretained(this)))); | 375 base::Unretained(this)))); |
| 362 | 376 |
| 363 ReloadDeviceSettings(); | 377 ReloadDeviceSettings(); |
| 364 Mock::VerifyAndClearExpectations(this); | 378 Mock::VerifyAndClearExpectations(this); |
| 365 } | 379 } |
| 366 | 380 |
| 367 TEST_F(DeviceSettingsProviderTest, StatsReportingMigration) { | |
| 368 // Create the legacy consent file. | |
| 369 base::FilePath consent_file; | |
| 370 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &consent_file)); | |
| 371 consent_file = consent_file.AppendASCII("Consent To Send Stats"); | |
| 372 ASSERT_EQ(1, base::WriteFile(consent_file, "0", 1)); | |
| 373 | |
| 374 // This should trigger migration because the metrics policy isn't in the blob. | |
| 375 device_settings_test_helper_.set_policy_blob(std::string()); | |
| 376 FlushDeviceSettings(); | |
| 377 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); | |
| 378 | |
| 379 // Verify that migration has kicked in. | |
| 380 const base::Value* saved_value = provider_->Get(kStatsReportingPref); | |
| 381 ASSERT_TRUE(saved_value); | |
| 382 bool bool_value; | |
| 383 EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value)); | |
| 384 EXPECT_FALSE(bool_value); | |
| 385 } | |
| 386 | |
| 387 TEST_F(DeviceSettingsProviderTest, LegacyDeviceLocalAccounts) { | 381 TEST_F(DeviceSettingsProviderTest, LegacyDeviceLocalAccounts) { |
| 388 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); | 382 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); |
| 389 em::DeviceLocalAccountInfoProto* account = | 383 em::DeviceLocalAccountInfoProto* account = |
| 390 device_policy_.payload().mutable_device_local_accounts()->add_account(); | 384 device_policy_.payload().mutable_device_local_accounts()->add_account(); |
| 391 account->set_deprecated_public_session_id( | 385 account->set_deprecated_public_session_id( |
| 392 policy::PolicyBuilder::kFakeUsername); | 386 policy::PolicyBuilder::kFakeUsername); |
| 393 device_policy_.Build(); | 387 device_policy_.Build(); |
| 394 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 388 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 395 ReloadDeviceSettings(); | 389 ReloadDeviceSettings(); |
| 396 Mock::VerifyAndClearExpectations(this); | 390 Mock::VerifyAndClearExpectations(this); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 } | 493 } |
| 500 | 494 |
| 501 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { | 495 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { |
| 502 SetLogUploadSettings(true); | 496 SetLogUploadSettings(true); |
| 503 VerifyLogUploadSettings(true); | 497 VerifyLogUploadSettings(true); |
| 504 | 498 |
| 505 SetLogUploadSettings(false); | 499 SetLogUploadSettings(false); |
| 506 VerifyLogUploadSettings(false); | 500 VerifyLogUploadSettings(false); |
| 507 } | 501 } |
| 508 } // namespace chromeos | 502 } // namespace chromeos |
| OLD | NEW |