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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 em::DeviceHeartbeatSettingsProto* proto = | 92 em::DeviceHeartbeatSettingsProto* proto = |
93 device_policy_.payload().mutable_device_heartbeat_settings(); | 93 device_policy_.payload().mutable_device_heartbeat_settings(); |
94 proto->set_heartbeat_enabled(enable_heartbeat); | 94 proto->set_heartbeat_enabled(enable_heartbeat); |
95 proto->set_heartbeat_frequency(frequency); | 95 proto->set_heartbeat_frequency(frequency); |
96 device_policy_.Build(); | 96 device_policy_.Build(); |
97 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 97 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
98 ReloadDeviceSettings(); | 98 ReloadDeviceSettings(); |
99 Mock::VerifyAndClearExpectations(this); | 99 Mock::VerifyAndClearExpectations(this); |
100 } | 100 } |
101 | 101 |
| 102 // Helper routine to enable/disable log upload settings in policy. |
| 103 void SetLogUploadSettings(bool enable_log_upload) { |
| 104 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); |
| 105 em::DeviceLogUploadSettingsProto* proto = |
| 106 device_policy_.payload().mutable_device_log_upload_settings(); |
| 107 proto->set_log_upload_enabled(enable_log_upload); |
| 108 device_policy_.Build(); |
| 109 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 110 ReloadDeviceSettings(); |
| 111 Mock::VerifyAndClearExpectations(this); |
| 112 } |
| 113 |
102 // Helper routine to ensure all heartbeat policies have been correctly | 114 // Helper routine to ensure all heartbeat policies have been correctly |
103 // decoded. | 115 // decoded. |
104 void VerifyHeartbeatSettings(bool expected_enable_state, | 116 void VerifyHeartbeatSettings(bool expected_enable_state, |
105 int expected_frequency) { | 117 int expected_frequency) { |
106 | 118 |
107 const base::FundamentalValue expected_enabled_value(expected_enable_state); | 119 const base::FundamentalValue expected_enabled_value(expected_enable_state); |
108 EXPECT_TRUE(base::Value::Equals(provider_->Get(kHeartbeatEnabled), | 120 EXPECT_TRUE(base::Value::Equals(provider_->Get(kHeartbeatEnabled), |
109 &expected_enabled_value)); | 121 &expected_enabled_value)); |
110 | 122 |
111 const base::FundamentalValue expected_frequency_value(expected_frequency); | 123 const base::FundamentalValue expected_frequency_value(expected_frequency); |
(...skipping 21 matching lines...) Expand all Loading... |
133 for (const auto& setting : reporting_settings) { | 145 for (const auto& setting : reporting_settings) { |
134 EXPECT_TRUE(base::Value::Equals(provider_->Get(setting), | 146 EXPECT_TRUE(base::Value::Equals(provider_->Get(setting), |
135 &expected_enable_value)) | 147 &expected_enable_value)) |
136 << "Value for " << setting << " does not match expected"; | 148 << "Value for " << setting << " does not match expected"; |
137 } | 149 } |
138 const base::FundamentalValue expected_frequency_value(expected_frequency); | 150 const base::FundamentalValue expected_frequency_value(expected_frequency); |
139 EXPECT_TRUE(base::Value::Equals(provider_->Get(kReportUploadFrequency), | 151 EXPECT_TRUE(base::Value::Equals(provider_->Get(kReportUploadFrequency), |
140 &expected_frequency_value)); | 152 &expected_frequency_value)); |
141 } | 153 } |
142 | 154 |
| 155 // Helper routine to ensure log upload policy has been correctly |
| 156 // decoded. |
| 157 void VerifyLogUploadSettings(bool expected_enable_state) { |
| 158 const base::FundamentalValue expected_enabled_value(expected_enable_state); |
| 159 EXPECT_TRUE(base::Value::Equals(provider_->Get(kLogUploadEnabled), |
| 160 &expected_enabled_value)); |
| 161 } |
| 162 |
143 // Helper routine to set LoginScreenDomainAutoComplete policy. | 163 // Helper routine to set LoginScreenDomainAutoComplete policy. |
144 void SetDomainAutoComplete(const std::string& domain) { | 164 void SetDomainAutoComplete(const std::string& domain) { |
145 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); | 165 EXPECT_CALL(*this, SettingChanged(_)).Times(AtLeast(1)); |
146 em::LoginScreenDomainAutoCompleteProto* proto = | 166 em::LoginScreenDomainAutoCompleteProto* proto = |
147 device_policy_.payload().mutable_login_screen_domain_auto_complete(); | 167 device_policy_.payload().mutable_login_screen_domain_auto_complete(); |
148 proto->set_login_screen_domain_auto_complete(domain); | 168 proto->set_login_screen_domain_auto_complete(domain); |
149 device_policy_.Build(); | 169 device_policy_.Build(); |
150 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 170 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
151 ReloadDeviceSettings(); | 171 ReloadDeviceSettings(); |
152 Mock::VerifyAndClearExpectations(this); | 172 Mock::VerifyAndClearExpectations(this); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 SetDomainAutoComplete(""); | 491 SetDomainAutoComplete(""); |
472 VerifyDomainAutoComplete(nullptr); | 492 VerifyDomainAutoComplete(nullptr); |
473 | 493 |
474 // Check some meaningful value. Policy should be set. | 494 // Check some meaningful value. Policy should be set. |
475 const std::string domain = "domain.test"; | 495 const std::string domain = "domain.test"; |
476 const base::StringValue domain_value(domain); | 496 const base::StringValue domain_value(domain); |
477 SetDomainAutoComplete(domain); | 497 SetDomainAutoComplete(domain); |
478 VerifyDomainAutoComplete(&domain_value); | 498 VerifyDomainAutoComplete(&domain_value); |
479 } | 499 } |
480 | 500 |
| 501 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { |
| 502 SetLogUploadSettings(true); |
| 503 VerifyLogUploadSettings(true); |
| 504 |
| 505 SetLogUploadSettings(false); |
| 506 VerifyLogUploadSettings(false); |
| 507 } |
481 } // namespace chromeos | 508 } // namespace chromeos |
OLD | NEW |