OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 std::unique_ptr<NetworkConfigurationHandler> network_configuration_handler_; | 298 std::unique_ptr<NetworkConfigurationHandler> network_configuration_handler_; |
299 base::MessageLoopForUI message_loop_; | 299 base::MessageLoopForUI message_loop_; |
300 base::DictionaryValue* dictionary_value_result_; | 300 base::DictionaryValue* dictionary_value_result_; |
301 }; | 301 }; |
302 | 302 |
303 TEST_F(NetworkConfigurationHandlerTest, GetProperties) { | 303 TEST_F(NetworkConfigurationHandlerTest, GetProperties) { |
304 std::string service_path = "/service/1"; | 304 std::string service_path = "/service/1"; |
305 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; | 305 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; |
306 std::string networkName = "MyNetwork"; | 306 std::string networkName = "MyNetwork"; |
307 std::string key = "SSID"; | 307 std::string key = "SSID"; |
308 std::unique_ptr<base::StringValue> networkNameValue( | 308 std::unique_ptr<base::Value> networkNameValue(new base::Value(networkName)); |
309 new base::StringValue(networkName)); | |
310 | 309 |
311 base::DictionaryValue value; | 310 base::DictionaryValue value; |
312 value.Set(key, new base::StringValue(networkName)); | 311 value.Set(key, new base::Value(networkName)); |
313 dictionary_value_result_ = &value; | 312 dictionary_value_result_ = &value; |
314 EXPECT_CALL(*mock_service_client_, | 313 EXPECT_CALL(*mock_service_client_, |
315 SetProperty(dbus::ObjectPath(service_path), key, | 314 SetProperty(dbus::ObjectPath(service_path), key, |
316 IsEqualTo(networkNameValue.get()), _, _)).Times(1); | 315 IsEqualTo(networkNameValue.get()), _, _)).Times(1); |
317 mock_service_client_->SetProperty( | 316 mock_service_client_->SetProperty( |
318 dbus::ObjectPath(service_path), key, *networkNameValue, | 317 dbus::ObjectPath(service_path), key, *networkNameValue, |
319 base::Bind(&base::DoNothing), base::Bind(&DBusErrorCallback)); | 318 base::Bind(&base::DoNothing), base::Bind(&DBusErrorCallback)); |
320 base::RunLoop().RunUntilIdle(); | 319 base::RunLoop().RunUntilIdle(); |
321 | 320 |
322 ShillServiceClient::DictionaryValueCallback get_properties_callback; | 321 ShillServiceClient::DictionaryValueCallback get_properties_callback; |
323 EXPECT_CALL(*mock_service_client_, GetProperties(_, _)) | 322 EXPECT_CALL(*mock_service_client_, GetProperties(_, _)) |
324 .WillOnce( | 323 .WillOnce( |
325 Invoke(this, &NetworkConfigurationHandlerTest::OnGetProperties)); | 324 Invoke(this, &NetworkConfigurationHandlerTest::OnGetProperties)); |
326 network_configuration_handler_->GetShillProperties( | 325 network_configuration_handler_->GetShillProperties( |
327 service_path, | 326 service_path, |
328 base::Bind(&DictionaryValueCallback, service_path, expected_json), | 327 base::Bind(&DictionaryValueCallback, service_path, expected_json), |
329 base::Bind(&ErrorCallback, false, service_path)); | 328 base::Bind(&ErrorCallback, false, service_path)); |
330 base::RunLoop().RunUntilIdle(); | 329 base::RunLoop().RunUntilIdle(); |
331 } | 330 } |
332 | 331 |
333 TEST_F(NetworkConfigurationHandlerTest, SetProperties) { | 332 TEST_F(NetworkConfigurationHandlerTest, SetProperties) { |
334 std::string service_path = "/service/1"; | 333 std::string service_path = "/service/1"; |
335 std::string networkName = "MyNetwork"; | 334 std::string networkName = "MyNetwork"; |
336 std::string key = "SSID"; | 335 std::string key = "SSID"; |
337 std::unique_ptr<base::StringValue> networkNameValue( | 336 std::unique_ptr<base::Value> networkNameValue(new base::Value(networkName)); |
338 new base::StringValue(networkName)); | |
339 | 337 |
340 base::DictionaryValue value; | 338 base::DictionaryValue value; |
341 value.Set(key, new base::StringValue(networkName)); | 339 value.Set(key, new base::Value(networkName)); |
342 dictionary_value_result_ = &value; | 340 dictionary_value_result_ = &value; |
343 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _)) | 341 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _)) |
344 .WillOnce( | 342 .WillOnce( |
345 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties)); | 343 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties)); |
346 network_configuration_handler_->SetShillProperties( | 344 network_configuration_handler_->SetShillProperties( |
347 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION, | 345 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION, |
348 base::Bind(&base::DoNothing), | 346 base::Bind(&base::DoNothing), |
349 base::Bind(&ErrorCallback, false, service_path)); | 347 base::Bind(&ErrorCallback, false, service_path)); |
350 base::RunLoop().RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
351 } | 349 } |
352 | 350 |
353 TEST_F(NetworkConfigurationHandlerTest, ClearProperties) { | 351 TEST_F(NetworkConfigurationHandlerTest, ClearProperties) { |
354 std::string service_path = "/service/1"; | 352 std::string service_path = "/service/1"; |
355 std::string networkName = "MyNetwork"; | 353 std::string networkName = "MyNetwork"; |
356 std::string key = "SSID"; | 354 std::string key = "SSID"; |
357 std::unique_ptr<base::StringValue> networkNameValue( | 355 std::unique_ptr<base::Value> networkNameValue(new base::Value(networkName)); |
358 new base::StringValue(networkName)); | |
359 | 356 |
360 // First set up a value to clear. | 357 // First set up a value to clear. |
361 base::DictionaryValue value; | 358 base::DictionaryValue value; |
362 value.Set(key, new base::StringValue(networkName)); | 359 value.Set(key, new base::Value(networkName)); |
363 dictionary_value_result_ = &value; | 360 dictionary_value_result_ = &value; |
364 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _)) | 361 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _)) |
365 .WillOnce( | 362 .WillOnce( |
366 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties)); | 363 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties)); |
367 network_configuration_handler_->SetShillProperties( | 364 network_configuration_handler_->SetShillProperties( |
368 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION, | 365 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION, |
369 base::Bind(&base::DoNothing), | 366 base::Bind(&base::DoNothing), |
370 base::Bind(&ErrorCallback, false, service_path)); | 367 base::Bind(&ErrorCallback, false, service_path)); |
371 base::RunLoop().RunUntilIdle(); | 368 base::RunLoop().RunUntilIdle(); |
372 | 369 |
373 // Now clear it. | 370 // Now clear it. |
374 std::vector<std::string> values_to_clear; | 371 std::vector<std::string> values_to_clear; |
375 values_to_clear.push_back(key); | 372 values_to_clear.push_back(key); |
376 EXPECT_CALL(*mock_service_client_, ClearProperties(_, _, _, _)) | 373 EXPECT_CALL(*mock_service_client_, ClearProperties(_, _, _, _)) |
377 .WillOnce( | 374 .WillOnce( |
378 Invoke(this, &NetworkConfigurationHandlerTest::OnClearProperties)); | 375 Invoke(this, &NetworkConfigurationHandlerTest::OnClearProperties)); |
379 network_configuration_handler_->ClearShillProperties( | 376 network_configuration_handler_->ClearShillProperties( |
380 service_path, values_to_clear, base::Bind(&base::DoNothing), | 377 service_path, values_to_clear, base::Bind(&base::DoNothing), |
381 base::Bind(&ErrorCallback, false, service_path)); | 378 base::Bind(&ErrorCallback, false, service_path)); |
382 base::RunLoop().RunUntilIdle(); | 379 base::RunLoop().RunUntilIdle(); |
383 } | 380 } |
384 | 381 |
385 TEST_F(NetworkConfigurationHandlerTest, ClearPropertiesError) { | 382 TEST_F(NetworkConfigurationHandlerTest, ClearPropertiesError) { |
386 std::string service_path = "/service/1"; | 383 std::string service_path = "/service/1"; |
387 std::string networkName = "MyNetwork"; | 384 std::string networkName = "MyNetwork"; |
388 std::string key = "SSID"; | 385 std::string key = "SSID"; |
389 std::unique_ptr<base::StringValue> networkNameValue( | 386 std::unique_ptr<base::Value> networkNameValue(new base::Value(networkName)); |
390 new base::StringValue(networkName)); | |
391 | 387 |
392 // First set up a value to clear. | 388 // First set up a value to clear. |
393 base::DictionaryValue value; | 389 base::DictionaryValue value; |
394 value.Set(key, new base::StringValue(networkName)); | 390 value.Set(key, new base::Value(networkName)); |
395 dictionary_value_result_ = &value; | 391 dictionary_value_result_ = &value; |
396 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _)) | 392 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _)) |
397 .WillOnce( | 393 .WillOnce( |
398 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties)); | 394 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties)); |
399 network_configuration_handler_->SetShillProperties( | 395 network_configuration_handler_->SetShillProperties( |
400 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION, | 396 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION, |
401 base::Bind(&base::DoNothing), | 397 base::Bind(&base::DoNothing), |
402 base::Bind(&ErrorCallback, false, service_path)); | 398 base::Bind(&ErrorCallback, false, service_path)); |
403 base::RunLoop().RunUntilIdle(); | 399 base::RunLoop().RunUntilIdle(); |
404 | 400 |
405 // Now clear it. | 401 // Now clear it. |
406 std::vector<std::string> values_to_clear; | 402 std::vector<std::string> values_to_clear; |
407 values_to_clear.push_back(key); | 403 values_to_clear.push_back(key); |
408 EXPECT_CALL(*mock_service_client_, ClearProperties(_, _, _, _)) | 404 EXPECT_CALL(*mock_service_client_, ClearProperties(_, _, _, _)) |
409 .WillOnce(Invoke( | 405 .WillOnce(Invoke( |
410 this, &NetworkConfigurationHandlerTest::OnClearPropertiesError)); | 406 this, &NetworkConfigurationHandlerTest::OnClearPropertiesError)); |
411 network_configuration_handler_->ClearShillProperties( | 407 network_configuration_handler_->ClearShillProperties( |
412 service_path, values_to_clear, base::Bind(&base::DoNothing), | 408 service_path, values_to_clear, base::Bind(&base::DoNothing), |
413 base::Bind(&ErrorCallback, true, service_path)); | 409 base::Bind(&ErrorCallback, true, service_path)); |
414 base::RunLoop().RunUntilIdle(); | 410 base::RunLoop().RunUntilIdle(); |
415 } | 411 } |
416 | 412 |
417 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { | 413 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { |
418 std::string networkName = "MyNetwork"; | 414 std::string networkName = "MyNetwork"; |
419 std::string key = "SSID"; | 415 std::string key = "SSID"; |
420 std::string type = "wifi"; | 416 std::string type = "wifi"; |
421 std::string profile = "profile path"; | 417 std::string profile = "profile path"; |
422 base::DictionaryValue value; | 418 base::DictionaryValue value; |
423 shill_property_util::SetSSID(networkName, &value); | 419 shill_property_util::SetSSID(networkName, &value); |
424 value.SetWithoutPathExpansion(shill::kTypeProperty, | 420 value.SetWithoutPathExpansion(shill::kTypeProperty, new base::Value(type)); |
425 new base::StringValue(type)); | |
426 value.SetWithoutPathExpansion(shill::kProfileProperty, | 421 value.SetWithoutPathExpansion(shill::kProfileProperty, |
427 new base::StringValue(profile)); | 422 new base::Value(profile)); |
428 | 423 |
429 EXPECT_CALL(*mock_manager_client_, | 424 EXPECT_CALL(*mock_manager_client_, |
430 ConfigureServiceForProfile(dbus::ObjectPath(profile), _, _, _)) | 425 ConfigureServiceForProfile(dbus::ObjectPath(profile), _, _, _)) |
431 .WillOnce( | 426 .WillOnce( |
432 Invoke(this, &NetworkConfigurationHandlerTest::OnConfigureService)); | 427 Invoke(this, &NetworkConfigurationHandlerTest::OnConfigureService)); |
433 CreateConfiguration("/service/2", value); | 428 CreateConfiguration("/service/2", value); |
434 base::RunLoop().RunUntilIdle(); | 429 base::RunLoop().RunUntilIdle(); |
435 } | 430 } |
436 | 431 |
437 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) { | 432 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 EXPECT_FALSE(test_observer->HasConfiguration(service_path)); | 740 EXPECT_FALSE(test_observer->HasConfiguration(service_path)); |
746 EXPECT_FALSE(test_observer->HasConfigurationInProfile( | 741 EXPECT_FALSE(test_observer->HasConfigurationInProfile( |
747 service_path, NetworkProfileHandler::GetSharedProfilePath())); | 742 service_path, NetworkProfileHandler::GetSharedProfilePath())); |
748 EXPECT_FALSE( | 743 EXPECT_FALSE( |
749 test_observer->HasConfigurationInProfile(service_path, user_profile)); | 744 test_observer->HasConfigurationInProfile(service_path, user_profile)); |
750 | 745 |
751 network_configuration_handler_->RemoveObserver(test_observer.get()); | 746 network_configuration_handler_->RemoveObserver(test_observer.get()); |
752 } | 747 } |
753 | 748 |
754 } // namespace chromeos | 749 } // namespace chromeos |
OLD | NEW |