OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <iostream> | 5 #include <iostream> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
12 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 12 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
13 #include "chromeos/dbus/mock_shill_manager_client.h" | 13 #include "chromeos/dbus/mock_shill_manager_client.h" |
14 #include "chromeos/dbus/mock_shill_profile_client.h" | 14 #include "chromeos/dbus/mock_shill_profile_client.h" |
15 #include "chromeos/dbus/mock_shill_service_client.h" | |
16 #include "chromeos/network/managed_network_configuration_handler_impl.h" | 15 #include "chromeos/network/managed_network_configuration_handler_impl.h" |
17 #include "chromeos/network/network_configuration_handler.h" | 16 #include "chromeos/network/network_configuration_handler.h" |
18 #include "chromeos/network/network_profile_handler.h" | 17 #include "chromeos/network/network_profile_handler.h" |
19 #include "chromeos/network/onc/onc_test_utils.h" | 18 #include "chromeos/network/onc/onc_test_utils.h" |
20 #include "chromeos/network/onc/onc_utils.h" | 19 #include "chromeos/network/onc/onc_utils.h" |
21 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
25 | 24 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 140 } |
142 | 141 |
143 private: | 142 private: |
144 DISALLOW_COPY_AND_ASSIGN(TestNetworkProfileHandler); | 143 DISALLOW_COPY_AND_ASSIGN(TestNetworkProfileHandler); |
145 }; | 144 }; |
146 | 145 |
147 } // namespace | 146 } // namespace |
148 | 147 |
149 class ManagedNetworkConfigurationHandlerTest : public testing::Test { | 148 class ManagedNetworkConfigurationHandlerTest : public testing::Test { |
150 public: | 149 public: |
151 ManagedNetworkConfigurationHandlerTest() { | 150 ManagedNetworkConfigurationHandlerTest() |
| 151 : mock_manager_client_(NULL), |
| 152 mock_profile_client_(NULL) { |
152 } | 153 } |
153 | 154 |
154 virtual ~ManagedNetworkConfigurationHandlerTest() { | 155 virtual ~ManagedNetworkConfigurationHandlerTest() { |
155 } | 156 } |
156 | 157 |
157 virtual void SetUp() OVERRIDE { | 158 virtual void SetUp() OVERRIDE { |
158 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; | 159 FakeDBusThreadManager* dbus_thread_manager = new FakeDBusThreadManager; |
159 EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) | 160 mock_manager_client_ = new StrictMock<MockShillManagerClient>(); |
160 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); | 161 mock_profile_client_ = new StrictMock<MockShillProfileClient>(); |
| 162 dbus_thread_manager->SetShillManagerClient( |
| 163 scoped_ptr<ShillManagerClient>(mock_manager_client_).Pass()); |
| 164 dbus_thread_manager->SetShillProfileClient( |
| 165 scoped_ptr<ShillProfileClient>(mock_profile_client_).Pass()); |
| 166 |
161 DBusThreadManager::InitializeForTesting(dbus_thread_manager); | 167 DBusThreadManager::InitializeForTesting(dbus_thread_manager); |
162 | 168 |
163 SetNetworkConfigurationHandlerExpectations(); | 169 SetNetworkConfigurationHandlerExpectations(); |
164 | 170 |
165 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) | 171 ON_CALL(*mock_profile_client_, GetProperties(_,_,_)) |
166 .WillRepeatedly(Return(&mock_manager_client_)); | |
167 EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient()) | |
168 .WillRepeatedly(Return(&mock_service_client_)); | |
169 EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient()) | |
170 .WillRepeatedly(Return(&mock_profile_client_)); | |
171 | |
172 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) | |
173 .WillByDefault(Invoke(&profiles_stub_, | 172 .WillByDefault(Invoke(&profiles_stub_, |
174 &ShillProfileTestClient::GetProperties)); | 173 &ShillProfileTestClient::GetProperties)); |
175 | 174 |
176 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) | 175 ON_CALL(*mock_profile_client_, GetEntry(_,_,_,_)) |
177 .WillByDefault(Invoke(&profiles_stub_, | 176 .WillByDefault(Invoke(&profiles_stub_, |
178 &ShillProfileTestClient::GetEntry)); | 177 &ShillProfileTestClient::GetEntry)); |
179 | 178 |
180 network_profile_handler_.reset(new TestNetworkProfileHandler()); | 179 network_profile_handler_.reset(new TestNetworkProfileHandler()); |
181 network_configuration_handler_.reset( | 180 network_configuration_handler_.reset( |
182 NetworkConfigurationHandler::InitializeForTest( | 181 NetworkConfigurationHandler::InitializeForTest( |
183 NULL /* no NetworkStateHandler */)); | 182 NULL /* no NetworkStateHandler */)); |
184 managed_network_configuration_handler_.reset( | 183 managed_network_configuration_handler_.reset( |
185 new ManagedNetworkConfigurationHandlerImpl()); | 184 new ManagedNetworkConfigurationHandlerImpl()); |
186 managed_network_configuration_handler_->Init( | 185 managed_network_configuration_handler_->Init( |
187 NULL /* no NetworkStateHandler */, | 186 NULL /* no NetworkStateHandler */, |
188 network_profile_handler_.get(), | 187 network_profile_handler_.get(), |
189 network_configuration_handler_.get()); | 188 network_configuration_handler_.get()); |
190 | 189 |
191 message_loop_.RunUntilIdle(); | 190 message_loop_.RunUntilIdle(); |
192 } | 191 } |
193 | 192 |
194 virtual void TearDown() OVERRIDE { | 193 virtual void TearDown() OVERRIDE { |
195 managed_network_configuration_handler_.reset(); | 194 managed_network_configuration_handler_.reset(); |
196 network_configuration_handler_.reset(); | 195 network_configuration_handler_.reset(); |
197 network_profile_handler_.reset(); | 196 network_profile_handler_.reset(); |
198 DBusThreadManager::Shutdown(); | 197 DBusThreadManager::Shutdown(); |
199 } | 198 } |
200 | 199 |
201 void VerifyAndClearExpectations() { | 200 void VerifyAndClearExpectations() { |
202 Mock::VerifyAndClearExpectations(&mock_manager_client_); | 201 Mock::VerifyAndClearExpectations(mock_manager_client_); |
203 Mock::VerifyAndClearExpectations(&mock_service_client_); | 202 Mock::VerifyAndClearExpectations(mock_profile_client_); |
204 Mock::VerifyAndClearExpectations(&mock_profile_client_); | |
205 SetNetworkConfigurationHandlerExpectations(); | 203 SetNetworkConfigurationHandlerExpectations(); |
206 } | 204 } |
207 | 205 |
208 void InitializeStandardProfiles() { | 206 void InitializeStandardProfiles() { |
209 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1); | 207 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1); |
210 network_profile_handler_-> | 208 network_profile_handler_-> |
211 AddProfileForTest(NetworkProfile(kUser1ProfilePath, kUser1)); | 209 AddProfileForTest(NetworkProfile(kUser1ProfilePath, kUser1)); |
212 network_profile_handler_-> | 210 network_profile_handler_-> |
213 AddProfileForTest(NetworkProfile(kSharedProfilePath, std::string())); | 211 AddProfileForTest(NetworkProfile(kSharedProfilePath, std::string())); |
214 } | 212 } |
(...skipping 25 matching lines...) Expand all Loading... |
240 policy->GetDictionaryWithoutPathExpansion( | 238 policy->GetDictionaryWithoutPathExpansion( |
241 ::onc::toplevel_config::kGlobalNetworkConfiguration, | 239 ::onc::toplevel_config::kGlobalNetworkConfiguration, |
242 &global_network_config); | 240 &global_network_config); |
243 | 241 |
244 managed_handler()->SetPolicy( | 242 managed_handler()->SetPolicy( |
245 onc_source, userhash, *network_configs, *global_network_config); | 243 onc_source, userhash, *network_configs, *global_network_config); |
246 } | 244 } |
247 | 245 |
248 void SetNetworkConfigurationHandlerExpectations() { | 246 void SetNetworkConfigurationHandlerExpectations() { |
249 // These calls occur in NetworkConfigurationHandler. | 247 // These calls occur in NetworkConfigurationHandler. |
250 EXPECT_CALL(mock_manager_client_, GetProperties(_)).Times(AnyNumber()); | 248 EXPECT_CALL(*mock_manager_client_, GetProperties(_)).Times(AnyNumber()); |
251 EXPECT_CALL(mock_manager_client_, | 249 EXPECT_CALL(*mock_manager_client_, |
252 AddPropertyChangedObserver(_)).Times(AnyNumber()); | 250 AddPropertyChangedObserver(_)).Times(AnyNumber()); |
253 EXPECT_CALL(mock_manager_client_, | 251 EXPECT_CALL(*mock_manager_client_, |
254 RemovePropertyChangedObserver(_)).Times(AnyNumber()); | 252 RemovePropertyChangedObserver(_)).Times(AnyNumber()); |
255 } | 253 } |
256 | 254 |
257 ManagedNetworkConfigurationHandler* managed_handler() { | 255 ManagedNetworkConfigurationHandler* managed_handler() { |
258 return managed_network_configuration_handler_.get(); | 256 return managed_network_configuration_handler_.get(); |
259 } | 257 } |
260 | 258 |
261 protected: | 259 protected: |
262 StrictMock<MockShillManagerClient> mock_manager_client_; | 260 MockShillManagerClient* mock_manager_client_; |
263 StrictMock<MockShillServiceClient> mock_service_client_; | 261 MockShillProfileClient* mock_profile_client_; |
264 StrictMock<MockShillProfileClient> mock_profile_client_; | |
265 ShillProfileTestClient profiles_stub_; | 262 ShillProfileTestClient profiles_stub_; |
266 scoped_ptr<TestNetworkProfileHandler> network_profile_handler_; | 263 scoped_ptr<TestNetworkProfileHandler> network_profile_handler_; |
267 scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_; | 264 scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_; |
268 scoped_ptr<ManagedNetworkConfigurationHandlerImpl> | 265 scoped_ptr<ManagedNetworkConfigurationHandlerImpl> |
269 managed_network_configuration_handler_; | 266 managed_network_configuration_handler_; |
270 base::MessageLoop message_loop_; | 267 base::MessageLoop message_loop_; |
271 | 268 |
272 private: | 269 private: |
273 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); | 270 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); |
274 }; | 271 }; |
275 | 272 |
276 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { | 273 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { |
277 InitializeStandardProfiles(); | 274 InitializeStandardProfiles(); |
278 message_loop_.RunUntilIdle(); | 275 message_loop_.RunUntilIdle(); |
279 } | 276 } |
280 | 277 |
281 TEST_F(ManagedNetworkConfigurationHandlerTest, RemoveIrrelevantFields) { | 278 TEST_F(ManagedNetworkConfigurationHandlerTest, RemoveIrrelevantFields) { |
282 InitializeStandardProfiles(); | 279 InitializeStandardProfiles(); |
283 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 280 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
284 test_utils::ReadTestDictionary( | 281 test_utils::ReadTestDictionary( |
285 "policy/shill_policy_on_unconfigured_wifi1.json"); | 282 "policy/shill_policy_on_unconfigured_wifi1.json"); |
286 | 283 |
287 EXPECT_CALL(mock_profile_client_, | 284 EXPECT_CALL(*mock_profile_client_, |
288 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 285 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
289 | 286 |
290 EXPECT_CALL(mock_manager_client_, | 287 EXPECT_CALL(*mock_manager_client_, |
291 ConfigureServiceForProfile( | 288 ConfigureServiceForProfile( |
292 dbus::ObjectPath(kUser1ProfilePath), | 289 dbus::ObjectPath(kUser1ProfilePath), |
293 IsEqualTo(expected_shill_properties.get()), | 290 IsEqualTo(expected_shill_properties.get()), |
294 _, _)); | 291 _, _)); |
295 | 292 |
296 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, | 293 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, |
297 kUser1, | 294 kUser1, |
298 "policy/policy_wifi1_with_redundant_fields.onc"); | 295 "policy/policy_wifi1_with_redundant_fields.onc"); |
299 message_loop_.RunUntilIdle(); | 296 message_loop_.RunUntilIdle(); |
300 } | 297 } |
301 | 298 |
302 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnconfigured) { | 299 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnconfigured) { |
303 InitializeStandardProfiles(); | 300 InitializeStandardProfiles(); |
304 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 301 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
305 test_utils::ReadTestDictionary( | 302 test_utils::ReadTestDictionary( |
306 "policy/shill_policy_on_unconfigured_wifi1.json"); | 303 "policy/shill_policy_on_unconfigured_wifi1.json"); |
307 | 304 |
308 EXPECT_CALL(mock_profile_client_, | 305 EXPECT_CALL(*mock_profile_client_, |
309 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 306 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
310 | 307 |
311 EXPECT_CALL(mock_manager_client_, | 308 EXPECT_CALL(*mock_manager_client_, |
312 ConfigureServiceForProfile( | 309 ConfigureServiceForProfile( |
313 dbus::ObjectPath(kUser1ProfilePath), | 310 dbus::ObjectPath(kUser1ProfilePath), |
314 IsEqualTo(expected_shill_properties.get()), | 311 IsEqualTo(expected_shill_properties.get()), |
315 _, _)); | 312 _, _)); |
316 | 313 |
317 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 314 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
318 message_loop_.RunUntilIdle(); | 315 message_loop_.RunUntilIdle(); |
319 } | 316 } |
320 | 317 |
321 // Ensure that EAP settings for ethernet are matched with the right profile | 318 // Ensure that EAP settings for ethernet are matched with the right profile |
322 // entry and written to the dedicated EthernetEAP service. | 319 // entry and written to the dedicated EthernetEAP service. |
323 TEST_F(ManagedNetworkConfigurationHandlerTest, | 320 TEST_F(ManagedNetworkConfigurationHandlerTest, |
324 SetPolicyManageUnmanagedEthernetEAP) { | 321 SetPolicyManageUnmanagedEthernetEAP) { |
325 InitializeStandardProfiles(); | 322 InitializeStandardProfiles(); |
326 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 323 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
327 test_utils::ReadTestDictionary( | 324 test_utils::ReadTestDictionary( |
328 "policy/" | 325 "policy/" |
329 "shill_policy_on_unmanaged_ethernet_eap.json"); | 326 "shill_policy_on_unmanaged_ethernet_eap.json"); |
330 | 327 |
331 SetUpEntry("policy/shill_unmanaged_ethernet_eap.json", | 328 SetUpEntry("policy/shill_unmanaged_ethernet_eap.json", |
332 kUser1ProfilePath, | 329 kUser1ProfilePath, |
333 "eth_entry"); | 330 "eth_entry"); |
334 | 331 |
335 // Also setup an unrelated WiFi configuration to verify that the right entry | 332 // Also setup an unrelated WiFi configuration to verify that the right entry |
336 // is matched. | 333 // is matched. |
337 SetUpEntry("policy/shill_unmanaged_wifi1.json", | 334 SetUpEntry("policy/shill_unmanaged_wifi1.json", |
338 kUser1ProfilePath, | 335 kUser1ProfilePath, |
339 "wifi_entry"); | 336 "wifi_entry"); |
340 | 337 |
341 EXPECT_CALL(mock_profile_client_, | 338 EXPECT_CALL(*mock_profile_client_, |
342 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 339 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
343 | 340 |
344 EXPECT_CALL(mock_profile_client_, | 341 EXPECT_CALL(*mock_profile_client_, |
345 GetEntry(dbus::ObjectPath(kUser1ProfilePath), _, _, _)).Times(2); | 342 GetEntry(dbus::ObjectPath(kUser1ProfilePath), _, _, _)).Times(2); |
346 | 343 |
347 EXPECT_CALL( | 344 EXPECT_CALL( |
348 mock_profile_client_, | 345 *mock_profile_client_, |
349 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "eth_entry", _, _)); | 346 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "eth_entry", _, _)); |
350 | 347 |
351 EXPECT_CALL( | 348 EXPECT_CALL( |
352 mock_manager_client_, | 349 *mock_manager_client_, |
353 ConfigureServiceForProfile(dbus::ObjectPath(kUser1ProfilePath), | 350 ConfigureServiceForProfile(dbus::ObjectPath(kUser1ProfilePath), |
354 IsEqualTo(expected_shill_properties.get()), | 351 IsEqualTo(expected_shill_properties.get()), |
355 _, _)); | 352 _, _)); |
356 | 353 |
357 SetPolicy( | 354 SetPolicy( |
358 ::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_ethernet_eap.onc"); | 355 ::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_ethernet_eap.onc"); |
359 message_loop_.RunUntilIdle(); | 356 message_loop_.RunUntilIdle(); |
360 } | 357 } |
361 | 358 |
362 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) { | 359 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) { |
363 InitializeStandardProfiles(); | 360 InitializeStandardProfiles(); |
364 EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _)); | 361 EXPECT_CALL(*mock_profile_client_, GetProperties(_, _, _)); |
365 | 362 |
366 EXPECT_CALL(mock_manager_client_, ConfigureServiceForProfile(_, _, _, _)); | 363 EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile(_, _, _, _)); |
367 | 364 |
368 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 365 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
369 message_loop_.RunUntilIdle(); | 366 message_loop_.RunUntilIdle(); |
370 VerifyAndClearExpectations(); | 367 VerifyAndClearExpectations(); |
371 | 368 |
372 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", | 369 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", |
373 kUser1ProfilePath, | 370 kUser1ProfilePath, |
374 "some_entry_path"); | 371 "some_entry_path"); |
375 | 372 |
376 EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _)); | 373 EXPECT_CALL(*mock_profile_client_, GetProperties(_, _, _)); |
377 | 374 |
378 EXPECT_CALL( | 375 EXPECT_CALL( |
379 mock_profile_client_, | 376 *mock_profile_client_, |
380 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "some_entry_path", _, _)); | 377 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "some_entry_path", _, _)); |
381 | 378 |
382 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 379 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
383 message_loop_.RunUntilIdle(); | 380 message_loop_.RunUntilIdle(); |
384 } | 381 } |
385 | 382 |
386 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnmanaged) { | 383 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnmanaged) { |
387 InitializeStandardProfiles(); | 384 InitializeStandardProfiles(); |
388 SetUpEntry("policy/shill_unmanaged_wifi1.json", | 385 SetUpEntry("policy/shill_unmanaged_wifi1.json", |
389 kUser1ProfilePath, | 386 kUser1ProfilePath, |
390 "old_entry_path"); | 387 "old_entry_path"); |
391 | 388 |
392 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 389 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
393 test_utils::ReadTestDictionary( | 390 test_utils::ReadTestDictionary( |
394 "policy/shill_policy_on_unmanaged_wifi1.json"); | 391 "policy/shill_policy_on_unmanaged_wifi1.json"); |
395 | 392 |
396 EXPECT_CALL(mock_profile_client_, | 393 EXPECT_CALL(*mock_profile_client_, |
397 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 394 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
398 | 395 |
399 EXPECT_CALL( | 396 EXPECT_CALL( |
400 mock_profile_client_, | 397 *mock_profile_client_, |
401 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); | 398 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); |
402 | 399 |
403 EXPECT_CALL( | 400 EXPECT_CALL( |
404 mock_profile_client_, | 401 *mock_profile_client_, |
405 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); | 402 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); |
406 | 403 |
407 EXPECT_CALL(mock_manager_client_, | 404 EXPECT_CALL(*mock_manager_client_, |
408 ConfigureServiceForProfile( | 405 ConfigureServiceForProfile( |
409 dbus::ObjectPath(kUser1ProfilePath), | 406 dbus::ObjectPath(kUser1ProfilePath), |
410 IsEqualTo(expected_shill_properties.get()), | 407 IsEqualTo(expected_shill_properties.get()), |
411 _, _)); | 408 _, _)); |
412 | 409 |
413 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 410 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
414 message_loop_.RunUntilIdle(); | 411 message_loop_.RunUntilIdle(); |
415 } | 412 } |
416 | 413 |
417 // Old ChromeOS versions may not have used the UIData property | 414 // Old ChromeOS versions may not have used the UIData property |
418 TEST_F(ManagedNetworkConfigurationHandlerTest, | 415 TEST_F(ManagedNetworkConfigurationHandlerTest, |
419 SetPolicyManageUnmanagedWithoutUIData) { | 416 SetPolicyManageUnmanagedWithoutUIData) { |
420 InitializeStandardProfiles(); | 417 InitializeStandardProfiles(); |
421 SetUpEntry("policy/shill_unmanaged_wifi1.json", | 418 SetUpEntry("policy/shill_unmanaged_wifi1.json", |
422 kUser1ProfilePath, | 419 kUser1ProfilePath, |
423 "old_entry_path"); | 420 "old_entry_path"); |
424 | 421 |
425 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 422 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
426 test_utils::ReadTestDictionary( | 423 test_utils::ReadTestDictionary( |
427 "policy/shill_policy_on_unmanaged_wifi1.json"); | 424 "policy/shill_policy_on_unmanaged_wifi1.json"); |
428 | 425 |
429 EXPECT_CALL(mock_profile_client_, | 426 EXPECT_CALL(*mock_profile_client_, |
430 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 427 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
431 | 428 |
432 EXPECT_CALL( | 429 EXPECT_CALL( |
433 mock_profile_client_, | 430 *mock_profile_client_, |
434 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); | 431 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); |
435 | 432 |
436 EXPECT_CALL( | 433 EXPECT_CALL( |
437 mock_profile_client_, | 434 *mock_profile_client_, |
438 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); | 435 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); |
439 | 436 |
440 EXPECT_CALL(mock_manager_client_, | 437 EXPECT_CALL(*mock_manager_client_, |
441 ConfigureServiceForProfile( | 438 ConfigureServiceForProfile( |
442 dbus::ObjectPath(kUser1ProfilePath), | 439 dbus::ObjectPath(kUser1ProfilePath), |
443 IsEqualTo(expected_shill_properties.get()), | 440 IsEqualTo(expected_shill_properties.get()), |
444 _, _)); | 441 _, _)); |
445 | 442 |
446 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 443 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
447 message_loop_.RunUntilIdle(); | 444 message_loop_.RunUntilIdle(); |
448 } | 445 } |
449 | 446 |
450 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) { | 447 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) { |
451 InitializeStandardProfiles(); | 448 InitializeStandardProfiles(); |
452 SetUpEntry("policy/shill_managed_wifi1.json", | 449 SetUpEntry("policy/shill_managed_wifi1.json", |
453 kUser1ProfilePath, | 450 kUser1ProfilePath, |
454 "old_entry_path"); | 451 "old_entry_path"); |
455 | 452 |
456 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 453 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
457 test_utils::ReadTestDictionary( | 454 test_utils::ReadTestDictionary( |
458 "policy/shill_policy_on_unmanaged_wifi1.json"); | 455 "policy/shill_policy_on_unmanaged_wifi1.json"); |
459 | 456 |
460 // The passphrase isn't sent again, because it's configured by the user and | 457 // The passphrase isn't sent again, because it's configured by the user and |
461 // Shill doesn't sent it on GetProperties calls. | 458 // Shill doesn't sent it on GetProperties calls. |
462 expected_shill_properties->RemoveWithoutPathExpansion( | 459 expected_shill_properties->RemoveWithoutPathExpansion( |
463 shill::kPassphraseProperty, NULL); | 460 shill::kPassphraseProperty, NULL); |
464 | 461 |
465 EXPECT_CALL(mock_profile_client_, | 462 EXPECT_CALL(*mock_profile_client_, |
466 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 463 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
467 | 464 |
468 EXPECT_CALL( | 465 EXPECT_CALL( |
469 mock_profile_client_, | 466 *mock_profile_client_, |
470 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); | 467 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); |
471 | 468 |
472 EXPECT_CALL( | 469 EXPECT_CALL( |
473 mock_profile_client_, | 470 *mock_profile_client_, |
474 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); | 471 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); |
475 | 472 |
476 EXPECT_CALL(mock_manager_client_, | 473 EXPECT_CALL(*mock_manager_client_, |
477 ConfigureServiceForProfile( | 474 ConfigureServiceForProfile( |
478 dbus::ObjectPath(kUser1ProfilePath), | 475 dbus::ObjectPath(kUser1ProfilePath), |
479 IsEqualTo(expected_shill_properties.get()), | 476 IsEqualTo(expected_shill_properties.get()), |
480 _, _)); | 477 _, _)); |
481 | 478 |
482 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 479 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
483 message_loop_.RunUntilIdle(); | 480 message_loop_.RunUntilIdle(); |
484 } | 481 } |
485 | 482 |
486 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { | 483 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { |
487 InitializeStandardProfiles(); | 484 InitializeStandardProfiles(); |
488 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", | 485 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", |
489 kUser1ProfilePath, | 486 kUser1ProfilePath, |
490 "old_entry_path"); | 487 "old_entry_path"); |
491 | 488 |
492 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 489 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
493 test_utils::ReadTestDictionary( | 490 test_utils::ReadTestDictionary( |
494 "policy/shill_policy_on_unmanaged_wifi1.json"); | 491 "policy/shill_policy_on_unmanaged_wifi1.json"); |
495 | 492 |
496 // The passphrase isn't sent again, because it's configured by the user and | 493 // The passphrase isn't sent again, because it's configured by the user and |
497 // Shill doesn't sent it on GetProperties calls. | 494 // Shill doesn't sent it on GetProperties calls. |
498 expected_shill_properties->RemoveWithoutPathExpansion( | 495 expected_shill_properties->RemoveWithoutPathExpansion( |
499 shill::kPassphraseProperty, NULL); | 496 shill::kPassphraseProperty, NULL); |
500 | 497 |
501 EXPECT_CALL(mock_profile_client_, | 498 EXPECT_CALL(*mock_profile_client_, |
502 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 499 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
503 | 500 |
504 EXPECT_CALL( | 501 EXPECT_CALL( |
505 mock_profile_client_, | 502 *mock_profile_client_, |
506 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); | 503 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); |
507 | 504 |
508 EXPECT_CALL(mock_manager_client_, | 505 EXPECT_CALL(*mock_manager_client_, |
509 ConfigureServiceForProfile( | 506 ConfigureServiceForProfile( |
510 dbus::ObjectPath(kUser1ProfilePath), | 507 dbus::ObjectPath(kUser1ProfilePath), |
511 IsEqualTo(expected_shill_properties.get()), | 508 IsEqualTo(expected_shill_properties.get()), |
512 _, _)); | 509 _, _)); |
513 | 510 |
514 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 511 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
515 message_loop_.RunUntilIdle(); | 512 message_loop_.RunUntilIdle(); |
516 VerifyAndClearExpectations(); | 513 VerifyAndClearExpectations(); |
517 | 514 |
518 // If we apply the policy again, without change, then the Shill profile will | 515 // If we apply the policy again, without change, then the Shill profile will |
519 // not be modified. | 516 // not be modified. |
520 EXPECT_CALL(mock_profile_client_, | 517 EXPECT_CALL(*mock_profile_client_, |
521 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 518 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
522 | 519 |
523 EXPECT_CALL( | 520 EXPECT_CALL( |
524 mock_profile_client_, | 521 *mock_profile_client_, |
525 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); | 522 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); |
526 | 523 |
527 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 524 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
528 message_loop_.RunUntilIdle(); | 525 message_loop_.RunUntilIdle(); |
529 } | 526 } |
530 | 527 |
531 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUnmanageManaged) { | 528 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUnmanageManaged) { |
532 InitializeStandardProfiles(); | 529 InitializeStandardProfiles(); |
533 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", | 530 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", |
534 kUser1ProfilePath, | 531 kUser1ProfilePath, |
535 "old_entry_path"); | 532 "old_entry_path"); |
536 | 533 |
537 EXPECT_CALL(mock_profile_client_, | 534 EXPECT_CALL(*mock_profile_client_, |
538 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 535 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
539 | 536 |
540 EXPECT_CALL(mock_profile_client_, | 537 EXPECT_CALL(*mock_profile_client_, |
541 GetEntry(dbus::ObjectPath(kUser1ProfilePath), | 538 GetEntry(dbus::ObjectPath(kUser1ProfilePath), |
542 "old_entry_path", | 539 "old_entry_path", |
543 _, _)); | 540 _, _)); |
544 | 541 |
545 EXPECT_CALL(mock_profile_client_, | 542 EXPECT_CALL(*mock_profile_client_, |
546 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), | 543 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), |
547 "old_entry_path", | 544 "old_entry_path", |
548 _, _)); | 545 _, _)); |
549 | 546 |
550 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, ""); | 547 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, ""); |
551 message_loop_.RunUntilIdle(); | 548 message_loop_.RunUntilIdle(); |
552 } | 549 } |
553 | 550 |
554 TEST_F(ManagedNetworkConfigurationHandlerTest, SetEmptyPolicyIgnoreUnmanaged) { | 551 TEST_F(ManagedNetworkConfigurationHandlerTest, SetEmptyPolicyIgnoreUnmanaged) { |
555 InitializeStandardProfiles(); | 552 InitializeStandardProfiles(); |
556 SetUpEntry("policy/shill_unmanaged_wifi1.json", | 553 SetUpEntry("policy/shill_unmanaged_wifi1.json", |
557 kUser1ProfilePath, | 554 kUser1ProfilePath, |
558 "old_entry_path"); | 555 "old_entry_path"); |
559 | 556 |
560 EXPECT_CALL(mock_profile_client_, | 557 EXPECT_CALL(*mock_profile_client_, |
561 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 558 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
562 | 559 |
563 EXPECT_CALL(mock_profile_client_, | 560 EXPECT_CALL(*mock_profile_client_, |
564 GetEntry(dbus::ObjectPath(kUser1ProfilePath), | 561 GetEntry(dbus::ObjectPath(kUser1ProfilePath), |
565 "old_entry_path", | 562 "old_entry_path", |
566 _, _)); | 563 _, _)); |
567 | 564 |
568 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, ""); | 565 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, ""); |
569 message_loop_.RunUntilIdle(); | 566 message_loop_.RunUntilIdle(); |
570 } | 567 } |
571 | 568 |
572 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmanaged) { | 569 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmanaged) { |
573 InitializeStandardProfiles(); | 570 InitializeStandardProfiles(); |
574 SetUpEntry("policy/shill_unmanaged_wifi2.json", | 571 SetUpEntry("policy/shill_unmanaged_wifi2.json", |
575 kUser1ProfilePath, | 572 kUser1ProfilePath, |
576 "wifi2_entry_path"); | 573 "wifi2_entry_path"); |
577 | 574 |
578 EXPECT_CALL(mock_profile_client_, | 575 EXPECT_CALL(*mock_profile_client_, |
579 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 576 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
580 | 577 |
581 EXPECT_CALL( | 578 EXPECT_CALL( |
582 mock_profile_client_, | 579 *mock_profile_client_, |
583 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _)); | 580 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _)); |
584 | 581 |
585 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 582 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
586 test_utils::ReadTestDictionary( | 583 test_utils::ReadTestDictionary( |
587 "policy/shill_policy_on_unconfigured_wifi1.json"); | 584 "policy/shill_policy_on_unconfigured_wifi1.json"); |
588 | 585 |
589 EXPECT_CALL(mock_manager_client_, | 586 EXPECT_CALL(*mock_manager_client_, |
590 ConfigureServiceForProfile( | 587 ConfigureServiceForProfile( |
591 dbus::ObjectPath(kUser1ProfilePath), | 588 dbus::ObjectPath(kUser1ProfilePath), |
592 IsEqualTo(expected_shill_properties.get()), | 589 IsEqualTo(expected_shill_properties.get()), |
593 _, _)); | 590 _, _)); |
594 | 591 |
595 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 592 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
596 message_loop_.RunUntilIdle(); | 593 message_loop_.RunUntilIdle(); |
597 } | 594 } |
598 | 595 |
599 TEST_F(ManagedNetworkConfigurationHandlerTest, AutoConnectDisallowed) { | 596 TEST_F(ManagedNetworkConfigurationHandlerTest, AutoConnectDisallowed) { |
600 InitializeStandardProfiles(); | 597 InitializeStandardProfiles(); |
601 SetUpEntry("policy/shill_unmanaged_wifi2.json", | 598 SetUpEntry("policy/shill_unmanaged_wifi2.json", |
602 kUser1ProfilePath, | 599 kUser1ProfilePath, |
603 "wifi2_entry_path"); | 600 "wifi2_entry_path"); |
604 | 601 |
605 EXPECT_CALL(mock_profile_client_, | 602 EXPECT_CALL(*mock_profile_client_, |
606 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 603 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
607 | 604 |
608 EXPECT_CALL( | 605 EXPECT_CALL( |
609 mock_profile_client_, | 606 *mock_profile_client_, |
610 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _)); | 607 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _)); |
611 | 608 |
612 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 609 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
613 test_utils::ReadTestDictionary( | 610 test_utils::ReadTestDictionary( |
614 "policy/shill_disallow_autoconnect_on_unmanaged_wifi2.json"); | 611 "policy/shill_disallow_autoconnect_on_unmanaged_wifi2.json"); |
615 | 612 |
616 EXPECT_CALL(mock_manager_client_, | 613 EXPECT_CALL(*mock_manager_client_, |
617 ConfigureServiceForProfile( | 614 ConfigureServiceForProfile( |
618 dbus::ObjectPath(kUser1ProfilePath), | 615 dbus::ObjectPath(kUser1ProfilePath), |
619 IsEqualTo(expected_shill_properties.get()), | 616 IsEqualTo(expected_shill_properties.get()), |
620 _, _)); | 617 _, _)); |
621 | 618 |
622 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, | 619 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, |
623 kUser1, | 620 kUser1, |
624 "policy/policy_disallow_autoconnect.onc"); | 621 "policy/policy_disallow_autoconnect.onc"); |
625 message_loop_.RunUntilIdle(); | 622 message_loop_.RunUntilIdle(); |
626 } | 623 } |
627 | 624 |
628 TEST_F(ManagedNetworkConfigurationHandlerTest, LateProfileLoading) { | 625 TEST_F(ManagedNetworkConfigurationHandlerTest, LateProfileLoading) { |
629 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | 626 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
630 | 627 |
631 message_loop_.RunUntilIdle(); | 628 message_loop_.RunUntilIdle(); |
632 VerifyAndClearExpectations(); | 629 VerifyAndClearExpectations(); |
633 | 630 |
634 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 631 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
635 test_utils::ReadTestDictionary( | 632 test_utils::ReadTestDictionary( |
636 "policy/shill_policy_on_unconfigured_wifi1.json"); | 633 "policy/shill_policy_on_unconfigured_wifi1.json"); |
637 | 634 |
638 EXPECT_CALL(mock_profile_client_, | 635 EXPECT_CALL(*mock_profile_client_, |
639 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | 636 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
640 | 637 |
641 EXPECT_CALL(mock_manager_client_, | 638 EXPECT_CALL(*mock_manager_client_, |
642 ConfigureServiceForProfile( | 639 ConfigureServiceForProfile( |
643 dbus::ObjectPath(kUser1ProfilePath), | 640 dbus::ObjectPath(kUser1ProfilePath), |
644 IsEqualTo(expected_shill_properties.get()), | 641 IsEqualTo(expected_shill_properties.get()), |
645 _, _)); | 642 _, _)); |
646 | 643 |
647 InitializeStandardProfiles(); | 644 InitializeStandardProfiles(); |
648 message_loop_.RunUntilIdle(); | 645 message_loop_.RunUntilIdle(); |
649 } | 646 } |
650 | 647 |
651 } // namespace chromeos | 648 } // namespace chromeos |
OLD | NEW |