1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #include "base/json/json_writer.h"
10 #include "base/location.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/stl_util.h"
14 #include "base/strings/string_piece.h"
15 #include "base/values.h"
16 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "chromeos/dbus/mock_shill_manager_client.h"
18 #include "chromeos/dbus/mock_shill_profile_client.h"
19 #include "chromeos/dbus/mock_shill_service_client.h"
20 #include "chromeos/network/network_configuration_handler.h"
21 #include "chromeos/network/network_configuration_observer.h"
22 #include "chromeos/network/network_profile_handler.h"
23 #include "chromeos/network/network_state.h"
24 #include "chromeos/network/network_state_handler.h"
25 #include "chromeos/network/network_state_handler_observer.h"
26 #include "chromeos/network/shill_property_util.h"
27 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "third_party/cros_system_api/dbus/service_constants.h"
32 using ::testing::AnyNumber
;
33 using ::testing::Invoke
;
34 using ::testing::Pointee
;
35 using ::testing::Return
;
36 using ::testing::SaveArg
;
37 using ::testing::StrEq
;
39 // Matcher to match base::Value.
40 MATCHER_P(IsEqualTo
, value
, "") {
41 return arg
.Equals(value
);
48 static std::string
PrettyJson(const base::DictionaryValue
& value
) {
50 base::JSONWriter::WriteWithOptions(
51 value
, base::JSONWriter::OPTIONS_PRETTY_PRINT
, &pretty
);
55 void DictionaryValueCallback(const std::string
& expected_id
,
56 const std::string
& expected_json
,
57 const std::string
& service_path
,
58 const base::DictionaryValue
& dictionary
) {
59 std::string dict_str
= PrettyJson(dictionary
);
60 EXPECT_EQ(expected_json
, dict_str
);
61 EXPECT_EQ(expected_id
, service_path
);
64 void ErrorCallback(bool error_expected
,
65 const std::string
& expected_id
,
66 const std::string
& error_name
,
67 scoped_ptr
<base::DictionaryValue
> error_data
) {
68 EXPECT_TRUE(error_expected
) << "Unexpected error: " << error_name
69 << " with associated data: \n"
70 << PrettyJson(*error_data
);
73 void StringResultCallback(const std::string
& expected_result
,
74 const std::string
& result
) {
75 EXPECT_EQ(expected_result
, result
);
78 void DBusErrorCallback(const std::string
& error_name
,
79 const std::string
& error_message
) {
80 EXPECT_TRUE(false) << "DBus Error: " << error_name
<< "(" << error_message
86 TestCallback() : run_count_(0) {}
87 void Run() { ++run_count_
; }
88 int run_count() const { return run_count_
; }
94 class TestNetworkConfigurationObserver
: public NetworkConfigurationObserver
{
96 TestNetworkConfigurationObserver() {}
97 ~TestNetworkConfigurationObserver() override
{
98 STLDeleteContainerPairSecondPointers(configurations_
.begin(),
99 configurations_
.end());
102 // NetworkConfigurationObserver
103 void OnConfigurationCreated(
104 const std::string
& service_path
,
105 const std::string
& profile_path
,
106 const base::DictionaryValue
& properties
,
107 NetworkConfigurationObserver::Source source
) override
{
108 ASSERT_EQ(0u, configurations_
.count(service_path
));
109 configurations_
[service_path
] = properties
.DeepCopy();
110 profiles_
[profile_path
].insert(service_path
);
113 void OnConfigurationRemoved(
114 const std::string
& service_path
,
115 const std::string
& guid
,
116 NetworkConfigurationObserver::Source source
) override
{
117 ASSERT_EQ(1u, configurations_
.count(service_path
));
118 delete configurations_
[service_path
];
119 configurations_
.erase(service_path
);
120 for (auto& p
: profiles_
) {
121 p
.second
.erase(service_path
);
125 void OnConfigurationProfileChanged(
126 const std::string
& service_path
,
127 const std::string
& profile_path
,
128 NetworkConfigurationObserver::Source source
) override
{
129 for (auto& p
: profiles_
) {
130 p
.second
.erase(service_path
);
132 profiles_
[profile_path
].insert(service_path
);
135 void OnPropertiesSet(const std::string
& service_path
,
136 const std::string
& guid
,
137 const base::DictionaryValue
& set_properties
,
138 NetworkConfigurationObserver::Source source
) override
{
139 configurations_
[service_path
]->MergeDictionary(&set_properties
);
142 bool HasConfiguration(const std::string
& service_path
) {
143 return configurations_
.count(service_path
) == 1;
146 std::string
GetStringProperty(const std::string
& service_path
,
147 const std::string
& property
) {
148 if (!HasConfiguration(service_path
))
151 configurations_
[service_path
]->GetStringWithoutPathExpansion(property
,
156 bool HasConfigurationInProfile(const std::string
& service_path
,
157 const std::string
& profile_path
) {
158 if (profiles_
.count(profile_path
) == 0)
160 return profiles_
[profile_path
].count(service_path
) == 1;
164 std::map
<std::string
, base::DictionaryValue
*> configurations_
;
165 std::map
<std::string
, std::set
<std::string
>> profiles_
;
167 DISALLOW_COPY_AND_ASSIGN(TestNetworkConfigurationObserver
);
172 class NetworkConfigurationHandlerTest
: public testing::Test
{
174 NetworkConfigurationHandlerTest()
175 : mock_manager_client_(NULL
),
176 mock_profile_client_(NULL
),
177 mock_service_client_(NULL
),
178 dictionary_value_result_(NULL
) {}
179 ~NetworkConfigurationHandlerTest() override
{}
181 void SetUp() override
{
182 scoped_ptr
<DBusThreadManagerSetter
> dbus_setter
=
183 DBusThreadManager::GetSetterForTesting();
184 mock_manager_client_
= new MockShillManagerClient();
185 mock_profile_client_
= new MockShillProfileClient();
186 mock_service_client_
= new MockShillServiceClient();
187 dbus_setter
->SetShillManagerClient(
188 scoped_ptr
<ShillManagerClient
>(mock_manager_client_
).Pass());
189 dbus_setter
->SetShillProfileClient(
190 scoped_ptr
<ShillProfileClient
>(mock_profile_client_
).Pass());
191 dbus_setter
->SetShillServiceClient(
192 scoped_ptr
<ShillServiceClient
>(mock_service_client_
).Pass());
194 EXPECT_CALL(*mock_service_client_
, GetProperties(_
, _
)).Times(AnyNumber());
195 EXPECT_CALL(*mock_manager_client_
, GetProperties(_
)).Times(AnyNumber());
196 EXPECT_CALL(*mock_manager_client_
, AddPropertyChangedObserver(_
))
198 EXPECT_CALL(*mock_manager_client_
, RemovePropertyChangedObserver(_
))
201 network_state_handler_
.reset(NetworkStateHandler::InitializeForTest());
202 network_configuration_handler_
.reset(new NetworkConfigurationHandler());
203 network_configuration_handler_
->Init(network_state_handler_
.get(),
204 NULL
/* network_device_handler */);
205 message_loop_
.RunUntilIdle();
208 void TearDown() override
{
209 network_configuration_handler_
.reset();
210 network_state_handler_
.reset();
211 DBusThreadManager::Shutdown();
214 // Handles responses for GetProperties method calls.
215 void OnGetProperties(
216 const dbus::ObjectPath
& path
,
217 const ShillClientHelper::DictionaryValueCallback
& callback
) {
218 callback
.Run(DBUS_METHOD_CALL_SUCCESS
, *dictionary_value_result_
);
221 // Handles responses for SetProperties method calls.
222 void OnSetProperties(const dbus::ObjectPath
& service_path
,
223 const base::DictionaryValue
& properties
,
224 const base::Closure
& callback
,
225 const ShillClientHelper::ErrorCallback
& error_callback
) {
229 // Handles responses for ClearProperties method calls.
230 void OnClearProperties(
231 const dbus::ObjectPath
& service_path
,
232 const std::vector
<std::string
>& names
,
233 const ShillClientHelper::ListValueCallback
& callback
,
234 const ShillClientHelper::ErrorCallback
& error_callback
) {
235 base::ListValue result
;
236 result
.AppendBoolean(true);
237 callback
.Run(result
);
240 // Handles responses for ClearProperties method calls, and simulates an error
242 void OnClearPropertiesError(
243 const dbus::ObjectPath
& service_path
,
244 const std::vector
<std::string
>& names
,
245 const ShillClientHelper::ListValueCallback
& callback
,
246 const ShillClientHelper::ErrorCallback
& error_callback
) {
247 base::ListValue result
;
248 result
.AppendBoolean(false);
249 callback
.Run(result
);
252 void OnConfigureService(
253 const dbus::ObjectPath
& profile_path
,
254 const base::DictionaryValue
& properties
,
255 const ObjectPathCallback
& callback
,
256 const ShillClientHelper::ErrorCallback
& error_callback
) {
257 callback
.Run(dbus::ObjectPath("/service/2"));
260 void OnGetLoadableProfileEntries(
261 const dbus::ObjectPath
& service_path
,
262 const ShillClientHelper::DictionaryValueCallback
& callback
) {
263 base::DictionaryValue entries
;
264 entries
.SetString("profile1", "entry1");
265 entries
.SetString("profile2", "entry2");
266 callback
.Run(DBUS_METHOD_CALL_SUCCESS
, entries
);
269 void OnDeleteEntry(const dbus::ObjectPath
& profile_path
,
270 const std::string
& entry_path
,
271 const base::Closure
& callback
,
272 const ShillClientHelper::ErrorCallback
& error_callback
) {
273 // Don't run the callback immediately to emulate actual behavior.
274 message_loop_
.task_runner()->PostTask(FROM_HERE
, callback
);
277 bool PendingProfileEntryDeleterForTest(const std::string
& service_path
) {
278 return network_configuration_handler_
->PendingProfileEntryDeleterForTest(
282 void CreateConfiguration(const std::string
& service_path
,
283 const base::DictionaryValue
& properties
) {
284 network_configuration_handler_
->CreateShillConfiguration(
285 properties
, NetworkConfigurationObserver::SOURCE_USER_ACTION
,
286 base::Bind(&StringResultCallback
, service_path
),
287 base::Bind(&ErrorCallback
, false, std::string()));
291 MockShillManagerClient
* mock_manager_client_
;
292 MockShillProfileClient
* mock_profile_client_
;
293 MockShillServiceClient
* mock_service_client_
;
294 scoped_ptr
<NetworkStateHandler
> network_state_handler_
;
295 scoped_ptr
<NetworkConfigurationHandler
> network_configuration_handler_
;
296 base::MessageLoopForUI message_loop_
;
297 base::DictionaryValue
* dictionary_value_result_
;
300 TEST_F(NetworkConfigurationHandlerTest
, GetProperties
) {
301 std::string service_path
= "/service/1";
302 std::string expected_json
= "{\n \"SSID\": \"MyNetwork\"\n}\n";
303 std::string networkName
= "MyNetwork";
304 std::string key
= "SSID";
305 scoped_ptr
<base::StringValue
> networkNameValue(
306 new base::StringValue(networkName
));
308 base::DictionaryValue value
;
309 value
.Set(key
, new base::StringValue(networkName
));
310 dictionary_value_result_
= &value
;
311 EXPECT_CALL(*mock_service_client_
,
312 SetProperty(dbus::ObjectPath(service_path
), key
,
313 IsEqualTo(networkNameValue
.get()), _
, _
)).Times(1);
314 mock_service_client_
->SetProperty(
315 dbus::ObjectPath(service_path
), key
, *networkNameValue
,
316 base::Bind(&base::DoNothing
), base::Bind(&DBusErrorCallback
));
317 message_loop_
.RunUntilIdle();
319 ShillServiceClient::DictionaryValueCallback get_properties_callback
;
320 EXPECT_CALL(*mock_service_client_
, GetProperties(_
, _
))
322 Invoke(this, &NetworkConfigurationHandlerTest::OnGetProperties
));
323 network_configuration_handler_
->GetShillProperties(
325 base::Bind(&DictionaryValueCallback
, service_path
, expected_json
),
326 base::Bind(&ErrorCallback
, false, service_path
));
327 message_loop_
.RunUntilIdle();
330 TEST_F(NetworkConfigurationHandlerTest
, SetProperties
) {
331 std::string service_path
= "/service/1";
332 std::string networkName
= "MyNetwork";
333 std::string key
= "SSID";
334 scoped_ptr
<base::StringValue
> networkNameValue(
335 new base::StringValue(networkName
));
337 base::DictionaryValue value
;
338 value
.Set(key
, new base::StringValue(networkName
));
339 dictionary_value_result_
= &value
;
340 EXPECT_CALL(*mock_service_client_
, SetProperties(_
, _
, _
, _
))
342 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties
));
343 network_configuration_handler_
->SetShillProperties(
344 service_path
, value
, NetworkConfigurationObserver::SOURCE_USER_ACTION
,
345 base::Bind(&base::DoNothing
),
346 base::Bind(&ErrorCallback
, false, service_path
));
347 message_loop_
.RunUntilIdle();
350 TEST_F(NetworkConfigurationHandlerTest
, ClearProperties
) {
351 std::string service_path
= "/service/1";
352 std::string networkName
= "MyNetwork";
353 std::string key
= "SSID";
354 scoped_ptr
<base::StringValue
> networkNameValue(
355 new base::StringValue(networkName
));
357 // First set up a value to clear.
358 base::DictionaryValue value
;
359 value
.Set(key
, new base::StringValue(networkName
));
360 dictionary_value_result_
= &value
;
361 EXPECT_CALL(*mock_service_client_
, SetProperties(_
, _
, _
, _
))
363 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties
));
364 network_configuration_handler_
->SetShillProperties(
365 service_path
, value
, NetworkConfigurationObserver::SOURCE_USER_ACTION
,
366 base::Bind(&base::DoNothing
),
367 base::Bind(&ErrorCallback
, false, service_path
));
368 message_loop_
.RunUntilIdle();
371 std::vector
<std::string
> values_to_clear
;
372 values_to_clear
.push_back(key
);
373 EXPECT_CALL(*mock_service_client_
, ClearProperties(_
, _
, _
, _
))
375 Invoke(this, &NetworkConfigurationHandlerTest::OnClearProperties
));
376 network_configuration_handler_
->ClearShillProperties(
377 service_path
, values_to_clear
, base::Bind(&base::DoNothing
),
378 base::Bind(&ErrorCallback
, false, service_path
));
379 message_loop_
.RunUntilIdle();
382 TEST_F(NetworkConfigurationHandlerTest
, ClearPropertiesError
) {
383 std::string service_path
= "/service/1";
384 std::string networkName
= "MyNetwork";
385 std::string key
= "SSID";
386 scoped_ptr
<base::StringValue
> networkNameValue(
387 new base::StringValue(networkName
));
389 // First set up a value to clear.
390 base::DictionaryValue value
;
391 value
.Set(key
, new base::StringValue(networkName
));
392 dictionary_value_result_
= &value
;
393 EXPECT_CALL(*mock_service_client_
, SetProperties(_
, _
, _
, _
))
395 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties
));
396 network_configuration_handler_
->SetShillProperties(
397 service_path
, value
, NetworkConfigurationObserver::SOURCE_USER_ACTION
,
398 base::Bind(&base::DoNothing
),
399 base::Bind(&ErrorCallback
, false, service_path
));
400 message_loop_
.RunUntilIdle();
403 std::vector
<std::string
> values_to_clear
;
404 values_to_clear
.push_back(key
);
405 EXPECT_CALL(*mock_service_client_
, ClearProperties(_
, _
, _
, _
))
407 this, &NetworkConfigurationHandlerTest::OnClearPropertiesError
));
408 network_configuration_handler_
->ClearShillProperties(
409 service_path
, values_to_clear
, base::Bind(&base::DoNothing
),
410 base::Bind(&ErrorCallback
, true, service_path
));
411 message_loop_
.RunUntilIdle();
414 TEST_F(NetworkConfigurationHandlerTest
, CreateConfiguration
) {
415 std::string networkName
= "MyNetwork";
416 std::string key
= "SSID";
417 std::string type
= "wifi";
418 std::string profile
= "profile path";
419 base::DictionaryValue value
;
420 shill_property_util::SetSSID(networkName
, &value
);
421 value
.SetWithoutPathExpansion(shill::kTypeProperty
,
422 new base::StringValue(type
));
423 value
.SetWithoutPathExpansion(shill::kProfileProperty
,
424 new base::StringValue(profile
));
426 EXPECT_CALL(*mock_manager_client_
,
427 ConfigureServiceForProfile(dbus::ObjectPath(profile
), _
, _
, _
))
429 Invoke(this, &NetworkConfigurationHandlerTest::OnConfigureService
));
430 CreateConfiguration("/service/2", value
);
431 message_loop_
.RunUntilIdle();
434 TEST_F(NetworkConfigurationHandlerTest
, RemoveConfiguration
) {
435 std::string service_path
= "/service/1";
437 TestCallback test_callback
;
438 EXPECT_CALL(*mock_service_client_
, GetLoadableProfileEntries(_
, _
))
440 this, &NetworkConfigurationHandlerTest::OnGetLoadableProfileEntries
));
441 EXPECT_CALL(*mock_profile_client_
, DeleteEntry(_
, _
, _
, _
))
443 Invoke(this, &NetworkConfigurationHandlerTest::OnDeleteEntry
));
445 network_configuration_handler_
->RemoveConfiguration(
446 service_path
, NetworkConfigurationObserver::SOURCE_USER_ACTION
,
447 base::Bind(&TestCallback::Run
, base::Unretained(&test_callback
)),
448 base::Bind(&ErrorCallback
, false, service_path
));
449 message_loop_
.RunUntilIdle();
450 EXPECT_EQ(1, test_callback
.run_count());
451 EXPECT_FALSE(PendingProfileEntryDeleterForTest(service_path
));
454 ////////////////////////////////////////////////////////////////////////////////
459 class TestObserver
: public chromeos::NetworkStateHandlerObserver
{
461 TestObserver() : network_list_changed_count_(0) {}
462 ~TestObserver() override
{}
464 void NetworkListChanged() override
{ ++network_list_changed_count_
; }
466 void NetworkPropertiesUpdated(const NetworkState
* network
) override
{
467 property_updates_
[network
->path()]++;
470 size_t network_list_changed_count() { return network_list_changed_count_
; }
472 int PropertyUpdatesForService(const std::string
& service_path
) {
473 return property_updates_
[service_path
];
476 void ClearPropertyUpdates() { property_updates_
.clear(); }
479 size_t network_list_changed_count_
;
480 std::map
<std::string
, int> property_updates_
;
482 DISALLOW_COPY_AND_ASSIGN(TestObserver
);
487 class NetworkConfigurationHandlerStubTest
: public testing::Test
{
489 NetworkConfigurationHandlerStubTest() {}
491 ~NetworkConfigurationHandlerStubTest() override
{}
493 void SetUp() override
{
494 DBusThreadManager::Initialize();
496 network_state_handler_
.reset(NetworkStateHandler::InitializeForTest());
497 test_observer_
.reset(new TestObserver());
498 network_state_handler_
->AddObserver(test_observer_
.get(), FROM_HERE
);
500 network_configuration_handler_
.reset(new NetworkConfigurationHandler());
501 network_configuration_handler_
->Init(network_state_handler_
.get(),
502 NULL
/* network_device_handler */);
504 message_loop_
.RunUntilIdle();
505 test_observer_
->ClearPropertyUpdates();
508 void TearDown() override
{
509 network_configuration_handler_
.reset();
510 network_state_handler_
->RemoveObserver(test_observer_
.get(), FROM_HERE
);
511 network_state_handler_
.reset();
512 DBusThreadManager::Shutdown();
515 void SuccessCallback(const std::string
& callback_name
) {
516 success_callback_name_
= callback_name
;
519 void GetPropertiesCallback(const std::string
& service_path
,
520 const base::DictionaryValue
& dictionary
) {
521 get_properties_path_
= service_path
;
522 get_properties_
.reset(dictionary
.DeepCopy());
525 void CreateConfigurationCallback(const std::string
& service_path
) {
526 create_service_path_
= service_path
;
529 void CreateTestConfiguration(const std::string
& service_path
,
530 const std::string
& type
) {
531 base::DictionaryValue properties
;
532 shill_property_util::SetSSID(service_path
, &properties
);
533 properties
.SetStringWithoutPathExpansion(shill::kNameProperty
,
535 properties
.SetStringWithoutPathExpansion(shill::kGuidProperty
,
537 properties
.SetStringWithoutPathExpansion(shill::kTypeProperty
, type
);
538 properties
.SetStringWithoutPathExpansion(shill::kStateProperty
,
540 properties
.SetStringWithoutPathExpansion(
541 shill::kProfileProperty
, NetworkProfileHandler::GetSharedProfilePath());
543 network_configuration_handler_
->CreateShillConfiguration(
544 properties
, NetworkConfigurationObserver::SOURCE_USER_ACTION
,
546 &NetworkConfigurationHandlerStubTest::CreateConfigurationCallback
,
547 base::Unretained(this)),
548 base::Bind(&ErrorCallback
, false, service_path
));
549 message_loop_
.RunUntilIdle();
553 bool GetServiceStringProperty(const std::string
& service_path
,
554 const std::string
& key
,
555 std::string
* result
) {
556 ShillServiceClient::TestInterface
* service_test
=
557 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
558 const base::DictionaryValue
* properties
=
559 service_test
->GetServiceProperties(service_path
);
560 if (properties
&& properties
->GetStringWithoutPathExpansion(key
, result
))
565 bool GetReceivedStringProperty(const std::string
& service_path
,
566 const std::string
& key
,
567 std::string
* result
) {
568 if (get_properties_path_
!= service_path
)
570 if (get_properties_
&&
571 get_properties_
->GetStringWithoutPathExpansion(key
, result
))
576 scoped_ptr
<NetworkStateHandler
> network_state_handler_
;
577 scoped_ptr
<NetworkConfigurationHandler
> network_configuration_handler_
;
578 scoped_ptr
<TestObserver
> test_observer_
;
579 base::MessageLoopForUI message_loop_
;
580 std::string success_callback_name_
;
581 std::string get_properties_path_
;
582 scoped_ptr
<base::DictionaryValue
> get_properties_
;
583 std::string create_service_path_
;
586 TEST_F(NetworkConfigurationHandlerStubTest
, StubSetAndClearProperties
) {
587 // TODO(stevenjb): Remove dependency on default Stub service.
588 const std::string
service_path("/service/wifi1");
589 const std::string
test_identity("test_identity");
590 const std::string
test_passphrase("test_passphrase");
593 base::DictionaryValue properties_to_set
;
594 properties_to_set
.SetStringWithoutPathExpansion(shill::kIdentityProperty
,
596 properties_to_set
.SetStringWithoutPathExpansion(shill::kPassphraseProperty
,
598 network_configuration_handler_
->SetShillProperties(
599 service_path
, properties_to_set
,
600 NetworkConfigurationObserver::SOURCE_USER_ACTION
,
601 base::Bind(&NetworkConfigurationHandlerStubTest::SuccessCallback
,
602 base::Unretained(this), "SetProperties"),
603 base::Bind(&ErrorCallback
, false, service_path
));
604 message_loop_
.RunUntilIdle();
606 EXPECT_EQ("SetProperties", success_callback_name_
);
607 std::string identity
, passphrase
;
608 EXPECT_TRUE(GetServiceStringProperty(service_path
, shill::kIdentityProperty
,
610 EXPECT_TRUE(GetServiceStringProperty(service_path
, shill::kPassphraseProperty
,
612 EXPECT_EQ(test_identity
, identity
);
613 EXPECT_EQ(test_passphrase
, passphrase
);
614 EXPECT_EQ(1, test_observer_
->PropertyUpdatesForService(service_path
));
617 std::vector
<std::string
> properties_to_clear
;
618 properties_to_clear
.push_back(shill::kIdentityProperty
);
619 properties_to_clear
.push_back(shill::kPassphraseProperty
);
620 network_configuration_handler_
->ClearShillProperties(
621 service_path
, properties_to_clear
,
622 base::Bind(&NetworkConfigurationHandlerStubTest::SuccessCallback
,
623 base::Unretained(this), "ClearProperties"),
624 base::Bind(&ErrorCallback
, false, service_path
));
625 message_loop_
.RunUntilIdle();
627 EXPECT_EQ("ClearProperties", success_callback_name_
);
628 EXPECT_FALSE(GetServiceStringProperty(service_path
, shill::kIdentityProperty
,
630 EXPECT_FALSE(GetServiceStringProperty(service_path
, shill::kIdentityProperty
,
632 EXPECT_EQ(2, test_observer_
->PropertyUpdatesForService(service_path
));
635 TEST_F(NetworkConfigurationHandlerStubTest
, StubGetNameFromWifiHex
) {
636 // TODO(stevenjb): Remove dependency on default Stub service.
637 const std::string
service_path("/service/wifi1");
638 std::string wifi_hex
= "5468697320697320484558205353494421";
639 std::string expected_name
= "This is HEX SSID!";
642 base::DictionaryValue properties_to_set
;
643 properties_to_set
.SetStringWithoutPathExpansion(shill::kWifiHexSsid
,
645 network_configuration_handler_
->SetShillProperties(
646 service_path
, properties_to_set
,
647 NetworkConfigurationObserver::SOURCE_USER_ACTION
,
648 base::Bind(&base::DoNothing
),
649 base::Bind(&ErrorCallback
, false, service_path
));
650 message_loop_
.RunUntilIdle();
651 std::string wifi_hex_result
;
652 EXPECT_TRUE(GetServiceStringProperty(service_path
, shill::kWifiHexSsid
,
654 EXPECT_EQ(wifi_hex
, wifi_hex_result
);
657 network_configuration_handler_
->GetShillProperties(
659 base::Bind(&NetworkConfigurationHandlerStubTest::GetPropertiesCallback
,
660 base::Unretained(this)),
661 base::Bind(&ErrorCallback
, false, service_path
));
662 message_loop_
.RunUntilIdle();
664 EXPECT_EQ(service_path
, get_properties_path_
);
665 std::string name_result
;
666 EXPECT_TRUE(GetReceivedStringProperty(service_path
, shill::kNameProperty
,
668 EXPECT_EQ(expected_name
, name_result
);
671 TEST_F(NetworkConfigurationHandlerStubTest
, StubCreateConfiguration
) {
672 const std::string
service_path("/service/test_wifi");
673 CreateTestConfiguration(service_path
, shill::kTypeWifi
);
675 EXPECT_FALSE(create_service_path_
.empty());
678 EXPECT_TRUE(GetServiceStringProperty(create_service_path_
,
679 shill::kGuidProperty
, &guid
));
680 EXPECT_EQ(service_path
, guid
);
682 std::string actual_profile
;
683 EXPECT_TRUE(GetServiceStringProperty(
684 create_service_path_
, shill::kProfileProperty
, &actual_profile
));
685 EXPECT_EQ(NetworkProfileHandler::GetSharedProfilePath(), actual_profile
);
688 TEST_F(NetworkConfigurationHandlerStubTest
, NetworkConfigurationObserver
) {
689 const std::string
service_path("/service/test_wifi");
690 const std::string
test_passphrase("test_passphrase");
692 scoped_ptr
<TestNetworkConfigurationObserver
> test_observer(
693 new TestNetworkConfigurationObserver
);
694 network_configuration_handler_
->AddObserver(test_observer
.get());
695 CreateTestConfiguration(service_path
, shill::kTypeWifi
);
697 EXPECT_TRUE(test_observer
->HasConfiguration(service_path
));
698 EXPECT_TRUE(test_observer
->HasConfigurationInProfile(
699 service_path
, NetworkProfileHandler::GetSharedProfilePath()));
700 EXPECT_EQ(shill::kTypeWifi
, test_observer
->GetStringProperty(
701 service_path
, shill::kTypeProperty
));
703 base::DictionaryValue properties_to_set
;
704 properties_to_set
.SetStringWithoutPathExpansion(shill::kPassphraseProperty
,
706 network_configuration_handler_
->SetShillProperties(
707 service_path
, properties_to_set
,
708 NetworkConfigurationObserver::SOURCE_USER_ACTION
,
709 base::Bind(&base::DoNothing
),
710 base::Bind(&ErrorCallback
, false, service_path
));
711 message_loop_
.RunUntilIdle();
712 EXPECT_EQ(test_passphrase
, test_observer
->GetStringProperty(
713 service_path
, shill::kPassphraseProperty
));
715 std::string user_profile
= "/profiles/user1";
716 std::string userhash
= "user1";
717 DBusThreadManager::Get()
718 ->GetShillProfileClient()
720 ->AddProfile(user_profile
, userhash
);
722 network_configuration_handler_
->SetNetworkProfile(
723 service_path
, user_profile
,
724 NetworkConfigurationObserver::SOURCE_USER_ACTION
,
725 base::Bind(&base::DoNothing
),
726 base::Bind(&ErrorCallback
, false, service_path
));
727 message_loop_
.RunUntilIdle();
728 EXPECT_TRUE(test_observer
->HasConfiguration(service_path
));
729 EXPECT_FALSE(test_observer
->HasConfigurationInProfile(
730 service_path
, NetworkProfileHandler::GetSharedProfilePath()));
732 test_observer
->HasConfigurationInProfile(service_path
, user_profile
));
734 network_configuration_handler_
->RemoveConfiguration(
735 service_path
, NetworkConfigurationObserver::SOURCE_USER_ACTION
,
736 base::Bind(&base::DoNothing
),
737 base::Bind(&ErrorCallback
, false, service_path
));
738 message_loop_
.RunUntilIdle();
740 EXPECT_FALSE(test_observer
->HasConfiguration(service_path
));
741 EXPECT_FALSE(test_observer
->HasConfigurationInProfile(
742 service_path
, NetworkProfileHandler::GetSharedProfilePath()));
744 test_observer
->HasConfigurationInProfile(service_path
, user_profile
));
746 network_configuration_handler_
->RemoveObserver(test_observer
.get());
749 } // namespace chromeos