Remove ViewMsg_UpdateRect_ACK
[chromium-blink-merge.git] / chromeos / network / managed_network_configuration_handler_unittest.cc
blob0107eebd3a629d3f60878d9d4817f33119e29476
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.
5 #include <iostream>
6 #include <sstream>
8 #include "base/bind.h"
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;
37 using ::testing::_;
39 namespace test_utils = ::chromeos::onc::test_utils;
41 namespace chromeos {
43 namespace {
45 std::string ValueToString(const base::Value* value) {
46 std::stringstream str;
47 str << *value;
48 return str.str();
51 const char kUser1[] = "user1";
52 const char kUser1ProfilePath[] = "/profile/user1/shill";
54 // Matcher to match base::Value.
55 MATCHER_P(IsEqualTo,
56 value,
57 std::string(negation ? "isn't" : "is") + " equal to " +
58 ValueToString(value)) {
59 return value->Equals(&arg);
62 class ShillProfileTestClient {
63 public:
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))
71 return;
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);
83 ASSERT_TRUE(entries);
85 base::DictionaryValue* new_entry = entry.DeepCopy();
86 new_entry->SetStringWithoutPathExpansion(shill::kProfileProperty,
87 profile_path);
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(),
96 &entries);
97 ASSERT_TRUE(entries);
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();
103 it.Advance()) {
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(),
120 &entries);
121 ASSERT_TRUE(entries);
123 base::DictionaryValue* entry = NULL;
124 entries->GetDictionaryWithoutPathExpansion(entry_path, &entry);
125 ASSERT_TRUE(entry);
126 callback.Run(*entry);
129 protected:
130 base::DictionaryValue profile_entries_;
131 std::map<std::string, std::string> profile_to_user_;
134 class TestNetworkProfileHandler : public NetworkProfileHandler {
135 public:
136 TestNetworkProfileHandler() {
137 Init(NULL /* No NetworkStateHandler */);
139 virtual ~TestNetworkProfileHandler() {}
141 void AddProfileForTest(const NetworkProfile& profile) {
142 AddProfile(profile);
145 private:
146 DISALLOW_COPY_AND_ASSIGN(TestNetworkProfileHandler);
149 } // namespace
151 class ManagedNetworkConfigurationHandlerTest : public testing::Test {
152 public:
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());
193 message_loop_.RunUntilIdle();
196 virtual void TearDown() OVERRIDE {
197 managed_network_configuration_handler_.reset();
198 network_configuration_handler_.reset();
199 network_profile_handler_.reset();
200 DBusThreadManager::Shutdown();
203 void VerifyAndClearExpectations() {
204 Mock::VerifyAndClearExpectations(mock_manager_client_);
205 Mock::VerifyAndClearExpectations(mock_profile_client_);
206 SetNetworkConfigurationHandlerExpectations();
209 void InitializeStandardProfiles() {
210 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1);
211 network_profile_handler_->
212 AddProfileForTest(NetworkProfile(kUser1ProfilePath, kUser1));
213 network_profile_handler_->
214 AddProfileForTest(NetworkProfile(
215 NetworkProfileHandler::GetSharedProfilePath(), std::string()));
218 void SetUpEntry(const std::string& path_to_shill_json,
219 const std::string& profile_path,
220 const std::string& entry_path) {
221 scoped_ptr<base::DictionaryValue> entry =
222 test_utils::ReadTestDictionary(path_to_shill_json);
223 profiles_stub_.AddEntry(profile_path, entry_path, *entry);
226 void SetPolicy(::onc::ONCSource onc_source,
227 const std::string& userhash,
228 const std::string& path_to_onc) {
229 scoped_ptr<base::DictionaryValue> policy;
230 if (path_to_onc.empty())
231 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration);
232 else
233 policy = test_utils::ReadTestDictionary(path_to_onc);
235 base::ListValue empty_network_configs;
236 base::ListValue* network_configs = &empty_network_configs;
237 policy->GetListWithoutPathExpansion(
238 ::onc::toplevel_config::kNetworkConfigurations, &network_configs);
240 base::DictionaryValue empty_global_config;
241 base::DictionaryValue* global_network_config = &empty_global_config;
242 policy->GetDictionaryWithoutPathExpansion(
243 ::onc::toplevel_config::kGlobalNetworkConfiguration,
244 &global_network_config);
246 managed_handler()->SetPolicy(
247 onc_source, userhash, *network_configs, *global_network_config);
250 void SetNetworkConfigurationHandlerExpectations() {
251 // These calls occur in NetworkConfigurationHandler.
252 EXPECT_CALL(*mock_manager_client_, GetProperties(_)).Times(AnyNumber());
253 EXPECT_CALL(*mock_manager_client_,
254 AddPropertyChangedObserver(_)).Times(AnyNumber());
255 EXPECT_CALL(*mock_manager_client_,
256 RemovePropertyChangedObserver(_)).Times(AnyNumber());
259 ManagedNetworkConfigurationHandler* managed_handler() {
260 return managed_network_configuration_handler_.get();
263 protected:
264 MockShillManagerClient* mock_manager_client_;
265 MockShillProfileClient* mock_profile_client_;
266 ShillProfileTestClient profiles_stub_;
267 scoped_ptr<TestNetworkProfileHandler> network_profile_handler_;
268 scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_;
269 scoped_ptr<ManagedNetworkConfigurationHandlerImpl>
270 managed_network_configuration_handler_;
271 base::MessageLoop message_loop_;
273 private:
274 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest);
277 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) {
278 InitializeStandardProfiles();
279 message_loop_.RunUntilIdle();
282 TEST_F(ManagedNetworkConfigurationHandlerTest, RemoveIrrelevantFields) {
283 InitializeStandardProfiles();
284 scoped_ptr<base::DictionaryValue> expected_shill_properties =
285 test_utils::ReadTestDictionary(
286 "policy/shill_policy_on_unconfigured_wifi1.json");
288 EXPECT_CALL(*mock_profile_client_,
289 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
291 EXPECT_CALL(*mock_manager_client_,
292 ConfigureServiceForProfile(
293 dbus::ObjectPath(kUser1ProfilePath),
294 IsEqualTo(expected_shill_properties.get()),
295 _, _));
297 SetPolicy(::onc::ONC_SOURCE_USER_POLICY,
298 kUser1,
299 "policy/policy_wifi1_with_redundant_fields.onc");
300 message_loop_.RunUntilIdle();
303 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnconfigured) {
304 InitializeStandardProfiles();
305 scoped_ptr<base::DictionaryValue> expected_shill_properties =
306 test_utils::ReadTestDictionary(
307 "policy/shill_policy_on_unconfigured_wifi1.json");
309 EXPECT_CALL(*mock_profile_client_,
310 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
312 EXPECT_CALL(*mock_manager_client_,
313 ConfigureServiceForProfile(
314 dbus::ObjectPath(kUser1ProfilePath),
315 IsEqualTo(expected_shill_properties.get()),
316 _, _));
318 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
319 message_loop_.RunUntilIdle();
322 // Ensure that EAP settings for ethernet are matched with the right profile
323 // entry and written to the dedicated EthernetEAP service.
324 TEST_F(ManagedNetworkConfigurationHandlerTest,
325 SetPolicyManageUnmanagedEthernetEAP) {
326 InitializeStandardProfiles();
327 scoped_ptr<base::DictionaryValue> expected_shill_properties =
328 test_utils::ReadTestDictionary(
329 "policy/"
330 "shill_policy_on_unmanaged_ethernet_eap.json");
332 SetUpEntry("policy/shill_unmanaged_ethernet_eap.json",
333 kUser1ProfilePath,
334 "eth_entry");
336 // Also setup an unrelated WiFi configuration to verify that the right entry
337 // is matched.
338 SetUpEntry("policy/shill_unmanaged_wifi1.json",
339 kUser1ProfilePath,
340 "wifi_entry");
342 EXPECT_CALL(*mock_profile_client_,
343 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
345 EXPECT_CALL(*mock_profile_client_,
346 GetEntry(dbus::ObjectPath(kUser1ProfilePath), _, _, _)).Times(2);
348 EXPECT_CALL(
349 *mock_profile_client_,
350 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "eth_entry", _, _));
352 EXPECT_CALL(
353 *mock_manager_client_,
354 ConfigureServiceForProfile(dbus::ObjectPath(kUser1ProfilePath),
355 IsEqualTo(expected_shill_properties.get()),
356 _, _));
358 SetPolicy(
359 ::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_ethernet_eap.onc");
360 message_loop_.RunUntilIdle();
363 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) {
364 InitializeStandardProfiles();
365 EXPECT_CALL(*mock_profile_client_, GetProperties(_, _, _));
367 EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile(_, _, _, _));
369 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
370 message_loop_.RunUntilIdle();
371 VerifyAndClearExpectations();
373 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json",
374 kUser1ProfilePath,
375 "some_entry_path");
377 EXPECT_CALL(*mock_profile_client_, GetProperties(_, _, _));
379 EXPECT_CALL(
380 *mock_profile_client_,
381 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "some_entry_path", _, _));
383 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
384 message_loop_.RunUntilIdle();
387 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnmanaged) {
388 InitializeStandardProfiles();
389 SetUpEntry("policy/shill_unmanaged_wifi1.json",
390 kUser1ProfilePath,
391 "old_entry_path");
393 scoped_ptr<base::DictionaryValue> expected_shill_properties =
394 test_utils::ReadTestDictionary(
395 "policy/shill_policy_on_unmanaged_wifi1.json");
397 EXPECT_CALL(*mock_profile_client_,
398 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
400 EXPECT_CALL(
401 *mock_profile_client_,
402 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _));
404 EXPECT_CALL(
405 *mock_profile_client_,
406 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _));
408 EXPECT_CALL(*mock_manager_client_,
409 ConfigureServiceForProfile(
410 dbus::ObjectPath(kUser1ProfilePath),
411 IsEqualTo(expected_shill_properties.get()),
412 _, _));
414 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
415 message_loop_.RunUntilIdle();
418 // Old ChromeOS versions may not have used the UIData property
419 TEST_F(ManagedNetworkConfigurationHandlerTest,
420 SetPolicyManageUnmanagedWithoutUIData) {
421 InitializeStandardProfiles();
422 SetUpEntry("policy/shill_unmanaged_wifi1.json",
423 kUser1ProfilePath,
424 "old_entry_path");
426 scoped_ptr<base::DictionaryValue> expected_shill_properties =
427 test_utils::ReadTestDictionary(
428 "policy/shill_policy_on_unmanaged_wifi1.json");
430 EXPECT_CALL(*mock_profile_client_,
431 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
433 EXPECT_CALL(
434 *mock_profile_client_,
435 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _));
437 EXPECT_CALL(
438 *mock_profile_client_,
439 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _));
441 EXPECT_CALL(*mock_manager_client_,
442 ConfigureServiceForProfile(
443 dbus::ObjectPath(kUser1ProfilePath),
444 IsEqualTo(expected_shill_properties.get()),
445 _, _));
447 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
448 message_loop_.RunUntilIdle();
451 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) {
452 InitializeStandardProfiles();
453 SetUpEntry("policy/shill_managed_wifi1.json",
454 kUser1ProfilePath,
455 "old_entry_path");
457 scoped_ptr<base::DictionaryValue> expected_shill_properties =
458 test_utils::ReadTestDictionary(
459 "policy/shill_policy_on_unmanaged_wifi1.json");
461 // The passphrase isn't sent again, because it's configured by the user and
462 // Shill doesn't sent it on GetProperties calls.
463 expected_shill_properties->RemoveWithoutPathExpansion(
464 shill::kPassphraseProperty, NULL);
466 EXPECT_CALL(*mock_profile_client_,
467 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
469 EXPECT_CALL(
470 *mock_profile_client_,
471 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _));
473 EXPECT_CALL(
474 *mock_profile_client_,
475 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _));
477 EXPECT_CALL(*mock_manager_client_,
478 ConfigureServiceForProfile(
479 dbus::ObjectPath(kUser1ProfilePath),
480 IsEqualTo(expected_shill_properties.get()),
481 _, _));
483 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
484 message_loop_.RunUntilIdle();
487 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) {
488 InitializeStandardProfiles();
489 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json",
490 kUser1ProfilePath,
491 "old_entry_path");
493 scoped_ptr<base::DictionaryValue> expected_shill_properties =
494 test_utils::ReadTestDictionary(
495 "policy/shill_policy_on_unmanaged_wifi1.json");
497 // The passphrase isn't sent again, because it's configured by the user and
498 // Shill doesn't sent it on GetProperties calls.
499 expected_shill_properties->RemoveWithoutPathExpansion(
500 shill::kPassphraseProperty, NULL);
502 EXPECT_CALL(*mock_profile_client_,
503 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
505 EXPECT_CALL(
506 *mock_profile_client_,
507 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _));
509 EXPECT_CALL(*mock_manager_client_,
510 ConfigureServiceForProfile(
511 dbus::ObjectPath(kUser1ProfilePath),
512 IsEqualTo(expected_shill_properties.get()),
513 _, _));
515 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
516 message_loop_.RunUntilIdle();
517 VerifyAndClearExpectations();
519 // If we apply the policy again, without change, then the Shill profile will
520 // not be modified.
521 EXPECT_CALL(*mock_profile_client_,
522 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
524 EXPECT_CALL(
525 *mock_profile_client_,
526 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _));
528 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
529 message_loop_.RunUntilIdle();
532 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUnmanageManaged) {
533 InitializeStandardProfiles();
534 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json",
535 kUser1ProfilePath,
536 "old_entry_path");
538 EXPECT_CALL(*mock_profile_client_,
539 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
541 EXPECT_CALL(*mock_profile_client_,
542 GetEntry(dbus::ObjectPath(kUser1ProfilePath),
543 "old_entry_path",
544 _, _));
546 EXPECT_CALL(*mock_profile_client_,
547 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath),
548 "old_entry_path",
549 _, _));
551 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "");
552 message_loop_.RunUntilIdle();
555 TEST_F(ManagedNetworkConfigurationHandlerTest, SetEmptyPolicyIgnoreUnmanaged) {
556 InitializeStandardProfiles();
557 SetUpEntry("policy/shill_unmanaged_wifi1.json",
558 kUser1ProfilePath,
559 "old_entry_path");
561 EXPECT_CALL(*mock_profile_client_,
562 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
564 EXPECT_CALL(*mock_profile_client_,
565 GetEntry(dbus::ObjectPath(kUser1ProfilePath),
566 "old_entry_path",
567 _, _));
569 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "");
570 message_loop_.RunUntilIdle();
573 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmanaged) {
574 InitializeStandardProfiles();
575 SetUpEntry("policy/shill_unmanaged_wifi2.json",
576 kUser1ProfilePath,
577 "wifi2_entry_path");
579 EXPECT_CALL(*mock_profile_client_,
580 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
582 EXPECT_CALL(
583 *mock_profile_client_,
584 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _));
586 scoped_ptr<base::DictionaryValue> expected_shill_properties =
587 test_utils::ReadTestDictionary(
588 "policy/shill_policy_on_unconfigured_wifi1.json");
590 EXPECT_CALL(*mock_manager_client_,
591 ConfigureServiceForProfile(
592 dbus::ObjectPath(kUser1ProfilePath),
593 IsEqualTo(expected_shill_properties.get()),
594 _, _));
596 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
597 message_loop_.RunUntilIdle();
600 TEST_F(ManagedNetworkConfigurationHandlerTest, AutoConnectDisallowed) {
601 InitializeStandardProfiles();
602 SetUpEntry("policy/shill_unmanaged_wifi2.json",
603 kUser1ProfilePath,
604 "wifi2_entry_path");
606 EXPECT_CALL(*mock_profile_client_,
607 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
609 EXPECT_CALL(
610 *mock_profile_client_,
611 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _));
613 scoped_ptr<base::DictionaryValue> expected_shill_properties =
614 test_utils::ReadTestDictionary(
615 "policy/shill_disallow_autoconnect_on_unmanaged_wifi2.json");
617 EXPECT_CALL(*mock_manager_client_,
618 ConfigureServiceForProfile(
619 dbus::ObjectPath(kUser1ProfilePath),
620 IsEqualTo(expected_shill_properties.get()),
621 _, _));
623 SetPolicy(::onc::ONC_SOURCE_USER_POLICY,
624 kUser1,
625 "policy/policy_disallow_autoconnect.onc");
626 message_loop_.RunUntilIdle();
629 TEST_F(ManagedNetworkConfigurationHandlerTest, LateProfileLoading) {
630 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
632 message_loop_.RunUntilIdle();
633 VerifyAndClearExpectations();
635 scoped_ptr<base::DictionaryValue> expected_shill_properties =
636 test_utils::ReadTestDictionary(
637 "policy/shill_policy_on_unconfigured_wifi1.json");
639 EXPECT_CALL(*mock_profile_client_,
640 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
642 EXPECT_CALL(*mock_manager_client_,
643 ConfigureServiceForProfile(
644 dbus::ObjectPath(kUser1ProfilePath),
645 IsEqualTo(expected_shill_properties.get()),
646 _, _));
648 InitializeStandardProfiles();
649 message_loop_.RunUntilIdle();
652 class ManagedNetworkConfigurationHandlerShutdownTest
653 : public ManagedNetworkConfigurationHandlerTest {
654 public:
655 virtual void SetUp() OVERRIDE {
656 ManagedNetworkConfigurationHandlerTest::SetUp();
657 ON_CALL(*mock_profile_client_, GetProperties(_, _, _)).WillByDefault(
658 Invoke(&ManagedNetworkConfigurationHandlerShutdownTest::GetProperties));
661 static void GetProperties(
662 const dbus::ObjectPath& profile_path,
663 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback,
664 const ShillClientHelper::ErrorCallback& error_callback) {
665 base::MessageLoop::current()->PostTask(
666 FROM_HERE,
667 base::Bind(ManagedNetworkConfigurationHandlerShutdownTest::
668 CallbackWithEmptyDictionary,
669 callback));
672 static void CallbackWithEmptyDictionary(
673 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback) {
674 callback.Run(base::DictionaryValue());
678 TEST_F(ManagedNetworkConfigurationHandlerShutdownTest,
679 DuringPolicyApplication) {
680 InitializeStandardProfiles();
682 EXPECT_CALL(*mock_profile_client_,
683 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
685 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
686 managed_network_configuration_handler_.reset();
687 message_loop_.RunUntilIdle();
690 } // namespace chromeos