OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
| 6 |
| 7 #include <memory> |
6 #include <utility> | 8 #include <utility> |
7 | 9 |
8 #include "base/bind.h" | 10 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 12 #include "base/callback.h" |
11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
12 #include "base/macros.h" | 14 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h" | 17 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h" |
17 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" | 18 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" |
18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
19 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" | 20 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" |
20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
21 #include "chromeos/network/fake_network_device_handler.h" | 22 #include "chromeos/network/fake_network_device_handler.h" |
22 #include "chromeos/network/mock_managed_network_configuration_handler.h" | 23 #include "chromeos/network/mock_managed_network_configuration_handler.h" |
23 #include "chromeos/network/onc/onc_certificate_importer.h" | 24 #include "chromeos/network/onc/onc_certificate_importer.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 if (expected_onc_certificates_) { | 136 if (expected_onc_certificates_) { |
136 EXPECT_TRUE(chromeos::onc::test_utils::Equals( | 137 EXPECT_TRUE(chromeos::onc::test_utils::Equals( |
137 expected_onc_certificates_.get(), &certificates)); | 138 expected_onc_certificates_.get(), &certificates)); |
138 } | 139 } |
139 ++call_count_; | 140 ++call_count_; |
140 done_callback.Run(true, onc_trusted_certificates_); | 141 done_callback.Run(true, onc_trusted_certificates_); |
141 } | 142 } |
142 | 143 |
143 private: | 144 private: |
144 ::onc::ONCSource expected_onc_source_; | 145 ::onc::ONCSource expected_onc_source_; |
145 scoped_ptr<base::ListValue> expected_onc_certificates_; | 146 std::unique_ptr<base::ListValue> expected_onc_certificates_; |
146 net::CertificateList onc_trusted_certificates_; | 147 net::CertificateList onc_trusted_certificates_; |
147 unsigned int call_count_; | 148 unsigned int call_count_; |
148 | 149 |
149 DISALLOW_COPY_AND_ASSIGN(FakeCertificateImporter); | 150 DISALLOW_COPY_AND_ASSIGN(FakeCertificateImporter); |
150 }; | 151 }; |
151 | 152 |
152 const char kFakeONC[] = | 153 const char kFakeONC[] = |
153 "{ \"NetworkConfigurations\": [" | 154 "{ \"NetworkConfigurations\": [" |
154 " { \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5040}\"," | 155 " { \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5040}\"," |
155 " \"Type\": \"WiFi\"," | 156 " \"Type\": \"WiFi\"," |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 NetworkConfigurationUpdaterTest() : certificate_importer_(NULL) {} | 209 NetworkConfigurationUpdaterTest() : certificate_importer_(NULL) {} |
209 | 210 |
210 void SetUp() override { | 211 void SetUp() override { |
211 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 212 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
212 .WillRepeatedly(Return(false)); | 213 .WillRepeatedly(Return(false)); |
213 provider_.Init(); | 214 provider_.Init(); |
214 PolicyServiceImpl::Providers providers; | 215 PolicyServiceImpl::Providers providers; |
215 providers.push_back(&provider_); | 216 providers.push_back(&provider_); |
216 policy_service_.reset(new PolicyServiceImpl(providers)); | 217 policy_service_.reset(new PolicyServiceImpl(providers)); |
217 | 218 |
218 scoped_ptr<base::DictionaryValue> fake_toplevel_onc = | 219 std::unique_ptr<base::DictionaryValue> fake_toplevel_onc = |
219 chromeos::onc::ReadDictionaryFromJson(kFakeONC); | 220 chromeos::onc::ReadDictionaryFromJson(kFakeONC); |
220 | 221 |
221 base::ListValue* network_configs = NULL; | 222 base::ListValue* network_configs = NULL; |
222 fake_toplevel_onc->GetListWithoutPathExpansion( | 223 fake_toplevel_onc->GetListWithoutPathExpansion( |
223 onc::toplevel_config::kNetworkConfigurations, &network_configs); | 224 onc::toplevel_config::kNetworkConfigurations, &network_configs); |
224 AppendAll(*network_configs, &fake_network_configs_); | 225 AppendAll(*network_configs, &fake_network_configs_); |
225 | 226 |
226 base::DictionaryValue* global_config = NULL; | 227 base::DictionaryValue* global_config = NULL; |
227 fake_toplevel_onc->GetDictionaryWithoutPathExpansion( | 228 fake_toplevel_onc->GetDictionaryWithoutPathExpansion( |
228 onc::toplevel_config::kGlobalNetworkConfiguration, &global_config); | 229 onc::toplevel_config::kGlobalNetworkConfiguration, &global_config); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 StrictMock<chromeos::MockManagedNetworkConfigurationHandler> | 293 StrictMock<chromeos::MockManagedNetworkConfigurationHandler> |
293 network_config_handler_; | 294 network_config_handler_; |
294 FakeNetworkDeviceHandler network_device_handler_; | 295 FakeNetworkDeviceHandler network_device_handler_; |
295 chromeos::ScopedCrosSettingsTestHelper settings_helper_; | 296 chromeos::ScopedCrosSettingsTestHelper settings_helper_; |
296 | 297 |
297 // Ownership of certificate_importer_owned_ is passed to the | 298 // Ownership of certificate_importer_owned_ is passed to the |
298 // NetworkConfigurationUpdater. When that happens, |certificate_importer_| | 299 // NetworkConfigurationUpdater. When that happens, |certificate_importer_| |
299 // continues to point to that instance but |certificate_importer_owned_| is | 300 // continues to point to that instance but |certificate_importer_owned_| is |
300 // released. | 301 // released. |
301 FakeCertificateImporter* certificate_importer_; | 302 FakeCertificateImporter* certificate_importer_; |
302 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_owned_; | 303 std::unique_ptr<chromeos::onc::CertificateImporter> |
| 304 certificate_importer_owned_; |
303 | 305 |
304 StrictMock<MockConfigurationPolicyProvider> provider_; | 306 StrictMock<MockConfigurationPolicyProvider> provider_; |
305 scoped_ptr<PolicyServiceImpl> policy_service_; | 307 std::unique_ptr<PolicyServiceImpl> policy_service_; |
306 FakeUser fake_user_; | 308 FakeUser fake_user_; |
307 | 309 |
308 TestingProfile profile_; | 310 TestingProfile profile_; |
309 | 311 |
310 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; | 312 std::unique_ptr<NetworkConfigurationUpdater> network_configuration_updater_; |
311 content::TestBrowserThreadBundle thread_bundle_; | 313 content::TestBrowserThreadBundle thread_bundle_; |
312 }; | 314 }; |
313 | 315 |
314 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) { | 316 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) { |
315 // Ignore network config updates. | 317 // Ignore network config updates. |
316 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); | 318 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); |
317 | 319 |
318 settings_helper_.ReplaceProvider(chromeos::kSignedDataRoamingEnabled); | 320 settings_helper_.ReplaceProvider(chromeos::kSignedDataRoamingEnabled); |
319 settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, false); | 321 settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, false); |
320 EXPECT_FALSE(network_device_handler_.allow_roaming_); | 322 EXPECT_FALSE(network_device_handler_.allow_roaming_); |
321 | 323 |
322 CreateNetworkConfigurationUpdaterForDevicePolicy(); | 324 CreateNetworkConfigurationUpdaterForDevicePolicy(); |
323 MarkPolicyProviderInitialized(); | 325 MarkPolicyProviderInitialized(); |
324 settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, true); | 326 settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, true); |
325 EXPECT_TRUE(network_device_handler_.allow_roaming_); | 327 EXPECT_TRUE(network_device_handler_.allow_roaming_); |
326 | 328 |
327 settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, false); | 329 settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, false); |
328 EXPECT_FALSE(network_device_handler_.allow_roaming_); | 330 EXPECT_FALSE(network_device_handler_.allow_roaming_); |
329 } | 331 } |
330 | 332 |
331 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) { | 333 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) { |
332 scoped_ptr<base::DictionaryValue> onc_repaired = | 334 std::unique_ptr<base::DictionaryValue> onc_repaired = |
333 chromeos::onc::test_utils::ReadTestDictionary( | 335 chromeos::onc::test_utils::ReadTestDictionary( |
334 "repaired_toplevel_partially_invalid.onc"); | 336 "repaired_toplevel_partially_invalid.onc"); |
335 | 337 |
336 base::ListValue* network_configs_repaired = NULL; | 338 base::ListValue* network_configs_repaired = NULL; |
337 onc_repaired->GetListWithoutPathExpansion( | 339 onc_repaired->GetListWithoutPathExpansion( |
338 onc::toplevel_config::kNetworkConfigurations, &network_configs_repaired); | 340 onc::toplevel_config::kNetworkConfigurations, &network_configs_repaired); |
339 ASSERT_TRUE(network_configs_repaired); | 341 ASSERT_TRUE(network_configs_repaired); |
340 | 342 |
341 base::DictionaryValue* global_config_repaired = NULL; | 343 base::DictionaryValue* global_config_repaired = NULL; |
342 onc_repaired->GetDictionaryWithoutPathExpansion( | 344 onc_repaired->GetDictionaryWithoutPathExpansion( |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 EXPECT_EQ(ExpectedImportCertificatesCallCount(), | 669 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
668 certificate_importer_->GetAndResetImportCount()); | 670 certificate_importer_->GetAndResetImportCount()); |
669 } | 671 } |
670 | 672 |
671 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, | 673 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, |
672 NetworkConfigurationUpdaterTestWithParam, | 674 NetworkConfigurationUpdaterTestWithParam, |
673 testing::Values(key::kDeviceOpenNetworkConfiguration, | 675 testing::Values(key::kDeviceOpenNetworkConfiguration, |
674 key::kOpenNetworkConfiguration)); | 676 key::kOpenNetworkConfiguration)); |
675 | 677 |
676 } // namespace policy | 678 } // namespace policy |
OLD | NEW |