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
3 // found in the LICENSE file.
9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/stl_util.h"
13 #include "base/values.h"
14 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "chromeos/dbus/fake_dbus_thread_manager.h"
16 #include "chromeos/dbus/mock_shill_manager_client.h"
17 #include "chromeos/dbus/mock_shill_profile_client.h"
18 #include "chromeos/dbus/shill_client_helper.h"
19 #include "chromeos/network/managed_network_configuration_handler_impl.h"
20 #include "chromeos/network/network_configuration_handler.h"
21 #include "chromeos/network/network_profile_handler.h"
22 #include "chromeos/network/onc/onc_test_utils.h"
23 #include "chromeos/network/onc/onc_utils.h"
24 #include "dbus/object_path.h"
25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/cros_system_api/dbus/service_constants.h"
29 using ::testing::AnyNumber
;
30 using ::testing::Invoke
;
31 using ::testing::Mock
;
32 using ::testing::Pointee
;
33 using ::testing::Return
;
34 using ::testing::SaveArg
;
35 using ::testing::StrEq
;
36 using ::testing::StrictMock
;
39 namespace test_utils
= ::chromeos::onc::test_utils
;
45 std::string
ValueToString(const base::Value
* value
) {
46 std::stringstream str
;
51 const char kUser1
[] = "user1";
52 const char kUser1ProfilePath
[] = "/profile/user1/shill";
54 // Matcher to match base::Value.
57 std::string(negation
? "isn't" : "is") + " equal to " +
58 ValueToString(value
)) {
59 return value
->Equals(&arg
);
62 class ShillProfileTestClient
{
64 typedef ShillClientHelper::DictionaryValueCallbackWithoutStatus
65 DictionaryValueCallbackWithoutStatus
;
66 typedef ShillClientHelper::ErrorCallback ErrorCallback
;
68 void AddProfile(const std::string
& profile_path
,
69 const std::string
& userhash
) {
70 if (profile_entries_
.HasKey(profile_path
))
73 base::DictionaryValue
* profile
= new base::DictionaryValue
;
74 profile_entries_
.SetWithoutPathExpansion(profile_path
, profile
);
75 profile_to_user_
[profile_path
] = userhash
;
78 void AddEntry(const std::string
& profile_path
,
79 const std::string
& entry_path
,
80 const base::DictionaryValue
& entry
) {
81 base::DictionaryValue
* entries
= NULL
;
82 profile_entries_
.GetDictionaryWithoutPathExpansion(profile_path
, &entries
);
85 base::DictionaryValue
* new_entry
= entry
.DeepCopy();
86 new_entry
->SetStringWithoutPathExpansion(shill::kProfileProperty
,
88 entries
->SetWithoutPathExpansion(entry_path
, new_entry
);
91 void GetProperties(const dbus::ObjectPath
& profile_path
,
92 const DictionaryValueCallbackWithoutStatus
& callback
,
93 const ErrorCallback
& error_callback
) {
94 base::DictionaryValue
* entries
= NULL
;
95 profile_entries_
.GetDictionaryWithoutPathExpansion(profile_path
.value(),
99 scoped_ptr
<base::DictionaryValue
> result(new base::DictionaryValue
);
100 base::ListValue
* entry_paths
= new base::ListValue
;
101 result
->SetWithoutPathExpansion(shill::kEntriesProperty
, entry_paths
);
102 for (base::DictionaryValue::Iterator
it(*entries
); !it
.IsAtEnd();
104 entry_paths
->AppendString(it
.key());
107 ASSERT_TRUE(ContainsKey(profile_to_user_
, profile_path
.value()));
108 const std::string
& userhash
= profile_to_user_
[profile_path
.value()];
109 result
->SetStringWithoutPathExpansion(shill::kUserHashProperty
, userhash
);
111 callback
.Run(*result
);
114 void GetEntry(const dbus::ObjectPath
& profile_path
,
115 const std::string
& entry_path
,
116 const DictionaryValueCallbackWithoutStatus
& callback
,
117 const ErrorCallback
& error_callback
) {
118 base::DictionaryValue
* entries
= NULL
;
119 profile_entries_
.GetDictionaryWithoutPathExpansion(profile_path
.value(),
121 ASSERT_TRUE(entries
);
123 base::DictionaryValue
* entry
= NULL
;
124 entries
->GetDictionaryWithoutPathExpansion(entry_path
, &entry
);
126 callback
.Run(*entry
);
130 base::DictionaryValue profile_entries_
;
131 std::map
<std::string
, std::string
> profile_to_user_
;
134 class TestNetworkProfileHandler
: public NetworkProfileHandler
{
136 TestNetworkProfileHandler() {
139 virtual ~TestNetworkProfileHandler() {}
141 void AddProfileForTest(const NetworkProfile
& profile
) {
146 DISALLOW_COPY_AND_ASSIGN(TestNetworkProfileHandler
);
151 class ManagedNetworkConfigurationHandlerTest
: public testing::Test
{
153 ManagedNetworkConfigurationHandlerTest()
154 : mock_manager_client_(NULL
),
155 mock_profile_client_(NULL
) {
158 virtual ~ManagedNetworkConfigurationHandlerTest() {
161 virtual void SetUp() OVERRIDE
{
162 FakeDBusThreadManager
* dbus_thread_manager
= new FakeDBusThreadManager
;
163 mock_manager_client_
= new StrictMock
<MockShillManagerClient
>();
164 mock_profile_client_
= new StrictMock
<MockShillProfileClient
>();
165 dbus_thread_manager
->SetShillManagerClient(
166 scoped_ptr
<ShillManagerClient
>(mock_manager_client_
).Pass());
167 dbus_thread_manager
->SetShillProfileClient(
168 scoped_ptr
<ShillProfileClient
>(mock_profile_client_
).Pass());
170 DBusThreadManager::InitializeForTesting(dbus_thread_manager
);
172 SetNetworkConfigurationHandlerExpectations();
174 ON_CALL(*mock_profile_client_
, GetProperties(_
,_
,_
))
175 .WillByDefault(Invoke(&profiles_stub_
,
176 &ShillProfileTestClient::GetProperties
));
178 ON_CALL(*mock_profile_client_
, GetEntry(_
,_
,_
,_
))
179 .WillByDefault(Invoke(&profiles_stub_
,
180 &ShillProfileTestClient::GetEntry
));
182 network_profile_handler_
.reset(new TestNetworkProfileHandler());
183 network_configuration_handler_
.reset(
184 NetworkConfigurationHandler::InitializeForTest(
185 NULL
/* no NetworkStateHandler */));
186 managed_network_configuration_handler_
.reset(
187 new ManagedNetworkConfigurationHandlerImpl());
188 managed_network_configuration_handler_
->Init(
189 NULL
/* no NetworkStateHandler */,
190 network_profile_handler_
.get(),
191 network_configuration_handler_
.get(),
192 NULL
/* no DeviceHandler */);
194 message_loop_
.RunUntilIdle();
197 virtual void TearDown() OVERRIDE
{
198 managed_network_configuration_handler_
.reset();
199 network_configuration_handler_
.reset();
200 network_profile_handler_
.reset();
201 DBusThreadManager::Shutdown();
204 void VerifyAndClearExpectations() {
205 Mock::VerifyAndClearExpectations(mock_manager_client_
);
206 Mock::VerifyAndClearExpectations(mock_profile_client_
);
207 SetNetworkConfigurationHandlerExpectations();
210 void InitializeStandardProfiles() {
211 profiles_stub_
.AddProfile(kUser1ProfilePath
, kUser1
);
212 network_profile_handler_
->
213 AddProfileForTest(NetworkProfile(kUser1ProfilePath
, kUser1
));
214 network_profile_handler_
->
215 AddProfileForTest(NetworkProfile(
216 NetworkProfileHandler::GetSharedProfilePath(), std::string()));
219 void SetUpEntry(const std::string
& path_to_shill_json
,
220 const std::string
& profile_path
,
221 const std::string
& entry_path
) {
222 scoped_ptr
<base::DictionaryValue
> entry
=
223 test_utils::ReadTestDictionary(path_to_shill_json
);
224 profiles_stub_
.AddEntry(profile_path
, entry_path
, *entry
);
227 void SetPolicy(::onc::ONCSource onc_source
,
228 const std::string
& userhash
,
229 const std::string
& path_to_onc
) {
230 scoped_ptr
<base::DictionaryValue
> policy
;
231 if (path_to_onc
.empty())
232 policy
= onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration
);
234 policy
= test_utils::ReadTestDictionary(path_to_onc
);
236 base::ListValue empty_network_configs
;
237 base::ListValue
* network_configs
= &empty_network_configs
;
238 policy
->GetListWithoutPathExpansion(
239 ::onc::toplevel_config::kNetworkConfigurations
, &network_configs
);
241 base::DictionaryValue empty_global_config
;
242 base::DictionaryValue
* global_network_config
= &empty_global_config
;
243 policy
->GetDictionaryWithoutPathExpansion(
244 ::onc::toplevel_config::kGlobalNetworkConfiguration
,
245 &global_network_config
);
247 managed_handler()->SetPolicy(
248 onc_source
, userhash
, *network_configs
, *global_network_config
);
251 void SetNetworkConfigurationHandlerExpectations() {
252 // These calls occur in NetworkConfigurationHandler.
253 EXPECT_CALL(*mock_manager_client_
, GetProperties(_
)).Times(AnyNumber());
254 EXPECT_CALL(*mock_manager_client_
,
255 AddPropertyChangedObserver(_
)).Times(AnyNumber());
256 EXPECT_CALL(*mock_manager_client_
,
257 RemovePropertyChangedObserver(_
)).Times(AnyNumber());
260 ManagedNetworkConfigurationHandler
* managed_handler() {
261 return managed_network_configuration_handler_
.get();
265 MockShillManagerClient
* mock_manager_client_
;
266 MockShillProfileClient
* mock_profile_client_
;
267 ShillProfileTestClient profiles_stub_
;
268 scoped_ptr
<TestNetworkProfileHandler
> network_profile_handler_
;
269 scoped_ptr
<NetworkConfigurationHandler
> network_configuration_handler_
;
270 scoped_ptr
<ManagedNetworkConfigurationHandlerImpl
>
271 managed_network_configuration_handler_
;
272 base::MessageLoop message_loop_
;
275 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest
);
278 TEST_F(ManagedNetworkConfigurationHandlerTest
, ProfileInitialization
) {
279 InitializeStandardProfiles();
280 message_loop_
.RunUntilIdle();
283 TEST_F(ManagedNetworkConfigurationHandlerTest
, RemoveIrrelevantFields
) {
284 InitializeStandardProfiles();
285 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
286 test_utils::ReadTestDictionary(
287 "policy/shill_policy_on_unconfigured_wifi1.json");
289 EXPECT_CALL(*mock_profile_client_
,
290 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
292 EXPECT_CALL(*mock_manager_client_
,
293 ConfigureServiceForProfile(
294 dbus::ObjectPath(kUser1ProfilePath
),
295 IsEqualTo(expected_shill_properties
.get()),
298 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
,
300 "policy/policy_wifi1_with_redundant_fields.onc");
301 message_loop_
.RunUntilIdle();
304 TEST_F(ManagedNetworkConfigurationHandlerTest
, SetPolicyManageUnconfigured
) {
305 InitializeStandardProfiles();
306 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
307 test_utils::ReadTestDictionary(
308 "policy/shill_policy_on_unconfigured_wifi1.json");
310 EXPECT_CALL(*mock_profile_client_
,
311 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
313 EXPECT_CALL(*mock_manager_client_
,
314 ConfigureServiceForProfile(
315 dbus::ObjectPath(kUser1ProfilePath
),
316 IsEqualTo(expected_shill_properties
.get()),
319 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
320 message_loop_
.RunUntilIdle();
323 // Ensure that EAP settings for ethernet are matched with the right profile
324 // entry and written to the dedicated EthernetEAP service.
325 TEST_F(ManagedNetworkConfigurationHandlerTest
,
326 SetPolicyManageUnmanagedEthernetEAP
) {
327 InitializeStandardProfiles();
328 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
329 test_utils::ReadTestDictionary(
331 "shill_policy_on_unmanaged_ethernet_eap.json");
333 SetUpEntry("policy/shill_unmanaged_ethernet_eap.json",
337 // Also setup an unrelated WiFi configuration to verify that the right entry
339 SetUpEntry("policy/shill_unmanaged_wifi1.json",
343 EXPECT_CALL(*mock_profile_client_
,
344 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
346 EXPECT_CALL(*mock_profile_client_
,
347 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), _
, _
, _
)).Times(2);
350 *mock_profile_client_
,
351 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath
), "eth_entry", _
, _
));
354 *mock_manager_client_
,
355 ConfigureServiceForProfile(dbus::ObjectPath(kUser1ProfilePath
),
356 IsEqualTo(expected_shill_properties
.get()),
360 ::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_ethernet_eap.onc");
361 message_loop_
.RunUntilIdle();
364 TEST_F(ManagedNetworkConfigurationHandlerTest
, SetPolicyIgnoreUnmodified
) {
365 InitializeStandardProfiles();
366 EXPECT_CALL(*mock_profile_client_
, GetProperties(_
, _
, _
));
368 EXPECT_CALL(*mock_manager_client_
, ConfigureServiceForProfile(_
, _
, _
, _
));
370 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
371 message_loop_
.RunUntilIdle();
372 VerifyAndClearExpectations();
374 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json",
378 EXPECT_CALL(*mock_profile_client_
, GetProperties(_
, _
, _
));
381 *mock_profile_client_
,
382 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "some_entry_path", _
, _
));
384 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
385 message_loop_
.RunUntilIdle();
388 TEST_F(ManagedNetworkConfigurationHandlerTest
, SetPolicyManageUnmanaged
) {
389 InitializeStandardProfiles();
390 SetUpEntry("policy/shill_unmanaged_wifi1.json",
394 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
395 test_utils::ReadTestDictionary(
396 "policy/shill_policy_on_unmanaged_wifi1.json");
398 EXPECT_CALL(*mock_profile_client_
,
399 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
402 *mock_profile_client_
,
403 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "old_entry_path", _
, _
));
406 *mock_profile_client_
,
407 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath
), "old_entry_path", _
, _
));
409 EXPECT_CALL(*mock_manager_client_
,
410 ConfigureServiceForProfile(
411 dbus::ObjectPath(kUser1ProfilePath
),
412 IsEqualTo(expected_shill_properties
.get()),
415 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
416 message_loop_
.RunUntilIdle();
419 // Old ChromeOS versions may not have used the UIData property
420 TEST_F(ManagedNetworkConfigurationHandlerTest
,
421 SetPolicyManageUnmanagedWithoutUIData
) {
422 InitializeStandardProfiles();
423 SetUpEntry("policy/shill_unmanaged_wifi1.json",
427 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
428 test_utils::ReadTestDictionary(
429 "policy/shill_policy_on_unmanaged_wifi1.json");
431 EXPECT_CALL(*mock_profile_client_
,
432 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
435 *mock_profile_client_
,
436 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "old_entry_path", _
, _
));
439 *mock_profile_client_
,
440 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath
), "old_entry_path", _
, _
));
442 EXPECT_CALL(*mock_manager_client_
,
443 ConfigureServiceForProfile(
444 dbus::ObjectPath(kUser1ProfilePath
),
445 IsEqualTo(expected_shill_properties
.get()),
448 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
449 message_loop_
.RunUntilIdle();
452 TEST_F(ManagedNetworkConfigurationHandlerTest
, SetPolicyUpdateManagedNewGUID
) {
453 InitializeStandardProfiles();
454 SetUpEntry("policy/shill_managed_wifi1.json",
458 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
459 test_utils::ReadTestDictionary(
460 "policy/shill_policy_on_unmanaged_wifi1.json");
462 // The passphrase isn't sent again, because it's configured by the user and
463 // Shill doesn't send it on GetProperties calls.
464 expected_shill_properties
->RemoveWithoutPathExpansion(
465 shill::kPassphraseProperty
, NULL
);
467 EXPECT_CALL(*mock_profile_client_
,
468 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
471 *mock_profile_client_
,
472 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "old_entry_path", _
, _
));
475 *mock_profile_client_
,
476 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath
), "old_entry_path", _
, _
));
478 EXPECT_CALL(*mock_manager_client_
,
479 ConfigureServiceForProfile(
480 dbus::ObjectPath(kUser1ProfilePath
),
481 IsEqualTo(expected_shill_properties
.get()),
484 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
485 message_loop_
.RunUntilIdle();
488 TEST_F(ManagedNetworkConfigurationHandlerTest
, SetPolicyUpdateManagedVPN
) {
489 InitializeStandardProfiles();
490 SetUpEntry("policy/shill_managed_vpn.json", kUser1ProfilePath
, "entry_path");
492 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
493 test_utils::ReadTestDictionary(
494 "policy/shill_policy_on_managed_vpn.json");
496 EXPECT_CALL(*mock_profile_client_
,
497 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
500 *mock_profile_client_
,
501 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "entry_path", _
, _
));
503 EXPECT_CALL(*mock_manager_client_
,
504 ConfigureServiceForProfile(
505 dbus::ObjectPath(kUser1ProfilePath
),
506 IsEqualTo(expected_shill_properties
.get()),
509 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_vpn.onc");
510 message_loop_
.RunUntilIdle();
511 VerifyAndClearExpectations();
514 TEST_F(ManagedNetworkConfigurationHandlerTest
,
515 SetPolicyUpdateManagedEquivalentSecurity
) {
516 InitializeStandardProfiles();
517 SetUpEntry("policy/shill_managed_wifi1_rsn.json",
521 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
522 test_utils::ReadTestDictionary(
523 "policy/shill_policy_on_unmanaged_wifi1.json");
525 // The passphrase isn't sent again, because it's configured by the user and
526 // Shill doesn't send it on GetProperties calls.
527 expected_shill_properties
->RemoveWithoutPathExpansion(
528 shill::kPassphraseProperty
, NULL
);
530 EXPECT_CALL(*mock_profile_client_
,
531 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
534 *mock_profile_client_
,
535 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "old_entry_path", _
, _
));
537 // The existing entry must not be deleted because the Security type 'rsa' is
538 // equivalent to 'psk' when identifying networks.
541 *mock_manager_client_
,
542 ConfigureServiceForProfile(dbus::ObjectPath(kUser1ProfilePath
),
543 IsEqualTo(expected_shill_properties
.get()),
546 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
547 message_loop_
.RunUntilIdle();
550 TEST_F(ManagedNetworkConfigurationHandlerTest
, SetPolicyReapplyToManaged
) {
551 InitializeStandardProfiles();
552 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json",
556 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
557 test_utils::ReadTestDictionary(
558 "policy/shill_policy_on_unmanaged_wifi1.json");
560 // The passphrase isn't sent again, because it's configured by the user and
561 // Shill doesn't send it on GetProperties calls.
562 expected_shill_properties
->RemoveWithoutPathExpansion(
563 shill::kPassphraseProperty
, NULL
);
565 EXPECT_CALL(*mock_profile_client_
,
566 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
569 *mock_profile_client_
,
570 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "old_entry_path", _
, _
));
572 EXPECT_CALL(*mock_manager_client_
,
573 ConfigureServiceForProfile(
574 dbus::ObjectPath(kUser1ProfilePath
),
575 IsEqualTo(expected_shill_properties
.get()),
578 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
579 message_loop_
.RunUntilIdle();
580 VerifyAndClearExpectations();
582 // If we apply the policy again, without change, then the Shill profile will
584 EXPECT_CALL(*mock_profile_client_
,
585 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
588 *mock_profile_client_
,
589 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "old_entry_path", _
, _
));
591 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
592 message_loop_
.RunUntilIdle();
595 TEST_F(ManagedNetworkConfigurationHandlerTest
, SetPolicyUnmanageManaged
) {
596 InitializeStandardProfiles();
597 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json",
601 EXPECT_CALL(*mock_profile_client_
,
602 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
604 EXPECT_CALL(*mock_profile_client_
,
605 GetEntry(dbus::ObjectPath(kUser1ProfilePath
),
609 EXPECT_CALL(*mock_profile_client_
,
610 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath
),
614 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "");
615 message_loop_
.RunUntilIdle();
618 TEST_F(ManagedNetworkConfigurationHandlerTest
, SetEmptyPolicyIgnoreUnmanaged
) {
619 InitializeStandardProfiles();
620 SetUpEntry("policy/shill_unmanaged_wifi1.json",
624 EXPECT_CALL(*mock_profile_client_
,
625 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
627 EXPECT_CALL(*mock_profile_client_
,
628 GetEntry(dbus::ObjectPath(kUser1ProfilePath
),
632 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "");
633 message_loop_
.RunUntilIdle();
636 TEST_F(ManagedNetworkConfigurationHandlerTest
, SetPolicyIgnoreUnmanaged
) {
637 InitializeStandardProfiles();
638 SetUpEntry("policy/shill_unmanaged_wifi2.json",
642 EXPECT_CALL(*mock_profile_client_
,
643 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
646 *mock_profile_client_
,
647 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "wifi2_entry_path", _
, _
));
649 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
650 test_utils::ReadTestDictionary(
651 "policy/shill_policy_on_unconfigured_wifi1.json");
653 EXPECT_CALL(*mock_manager_client_
,
654 ConfigureServiceForProfile(
655 dbus::ObjectPath(kUser1ProfilePath
),
656 IsEqualTo(expected_shill_properties
.get()),
659 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
660 message_loop_
.RunUntilIdle();
663 TEST_F(ManagedNetworkConfigurationHandlerTest
, AutoConnectDisallowed
) {
664 InitializeStandardProfiles();
665 SetUpEntry("policy/shill_unmanaged_wifi2.json",
669 EXPECT_CALL(*mock_profile_client_
,
670 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
673 *mock_profile_client_
,
674 GetEntry(dbus::ObjectPath(kUser1ProfilePath
), "wifi2_entry_path", _
, _
));
676 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
677 test_utils::ReadTestDictionary(
678 "policy/shill_disallow_autoconnect_on_unmanaged_wifi2.json");
680 EXPECT_CALL(*mock_manager_client_
,
681 ConfigureServiceForProfile(
682 dbus::ObjectPath(kUser1ProfilePath
),
683 IsEqualTo(expected_shill_properties
.get()),
686 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
,
688 "policy/policy_disallow_autoconnect.onc");
689 message_loop_
.RunUntilIdle();
692 TEST_F(ManagedNetworkConfigurationHandlerTest
, LateProfileLoading
) {
693 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
695 message_loop_
.RunUntilIdle();
696 VerifyAndClearExpectations();
698 scoped_ptr
<base::DictionaryValue
> expected_shill_properties
=
699 test_utils::ReadTestDictionary(
700 "policy/shill_policy_on_unconfigured_wifi1.json");
702 EXPECT_CALL(*mock_profile_client_
,
703 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
705 EXPECT_CALL(*mock_manager_client_
,
706 ConfigureServiceForProfile(
707 dbus::ObjectPath(kUser1ProfilePath
),
708 IsEqualTo(expected_shill_properties
.get()),
711 InitializeStandardProfiles();
712 message_loop_
.RunUntilIdle();
715 class ManagedNetworkConfigurationHandlerShutdownTest
716 : public ManagedNetworkConfigurationHandlerTest
{
718 virtual void SetUp() OVERRIDE
{
719 ManagedNetworkConfigurationHandlerTest::SetUp();
720 ON_CALL(*mock_profile_client_
, GetProperties(_
, _
, _
)).WillByDefault(
721 Invoke(&ManagedNetworkConfigurationHandlerShutdownTest::GetProperties
));
724 static void GetProperties(
725 const dbus::ObjectPath
& profile_path
,
726 const ShillClientHelper::DictionaryValueCallbackWithoutStatus
& callback
,
727 const ShillClientHelper::ErrorCallback
& error_callback
) {
728 base::MessageLoop::current()->PostTask(
730 base::Bind(ManagedNetworkConfigurationHandlerShutdownTest::
731 CallbackWithEmptyDictionary
,
735 static void CallbackWithEmptyDictionary(
736 const ShillClientHelper::DictionaryValueCallbackWithoutStatus
& callback
) {
737 callback
.Run(base::DictionaryValue());
741 TEST_F(ManagedNetworkConfigurationHandlerShutdownTest
,
742 DuringPolicyApplication
) {
743 InitializeStandardProfiles();
745 EXPECT_CALL(*mock_profile_client_
,
746 GetProperties(dbus::ObjectPath(kUser1ProfilePath
), _
, _
));
748 SetPolicy(::onc::ONC_SOURCE_USER_POLICY
, kUser1
, "policy/policy_wifi1.onc");
749 managed_network_configuration_handler_
.reset();
750 message_loop_
.RunUntilIdle();
753 } // namespace chromeos