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/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 "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 8 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
10 #include "chrome/browser/policy/policy_map.h" | 10 #include "chrome/browser/policy/policy_map.h" |
11 #include "chrome/browser/policy/policy_service_impl.h" | 11 #include "chrome/browser/policy/policy_service_impl.h" |
| 12 #include "chromeos/network/onc/onc_constants.h" |
12 #include "policy/policy_constants.h" | 13 #include "policy/policy_constants.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 using testing::AtLeast; | 17 using testing::AtLeast; |
17 using testing::Mock; | 18 using testing::Mock; |
18 using testing::Ne; | 19 using testing::Ne; |
19 using testing::Return; | 20 using testing::Return; |
20 using testing::_; | 21 using testing::_; |
21 | 22 |
(...skipping 13 matching lines...) Expand all Loading... |
35 PolicyServiceImpl::Providers providers; | 36 PolicyServiceImpl::Providers providers; |
36 providers.push_back(&provider_); | 37 providers.push_back(&provider_); |
37 policy_service_.reset(new PolicyServiceImpl(providers)); | 38 policy_service_.reset(new PolicyServiceImpl(providers)); |
38 } | 39 } |
39 | 40 |
40 virtual void TearDown() OVERRIDE { | 41 virtual void TearDown() OVERRIDE { |
41 provider_.Shutdown(); | 42 provider_.Shutdown(); |
42 } | 43 } |
43 | 44 |
44 // Maps configuration policy name to corresponding ONC source. | 45 // Maps configuration policy name to corresponding ONC source. |
45 static chromeos::NetworkUIData::ONCSource NameToONCSource( | 46 static chromeos::onc::ONCSource NameToONCSource( |
46 const std::string& name) { | 47 const std::string& name) { |
47 if (name == key::kDeviceOpenNetworkConfiguration) | 48 if (name == key::kDeviceOpenNetworkConfiguration) |
48 return chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY; | 49 return chromeos::onc::ONC_SOURCE_DEVICE_POLICY; |
49 if (name == key::kOpenNetworkConfiguration) | 50 if (name == key::kOpenNetworkConfiguration) |
50 return chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY; | 51 return chromeos::onc::ONC_SOURCE_USER_POLICY; |
51 return chromeos::NetworkUIData::ONC_SOURCE_NONE; | 52 return chromeos::onc::ONC_SOURCE_NONE; |
52 } | 53 } |
53 | 54 |
54 chromeos::MockNetworkLibrary network_library_; | 55 chromeos::MockNetworkLibrary network_library_; |
55 MockConfigurationPolicyProvider provider_; | 56 MockConfigurationPolicyProvider provider_; |
56 scoped_ptr<PolicyServiceImpl> policy_service_; | 57 scoped_ptr<PolicyServiceImpl> policy_service_; |
57 }; | 58 }; |
58 | 59 |
59 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdates) { | 60 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdates) { |
60 PolicyMap policy; | 61 PolicyMap policy; |
61 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 62 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
62 Value::CreateStringValue(kFakeONC)); | 63 Value::CreateStringValue(kFakeONC)); |
63 provider_.UpdateChromePolicy(policy); | 64 provider_.UpdateChromePolicy(policy); |
64 | 65 |
65 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); | 66 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); |
66 | 67 |
67 // Initially, only the device policy is applied. The user policy is only | 68 // Initially, only the device policy is applied. The user policy is only |
68 // applied after the user profile was initialized. | 69 // applied after the user profile was initialized. |
69 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ? | 70 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ? |
70 kFakeONC : kEmptyConfiguration; | 71 kFakeONC : kEmptyConfiguration; |
71 EXPECT_CALL(network_library_, LoadOncNetworks( | 72 EXPECT_CALL(network_library_, LoadOncNetworks( |
72 device_onc, "", chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY, _, _)); | 73 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); |
73 | 74 |
74 { | 75 { |
75 NetworkConfigurationUpdater updater(policy_service_.get(), | 76 NetworkConfigurationUpdater updater(policy_service_.get(), |
76 &network_library_); | 77 &network_library_); |
77 Mock::VerifyAndClearExpectations(&network_library_); | 78 Mock::VerifyAndClearExpectations(&network_library_); |
78 | 79 |
79 // After the user policy is initialized, we always push both policies to the | 80 // After the user policy is initialized, we always push both policies to the |
80 // NetworkLibrary. | 81 // NetworkLibrary. |
81 EXPECT_CALL(network_library_, LoadOncNetworks( | 82 EXPECT_CALL(network_library_, LoadOncNetworks( |
82 kFakeONC, "", NameToONCSource(GetParam()), _, _)); | 83 kFakeONC, "", NameToONCSource(GetParam()), _)); |
83 EXPECT_CALL(network_library_, LoadOncNetworks( | 84 EXPECT_CALL(network_library_, LoadOncNetworks( |
84 kEmptyConfiguration, "", Ne(NameToONCSource(GetParam())), _, _)); | 85 kEmptyConfiguration, "", Ne(NameToONCSource(GetParam())), _)); |
85 | 86 |
86 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 87 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
87 | 88 |
88 updater.OnUserPolicyInitialized(); | 89 updater.OnUserPolicyInitialized(); |
89 } | 90 } |
90 Mock::VerifyAndClearExpectations(&network_library_); | 91 Mock::VerifyAndClearExpectations(&network_library_); |
91 } | 92 } |
92 | 93 |
93 TEST_P(NetworkConfigurationUpdaterTest, AllowWebTrust) { | 94 TEST_P(NetworkConfigurationUpdaterTest, AllowWebTrust) { |
94 { | 95 { |
95 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); | 96 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); |
96 | 97 |
97 // Initially web trust is disabled. | 98 // Initially web trust is disabled. |
98 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, false, _)) | 99 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, false)) |
99 .Times(AtLeast(0)); | 100 .Times(AtLeast(0)); |
100 NetworkConfigurationUpdater updater(policy_service_.get(), | 101 NetworkConfigurationUpdater updater(policy_service_.get(), |
101 &network_library_); | 102 &network_library_); |
102 updater.OnUserPolicyInitialized(); | 103 updater.OnUserPolicyInitialized(); |
103 Mock::VerifyAndClearExpectations(&network_library_); | 104 Mock::VerifyAndClearExpectations(&network_library_); |
104 | 105 |
105 // Web trust should be forwarded to LoadOncNetworks. | 106 // Web trust should be forwarded to LoadOncNetworks. |
106 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, true, _)) | 107 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, true)) |
107 .Times(AtLeast(0)); | 108 .Times(AtLeast(0)); |
108 | 109 |
109 updater.set_allow_web_trust(true); | 110 updater.set_allow_web_trust(true); |
110 | 111 |
111 PolicyMap policy; | 112 PolicyMap policy; |
112 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 113 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
113 Value::CreateStringValue(kFakeONC)); | 114 Value::CreateStringValue(kFakeONC)); |
114 provider_.UpdateChromePolicy(policy); | 115 provider_.UpdateChromePolicy(policy); |
115 Mock::VerifyAndClearExpectations(&network_library_); | 116 Mock::VerifyAndClearExpectations(&network_library_); |
116 | 117 |
117 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 118 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
118 } | 119 } |
119 Mock::VerifyAndClearExpectations(&network_library_); | 120 Mock::VerifyAndClearExpectations(&network_library_); |
120 } | 121 } |
121 | 122 |
122 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { | 123 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { |
123 { | 124 { |
124 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); | 125 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); |
125 | 126 |
126 // Ignore the initial updates. | 127 // Ignore the initial updates. |
127 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, _, _)) | 128 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, _)) |
128 .Times(AtLeast(0)); | 129 .Times(AtLeast(0)); |
129 NetworkConfigurationUpdater updater(policy_service_.get(), | 130 NetworkConfigurationUpdater updater(policy_service_.get(), |
130 &network_library_); | 131 &network_library_); |
131 updater.OnUserPolicyInitialized(); | 132 updater.OnUserPolicyInitialized(); |
132 Mock::VerifyAndClearExpectations(&network_library_); | 133 Mock::VerifyAndClearExpectations(&network_library_); |
133 | 134 |
134 // We should update if policy changes. | 135 // We should update if policy changes. |
135 EXPECT_CALL(network_library_, LoadOncNetworks( | 136 EXPECT_CALL(network_library_, LoadOncNetworks( |
136 kFakeONC, "", NameToONCSource(GetParam()), _, _)); | 137 kFakeONC, "", NameToONCSource(GetParam()), _)); |
137 | 138 |
138 // In the current implementation, we always apply both policies. | 139 // In the current implementation, we always apply both policies. |
139 EXPECT_CALL(network_library_, LoadOncNetworks( | 140 EXPECT_CALL(network_library_, LoadOncNetworks( |
140 kEmptyConfiguration, "", Ne(NameToONCSource(GetParam())), _, _)); | 141 kEmptyConfiguration, "", Ne(NameToONCSource(GetParam())), _)); |
141 | 142 |
142 PolicyMap policy; | 143 PolicyMap policy; |
143 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 144 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
144 Value::CreateStringValue(kFakeONC)); | 145 Value::CreateStringValue(kFakeONC)); |
145 provider_.UpdateChromePolicy(policy); | 146 provider_.UpdateChromePolicy(policy); |
146 Mock::VerifyAndClearExpectations(&network_library_); | 147 Mock::VerifyAndClearExpectations(&network_library_); |
147 | 148 |
148 // Another update is expected if the policy goes away. In the current | 149 // Another update is expected if the policy goes away. In the current |
149 // implementation, we always apply both policies. | 150 // implementation, we always apply both policies. |
150 EXPECT_CALL(network_library_, LoadOncNetworks( | 151 EXPECT_CALL(network_library_, LoadOncNetworks( |
151 kEmptyConfiguration, "", | 152 kEmptyConfiguration, "", |
152 chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY, _, _)); | 153 chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); |
153 | 154 |
154 EXPECT_CALL(network_library_, LoadOncNetworks( | 155 EXPECT_CALL(network_library_, LoadOncNetworks( |
155 kEmptyConfiguration, "", | 156 kEmptyConfiguration, "", |
156 chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY, _, _)); | 157 chromeos::onc::ONC_SOURCE_USER_POLICY, _)); |
157 | 158 |
158 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 159 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
159 | 160 |
160 policy.Erase(GetParam()); | 161 policy.Erase(GetParam()); |
161 provider_.UpdateChromePolicy(policy); | 162 provider_.UpdateChromePolicy(policy); |
162 } | 163 } |
163 Mock::VerifyAndClearExpectations(&network_library_); | 164 Mock::VerifyAndClearExpectations(&network_library_); |
164 } | 165 } |
165 | 166 |
166 INSTANTIATE_TEST_CASE_P( | 167 INSTANTIATE_TEST_CASE_P( |
167 NetworkConfigurationUpdaterTestInstance, | 168 NetworkConfigurationUpdaterTestInstance, |
168 NetworkConfigurationUpdaterTest, | 169 NetworkConfigurationUpdaterTest, |
169 testing::Values(key::kDeviceOpenNetworkConfiguration, | 170 testing::Values(key::kDeviceOpenNetworkConfiguration, |
170 key::kOpenNetworkConfiguration)); | 171 key::kOpenNetworkConfiguration)); |
171 | 172 |
172 } // namespace policy | 173 } // namespace policy |
OLD | NEW |