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