managed_network_configuration_handler_unittest.cc revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
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. 4 5#include <iostream> 6#include <sstream> 7 8#include "base/memory/scoped_ptr.h" 9#include "base/message_loop/message_loop.h" 10#include "base/stl_util.h" 11#include "chromeos/dbus/dbus_thread_manager.h" 12#include "chromeos/dbus/mock_dbus_thread_manager.h" 13#include "chromeos/dbus/mock_shill_manager_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" 17#include "chromeos/network/network_configuration_handler.h" 18#include "chromeos/network/network_profile_handler.h" 19#include "chromeos/network/onc/onc_test_utils.h" 20#include "chromeos/network/onc/onc_utils.h" 21#include "dbus/object_path.h" 22#include "testing/gmock/include/gmock/gmock.h" 23#include "testing/gtest/include/gtest/gtest.h" 24#include "third_party/cros_system_api/dbus/service_constants.h" 25 26using ::testing::AnyNumber; 27using ::testing::Invoke; 28using ::testing::Mock; 29using ::testing::Pointee; 30using ::testing::Return; 31using ::testing::SaveArg; 32using ::testing::StrEq; 33using ::testing::StrictMock; 34using ::testing::_; 35 36namespace test_utils = ::chromeos::onc::test_utils; 37 38namespace chromeos { 39 40namespace { 41 42std::string ValueToString(const base::Value* value) { 43 std::stringstream str; 44 str << *value; 45 return str.str(); 46} 47 48const char kSharedProfilePath[] = "/profile/default"; 49const char kUser1[] = "user1"; 50const char kUser1ProfilePath[] = "/profile/user1/shill"; 51 52// Matcher to match base::Value. 53MATCHER_P(IsEqualTo, 54 value, 55 std::string(negation ? "isn't" : "is") + " equal to " + 56 ValueToString(value)) { 57 return value->Equals(&arg); 58} 59 60class ShillProfileTestClient { 61 public: 62 typedef ShillClientHelper::DictionaryValueCallbackWithoutStatus 63 DictionaryValueCallbackWithoutStatus; 64 typedef ShillClientHelper::ErrorCallback ErrorCallback; 65 66 void AddProfile(const std::string& profile_path, 67 const std::string& userhash) { 68 if (profile_entries_.HasKey(profile_path)) 69 return; 70 71 base::DictionaryValue* profile = new base::DictionaryValue; 72 profile_entries_.SetWithoutPathExpansion(profile_path, profile); 73 profile_to_user_[profile_path] = userhash; 74 } 75 76 void AddEntry(const std::string& profile_path, 77 const std::string& entry_path, 78 const base::DictionaryValue& entry) { 79 base::DictionaryValue* entries = NULL; 80 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path, &entries); 81 ASSERT_TRUE(entries); 82 83 base::DictionaryValue* new_entry = entry.DeepCopy(); 84 new_entry->SetStringWithoutPathExpansion(shill::kProfileProperty, 85 profile_path); 86 entries->SetWithoutPathExpansion(entry_path, new_entry); 87 } 88 89 void GetProperties(const dbus::ObjectPath& profile_path, 90 const DictionaryValueCallbackWithoutStatus& callback, 91 const ErrorCallback& error_callback) { 92 base::DictionaryValue* entries = NULL; 93 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path.value(), 94 &entries); 95 ASSERT_TRUE(entries); 96 97 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); 98 base::ListValue* entry_paths = new base::ListValue; 99 result->SetWithoutPathExpansion(shill::kEntriesProperty, entry_paths); 100 for (base::DictionaryValue::Iterator it(*entries); !it.IsAtEnd(); 101 it.Advance()) { 102 entry_paths->AppendString(it.key()); 103 } 104 105 ASSERT_TRUE(ContainsKey(profile_to_user_, profile_path.value())); 106 const std::string& userhash = profile_to_user_[profile_path.value()]; 107 result->SetStringWithoutPathExpansion(shill::kUserHashProperty, userhash); 108 109 callback.Run(*result); 110 } 111 112 void GetEntry(const dbus::ObjectPath& profile_path, 113 const std::string& entry_path, 114 const DictionaryValueCallbackWithoutStatus& callback, 115 const ErrorCallback& error_callback) { 116 base::DictionaryValue* entries = NULL; 117 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path.value(), 118 &entries); 119 ASSERT_TRUE(entries); 120 121 base::DictionaryValue* entry = NULL; 122 entries->GetDictionaryWithoutPathExpansion(entry_path, &entry); 123 ASSERT_TRUE(entry); 124 callback.Run(*entry); 125 } 126 127 protected: 128 base::DictionaryValue profile_entries_; 129 std::map<std::string, std::string> profile_to_user_; 130}; 131 132class TestNetworkProfileHandler : public NetworkProfileHandler { 133 public: 134 TestNetworkProfileHandler() { 135 Init(NULL /* No NetworkStateHandler */); 136 } 137 virtual ~TestNetworkProfileHandler() {} 138 139 void AddProfileForTest(const NetworkProfile& profile) { 140 AddProfile(profile); 141 } 142 143 private: 144 DISALLOW_COPY_AND_ASSIGN(TestNetworkProfileHandler); 145}; 146 147} // namespace 148 149class ManagedNetworkConfigurationHandlerTest : public testing::Test { 150 public: 151 ManagedNetworkConfigurationHandlerTest() { 152 } 153 154 virtual ~ManagedNetworkConfigurationHandlerTest() { 155 } 156 157 virtual void SetUp() OVERRIDE { 158 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; 159 EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) 160 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); 161 DBusThreadManager::InitializeForTesting(dbus_thread_manager); 162 163 SetNetworkConfigurationHandlerExpectations(); 164 165 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) 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_, 174 &ShillProfileTestClient::GetProperties)); 175 176 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) 177 .WillByDefault(Invoke(&profiles_stub_, 178 &ShillProfileTestClient::GetEntry)); 179 180 network_profile_handler_.reset(new TestNetworkProfileHandler()); 181 network_configuration_handler_.reset( 182 NetworkConfigurationHandler::InitializeForTest( 183 NULL /* no NetworkStateHandler */)); 184 managed_network_configuration_handler_.reset( 185 new ManagedNetworkConfigurationHandlerImpl()); 186 managed_network_configuration_handler_->Init( 187 NULL /* no NetworkStateHandler */, 188 network_profile_handler_.get(), 189 network_configuration_handler_.get()); 190 191 message_loop_.RunUntilIdle(); 192 } 193 194 virtual void TearDown() OVERRIDE { 195 managed_network_configuration_handler_.reset(); 196 network_configuration_handler_.reset(); 197 network_profile_handler_.reset(); 198 DBusThreadManager::Shutdown(); 199 } 200 201 void VerifyAndClearExpectations() { 202 Mock::VerifyAndClearExpectations(&mock_manager_client_); 203 Mock::VerifyAndClearExpectations(&mock_service_client_); 204 Mock::VerifyAndClearExpectations(&mock_profile_client_); 205 SetNetworkConfigurationHandlerExpectations(); 206 } 207 208 void InitializeStandardProfiles() { 209 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1); 210 network_profile_handler_-> 211 AddProfileForTest(NetworkProfile(kUser1ProfilePath, kUser1)); 212 network_profile_handler_-> 213 AddProfileForTest(NetworkProfile(kSharedProfilePath, std::string())); 214 } 215 216 void SetUpEntry(const std::string& path_to_shill_json, 217 const std::string& profile_path, 218 const std::string& entry_path) { 219 scoped_ptr<base::DictionaryValue> entry = 220 test_utils::ReadTestDictionary(path_to_shill_json); 221 profiles_stub_.AddEntry(profile_path, entry_path, *entry); 222 } 223 224 void SetPolicy(::onc::ONCSource onc_source, 225 const std::string& userhash, 226 const std::string& path_to_onc) { 227 scoped_ptr<base::DictionaryValue> policy; 228 if (path_to_onc.empty()) 229 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); 230 else 231 policy = test_utils::ReadTestDictionary(path_to_onc); 232 233 base::ListValue empty_network_configs; 234 base::ListValue* network_configs = &empty_network_configs; 235 policy->GetListWithoutPathExpansion( 236 ::onc::toplevel_config::kNetworkConfigurations, &network_configs); 237 238 base::DictionaryValue empty_global_config; 239 base::DictionaryValue* global_network_config = &empty_global_config; 240 policy->GetDictionaryWithoutPathExpansion( 241 ::onc::toplevel_config::kGlobalNetworkConfiguration, 242 &global_network_config); 243 244 managed_handler()->SetPolicy( 245 onc_source, userhash, *network_configs, *global_network_config); 246 } 247 248 void SetNetworkConfigurationHandlerExpectations() { 249 // These calls occur in NetworkConfigurationHandler. 250 EXPECT_CALL(mock_manager_client_, GetProperties(_)).Times(AnyNumber()); 251 EXPECT_CALL(mock_manager_client_, 252 AddPropertyChangedObserver(_)).Times(AnyNumber()); 253 EXPECT_CALL(mock_manager_client_, 254 RemovePropertyChangedObserver(_)).Times(AnyNumber()); 255 } 256 257 ManagedNetworkConfigurationHandler* managed_handler() { 258 return managed_network_configuration_handler_.get(); 259 } 260 261 protected: 262 StrictMock<MockShillManagerClient> mock_manager_client_; 263 StrictMock<MockShillServiceClient> mock_service_client_; 264 StrictMock<MockShillProfileClient> mock_profile_client_; 265 ShillProfileTestClient profiles_stub_; 266 scoped_ptr<TestNetworkProfileHandler> network_profile_handler_; 267 scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_; 268 scoped_ptr<ManagedNetworkConfigurationHandlerImpl> 269 managed_network_configuration_handler_; 270 base::MessageLoop message_loop_; 271 272 private: 273 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); 274}; 275 276TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { 277 InitializeStandardProfiles(); 278 message_loop_.RunUntilIdle(); 279} 280 281TEST_F(ManagedNetworkConfigurationHandlerTest, RemoveIrrelevantFields) { 282 InitializeStandardProfiles(); 283 scoped_ptr<base::DictionaryValue> expected_shill_properties = 284 test_utils::ReadTestDictionary( 285 "policy/shill_policy_on_unconfigured_wifi1.json"); 286 287 EXPECT_CALL(mock_profile_client_, 288 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 289 290 EXPECT_CALL(mock_manager_client_, 291 ConfigureServiceForProfile( 292 dbus::ObjectPath(kUser1ProfilePath), 293 IsEqualTo(expected_shill_properties.get()), 294 _, _)); 295 296 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, 297 kUser1, 298 "policy/policy_wifi1_with_redundant_fields.onc"); 299 message_loop_.RunUntilIdle(); 300} 301 302TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnconfigured) { 303 InitializeStandardProfiles(); 304 scoped_ptr<base::DictionaryValue> expected_shill_properties = 305 test_utils::ReadTestDictionary( 306 "policy/shill_policy_on_unconfigured_wifi1.json"); 307 308 EXPECT_CALL(mock_profile_client_, 309 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 310 311 EXPECT_CALL(mock_manager_client_, 312 ConfigureServiceForProfile( 313 dbus::ObjectPath(kUser1ProfilePath), 314 IsEqualTo(expected_shill_properties.get()), 315 _, _)); 316 317 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 318 message_loop_.RunUntilIdle(); 319} 320 321// Ensure that EAP settings for ethernet are matched with the right profile 322// entry and written to the dedicated EthernetEAP service. 323TEST_F(ManagedNetworkConfigurationHandlerTest, 324 SetPolicyManageUnmanagedEthernetEAP) { 325 InitializeStandardProfiles(); 326 scoped_ptr<base::DictionaryValue> expected_shill_properties = 327 test_utils::ReadTestDictionary( 328 "policy/" 329 "shill_policy_on_unmanaged_ethernet_eap.json"); 330 331 SetUpEntry("policy/shill_unmanaged_ethernet_eap.json", 332 kUser1ProfilePath, 333 "eth_entry"); 334 335 // Also setup an unrelated WiFi configuration to verify that the right entry 336 // is matched. 337 SetUpEntry("policy/shill_unmanaged_wifi1.json", 338 kUser1ProfilePath, 339 "wifi_entry"); 340 341 EXPECT_CALL(mock_profile_client_, 342 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 343 344 EXPECT_CALL(mock_profile_client_, 345 GetEntry(dbus::ObjectPath(kUser1ProfilePath), _, _, _)).Times(2); 346 347 EXPECT_CALL( 348 mock_profile_client_, 349 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "eth_entry", _, _)); 350 351 EXPECT_CALL( 352 mock_manager_client_, 353 ConfigureServiceForProfile(dbus::ObjectPath(kUser1ProfilePath), 354 IsEqualTo(expected_shill_properties.get()), 355 _, _)); 356 357 SetPolicy( 358 ::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_ethernet_eap.onc"); 359 message_loop_.RunUntilIdle(); 360} 361 362TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) { 363 InitializeStandardProfiles(); 364 EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _)); 365 366 EXPECT_CALL(mock_manager_client_, ConfigureServiceForProfile(_, _, _, _)); 367 368 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 369 message_loop_.RunUntilIdle(); 370 VerifyAndClearExpectations(); 371 372 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", 373 kUser1ProfilePath, 374 "some_entry_path"); 375 376 EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _)); 377 378 EXPECT_CALL( 379 mock_profile_client_, 380 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "some_entry_path", _, _)); 381 382 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 383 message_loop_.RunUntilIdle(); 384} 385 386TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnmanaged) { 387 InitializeStandardProfiles(); 388 SetUpEntry("policy/shill_unmanaged_wifi1.json", 389 kUser1ProfilePath, 390 "old_entry_path"); 391 392 scoped_ptr<base::DictionaryValue> expected_shill_properties = 393 test_utils::ReadTestDictionary( 394 "policy/shill_policy_on_unmanaged_wifi1.json"); 395 396 EXPECT_CALL(mock_profile_client_, 397 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 398 399 EXPECT_CALL( 400 mock_profile_client_, 401 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); 402 403 EXPECT_CALL( 404 mock_profile_client_, 405 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); 406 407 EXPECT_CALL(mock_manager_client_, 408 ConfigureServiceForProfile( 409 dbus::ObjectPath(kUser1ProfilePath), 410 IsEqualTo(expected_shill_properties.get()), 411 _, _)); 412 413 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 414 message_loop_.RunUntilIdle(); 415} 416 417// Old ChromeOS versions may not have used the UIData property 418TEST_F(ManagedNetworkConfigurationHandlerTest, 419 SetPolicyManageUnmanagedWithoutUIData) { 420 InitializeStandardProfiles(); 421 SetUpEntry("policy/shill_unmanaged_wifi1.json", 422 kUser1ProfilePath, 423 "old_entry_path"); 424 425 scoped_ptr<base::DictionaryValue> expected_shill_properties = 426 test_utils::ReadTestDictionary( 427 "policy/shill_policy_on_unmanaged_wifi1.json"); 428 429 EXPECT_CALL(mock_profile_client_, 430 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 431 432 EXPECT_CALL( 433 mock_profile_client_, 434 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); 435 436 EXPECT_CALL( 437 mock_profile_client_, 438 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); 439 440 EXPECT_CALL(mock_manager_client_, 441 ConfigureServiceForProfile( 442 dbus::ObjectPath(kUser1ProfilePath), 443 IsEqualTo(expected_shill_properties.get()), 444 _, _)); 445 446 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 447 message_loop_.RunUntilIdle(); 448} 449 450TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) { 451 InitializeStandardProfiles(); 452 SetUpEntry("policy/shill_managed_wifi1.json", 453 kUser1ProfilePath, 454 "old_entry_path"); 455 456 scoped_ptr<base::DictionaryValue> expected_shill_properties = 457 test_utils::ReadTestDictionary( 458 "policy/shill_policy_on_unmanaged_wifi1.json"); 459 460 // The passphrase isn't sent again, because it's configured by the user and 461 // Shill doesn't sent it on GetProperties calls. 462 expected_shill_properties->RemoveWithoutPathExpansion( 463 shill::kPassphraseProperty, NULL); 464 465 EXPECT_CALL(mock_profile_client_, 466 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 467 468 EXPECT_CALL( 469 mock_profile_client_, 470 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); 471 472 EXPECT_CALL( 473 mock_profile_client_, 474 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); 475 476 EXPECT_CALL(mock_manager_client_, 477 ConfigureServiceForProfile( 478 dbus::ObjectPath(kUser1ProfilePath), 479 IsEqualTo(expected_shill_properties.get()), 480 _, _)); 481 482 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 483 message_loop_.RunUntilIdle(); 484} 485 486TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { 487 InitializeStandardProfiles(); 488 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", 489 kUser1ProfilePath, 490 "old_entry_path"); 491 492 scoped_ptr<base::DictionaryValue> expected_shill_properties = 493 test_utils::ReadTestDictionary( 494 "policy/shill_policy_on_unmanaged_wifi1.json"); 495 496 // The passphrase isn't sent again, because it's configured by the user and 497 // Shill doesn't sent it on GetProperties calls. 498 expected_shill_properties->RemoveWithoutPathExpansion( 499 shill::kPassphraseProperty, NULL); 500 501 EXPECT_CALL(mock_profile_client_, 502 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 503 504 EXPECT_CALL( 505 mock_profile_client_, 506 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); 507 508 EXPECT_CALL(mock_manager_client_, 509 ConfigureServiceForProfile( 510 dbus::ObjectPath(kUser1ProfilePath), 511 IsEqualTo(expected_shill_properties.get()), 512 _, _)); 513 514 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 515 message_loop_.RunUntilIdle(); 516 VerifyAndClearExpectations(); 517 518 // If we apply the policy again, without change, then the Shill profile will 519 // not be modified. 520 EXPECT_CALL(mock_profile_client_, 521 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 522 523 EXPECT_CALL( 524 mock_profile_client_, 525 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); 526 527 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 528 message_loop_.RunUntilIdle(); 529} 530 531TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUnmanageManaged) { 532 InitializeStandardProfiles(); 533 SetUpEntry("policy/shill_policy_on_unmanaged_wifi1.json", 534 kUser1ProfilePath, 535 "old_entry_path"); 536 537 EXPECT_CALL(mock_profile_client_, 538 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 539 540 EXPECT_CALL(mock_profile_client_, 541 GetEntry(dbus::ObjectPath(kUser1ProfilePath), 542 "old_entry_path", 543 _, _)); 544 545 EXPECT_CALL(mock_profile_client_, 546 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), 547 "old_entry_path", 548 _, _)); 549 550 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, ""); 551 message_loop_.RunUntilIdle(); 552} 553 554TEST_F(ManagedNetworkConfigurationHandlerTest, SetEmptyPolicyIgnoreUnmanaged) { 555 InitializeStandardProfiles(); 556 SetUpEntry("policy/shill_unmanaged_wifi1.json", 557 kUser1ProfilePath, 558 "old_entry_path"); 559 560 EXPECT_CALL(mock_profile_client_, 561 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 562 563 EXPECT_CALL(mock_profile_client_, 564 GetEntry(dbus::ObjectPath(kUser1ProfilePath), 565 "old_entry_path", 566 _, _)); 567 568 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, ""); 569 message_loop_.RunUntilIdle(); 570} 571 572TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmanaged) { 573 InitializeStandardProfiles(); 574 SetUpEntry("policy/shill_unmanaged_wifi2.json", 575 kUser1ProfilePath, 576 "wifi2_entry_path"); 577 578 EXPECT_CALL(mock_profile_client_, 579 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 580 581 EXPECT_CALL( 582 mock_profile_client_, 583 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _)); 584 585 scoped_ptr<base::DictionaryValue> expected_shill_properties = 586 test_utils::ReadTestDictionary( 587 "policy/shill_policy_on_unconfigured_wifi1.json"); 588 589 EXPECT_CALL(mock_manager_client_, 590 ConfigureServiceForProfile( 591 dbus::ObjectPath(kUser1ProfilePath), 592 IsEqualTo(expected_shill_properties.get()), 593 _, _)); 594 595 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 596 message_loop_.RunUntilIdle(); 597} 598 599TEST_F(ManagedNetworkConfigurationHandlerTest, AutoConnectDisallowed) { 600 InitializeStandardProfiles(); 601 SetUpEntry("policy/shill_unmanaged_wifi2.json", 602 kUser1ProfilePath, 603 "wifi2_entry_path"); 604 605 EXPECT_CALL(mock_profile_client_, 606 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 607 608 EXPECT_CALL( 609 mock_profile_client_, 610 GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _)); 611 612 scoped_ptr<base::DictionaryValue> expected_shill_properties = 613 test_utils::ReadTestDictionary( 614 "policy/shill_disallow_autoconnect_on_unmanaged_wifi2.json"); 615 616 EXPECT_CALL(mock_manager_client_, 617 ConfigureServiceForProfile( 618 dbus::ObjectPath(kUser1ProfilePath), 619 IsEqualTo(expected_shill_properties.get()), 620 _, _)); 621 622 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, 623 kUser1, 624 "policy/policy_disallow_autoconnect.onc"); 625 message_loop_.RunUntilIdle(); 626} 627 628TEST_F(ManagedNetworkConfigurationHandlerTest, LateProfileLoading) { 629 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 630 631 message_loop_.RunUntilIdle(); 632 VerifyAndClearExpectations(); 633 634 scoped_ptr<base::DictionaryValue> expected_shill_properties = 635 test_utils::ReadTestDictionary( 636 "policy/shill_policy_on_unconfigured_wifi1.json"); 637 638 EXPECT_CALL(mock_profile_client_, 639 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 640 641 EXPECT_CALL(mock_manager_client_, 642 ConfigureServiceForProfile( 643 dbus::ObjectPath(kUser1ProfilePath), 644 IsEqualTo(expected_shill_properties.get()), 645 _, _)); 646 647 InitializeStandardProfiles(); 648 message_loop_.RunUntilIdle(); 649} 650 651} // namespace chromeos 652