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 "base/message_loop.h" |
| 9 #include "base/run_loop.h" |
8 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 10 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 11 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
10 #include "chrome/browser/policy/policy_map.h" | 12 #include "chrome/browser/policy/policy_map.h" |
11 #include "chrome/browser/policy/policy_service_impl.h" | 13 #include "chrome/browser/policy/policy_service_impl.h" |
12 #include "chromeos/network/onc/onc_constants.h" | 14 #include "chromeos/network/onc/onc_constants.h" |
13 #include "chromeos/network/onc/onc_utils.h" | 15 #include "chromeos/network/onc/onc_utils.h" |
14 #include "policy/policy_constants.h" | 16 #include "policy/policy_constants.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 | 19 |
(...skipping 16 matching lines...) Expand all Loading... |
34 provider_.Init(); | 36 provider_.Init(); |
35 PolicyServiceImpl::Providers providers; | 37 PolicyServiceImpl::Providers providers; |
36 providers.push_back(&provider_); | 38 providers.push_back(&provider_); |
37 policy_service_.reset(new PolicyServiceImpl(providers)); | 39 policy_service_.reset(new PolicyServiceImpl(providers)); |
38 } | 40 } |
39 | 41 |
40 virtual void TearDown() OVERRIDE { | 42 virtual void TearDown() OVERRIDE { |
41 provider_.Shutdown(); | 43 provider_.Shutdown(); |
42 } | 44 } |
43 | 45 |
| 46 void UpdateProviderPolicy(const PolicyMap& policy) { |
| 47 provider_.UpdateChromePolicy(policy); |
| 48 base::RunLoop loop; |
| 49 loop.RunUntilIdle(); |
| 50 } |
| 51 |
44 // Maps configuration policy name to corresponding ONC source. | 52 // Maps configuration policy name to corresponding ONC source. |
45 static chromeos::onc::ONCSource NameToONCSource( | 53 static chromeos::onc::ONCSource NameToONCSource( |
46 const std::string& name) { | 54 const std::string& name) { |
47 if (name == key::kDeviceOpenNetworkConfiguration) | 55 if (name == key::kDeviceOpenNetworkConfiguration) |
48 return chromeos::onc::ONC_SOURCE_DEVICE_POLICY; | 56 return chromeos::onc::ONC_SOURCE_DEVICE_POLICY; |
49 if (name == key::kOpenNetworkConfiguration) | 57 if (name == key::kOpenNetworkConfiguration) |
50 return chromeos::onc::ONC_SOURCE_USER_POLICY; | 58 return chromeos::onc::ONC_SOURCE_USER_POLICY; |
51 return chromeos::onc::ONC_SOURCE_NONE; | 59 return chromeos::onc::ONC_SOURCE_NONE; |
52 } | 60 } |
53 | 61 |
54 chromeos::MockNetworkLibrary network_library_; | 62 chromeos::MockNetworkLibrary network_library_; |
55 MockConfigurationPolicyProvider provider_; | 63 MockConfigurationPolicyProvider provider_; |
56 scoped_ptr<PolicyServiceImpl> policy_service_; | 64 scoped_ptr<PolicyServiceImpl> policy_service_; |
| 65 MessageLoop loop_; |
57 }; | 66 }; |
58 | 67 |
59 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdates) { | 68 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdates) { |
60 PolicyMap policy; | 69 PolicyMap policy; |
61 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 70 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
62 Value::CreateStringValue(kFakeONC)); | 71 Value::CreateStringValue(kFakeONC)); |
63 provider_.UpdateChromePolicy(policy); | 72 UpdateProviderPolicy(policy); |
64 | 73 |
65 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); | 74 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); |
66 | 75 |
67 // Initially, only the device policy is applied. The user policy is only | 76 // Initially, only the device policy is applied. The user policy is only |
68 // applied after the user profile was initialized. | 77 // applied after the user profile was initialized. |
69 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ? | 78 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ? |
70 kFakeONC : chromeos::onc::kEmptyUnencryptedConfiguration; | 79 kFakeONC : chromeos::onc::kEmptyUnencryptedConfiguration; |
71 EXPECT_CALL(network_library_, LoadOncNetworks( | 80 EXPECT_CALL(network_library_, LoadOncNetworks( |
72 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); | 81 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); |
73 | 82 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 116 |
108 // Web trust should be forwarded to LoadOncNetworks. | 117 // Web trust should be forwarded to LoadOncNetworks. |
109 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, true)) | 118 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, true)) |
110 .Times(AtLeast(0)); | 119 .Times(AtLeast(0)); |
111 | 120 |
112 updater.set_allow_web_trust(true); | 121 updater.set_allow_web_trust(true); |
113 | 122 |
114 PolicyMap policy; | 123 PolicyMap policy; |
115 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 124 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
116 Value::CreateStringValue(kFakeONC)); | 125 Value::CreateStringValue(kFakeONC)); |
117 provider_.UpdateChromePolicy(policy); | 126 UpdateProviderPolicy(policy); |
118 Mock::VerifyAndClearExpectations(&network_library_); | 127 Mock::VerifyAndClearExpectations(&network_library_); |
119 | 128 |
120 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 129 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
121 } | 130 } |
122 Mock::VerifyAndClearExpectations(&network_library_); | 131 Mock::VerifyAndClearExpectations(&network_library_); |
123 } | 132 } |
124 | 133 |
125 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { | 134 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { |
126 { | 135 { |
127 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); | 136 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); |
(...skipping 13 matching lines...) Expand all Loading... |
141 // In the current implementation, we always apply both policies. | 150 // In the current implementation, we always apply both policies. |
142 EXPECT_CALL(network_library_, LoadOncNetworks( | 151 EXPECT_CALL(network_library_, LoadOncNetworks( |
143 chromeos::onc::kEmptyUnencryptedConfiguration, | 152 chromeos::onc::kEmptyUnencryptedConfiguration, |
144 "", | 153 "", |
145 Ne(NameToONCSource(GetParam())), | 154 Ne(NameToONCSource(GetParam())), |
146 _)); | 155 _)); |
147 | 156 |
148 PolicyMap policy; | 157 PolicyMap policy; |
149 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 158 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
150 Value::CreateStringValue(kFakeONC)); | 159 Value::CreateStringValue(kFakeONC)); |
151 provider_.UpdateChromePolicy(policy); | 160 UpdateProviderPolicy(policy); |
152 Mock::VerifyAndClearExpectations(&network_library_); | 161 Mock::VerifyAndClearExpectations(&network_library_); |
153 | 162 |
154 // Another update is expected if the policy goes away. In the current | 163 // Another update is expected if the policy goes away. In the current |
155 // implementation, we always apply both policies. | 164 // implementation, we always apply both policies. |
156 EXPECT_CALL(network_library_, LoadOncNetworks( | 165 EXPECT_CALL(network_library_, LoadOncNetworks( |
157 chromeos::onc::kEmptyUnencryptedConfiguration, "", | 166 chromeos::onc::kEmptyUnencryptedConfiguration, "", |
158 chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); | 167 chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); |
159 | 168 |
160 EXPECT_CALL(network_library_, LoadOncNetworks( | 169 EXPECT_CALL(network_library_, LoadOncNetworks( |
161 chromeos::onc::kEmptyUnencryptedConfiguration, "", | 170 chromeos::onc::kEmptyUnencryptedConfiguration, "", |
162 chromeos::onc::ONC_SOURCE_USER_POLICY, _)); | 171 chromeos::onc::ONC_SOURCE_USER_POLICY, _)); |
163 | 172 |
164 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 173 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
165 | 174 |
166 policy.Erase(GetParam()); | 175 policy.Erase(GetParam()); |
167 provider_.UpdateChromePolicy(policy); | 176 UpdateProviderPolicy(policy); |
168 } | 177 } |
169 Mock::VerifyAndClearExpectations(&network_library_); | 178 Mock::VerifyAndClearExpectations(&network_library_); |
170 } | 179 } |
171 | 180 |
172 INSTANTIATE_TEST_CASE_P( | 181 INSTANTIATE_TEST_CASE_P( |
173 NetworkConfigurationUpdaterTestInstance, | 182 NetworkConfigurationUpdaterTestInstance, |
174 NetworkConfigurationUpdaterTest, | 183 NetworkConfigurationUpdaterTest, |
175 testing::Values(key::kDeviceOpenNetworkConfiguration, | 184 testing::Values(key::kDeviceOpenNetworkConfiguration, |
176 key::kOpenNetworkConfiguration)); | 185 key::kOpenNetworkConfiguration)); |
177 | 186 |
178 } // namespace policy | 187 } // namespace policy |
OLD | NEW |