| 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 "chromeos/network/network_connection_handler.h" | 5 #include "chromeos/network/network_connection_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 GetResultAndReset()); | 427 GetResultAndReset()); |
| 428 | 428 |
| 429 EXPECT_TRUE(Configure(kConfigConnectable)); | 429 EXPECT_TRUE(Configure(kConfigConnectable)); |
| 430 Disconnect("wifi0"); | 430 Disconnect("wifi0"); |
| 431 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); | 431 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); |
| 432 } | 432 } |
| 433 | 433 |
| 434 namespace { | 434 namespace { |
| 435 | 435 |
| 436 const char* kConfigUnmanagedSharedConnected = | 436 const char* kConfigUnmanagedSharedConnected = |
| 437 "{ \"GUID\": \"wifi0\", \"Type\": \"wifi\", \"State\": \"online\" }"; | 437 "{ \"GUID\": \"wifi0\", \"Type\": \"wifi\", \"State\": \"online\", " |
| 438 " \"Security\": \"wpa\" }"; |
| 438 const char* kConfigManagedSharedConnectable = | 439 const char* kConfigManagedSharedConnectable = |
| 439 "{ \"GUID\": \"wifi1\", \"Type\": \"wifi\", \"State\": \"idle\", " | 440 "{ \"GUID\": \"wifi1\", \"Type\": \"wifi\", \"State\": \"idle\", " |
| 440 " \"Connectable\": true }"; | 441 " \"Connectable\": true, \"Security\": \"wpa\" }"; |
| 441 | 442 |
| 442 const char* kPolicy = | 443 const char* kPolicy = |
| 443 "[ { \"GUID\": \"wifi1\"," | 444 "[ { \"GUID\": \"wifi1\"," |
| 444 " \"Name\": \"wifi1\"," | 445 " \"Name\": \"wifi1\"," |
| 445 " \"Type\": \"WiFi\"," | 446 " \"Type\": \"WiFi\"," |
| 446 " \"WiFi\": {" | 447 " \"WiFi\": {" |
| 447 " \"Security\": \"WPA-PSK\"," | 448 " \"Security\": \"WPA-PSK\"," |
| 448 " \"SSID\": \"wifi1\"," | 449 " \"SSID\": \"wifi1\"," |
| 449 " \"Passphrase\": \"passphrase\"" | 450 " \"Passphrase\": \"passphrase\"" |
| 450 " }" | 451 " }" |
| 451 "} ]"; | 452 "} ]"; |
| 452 | 453 |
| 453 } // namespace | 454 } // namespace |
| 454 | 455 |
| 455 TEST_F(NetworkConnectionHandlerTest, ReconnectOnLoginEarlyPolicyLoading) { | 456 TEST_F(NetworkConnectionHandlerTest, ReconnectOnCertLoading) { |
| 456 EXPECT_TRUE(Configure(kConfigUnmanagedSharedConnected)); | 457 EXPECT_TRUE(Configure(kConfigUnmanagedSharedConnected)); |
| 457 EXPECT_TRUE(Configure(kConfigManagedSharedConnectable)); | 458 EXPECT_TRUE(Configure(kConfigManagedSharedConnectable)); |
| 458 test_manager_client_->SetBestServiceToConnect("wifi1"); | 459 test_manager_client_->SetBestServiceToConnect("wifi1"); |
| 459 | 460 |
| 460 // User login shouldn't trigger any change because policy is not loaded yet. | 461 // User login shouldn't trigger any change until the certificates and policy |
| 462 // are loaded. |
| 461 LoginToRegularUser(); | 463 LoginToRegularUser(); |
| 462 EXPECT_EQ(shill::kStateOnline, | 464 EXPECT_EQ(shill::kStateOnline, |
| 463 GetServiceStringProperty("wifi0", shill::kStateProperty)); | 465 GetServiceStringProperty("wifi0", shill::kStateProperty)); |
| 464 EXPECT_EQ(shill::kStateIdle, | 466 EXPECT_EQ(shill::kStateIdle, |
| 465 GetServiceStringProperty("wifi1", shill::kStateProperty)); | 467 GetServiceStringProperty("wifi1", shill::kStateProperty)); |
| 466 | 468 |
| 467 // Applying the policy which restricts autoconnect should disconnect from the | 469 // Applying the policy which restricts autoconnect should disconnect from the |
| 468 // shared, unmanaged network. | 470 // shared, unmanaged network. |
| 469 base::DictionaryValue global_config; | 471 base::DictionaryValue global_config; |
| 470 global_config.SetBooleanWithoutPathExpansion( | 472 global_config.SetBooleanWithoutPathExpansion( |
| 471 ::onc::global_network_config::kAllowOnlyPolicyNetworksToAutoconnect, | 473 ::onc::global_network_config::kAllowOnlyPolicyNetworksToAutoconnect, |
| 472 true); | 474 true); |
| 473 | 475 |
| 474 SetupPolicy(kPolicy, global_config, false /* load as device policy */); | 476 SetupPolicy(kPolicy, global_config, false /* load as device policy */); |
| 475 EXPECT_EQ(shill::kStateIdle, | 477 EXPECT_EQ(shill::kStateIdle, |
| 476 GetServiceStringProperty("wifi0", shill::kStateProperty)); | 478 GetServiceStringProperty("wifi0", shill::kStateProperty)); |
| 477 EXPECT_EQ(shill::kStateIdle, | 479 EXPECT_EQ(shill::kStateIdle, |
| 478 GetServiceStringProperty("wifi1", shill::kStateProperty)); | 480 GetServiceStringProperty("wifi1", shill::kStateProperty)); |
| 479 | 481 |
| 480 // Certificate loading should trigger connecting to the 'best' network. | 482 // Certificate loading should trigger connecting to the 'best' network. |
| 481 StartCertLoader(); | 483 StartCertLoader(); |
| 482 EXPECT_EQ(shill::kStateIdle, | 484 EXPECT_EQ(shill::kStateIdle, |
| 483 GetServiceStringProperty("wifi0", shill::kStateProperty)); | 485 GetServiceStringProperty("wifi0", shill::kStateProperty)); |
| 484 EXPECT_EQ(shill::kStateOnline, | 486 EXPECT_EQ(shill::kStateOnline, |
| 485 GetServiceStringProperty("wifi1", shill::kStateProperty)); | 487 GetServiceStringProperty("wifi1", shill::kStateProperty)); |
| 486 } | 488 } |
| 487 | 489 |
| 488 TEST_F(NetworkConnectionHandlerTest, ReconnectOnLoginLatePolicyLoading) { | 490 TEST_F(NetworkConnectionHandlerTest, DisconnectOnPolicyLoading) { |
| 489 EXPECT_TRUE(Configure(kConfigUnmanagedSharedConnected)); | 491 EXPECT_TRUE(Configure(kConfigUnmanagedSharedConnected)); |
| 490 EXPECT_TRUE(Configure(kConfigManagedSharedConnectable)); | 492 EXPECT_TRUE(Configure(kConfigManagedSharedConnectable)); |
| 491 test_manager_client_->SetBestServiceToConnect("wifi1"); | |
| 492 | 493 |
| 493 // User login and certificate loading shouldn't trigger any change until the | 494 // User login and certificate loading shouldn't trigger any change until the |
| 494 // policy is loaded. | 495 // policy is loaded. |
| 495 LoginToRegularUser(); | 496 LoginToRegularUser(); |
| 496 StartCertLoader(); | 497 StartCertLoader(); |
| 497 EXPECT_EQ(shill::kStateOnline, | 498 EXPECT_EQ(shill::kStateOnline, |
| 498 GetServiceStringProperty("wifi0", shill::kStateProperty)); | 499 GetServiceStringProperty("wifi0", shill::kStateProperty)); |
| 499 EXPECT_EQ(shill::kStateIdle, | 500 EXPECT_EQ(shill::kStateIdle, |
| 500 GetServiceStringProperty("wifi1", shill::kStateProperty)); | 501 GetServiceStringProperty("wifi1", shill::kStateProperty)); |
| 501 | 502 |
| 502 // Applying the policy which restricts autoconnect should disconnect from the | |
| 503 // shared, unmanaged network. | |
| 504 base::DictionaryValue global_config; | 503 base::DictionaryValue global_config; |
| 505 global_config.SetBooleanWithoutPathExpansion( | 504 global_config.SetBooleanWithoutPathExpansion( |
| 506 ::onc::global_network_config::kAllowOnlyPolicyNetworksToAutoconnect, | 505 ::onc::global_network_config::kAllowOnlyPolicyNetworksToAutoconnect, |
| 507 true); | 506 true); |
| 508 | 507 |
| 508 // Applying the policy which restricts autoconnect should disconnect from the |
| 509 // shared, unmanaged network. |
| 510 // Because no best service is set, the fake implementation of |
| 511 // ConnectToBestServices will be a no-op. |
| 509 SetupPolicy(kPolicy, global_config, false /* load as device policy */); | 512 SetupPolicy(kPolicy, global_config, false /* load as device policy */); |
| 510 EXPECT_EQ(shill::kStateIdle, | 513 EXPECT_EQ(shill::kStateIdle, |
| 511 GetServiceStringProperty("wifi0", shill::kStateProperty)); | 514 GetServiceStringProperty("wifi0", shill::kStateProperty)); |
| 515 EXPECT_EQ(shill::kStateIdle, |
| 516 GetServiceStringProperty("wifi1", shill::kStateProperty)); |
| 517 } |
| 518 |
| 519 TEST_F(NetworkConnectionHandlerTest, ReconnectOnEmptyPolicyLoading) { |
| 520 EXPECT_TRUE(Configure(kConfigUnmanagedSharedConnected)); |
| 521 EXPECT_TRUE(Configure(kConfigManagedSharedConnectable)); |
| 522 test_manager_client_->SetBestServiceToConnect("wifi1"); |
| 523 |
| 524 // User login and certificate loading shouldn't trigger any change until the |
| 525 // policy is loaded. |
| 526 LoginToRegularUser(); |
| 527 StartCertLoader(); |
| 528 EXPECT_EQ(shill::kStateOnline, |
| 529 GetServiceStringProperty("wifi0", shill::kStateProperty)); |
| 530 EXPECT_EQ(shill::kStateIdle, |
| 531 GetServiceStringProperty("wifi1", shill::kStateProperty)); |
| 532 |
| 533 // Apply an empty policy should trigger connecting to the 'best' network. |
| 534 base::DictionaryValue global_config; |
| 535 SetupPolicy(kPolicy, global_config, false /* load as device policy */); |
| 536 EXPECT_EQ(shill::kStateIdle, |
| 537 GetServiceStringProperty("wifi0", shill::kStateProperty)); |
| 512 EXPECT_EQ(shill::kStateOnline, | 538 EXPECT_EQ(shill::kStateOnline, |
| 513 GetServiceStringProperty("wifi1", shill::kStateProperty)); | 539 GetServiceStringProperty("wifi1", shill::kStateProperty)); |
| 514 } | 540 } |
| 515 | 541 |
| 516 } // namespace chromeos | 542 } // namespace chromeos |
| 517 | 543 |
| 518 #endif | 544 #endif |
| OLD | NEW |