| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 device_policy_.Build(); | 124 device_policy_.Build(); |
| 125 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 125 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 126 ReloadDeviceSettings(); | 126 ReloadDeviceSettings(); |
| 127 Mock::VerifyAndClearExpectations(this); | 127 Mock::VerifyAndClearExpectations(this); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Helper routine to ensure all heartbeat policies have been correctly | 130 // Helper routine to ensure all heartbeat policies have been correctly |
| 131 // decoded. | 131 // decoded. |
| 132 void VerifyHeartbeatSettings(bool expected_enable_state, | 132 void VerifyHeartbeatSettings(bool expected_enable_state, |
| 133 int expected_frequency) { | 133 int expected_frequency) { |
| 134 | 134 const base::Value expected_enabled_value(expected_enable_state); |
| 135 const base::FundamentalValue expected_enabled_value(expected_enable_state); | |
| 136 EXPECT_TRUE(base::Value::Equals(provider_->Get(kHeartbeatEnabled), | 135 EXPECT_TRUE(base::Value::Equals(provider_->Get(kHeartbeatEnabled), |
| 137 &expected_enabled_value)); | 136 &expected_enabled_value)); |
| 138 | 137 |
| 139 const base::FundamentalValue expected_frequency_value(expected_frequency); | 138 const base::Value expected_frequency_value(expected_frequency); |
| 140 EXPECT_TRUE(base::Value::Equals(provider_->Get(kHeartbeatFrequency), | 139 EXPECT_TRUE(base::Value::Equals(provider_->Get(kHeartbeatFrequency), |
| 141 &expected_frequency_value)); | 140 &expected_frequency_value)); |
| 142 } | 141 } |
| 143 | 142 |
| 144 // Helper routine to ensure all reporting policies have been correctly | 143 // Helper routine to ensure all reporting policies have been correctly |
| 145 // decoded. | 144 // decoded. |
| 146 void VerifyReportingSettings(bool expected_enable_state, | 145 void VerifyReportingSettings(bool expected_enable_state, |
| 147 int expected_frequency) { | 146 int expected_frequency) { |
| 148 const char* reporting_settings[] = { | 147 const char* reporting_settings[] = { |
| 149 kReportDeviceVersionInfo, | 148 kReportDeviceVersionInfo, |
| 150 kReportDeviceActivityTimes, | 149 kReportDeviceActivityTimes, |
| 151 kReportDeviceBootMode, | 150 kReportDeviceBootMode, |
| 152 // Device location reporting is not currently supported. | 151 // Device location reporting is not currently supported. |
| 153 // kReportDeviceLocation, | 152 // kReportDeviceLocation, |
| 154 kReportDeviceNetworkInterfaces, | 153 kReportDeviceNetworkInterfaces, |
| 155 kReportDeviceUsers, | 154 kReportDeviceUsers, |
| 156 kReportDeviceHardwareStatus, | 155 kReportDeviceHardwareStatus, |
| 157 kReportDeviceSessionStatus, | 156 kReportDeviceSessionStatus, |
| 158 kReportOsUpdateStatus, | 157 kReportOsUpdateStatus, |
| 159 kReportRunningKioskApp | 158 kReportRunningKioskApp |
| 160 }; | 159 }; |
| 161 | 160 |
| 162 const base::FundamentalValue expected_enable_value(expected_enable_state); | 161 const base::Value expected_enable_value(expected_enable_state); |
| 163 for (auto* setting : reporting_settings) { | 162 for (auto* setting : reporting_settings) { |
| 164 EXPECT_TRUE(base::Value::Equals(provider_->Get(setting), | 163 EXPECT_TRUE(base::Value::Equals(provider_->Get(setting), |
| 165 &expected_enable_value)) | 164 &expected_enable_value)) |
| 166 << "Value for " << setting << " does not match expected"; | 165 << "Value for " << setting << " does not match expected"; |
| 167 } | 166 } |
| 168 const base::FundamentalValue expected_frequency_value(expected_frequency); | 167 const base::Value expected_frequency_value(expected_frequency); |
| 169 EXPECT_TRUE(base::Value::Equals(provider_->Get(kReportUploadFrequency), | 168 EXPECT_TRUE(base::Value::Equals(provider_->Get(kReportUploadFrequency), |
| 170 &expected_frequency_value)); | 169 &expected_frequency_value)); |
| 171 } | 170 } |
| 172 | 171 |
| 173 // Helper routine to ensure log upload policy has been correctly | 172 // Helper routine to ensure log upload policy has been correctly |
| 174 // decoded. | 173 // decoded. |
| 175 void VerifyLogUploadSettings(bool expected_enable_state) { | 174 void VerifyLogUploadSettings(bool expected_enable_state) { |
| 176 const base::FundamentalValue expected_enabled_value(expected_enable_state); | 175 const base::Value expected_enabled_value(expected_enable_state); |
| 177 EXPECT_TRUE(base::Value::Equals(provider_->Get(kSystemLogUploadEnabled), | 176 EXPECT_TRUE(base::Value::Equals(provider_->Get(kSystemLogUploadEnabled), |
| 178 &expected_enabled_value)); | 177 &expected_enabled_value)); |
| 179 } | 178 } |
| 180 | 179 |
| 181 // Helper routine to set LoginScreenDomainAutoComplete policy. | 180 // Helper routine to set LoginScreenDomainAutoComplete policy. |
| 182 void SetDomainAutoComplete(const std::string& domain) { | 181 void SetDomainAutoComplete(const std::string& domain) { |
| 183 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); | 182 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); |
| 184 em::LoginScreenDomainAutoCompleteProto* proto = | 183 em::LoginScreenDomainAutoCompleteProto* proto = |
| 185 device_policy_.payload().mutable_login_screen_domain_auto_complete(); | 184 device_policy_.payload().mutable_login_screen_domain_auto_complete(); |
| 186 proto->set_login_screen_domain_auto_complete(domain); | 185 proto->set_login_screen_domain_auto_complete(domain); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 const base::Value* saved_value = provider_->Get(kReleaseChannel); | 254 const base::Value* saved_value = provider_->Get(kReleaseChannel); |
| 256 ASSERT_TRUE(saved_value); | 255 ASSERT_TRUE(saved_value); |
| 257 EXPECT_TRUE(saved_value->GetAsString(&string_value)); | 256 EXPECT_TRUE(saved_value->GetAsString(&string_value)); |
| 258 ASSERT_EQ("stable-channel", string_value); | 257 ASSERT_EQ("stable-channel", string_value); |
| 259 } | 258 } |
| 260 | 259 |
| 261 TEST_F(DeviceSettingsProviderTest, SetPrefFailed) { | 260 TEST_F(DeviceSettingsProviderTest, SetPrefFailed) { |
| 262 SetMetricsReportingSettings(false); | 261 SetMetricsReportingSettings(false); |
| 263 | 262 |
| 264 // If we are not the owner no sets should work. | 263 // If we are not the owner no sets should work. |
| 265 base::FundamentalValue value(true); | 264 base::Value value(true); |
| 266 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1); | 265 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1); |
| 267 provider_->Set(kStatsReportingPref, value); | 266 provider_->Set(kStatsReportingPref, value); |
| 268 Mock::VerifyAndClearExpectations(this); | 267 Mock::VerifyAndClearExpectations(this); |
| 269 | 268 |
| 270 // This shouldn't trigger a write. | 269 // This shouldn't trigger a write. |
| 271 device_settings_test_helper_.set_policy_blob(std::string()); | 270 device_settings_test_helper_.set_policy_blob(std::string()); |
| 272 FlushDeviceSettings(); | 271 FlushDeviceSettings(); |
| 273 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); | 272 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); |
| 274 | 273 |
| 275 // Verify the change has not been applied. | 274 // Verify the change has not been applied. |
| 276 const base::Value* saved_value = provider_->Get(kStatsReportingPref); | 275 const base::Value* saved_value = provider_->Get(kStatsReportingPref); |
| 277 ASSERT_TRUE(saved_value); | 276 ASSERT_TRUE(saved_value); |
| 278 bool bool_value; | 277 bool bool_value; |
| 279 EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value)); | 278 EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value)); |
| 280 EXPECT_FALSE(bool_value); | 279 EXPECT_FALSE(bool_value); |
| 281 } | 280 } |
| 282 | 281 |
| 283 TEST_F(DeviceSettingsProviderTest, SetPrefSucceed) { | 282 TEST_F(DeviceSettingsProviderTest, SetPrefSucceed) { |
| 284 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); | 283 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); |
| 285 InitOwner(AccountId::FromUserEmail(device_policy_.policy_data().username()), | 284 InitOwner(AccountId::FromUserEmail(device_policy_.policy_data().username()), |
| 286 true); | 285 true); |
| 287 FlushDeviceSettings(); | 286 FlushDeviceSettings(); |
| 288 | 287 |
| 289 base::FundamentalValue value(true); | 288 base::Value value(true); |
| 290 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); | 289 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); |
| 291 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1); | 290 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1); |
| 292 provider_->Set(kStatsReportingPref, value); | 291 provider_->Set(kStatsReportingPref, value); |
| 293 Mock::VerifyAndClearExpectations(this); | 292 Mock::VerifyAndClearExpectations(this); |
| 294 | 293 |
| 295 // Process the store. | 294 // Process the store. |
| 296 device_settings_test_helper_.set_policy_blob(std::string()); | 295 device_settings_test_helper_.set_policy_blob(std::string()); |
| 297 FlushDeviceSettings(); | 296 FlushDeviceSettings(); |
| 298 | 297 |
| 299 // Verify that the device policy has been adjusted. | 298 // Verify that the device policy has been adjusted. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 device_policy_.policy_data().mutable_device_state()->set_device_mode( | 415 device_policy_.policy_data().mutable_device_state()->set_device_mode( |
| 417 em::DeviceState::DEVICE_MODE_DISABLED); | 416 em::DeviceState::DEVICE_MODE_DISABLED); |
| 418 device_policy_.policy_data().mutable_device_state()-> | 417 device_policy_.policy_data().mutable_device_state()-> |
| 419 mutable_disabled_state()->set_message(kDisabledMessage); | 418 mutable_disabled_state()->set_message(kDisabledMessage); |
| 420 device_policy_.Build(); | 419 device_policy_.Build(); |
| 421 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 420 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 422 ReloadDeviceSettings(); | 421 ReloadDeviceSettings(); |
| 423 Mock::VerifyAndClearExpectations(this); | 422 Mock::VerifyAndClearExpectations(this); |
| 424 | 423 |
| 425 // Verify that the device state has been decoded correctly. | 424 // Verify that the device state has been decoded correctly. |
| 426 const base::FundamentalValue expected_disabled_value(true); | 425 const base::Value expected_disabled_value(true); |
| 427 EXPECT_TRUE(base::Value::Equals(provider_->Get(kDeviceDisabled), | 426 EXPECT_TRUE(base::Value::Equals(provider_->Get(kDeviceDisabled), |
| 428 &expected_disabled_value)); | 427 &expected_disabled_value)); |
| 429 const base::StringValue expected_disabled_message_value(kDisabledMessage); | 428 const base::StringValue expected_disabled_message_value(kDisabledMessage); |
| 430 EXPECT_TRUE(base::Value::Equals(provider_->Get(kDeviceDisabledMessage), | 429 EXPECT_TRUE(base::Value::Equals(provider_->Get(kDeviceDisabledMessage), |
| 431 &expected_disabled_message_value)); | 430 &expected_disabled_message_value)); |
| 432 | 431 |
| 433 // Verify that a change to the device state triggers a notification. | 432 // Verify that a change to the device state triggers a notification. |
| 434 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); | 433 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); |
| 435 device_policy_.policy_data().mutable_device_state()->clear_device_mode(); | 434 device_policy_.policy_data().mutable_device_state()->clear_device_mode(); |
| 436 device_policy_.Build(); | 435 device_policy_.Build(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 } | 483 } |
| 485 | 484 |
| 486 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { | 485 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { |
| 487 SetLogUploadSettings(true); | 486 SetLogUploadSettings(true); |
| 488 VerifyLogUploadSettings(true); | 487 VerifyLogUploadSettings(true); |
| 489 | 488 |
| 490 SetLogUploadSettings(false); | 489 SetLogUploadSettings(false); |
| 491 VerifyLogUploadSettings(false); | 490 VerifyLogUploadSettings(false); |
| 492 } | 491 } |
| 493 } // namespace chromeos | 492 } // namespace chromeos |
| OLD | NEW |