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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" |
12 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h" | 13 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h" |
13 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" | 14 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" |
14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
15 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 16 #include "chrome/browser/chromeos/settings/settings_provider_test_base.h" |
16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | |
17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
18 #include "chromeos/network/fake_network_device_handler.h" | 18 #include "chromeos/network/fake_network_device_handler.h" |
19 #include "chromeos/network/mock_managed_network_configuration_handler.h" | 19 #include "chromeos/network/mock_managed_network_configuration_handler.h" |
20 #include "chromeos/network/onc/onc_certificate_importer.h" | 20 #include "chromeos/network/onc/onc_certificate_importer.h" |
21 #include "chromeos/network/onc/onc_test_utils.h" | 21 #include "chromeos/network/onc/onc_test_utils.h" |
22 #include "chromeos/network/onc/onc_utils.h" | 22 #include "chromeos/network/onc/onc_utils.h" |
23 #include "components/onc/onc_constants.h" | 23 #include "components/onc/onc_constants.h" |
24 #include "components/policy/core/common/external_data_fetcher.h" | 24 #include "components/policy/core/common/external_data_fetcher.h" |
25 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 25 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
26 #include "components/policy/core/common/policy_map.h" | 26 #include "components/policy/core/common/policy_map.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 | 192 |
193 ACTION_P(SetCertificateList, list) { | 193 ACTION_P(SetCertificateList, list) { |
194 if (arg2) | 194 if (arg2) |
195 *arg2 = list; | 195 *arg2 = list; |
196 return true; | 196 return true; |
197 } | 197 } |
198 | 198 |
199 } // namespace | 199 } // namespace |
200 | 200 |
201 class NetworkConfigurationUpdaterTest : public testing::Test { | 201 class NetworkConfigurationUpdaterTest |
| 202 : public testing::Test, |
| 203 public chromeos::SettingsProviderTestBase { |
202 protected: | 204 protected: |
203 NetworkConfigurationUpdaterTest() : certificate_importer_(NULL) {} | 205 NetworkConfigurationUpdaterTest() : certificate_importer_(NULL) {} |
204 | 206 |
205 virtual void SetUp() override { | 207 virtual void SetUp() override { |
206 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 208 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
207 .WillRepeatedly(Return(false)); | 209 .WillRepeatedly(Return(false)); |
208 provider_.Init(); | 210 provider_.Init(); |
209 PolicyServiceImpl::Providers providers; | 211 PolicyServiceImpl::Providers providers; |
210 providers.push_back(&provider_); | 212 providers.push_back(&provider_); |
211 policy_service_.reset(new PolicyServiceImpl(providers)); | 213 policy_service_.reset(new PolicyServiceImpl(providers)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 chromeos::CrosSettings::Get()); | 283 chromeos::CrosSettings::Get()); |
282 } | 284 } |
283 | 285 |
284 base::ListValue fake_network_configs_; | 286 base::ListValue fake_network_configs_; |
285 base::DictionaryValue fake_global_network_config_; | 287 base::DictionaryValue fake_global_network_config_; |
286 base::ListValue fake_certificates_; | 288 base::ListValue fake_certificates_; |
287 StrictMock<chromeos::MockManagedNetworkConfigurationHandler> | 289 StrictMock<chromeos::MockManagedNetworkConfigurationHandler> |
288 network_config_handler_; | 290 network_config_handler_; |
289 FakeNetworkDeviceHandler network_device_handler_; | 291 FakeNetworkDeviceHandler network_device_handler_; |
290 | 292 |
291 // Not used directly. Required for CrosSettings. | |
292 chromeos::ScopedTestDeviceSettingsService scoped_device_settings_service_; | |
293 chromeos::ScopedTestCrosSettings scoped_cros_settings_; | |
294 | |
295 // Ownership of certificate_importer_owned_ is passed to the | 293 // Ownership of certificate_importer_owned_ is passed to the |
296 // NetworkConfigurationUpdater. When that happens, |certificate_importer_| | 294 // NetworkConfigurationUpdater. When that happens, |certificate_importer_| |
297 // continues to point to that instance but |certificate_importer_owned_| is | 295 // continues to point to that instance but |certificate_importer_owned_| is |
298 // released. | 296 // released. |
299 FakeCertificateImporter* certificate_importer_; | 297 FakeCertificateImporter* certificate_importer_; |
300 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_owned_; | 298 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_owned_; |
301 | 299 |
302 StrictMock<MockConfigurationPolicyProvider> provider_; | 300 StrictMock<MockConfigurationPolicyProvider> provider_; |
303 scoped_ptr<PolicyServiceImpl> policy_service_; | 301 scoped_ptr<PolicyServiceImpl> policy_service_; |
304 FakeUser fake_user_; | 302 FakeUser fake_user_; |
305 | 303 |
306 TestingProfile profile_; | 304 TestingProfile profile_; |
307 | 305 |
308 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; | 306 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; |
309 content::TestBrowserThreadBundle thread_bundle_; | 307 content::TestBrowserThreadBundle thread_bundle_; |
310 }; | 308 }; |
311 | 309 |
312 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) { | 310 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) { |
313 // Ignore network config updates. | 311 // Ignore network config updates. |
314 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); | 312 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); |
315 | 313 |
316 // Setup the DataRoaming device setting. | 314 ReplaceProvider(chromeos::kSignedDataRoamingEnabled); |
317 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); | 315 InitOwnerSettingsService(nullptr); |
318 chromeos::CrosSettingsProvider* device_settings_provider = | 316 owner_settings_service_->SetBoolean(chromeos::kSignedDataRoamingEnabled, |
319 cros_settings->GetProvider(chromeos::kSignedDataRoamingEnabled); | 317 false); |
320 cros_settings->RemoveSettingsProvider(device_settings_provider); | |
321 delete device_settings_provider; | |
322 chromeos::StubCrosSettingsProvider* stub_settings_provider = | |
323 new chromeos::StubCrosSettingsProvider; | |
324 cros_settings->AddSettingsProvider(stub_settings_provider); | |
325 | |
326 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, | |
327 base::FundamentalValue(false)); | |
328 EXPECT_FALSE(network_device_handler_.allow_roaming_); | 318 EXPECT_FALSE(network_device_handler_.allow_roaming_); |
329 | 319 |
330 CreateNetworkConfigurationUpdaterForDevicePolicy(); | 320 CreateNetworkConfigurationUpdaterForDevicePolicy(); |
331 MarkPolicyProviderInitialized(); | 321 MarkPolicyProviderInitialized(); |
332 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, | 322 owner_settings_service_->SetBoolean(chromeos::kSignedDataRoamingEnabled, |
333 base::FundamentalValue(true)); | 323 true); |
334 EXPECT_TRUE(network_device_handler_.allow_roaming_); | 324 EXPECT_TRUE(network_device_handler_.allow_roaming_); |
335 | 325 |
336 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, | 326 owner_settings_service_->SetBoolean(chromeos::kSignedDataRoamingEnabled, |
337 base::FundamentalValue(false)); | 327 false); |
338 EXPECT_FALSE(network_device_handler_.allow_roaming_); | 328 EXPECT_FALSE(network_device_handler_.allow_roaming_); |
| 329 RestoreProvider(); |
339 } | 330 } |
340 | 331 |
341 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) { | 332 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) { |
342 scoped_ptr<base::DictionaryValue> onc_repaired = | 333 scoped_ptr<base::DictionaryValue> onc_repaired = |
343 chromeos::onc::test_utils::ReadTestDictionary( | 334 chromeos::onc::test_utils::ReadTestDictionary( |
344 "repaired_toplevel_partially_invalid.onc"); | 335 "repaired_toplevel_partially_invalid.onc"); |
345 | 336 |
346 base::ListValue* network_configs_repaired = NULL; | 337 base::ListValue* network_configs_repaired = NULL; |
347 onc_repaired->GetListWithoutPathExpansion( | 338 onc_repaired->GetListWithoutPathExpansion( |
348 onc::toplevel_config::kNetworkConfigurations, &network_configs_repaired); | 339 onc::toplevel_config::kNetworkConfigurations, &network_configs_repaired); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 EXPECT_EQ(ExpectedImportCertificatesCallCount(), | 664 EXPECT_EQ(ExpectedImportCertificatesCallCount(), |
674 certificate_importer_->GetAndResetImportCount()); | 665 certificate_importer_->GetAndResetImportCount()); |
675 } | 666 } |
676 | 667 |
677 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, | 668 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, |
678 NetworkConfigurationUpdaterTestWithParam, | 669 NetworkConfigurationUpdaterTestWithParam, |
679 testing::Values(key::kDeviceOpenNetworkConfiguration, | 670 testing::Values(key::kDeviceOpenNetworkConfiguration, |
680 key::kOpenNetworkConfiguration)); | 671 key::kOpenNetworkConfiguration)); |
681 | 672 |
682 } // namespace policy | 673 } // namespace policy |
OLD | NEW |