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

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

Issue 10377115: Refactored NetworkConfigurationUpdater to read policy from the PolicyService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Invoke callbacks the right way Created 8 years, 7 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 (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/policy/network_configuration_updater.h" 5 #include "chrome/browser/policy/network_configuration_updater.h"
6 6
7 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/chromeos/cros/mock_network_library.h" 8 #include "chrome/browser/chromeos/cros/mock_network_library.h"
8 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 9 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
9 #include "chrome/browser/policy/policy_map.h" 10 #include "chrome/browser/policy/policy_map.h"
11 #include "chrome/browser/policy/policy_service_impl.h"
10 #include "policy/policy_constants.h" 12 #include "policy/policy_constants.h"
11 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 using testing::Mock; 16 using testing::Mock;
15 using testing::Return; 17 using testing::Return;
16 using testing::_; 18 using testing::_;
17 19
18 namespace policy { 20 namespace policy {
19 21
20 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; 22 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }";
21 23
22 class NetworkConfigurationUpdaterTest 24 class NetworkConfigurationUpdaterTest
23 : public testing::TestWithParam<const char*> { 25 : public testing::TestWithParam<const char*> {
24 protected: 26 protected:
25 virtual void SetUp() OVERRIDE { 27 virtual void SetUp() OVERRIDE {
26 EXPECT_CALL(network_library_, LoadOncNetworks(_, "", _, _)) 28 EXPECT_CALL(network_library_, LoadOncNetworks(_, "", _, _))
27 .WillRepeatedly(Return(true)); 29 .WillRepeatedly(Return(true));
30 PolicyServiceImpl::Providers providers;
31 providers.push_back(&provider_);
32 policy_service_.reset(new PolicyServiceImpl(providers));
28 } 33 }
29 34
30 // Maps configuration policy name to corresponding ONC source. 35 // Maps configuration policy name to corresponding ONC source.
31 static chromeos::NetworkUIData::ONCSource NameToONCSource( 36 static chromeos::NetworkUIData::ONCSource NameToONCSource(
32 const std::string& name) { 37 const std::string& name) {
33 if (name == key::kDeviceOpenNetworkConfiguration) 38 if (name == key::kDeviceOpenNetworkConfiguration)
34 return chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY; 39 return chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY;
35 if (name == key::kOpenNetworkConfiguration) 40 if (name == key::kOpenNetworkConfiguration)
36 return chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY; 41 return chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY;
37 return chromeos::NetworkUIData::ONC_SOURCE_NONE; 42 return chromeos::NetworkUIData::ONC_SOURCE_NONE;
38 } 43 }
39 44
40 chromeos::MockNetworkLibrary network_library_; 45 chromeos::MockNetworkLibrary network_library_;
41 MockConfigurationPolicyProvider provider_; 46 MockConfigurationPolicyProvider provider_;
47 scoped_ptr<PolicyServiceImpl> policy_service_;
Mattias Nissler (ping if slow) 2012/05/14 08:14:25 I guess we eventually want a MockPolicyService tha
42 }; 48 };
43 49
44 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) { 50 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) {
45 PolicyMap policy; 51 PolicyMap policy;
46 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 52 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
47 Value::CreateStringValue(kFakeONC)); 53 Value::CreateStringValue(kFakeONC));
48 provider_.UpdateProviderChromePolicy(policy); 54 provider_.UpdateProviderChromePolicy(policy);
49 55
50 EXPECT_CALL(network_library_, 56 EXPECT_CALL(network_library_,
51 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 57 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _))
52 .WillOnce(Return(true)); 58 .WillOnce(Return(true));
53 59
54 NetworkConfigurationUpdater updater(&provider_, &network_library_); 60 NetworkConfigurationUpdater updater(policy_service_.get(), &network_library_);
55 Mock::VerifyAndClearExpectations(&network_library_); 61 Mock::VerifyAndClearExpectations(&network_library_);
56 } 62 }
57 63
58 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { 64 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) {
59 NetworkConfigurationUpdater updater(&provider_, &network_library_); 65 NetworkConfigurationUpdater updater(policy_service_.get(), &network_library_);
60 66
61 // We should update if policy changes. 67 // We should update if policy changes.
62 EXPECT_CALL(network_library_, 68 EXPECT_CALL(network_library_,
63 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 69 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _))
64 .WillOnce(Return(true)); 70 .WillOnce(Return(true));
65 PolicyMap policy; 71 PolicyMap policy;
66 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 72 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
67 Value::CreateStringValue(kFakeONC)); 73 Value::CreateStringValue(kFakeONC));
68 provider_.UpdateProviderChromePolicy(policy); 74 provider_.UpdateProviderChromePolicy(policy);
69 Mock::VerifyAndClearExpectations(&network_library_); 75 Mock::VerifyAndClearExpectations(&network_library_);
(...skipping 15 matching lines...) Expand all
85 Mock::VerifyAndClearExpectations(&network_library_); 91 Mock::VerifyAndClearExpectations(&network_library_);
86 } 92 }
87 93
88 INSTANTIATE_TEST_CASE_P( 94 INSTANTIATE_TEST_CASE_P(
89 NetworkConfigurationUpdaterTestInstance, 95 NetworkConfigurationUpdaterTestInstance,
90 NetworkConfigurationUpdaterTest, 96 NetworkConfigurationUpdaterTest,
91 testing::Values(key::kDeviceOpenNetworkConfiguration, 97 testing::Values(key::kDeviceOpenNetworkConfiguration,
92 key::kOpenNetworkConfiguration)); 98 key::kOpenNetworkConfiguration));
93 99
94 } // namespace policy 100 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698