Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: chrome/browser/chromeos/policy/network_configuration_updater_unittest.cc

Issue 1019283004: Switch to direct use of OwnerSettingsServiceChromeOS::Set() in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/policy/device_network_configuration_updater.h" 12 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h"
13 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" 13 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h"
14 #include "chrome/browser/chromeos/settings/cros_settings.h" 14 #include "chrome/browser/chromeos/settings/cros_settings.h"
15 #include "chrome/browser/chromeos/settings/device_settings_service.h" 15 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
16 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
17 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
18 #include "chromeos/network/fake_network_device_handler.h" 17 #include "chromeos/network/fake_network_device_handler.h"
19 #include "chromeos/network/mock_managed_network_configuration_handler.h" 18 #include "chromeos/network/mock_managed_network_configuration_handler.h"
20 #include "chromeos/network/onc/onc_certificate_importer.h" 19 #include "chromeos/network/onc/onc_certificate_importer.h"
21 #include "chromeos/network/onc/onc_test_utils.h" 20 #include "chromeos/network/onc/onc_test_utils.h"
22 #include "chromeos/network/onc/onc_utils.h" 21 #include "chromeos/network/onc/onc_utils.h"
23 #include "components/onc/onc_constants.h" 22 #include "components/onc/onc_constants.h"
24 #include "components/policy/core/common/external_data_fetcher.h" 23 #include "components/policy/core/common/external_data_fetcher.h"
25 #include "components/policy/core/common/mock_configuration_policy_provider.h" 24 #include "components/policy/core/common/mock_configuration_policy_provider.h"
26 #include "components/policy/core/common/policy_map.h" 25 #include "components/policy/core/common/policy_map.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 &network_device_handler_, 279 &network_device_handler_,
281 chromeos::CrosSettings::Get()); 280 chromeos::CrosSettings::Get());
282 } 281 }
283 282
284 base::ListValue fake_network_configs_; 283 base::ListValue fake_network_configs_;
285 base::DictionaryValue fake_global_network_config_; 284 base::DictionaryValue fake_global_network_config_;
286 base::ListValue fake_certificates_; 285 base::ListValue fake_certificates_;
287 StrictMock<chromeos::MockManagedNetworkConfigurationHandler> 286 StrictMock<chromeos::MockManagedNetworkConfigurationHandler>
288 network_config_handler_; 287 network_config_handler_;
289 FakeNetworkDeviceHandler network_device_handler_; 288 FakeNetworkDeviceHandler network_device_handler_;
290 289 chromeos::ScopedCrosSettingsTestHelper settings_helper_;
291 // Not used directly. Required for CrosSettings.
292 chromeos::ScopedTestDeviceSettingsService scoped_device_settings_service_;
293 chromeos::ScopedTestCrosSettings scoped_cros_settings_;
294 290
295 // Ownership of certificate_importer_owned_ is passed to the 291 // Ownership of certificate_importer_owned_ is passed to the
296 // NetworkConfigurationUpdater. When that happens, |certificate_importer_| 292 // NetworkConfigurationUpdater. When that happens, |certificate_importer_|
297 // continues to point to that instance but |certificate_importer_owned_| is 293 // continues to point to that instance but |certificate_importer_owned_| is
298 // released. 294 // released.
299 FakeCertificateImporter* certificate_importer_; 295 FakeCertificateImporter* certificate_importer_;
300 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_owned_; 296 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_owned_;
301 297
302 StrictMock<MockConfigurationPolicyProvider> provider_; 298 StrictMock<MockConfigurationPolicyProvider> provider_;
303 scoped_ptr<PolicyServiceImpl> policy_service_; 299 scoped_ptr<PolicyServiceImpl> policy_service_;
304 FakeUser fake_user_; 300 FakeUser fake_user_;
305 301
306 TestingProfile profile_; 302 TestingProfile profile_;
307 303
308 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; 304 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_;
309 content::TestBrowserThreadBundle thread_bundle_; 305 content::TestBrowserThreadBundle thread_bundle_;
310 }; 306 };
311 307
312 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) { 308 TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) {
313 // Ignore network config updates. 309 // Ignore network config updates.
314 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); 310 EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1));
315 311
316 // Setup the DataRoaming device setting. 312 settings_helper_.ReplaceProvider(chromeos::kSignedDataRoamingEnabled);
317 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); 313 settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, false);
318 chromeos::CrosSettingsProvider* device_settings_provider =
319 cros_settings->GetProvider(chromeos::kSignedDataRoamingEnabled);
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_); 314 EXPECT_FALSE(network_device_handler_.allow_roaming_);
329 315
330 CreateNetworkConfigurationUpdaterForDevicePolicy(); 316 CreateNetworkConfigurationUpdaterForDevicePolicy();
331 MarkPolicyProviderInitialized(); 317 MarkPolicyProviderInitialized();
332 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, 318 settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, true);
333 base::FundamentalValue(true));
334 EXPECT_TRUE(network_device_handler_.allow_roaming_); 319 EXPECT_TRUE(network_device_handler_.allow_roaming_);
335 320
336 chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, 321 settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, false);
337 base::FundamentalValue(false));
338 EXPECT_FALSE(network_device_handler_.allow_roaming_); 322 EXPECT_FALSE(network_device_handler_.allow_roaming_);
339 } 323 }
340 324
341 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) { 325 TEST_F(NetworkConfigurationUpdaterTest, PolicyIsValidatedAndRepaired) {
342 scoped_ptr<base::DictionaryValue> onc_repaired = 326 scoped_ptr<base::DictionaryValue> onc_repaired =
343 chromeos::onc::test_utils::ReadTestDictionary( 327 chromeos::onc::test_utils::ReadTestDictionary(
344 "repaired_toplevel_partially_invalid.onc"); 328 "repaired_toplevel_partially_invalid.onc");
345 329
346 base::ListValue* network_configs_repaired = NULL; 330 base::ListValue* network_configs_repaired = NULL;
347 onc_repaired->GetListWithoutPathExpansion( 331 onc_repaired->GetListWithoutPathExpansion(
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 EXPECT_EQ(ExpectedImportCertificatesCallCount(), 657 EXPECT_EQ(ExpectedImportCertificatesCallCount(),
674 certificate_importer_->GetAndResetImportCount()); 658 certificate_importer_->GetAndResetImportCount());
675 } 659 }
676 660
677 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, 661 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance,
678 NetworkConfigurationUpdaterTestWithParam, 662 NetworkConfigurationUpdaterTestWithParam,
679 testing::Values(key::kDeviceOpenNetworkConfiguration, 663 testing::Values(key::kDeviceOpenNetworkConfiguration,
680 key::kOpenNetworkConfiguration)); 664 key::kOpenNetworkConfiguration));
681 665
682 } // namespace policy 666 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698