Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chromeos/network/network_configuration_handler_unittest.cc

Issue 2314853004: Remove calls to deprecated MessageLoop methods in chromeos. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/strings/string_piece.h" 18 #include "base/strings/string_piece.h"
18 #include "base/values.h" 19 #include "base/values.h"
19 #include "chromeos/dbus/dbus_thread_manager.h" 20 #include "chromeos/dbus/dbus_thread_manager.h"
20 #include "chromeos/dbus/mock_shill_manager_client.h" 21 #include "chromeos/dbus/mock_shill_manager_client.h"
21 #include "chromeos/dbus/mock_shill_profile_client.h" 22 #include "chromeos/dbus/mock_shill_profile_client.h"
22 #include "chromeos/dbus/mock_shill_service_client.h" 23 #include "chromeos/dbus/mock_shill_service_client.h"
23 #include "chromeos/network/network_configuration_handler.h" 24 #include "chromeos/network/network_configuration_handler.h"
24 #include "chromeos/network/network_configuration_observer.h" 25 #include "chromeos/network/network_configuration_observer.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 EXPECT_CALL(*mock_manager_client_, GetProperties(_)).Times(AnyNumber()); 200 EXPECT_CALL(*mock_manager_client_, GetProperties(_)).Times(AnyNumber());
200 EXPECT_CALL(*mock_manager_client_, AddPropertyChangedObserver(_)) 201 EXPECT_CALL(*mock_manager_client_, AddPropertyChangedObserver(_))
201 .Times(AnyNumber()); 202 .Times(AnyNumber());
202 EXPECT_CALL(*mock_manager_client_, RemovePropertyChangedObserver(_)) 203 EXPECT_CALL(*mock_manager_client_, RemovePropertyChangedObserver(_))
203 .Times(AnyNumber()); 204 .Times(AnyNumber());
204 205
205 network_state_handler_.reset(NetworkStateHandler::InitializeForTest()); 206 network_state_handler_.reset(NetworkStateHandler::InitializeForTest());
206 network_configuration_handler_.reset(new NetworkConfigurationHandler()); 207 network_configuration_handler_.reset(new NetworkConfigurationHandler());
207 network_configuration_handler_->Init(network_state_handler_.get(), 208 network_configuration_handler_->Init(network_state_handler_.get(),
208 NULL /* network_device_handler */); 209 NULL /* network_device_handler */);
209 message_loop_.RunUntilIdle(); 210 base::RunLoop().RunUntilIdle();
210 } 211 }
211 212
212 void TearDown() override { 213 void TearDown() override {
213 network_configuration_handler_.reset(); 214 network_configuration_handler_.reset();
214 network_state_handler_.reset(); 215 network_state_handler_.reset();
215 DBusThreadManager::Shutdown(); 216 DBusThreadManager::Shutdown();
216 } 217 }
217 218
218 // Handles responses for GetProperties method calls. 219 // Handles responses for GetProperties method calls.
219 void OnGetProperties( 220 void OnGetProperties(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 base::Bind(&ServiceResultCallback, service_path), 291 base::Bind(&ServiceResultCallback, service_path),
291 base::Bind(&ErrorCallback, false, std::string())); 292 base::Bind(&ErrorCallback, false, std::string()));
292 } 293 }
293 294
294 protected: 295 protected:
295 MockShillManagerClient* mock_manager_client_; 296 MockShillManagerClient* mock_manager_client_;
296 MockShillProfileClient* mock_profile_client_; 297 MockShillProfileClient* mock_profile_client_;
297 MockShillServiceClient* mock_service_client_; 298 MockShillServiceClient* mock_service_client_;
298 std::unique_ptr<NetworkStateHandler> network_state_handler_; 299 std::unique_ptr<NetworkStateHandler> network_state_handler_;
299 std::unique_ptr<NetworkConfigurationHandler> network_configuration_handler_; 300 std::unique_ptr<NetworkConfigurationHandler> network_configuration_handler_;
300 base::MessageLoopForUI message_loop_; 301 base::MessageLoopForUI message_loop_;
armansito 2016/09/06 22:04:32 ditto
fdoray 2016/09/07 13:03:48 ditto
301 base::DictionaryValue* dictionary_value_result_; 302 base::DictionaryValue* dictionary_value_result_;
302 }; 303 };
303 304
304 TEST_F(NetworkConfigurationHandlerTest, GetProperties) { 305 TEST_F(NetworkConfigurationHandlerTest, GetProperties) {
305 std::string service_path = "/service/1"; 306 std::string service_path = "/service/1";
306 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; 307 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n";
307 std::string networkName = "MyNetwork"; 308 std::string networkName = "MyNetwork";
308 std::string key = "SSID"; 309 std::string key = "SSID";
309 std::unique_ptr<base::StringValue> networkNameValue( 310 std::unique_ptr<base::StringValue> networkNameValue(
310 new base::StringValue(networkName)); 311 new base::StringValue(networkName));
311 312
312 base::DictionaryValue value; 313 base::DictionaryValue value;
313 value.Set(key, new base::StringValue(networkName)); 314 value.Set(key, new base::StringValue(networkName));
314 dictionary_value_result_ = &value; 315 dictionary_value_result_ = &value;
315 EXPECT_CALL(*mock_service_client_, 316 EXPECT_CALL(*mock_service_client_,
316 SetProperty(dbus::ObjectPath(service_path), key, 317 SetProperty(dbus::ObjectPath(service_path), key,
317 IsEqualTo(networkNameValue.get()), _, _)).Times(1); 318 IsEqualTo(networkNameValue.get()), _, _)).Times(1);
318 mock_service_client_->SetProperty( 319 mock_service_client_->SetProperty(
319 dbus::ObjectPath(service_path), key, *networkNameValue, 320 dbus::ObjectPath(service_path), key, *networkNameValue,
320 base::Bind(&base::DoNothing), base::Bind(&DBusErrorCallback)); 321 base::Bind(&base::DoNothing), base::Bind(&DBusErrorCallback));
321 message_loop_.RunUntilIdle(); 322 base::RunLoop().RunUntilIdle();
322 323
323 ShillServiceClient::DictionaryValueCallback get_properties_callback; 324 ShillServiceClient::DictionaryValueCallback get_properties_callback;
324 EXPECT_CALL(*mock_service_client_, GetProperties(_, _)) 325 EXPECT_CALL(*mock_service_client_, GetProperties(_, _))
325 .WillOnce( 326 .WillOnce(
326 Invoke(this, &NetworkConfigurationHandlerTest::OnGetProperties)); 327 Invoke(this, &NetworkConfigurationHandlerTest::OnGetProperties));
327 network_configuration_handler_->GetShillProperties( 328 network_configuration_handler_->GetShillProperties(
328 service_path, 329 service_path,
329 base::Bind(&DictionaryValueCallback, service_path, expected_json), 330 base::Bind(&DictionaryValueCallback, service_path, expected_json),
330 base::Bind(&ErrorCallback, false, service_path)); 331 base::Bind(&ErrorCallback, false, service_path));
331 message_loop_.RunUntilIdle(); 332 base::RunLoop().RunUntilIdle();
332 } 333 }
333 334
334 TEST_F(NetworkConfigurationHandlerTest, SetProperties) { 335 TEST_F(NetworkConfigurationHandlerTest, SetProperties) {
335 std::string service_path = "/service/1"; 336 std::string service_path = "/service/1";
336 std::string networkName = "MyNetwork"; 337 std::string networkName = "MyNetwork";
337 std::string key = "SSID"; 338 std::string key = "SSID";
338 std::unique_ptr<base::StringValue> networkNameValue( 339 std::unique_ptr<base::StringValue> networkNameValue(
339 new base::StringValue(networkName)); 340 new base::StringValue(networkName));
340 341
341 base::DictionaryValue value; 342 base::DictionaryValue value;
342 value.Set(key, new base::StringValue(networkName)); 343 value.Set(key, new base::StringValue(networkName));
343 dictionary_value_result_ = &value; 344 dictionary_value_result_ = &value;
344 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _)) 345 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _))
345 .WillOnce( 346 .WillOnce(
346 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties)); 347 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties));
347 network_configuration_handler_->SetShillProperties( 348 network_configuration_handler_->SetShillProperties(
348 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION, 349 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION,
349 base::Bind(&base::DoNothing), 350 base::Bind(&base::DoNothing),
350 base::Bind(&ErrorCallback, false, service_path)); 351 base::Bind(&ErrorCallback, false, service_path));
351 message_loop_.RunUntilIdle(); 352 base::RunLoop().RunUntilIdle();
352 } 353 }
353 354
354 TEST_F(NetworkConfigurationHandlerTest, ClearProperties) { 355 TEST_F(NetworkConfigurationHandlerTest, ClearProperties) {
355 std::string service_path = "/service/1"; 356 std::string service_path = "/service/1";
356 std::string networkName = "MyNetwork"; 357 std::string networkName = "MyNetwork";
357 std::string key = "SSID"; 358 std::string key = "SSID";
358 std::unique_ptr<base::StringValue> networkNameValue( 359 std::unique_ptr<base::StringValue> networkNameValue(
359 new base::StringValue(networkName)); 360 new base::StringValue(networkName));
360 361
361 // First set up a value to clear. 362 // First set up a value to clear.
362 base::DictionaryValue value; 363 base::DictionaryValue value;
363 value.Set(key, new base::StringValue(networkName)); 364 value.Set(key, new base::StringValue(networkName));
364 dictionary_value_result_ = &value; 365 dictionary_value_result_ = &value;
365 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _)) 366 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _))
366 .WillOnce( 367 .WillOnce(
367 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties)); 368 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties));
368 network_configuration_handler_->SetShillProperties( 369 network_configuration_handler_->SetShillProperties(
369 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION, 370 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION,
370 base::Bind(&base::DoNothing), 371 base::Bind(&base::DoNothing),
371 base::Bind(&ErrorCallback, false, service_path)); 372 base::Bind(&ErrorCallback, false, service_path));
372 message_loop_.RunUntilIdle(); 373 base::RunLoop().RunUntilIdle();
373 374
374 // Now clear it. 375 // Now clear it.
375 std::vector<std::string> values_to_clear; 376 std::vector<std::string> values_to_clear;
376 values_to_clear.push_back(key); 377 values_to_clear.push_back(key);
377 EXPECT_CALL(*mock_service_client_, ClearProperties(_, _, _, _)) 378 EXPECT_CALL(*mock_service_client_, ClearProperties(_, _, _, _))
378 .WillOnce( 379 .WillOnce(
379 Invoke(this, &NetworkConfigurationHandlerTest::OnClearProperties)); 380 Invoke(this, &NetworkConfigurationHandlerTest::OnClearProperties));
380 network_configuration_handler_->ClearShillProperties( 381 network_configuration_handler_->ClearShillProperties(
381 service_path, values_to_clear, base::Bind(&base::DoNothing), 382 service_path, values_to_clear, base::Bind(&base::DoNothing),
382 base::Bind(&ErrorCallback, false, service_path)); 383 base::Bind(&ErrorCallback, false, service_path));
383 message_loop_.RunUntilIdle(); 384 base::RunLoop().RunUntilIdle();
384 } 385 }
385 386
386 TEST_F(NetworkConfigurationHandlerTest, ClearPropertiesError) { 387 TEST_F(NetworkConfigurationHandlerTest, ClearPropertiesError) {
387 std::string service_path = "/service/1"; 388 std::string service_path = "/service/1";
388 std::string networkName = "MyNetwork"; 389 std::string networkName = "MyNetwork";
389 std::string key = "SSID"; 390 std::string key = "SSID";
390 std::unique_ptr<base::StringValue> networkNameValue( 391 std::unique_ptr<base::StringValue> networkNameValue(
391 new base::StringValue(networkName)); 392 new base::StringValue(networkName));
392 393
393 // First set up a value to clear. 394 // First set up a value to clear.
394 base::DictionaryValue value; 395 base::DictionaryValue value;
395 value.Set(key, new base::StringValue(networkName)); 396 value.Set(key, new base::StringValue(networkName));
396 dictionary_value_result_ = &value; 397 dictionary_value_result_ = &value;
397 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _)) 398 EXPECT_CALL(*mock_service_client_, SetProperties(_, _, _, _))
398 .WillOnce( 399 .WillOnce(
399 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties)); 400 Invoke(this, &NetworkConfigurationHandlerTest::OnSetProperties));
400 network_configuration_handler_->SetShillProperties( 401 network_configuration_handler_->SetShillProperties(
401 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION, 402 service_path, value, NetworkConfigurationObserver::SOURCE_USER_ACTION,
402 base::Bind(&base::DoNothing), 403 base::Bind(&base::DoNothing),
403 base::Bind(&ErrorCallback, false, service_path)); 404 base::Bind(&ErrorCallback, false, service_path));
404 message_loop_.RunUntilIdle(); 405 base::RunLoop().RunUntilIdle();
405 406
406 // Now clear it. 407 // Now clear it.
407 std::vector<std::string> values_to_clear; 408 std::vector<std::string> values_to_clear;
408 values_to_clear.push_back(key); 409 values_to_clear.push_back(key);
409 EXPECT_CALL(*mock_service_client_, ClearProperties(_, _, _, _)) 410 EXPECT_CALL(*mock_service_client_, ClearProperties(_, _, _, _))
410 .WillOnce(Invoke( 411 .WillOnce(Invoke(
411 this, &NetworkConfigurationHandlerTest::OnClearPropertiesError)); 412 this, &NetworkConfigurationHandlerTest::OnClearPropertiesError));
412 network_configuration_handler_->ClearShillProperties( 413 network_configuration_handler_->ClearShillProperties(
413 service_path, values_to_clear, base::Bind(&base::DoNothing), 414 service_path, values_to_clear, base::Bind(&base::DoNothing),
414 base::Bind(&ErrorCallback, true, service_path)); 415 base::Bind(&ErrorCallback, true, service_path));
415 message_loop_.RunUntilIdle(); 416 base::RunLoop().RunUntilIdle();
416 } 417 }
417 418
418 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { 419 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) {
419 std::string networkName = "MyNetwork"; 420 std::string networkName = "MyNetwork";
420 std::string key = "SSID"; 421 std::string key = "SSID";
421 std::string type = "wifi"; 422 std::string type = "wifi";
422 std::string profile = "profile path"; 423 std::string profile = "profile path";
423 base::DictionaryValue value; 424 base::DictionaryValue value;
424 shill_property_util::SetSSID(networkName, &value); 425 shill_property_util::SetSSID(networkName, &value);
425 value.SetWithoutPathExpansion(shill::kTypeProperty, 426 value.SetWithoutPathExpansion(shill::kTypeProperty,
426 new base::StringValue(type)); 427 new base::StringValue(type));
427 value.SetWithoutPathExpansion(shill::kProfileProperty, 428 value.SetWithoutPathExpansion(shill::kProfileProperty,
428 new base::StringValue(profile)); 429 new base::StringValue(profile));
429 430
430 EXPECT_CALL(*mock_manager_client_, 431 EXPECT_CALL(*mock_manager_client_,
431 ConfigureServiceForProfile(dbus::ObjectPath(profile), _, _, _)) 432 ConfigureServiceForProfile(dbus::ObjectPath(profile), _, _, _))
432 .WillOnce( 433 .WillOnce(
433 Invoke(this, &NetworkConfigurationHandlerTest::OnConfigureService)); 434 Invoke(this, &NetworkConfigurationHandlerTest::OnConfigureService));
434 CreateConfiguration("/service/2", value); 435 CreateConfiguration("/service/2", value);
435 message_loop_.RunUntilIdle(); 436 base::RunLoop().RunUntilIdle();
436 } 437 }
437 438
438 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) { 439 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) {
439 std::string service_path = "/service/1"; 440 std::string service_path = "/service/1";
440 441
441 TestCallback test_callback; 442 TestCallback test_callback;
442 EXPECT_CALL(*mock_service_client_, GetLoadableProfileEntries(_, _)) 443 EXPECT_CALL(*mock_service_client_, GetLoadableProfileEntries(_, _))
443 .WillOnce(Invoke( 444 .WillOnce(Invoke(
444 this, &NetworkConfigurationHandlerTest::OnGetLoadableProfileEntries)); 445 this, &NetworkConfigurationHandlerTest::OnGetLoadableProfileEntries));
445 EXPECT_CALL(*mock_profile_client_, DeleteEntry(_, _, _, _)) 446 EXPECT_CALL(*mock_profile_client_, DeleteEntry(_, _, _, _))
446 .WillRepeatedly( 447 .WillRepeatedly(
447 Invoke(this, &NetworkConfigurationHandlerTest::OnDeleteEntry)); 448 Invoke(this, &NetworkConfigurationHandlerTest::OnDeleteEntry));
448 449
449 network_configuration_handler_->RemoveConfiguration( 450 network_configuration_handler_->RemoveConfiguration(
450 service_path, NetworkConfigurationObserver::SOURCE_USER_ACTION, 451 service_path, NetworkConfigurationObserver::SOURCE_USER_ACTION,
451 base::Bind(&TestCallback::Run, base::Unretained(&test_callback)), 452 base::Bind(&TestCallback::Run, base::Unretained(&test_callback)),
452 base::Bind(&ErrorCallback, false, service_path)); 453 base::Bind(&ErrorCallback, false, service_path));
453 message_loop_.RunUntilIdle(); 454 base::RunLoop().RunUntilIdle();
454 EXPECT_EQ(1, test_callback.run_count()); 455 EXPECT_EQ(1, test_callback.run_count());
455 EXPECT_FALSE(PendingProfileEntryDeleterForTest(service_path)); 456 EXPECT_FALSE(PendingProfileEntryDeleterForTest(service_path));
456 } 457 }
457 458
458 //////////////////////////////////////////////////////////////////////////////// 459 ////////////////////////////////////////////////////////////////////////////////
459 // Stub based tests 460 // Stub based tests
460 461
461 namespace { 462 namespace {
462 463
463 class TestObserver : public chromeos::NetworkStateHandlerObserver { 464 class TestObserver : public chromeos::NetworkStateHandlerObserver {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 DBusThreadManager::Initialize(); 499 DBusThreadManager::Initialize();
499 500
500 network_state_handler_.reset(NetworkStateHandler::InitializeForTest()); 501 network_state_handler_.reset(NetworkStateHandler::InitializeForTest());
501 test_observer_.reset(new TestObserver()); 502 test_observer_.reset(new TestObserver());
502 network_state_handler_->AddObserver(test_observer_.get(), FROM_HERE); 503 network_state_handler_->AddObserver(test_observer_.get(), FROM_HERE);
503 504
504 network_configuration_handler_.reset(new NetworkConfigurationHandler()); 505 network_configuration_handler_.reset(new NetworkConfigurationHandler());
505 network_configuration_handler_->Init(network_state_handler_.get(), 506 network_configuration_handler_->Init(network_state_handler_.get(),
506 NULL /* network_device_handler */); 507 NULL /* network_device_handler */);
507 508
508 message_loop_.RunUntilIdle(); 509 base::RunLoop().RunUntilIdle();
509 test_observer_->ClearPropertyUpdates(); 510 test_observer_->ClearPropertyUpdates();
510 } 511 }
511 512
512 void TearDown() override { 513 void TearDown() override {
513 network_configuration_handler_.reset(); 514 network_configuration_handler_.reset();
514 network_state_handler_->RemoveObserver(test_observer_.get(), FROM_HERE); 515 network_state_handler_->RemoveObserver(test_observer_.get(), FROM_HERE);
515 network_state_handler_.reset(); 516 network_state_handler_.reset();
516 DBusThreadManager::Shutdown(); 517 DBusThreadManager::Shutdown();
517 } 518 }
518 519
(...skipping 25 matching lines...) Expand all
544 shill::kStateIdle); 545 shill::kStateIdle);
545 properties.SetStringWithoutPathExpansion( 546 properties.SetStringWithoutPathExpansion(
546 shill::kProfileProperty, NetworkProfileHandler::GetSharedProfilePath()); 547 shill::kProfileProperty, NetworkProfileHandler::GetSharedProfilePath());
547 548
548 network_configuration_handler_->CreateShillConfiguration( 549 network_configuration_handler_->CreateShillConfiguration(
549 properties, NetworkConfigurationObserver::SOURCE_USER_ACTION, 550 properties, NetworkConfigurationObserver::SOURCE_USER_ACTION,
550 base::Bind( 551 base::Bind(
551 &NetworkConfigurationHandlerStubTest::CreateConfigurationCallback, 552 &NetworkConfigurationHandlerStubTest::CreateConfigurationCallback,
552 base::Unretained(this)), 553 base::Unretained(this)),
553 base::Bind(&ErrorCallback, false, service_path)); 554 base::Bind(&ErrorCallback, false, service_path));
554 message_loop_.RunUntilIdle(); 555 base::RunLoop().RunUntilIdle();
555 } 556 }
556 557
557 protected: 558 protected:
558 bool GetServiceStringProperty(const std::string& service_path, 559 bool GetServiceStringProperty(const std::string& service_path,
559 const std::string& key, 560 const std::string& key,
560 std::string* result) { 561 std::string* result) {
561 ShillServiceClient::TestInterface* service_test = 562 ShillServiceClient::TestInterface* service_test =
562 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 563 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
563 const base::DictionaryValue* properties = 564 const base::DictionaryValue* properties =
564 service_test->GetServiceProperties(service_path); 565 service_test->GetServiceProperties(service_path);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 properties_to_set.SetStringWithoutPathExpansion(shill::kIdentityProperty, 600 properties_to_set.SetStringWithoutPathExpansion(shill::kIdentityProperty,
600 test_identity); 601 test_identity);
601 properties_to_set.SetStringWithoutPathExpansion(shill::kPassphraseProperty, 602 properties_to_set.SetStringWithoutPathExpansion(shill::kPassphraseProperty,
602 test_passphrase); 603 test_passphrase);
603 network_configuration_handler_->SetShillProperties( 604 network_configuration_handler_->SetShillProperties(
604 service_path, properties_to_set, 605 service_path, properties_to_set,
605 NetworkConfigurationObserver::SOURCE_USER_ACTION, 606 NetworkConfigurationObserver::SOURCE_USER_ACTION,
606 base::Bind(&NetworkConfigurationHandlerStubTest::SuccessCallback, 607 base::Bind(&NetworkConfigurationHandlerStubTest::SuccessCallback,
607 base::Unretained(this), "SetProperties"), 608 base::Unretained(this), "SetProperties"),
608 base::Bind(&ErrorCallback, false, service_path)); 609 base::Bind(&ErrorCallback, false, service_path));
609 message_loop_.RunUntilIdle(); 610 base::RunLoop().RunUntilIdle();
610 611
611 EXPECT_EQ("SetProperties", success_callback_name_); 612 EXPECT_EQ("SetProperties", success_callback_name_);
612 std::string identity, passphrase; 613 std::string identity, passphrase;
613 EXPECT_TRUE(GetServiceStringProperty(service_path, shill::kIdentityProperty, 614 EXPECT_TRUE(GetServiceStringProperty(service_path, shill::kIdentityProperty,
614 &identity)); 615 &identity));
615 EXPECT_TRUE(GetServiceStringProperty(service_path, shill::kPassphraseProperty, 616 EXPECT_TRUE(GetServiceStringProperty(service_path, shill::kPassphraseProperty,
616 &passphrase)); 617 &passphrase));
617 EXPECT_EQ(test_identity, identity); 618 EXPECT_EQ(test_identity, identity);
618 EXPECT_EQ(test_passphrase, passphrase); 619 EXPECT_EQ(test_passphrase, passphrase);
619 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(service_path)); 620 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(service_path));
620 621
621 // Clear Properties 622 // Clear Properties
622 std::vector<std::string> properties_to_clear; 623 std::vector<std::string> properties_to_clear;
623 properties_to_clear.push_back(shill::kIdentityProperty); 624 properties_to_clear.push_back(shill::kIdentityProperty);
624 properties_to_clear.push_back(shill::kPassphraseProperty); 625 properties_to_clear.push_back(shill::kPassphraseProperty);
625 network_configuration_handler_->ClearShillProperties( 626 network_configuration_handler_->ClearShillProperties(
626 service_path, properties_to_clear, 627 service_path, properties_to_clear,
627 base::Bind(&NetworkConfigurationHandlerStubTest::SuccessCallback, 628 base::Bind(&NetworkConfigurationHandlerStubTest::SuccessCallback,
628 base::Unretained(this), "ClearProperties"), 629 base::Unretained(this), "ClearProperties"),
629 base::Bind(&ErrorCallback, false, service_path)); 630 base::Bind(&ErrorCallback, false, service_path));
630 message_loop_.RunUntilIdle(); 631 base::RunLoop().RunUntilIdle();
631 632
632 EXPECT_EQ("ClearProperties", success_callback_name_); 633 EXPECT_EQ("ClearProperties", success_callback_name_);
633 EXPECT_FALSE(GetServiceStringProperty(service_path, shill::kIdentityProperty, 634 EXPECT_FALSE(GetServiceStringProperty(service_path, shill::kIdentityProperty,
634 &identity)); 635 &identity));
635 EXPECT_FALSE(GetServiceStringProperty(service_path, shill::kIdentityProperty, 636 EXPECT_FALSE(GetServiceStringProperty(service_path, shill::kIdentityProperty,
636 &passphrase)); 637 &passphrase));
637 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(service_path)); 638 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(service_path));
638 } 639 }
639 640
640 TEST_F(NetworkConfigurationHandlerStubTest, StubGetNameFromWifiHex) { 641 TEST_F(NetworkConfigurationHandlerStubTest, StubGetNameFromWifiHex) {
641 // TODO(stevenjb): Remove dependency on default Stub service. 642 // TODO(stevenjb): Remove dependency on default Stub service.
642 const std::string service_path("/service/wifi1"); 643 const std::string service_path("/service/wifi1");
643 std::string wifi_hex = "5468697320697320484558205353494421"; 644 std::string wifi_hex = "5468697320697320484558205353494421";
644 std::string expected_name = "This is HEX SSID!"; 645 std::string expected_name = "This is HEX SSID!";
645 646
646 // Set Properties 647 // Set Properties
647 base::DictionaryValue properties_to_set; 648 base::DictionaryValue properties_to_set;
648 properties_to_set.SetStringWithoutPathExpansion(shill::kWifiHexSsid, 649 properties_to_set.SetStringWithoutPathExpansion(shill::kWifiHexSsid,
649 wifi_hex); 650 wifi_hex);
650 network_configuration_handler_->SetShillProperties( 651 network_configuration_handler_->SetShillProperties(
651 service_path, properties_to_set, 652 service_path, properties_to_set,
652 NetworkConfigurationObserver::SOURCE_USER_ACTION, 653 NetworkConfigurationObserver::SOURCE_USER_ACTION,
653 base::Bind(&base::DoNothing), 654 base::Bind(&base::DoNothing),
654 base::Bind(&ErrorCallback, false, service_path)); 655 base::Bind(&ErrorCallback, false, service_path));
655 message_loop_.RunUntilIdle(); 656 base::RunLoop().RunUntilIdle();
656 std::string wifi_hex_result; 657 std::string wifi_hex_result;
657 EXPECT_TRUE(GetServiceStringProperty(service_path, shill::kWifiHexSsid, 658 EXPECT_TRUE(GetServiceStringProperty(service_path, shill::kWifiHexSsid,
658 &wifi_hex_result)); 659 &wifi_hex_result));
659 EXPECT_EQ(wifi_hex, wifi_hex_result); 660 EXPECT_EQ(wifi_hex, wifi_hex_result);
660 661
661 // Get Properties 662 // Get Properties
662 network_configuration_handler_->GetShillProperties( 663 network_configuration_handler_->GetShillProperties(
663 service_path, 664 service_path,
664 base::Bind(&NetworkConfigurationHandlerStubTest::GetPropertiesCallback, 665 base::Bind(&NetworkConfigurationHandlerStubTest::GetPropertiesCallback,
665 base::Unretained(this)), 666 base::Unretained(this)),
666 base::Bind(&ErrorCallback, false, service_path)); 667 base::Bind(&ErrorCallback, false, service_path));
667 message_loop_.RunUntilIdle(); 668 base::RunLoop().RunUntilIdle();
668 669
669 EXPECT_EQ(service_path, get_properties_path_); 670 EXPECT_EQ(service_path, get_properties_path_);
670 std::string name_result; 671 std::string name_result;
671 EXPECT_TRUE(GetReceivedStringProperty(service_path, shill::kNameProperty, 672 EXPECT_TRUE(GetReceivedStringProperty(service_path, shill::kNameProperty,
672 &name_result)); 673 &name_result));
673 EXPECT_EQ(expected_name, name_result); 674 EXPECT_EQ(expected_name, name_result);
674 } 675 }
675 676
676 TEST_F(NetworkConfigurationHandlerStubTest, StubCreateConfiguration) { 677 TEST_F(NetworkConfigurationHandlerStubTest, StubCreateConfiguration) {
677 const std::string service_path("/service/test_wifi"); 678 const std::string service_path("/service/test_wifi");
(...skipping 28 matching lines...) Expand all
706 service_path, shill::kTypeProperty)); 707 service_path, shill::kTypeProperty));
707 708
708 base::DictionaryValue properties_to_set; 709 base::DictionaryValue properties_to_set;
709 properties_to_set.SetStringWithoutPathExpansion(shill::kPassphraseProperty, 710 properties_to_set.SetStringWithoutPathExpansion(shill::kPassphraseProperty,
710 test_passphrase); 711 test_passphrase);
711 network_configuration_handler_->SetShillProperties( 712 network_configuration_handler_->SetShillProperties(
712 service_path, properties_to_set, 713 service_path, properties_to_set,
713 NetworkConfigurationObserver::SOURCE_USER_ACTION, 714 NetworkConfigurationObserver::SOURCE_USER_ACTION,
714 base::Bind(&base::DoNothing), 715 base::Bind(&base::DoNothing),
715 base::Bind(&ErrorCallback, false, service_path)); 716 base::Bind(&ErrorCallback, false, service_path));
716 message_loop_.RunUntilIdle(); 717 base::RunLoop().RunUntilIdle();
717 EXPECT_EQ(test_passphrase, test_observer->GetStringProperty( 718 EXPECT_EQ(test_passphrase, test_observer->GetStringProperty(
718 service_path, shill::kPassphraseProperty)); 719 service_path, shill::kPassphraseProperty));
719 720
720 std::string user_profile = "/profiles/user1"; 721 std::string user_profile = "/profiles/user1";
721 std::string userhash = "user1"; 722 std::string userhash = "user1";
722 DBusThreadManager::Get() 723 DBusThreadManager::Get()
723 ->GetShillProfileClient() 724 ->GetShillProfileClient()
724 ->GetTestInterface() 725 ->GetTestInterface()
725 ->AddProfile(user_profile, userhash); 726 ->AddProfile(user_profile, userhash);
726 727
727 network_configuration_handler_->SetNetworkProfile( 728 network_configuration_handler_->SetNetworkProfile(
728 service_path, user_profile, 729 service_path, user_profile,
729 NetworkConfigurationObserver::SOURCE_USER_ACTION, 730 NetworkConfigurationObserver::SOURCE_USER_ACTION,
730 base::Bind(&base::DoNothing), 731 base::Bind(&base::DoNothing),
731 base::Bind(&ErrorCallback, false, service_path)); 732 base::Bind(&ErrorCallback, false, service_path));
732 message_loop_.RunUntilIdle(); 733 base::RunLoop().RunUntilIdle();
733 EXPECT_TRUE(test_observer->HasConfiguration(service_path)); 734 EXPECT_TRUE(test_observer->HasConfiguration(service_path));
734 EXPECT_FALSE(test_observer->HasConfigurationInProfile( 735 EXPECT_FALSE(test_observer->HasConfigurationInProfile(
735 service_path, NetworkProfileHandler::GetSharedProfilePath())); 736 service_path, NetworkProfileHandler::GetSharedProfilePath()));
736 EXPECT_TRUE( 737 EXPECT_TRUE(
737 test_observer->HasConfigurationInProfile(service_path, user_profile)); 738 test_observer->HasConfigurationInProfile(service_path, user_profile));
738 739
739 network_configuration_handler_->RemoveConfiguration( 740 network_configuration_handler_->RemoveConfiguration(
740 service_path, NetworkConfigurationObserver::SOURCE_USER_ACTION, 741 service_path, NetworkConfigurationObserver::SOURCE_USER_ACTION,
741 base::Bind(&base::DoNothing), 742 base::Bind(&base::DoNothing),
742 base::Bind(&ErrorCallback, false, service_path)); 743 base::Bind(&ErrorCallback, false, service_path));
743 message_loop_.RunUntilIdle(); 744 base::RunLoop().RunUntilIdle();
744 745
745 EXPECT_FALSE(test_observer->HasConfiguration(service_path)); 746 EXPECT_FALSE(test_observer->HasConfiguration(service_path));
746 EXPECT_FALSE(test_observer->HasConfigurationInProfile( 747 EXPECT_FALSE(test_observer->HasConfigurationInProfile(
747 service_path, NetworkProfileHandler::GetSharedProfilePath())); 748 service_path, NetworkProfileHandler::GetSharedProfilePath()));
748 EXPECT_FALSE( 749 EXPECT_FALSE(
749 test_observer->HasConfigurationInProfile(service_path, user_profile)); 750 test_observer->HasConfigurationInProfile(service_path, user_profile));
750 751
751 network_configuration_handler_->RemoveObserver(test_observer.get()); 752 network_configuration_handler_->RemoveObserver(test_observer.get());
752 } 753 }
753 754
754 } // namespace chromeos 755 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698