OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/auto_connect_handler.h" | 5 #include "chromeos/network/auto_connect_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 411 |
412 // Should not trigger any change until user policy is loaded | 412 // Should not trigger any change until user policy is loaded |
413 EXPECT_EQ(shill::kStateOnline, GetServiceState("wifi0")); | 413 EXPECT_EQ(shill::kStateOnline, GetServiceState("wifi0")); |
414 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); | 414 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); |
415 | 415 |
416 SetupPolicy(std::string(), base::DictionaryValue(), true); | 416 SetupPolicy(std::string(), base::DictionaryValue(), true); |
417 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi0")); | 417 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi0")); |
418 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); | 418 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); |
419 } | 419 } |
420 | 420 |
| 421 TEST_F(AutoConnectHandlerTest, |
| 422 DisconnectOnPolicyLoadingAllowOnlyPolicyNetworksToConnect) { |
| 423 EXPECT_TRUE(Configure(kConfigUnmanagedSharedConnected)); |
| 424 EXPECT_TRUE(Configure(kConfigManagedSharedConnectable)); |
| 425 |
| 426 // User login and certificate loading shouldn't trigger any change until the |
| 427 // policy is loaded. |
| 428 LoginToRegularUser(); |
| 429 StartCertLoader(); |
| 430 EXPECT_EQ(shill::kStateOnline, GetServiceState("wifi0")); |
| 431 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); |
| 432 |
| 433 base::DictionaryValue global_config; |
| 434 global_config.SetBooleanWithoutPathExpansion( |
| 435 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, true); |
| 436 |
| 437 // Applying the policy which restricts autoconnect should disconnect from the |
| 438 // shared, unmanaged network. |
| 439 // Because no best service is set, the fake implementation of |
| 440 // ConnectToBestServices will be a no-op. |
| 441 SetupPolicy(kPolicy, global_config, false /* load as device policy */); |
| 442 |
| 443 // Should not trigger any change until user policy is loaded |
| 444 EXPECT_EQ(shill::kStateOnline, GetServiceState("wifi0")); |
| 445 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); |
| 446 |
| 447 SetupPolicy(std::string(), base::DictionaryValue(), true); |
| 448 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi0")); |
| 449 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); |
| 450 } |
| 451 |
421 // After login a reconnect is triggered even if there is no managed network. | 452 // After login a reconnect is triggered even if there is no managed network. |
422 TEST_F(AutoConnectHandlerTest, ReconnectAfterLogin) { | 453 TEST_F(AutoConnectHandlerTest, ReconnectAfterLogin) { |
423 EXPECT_TRUE(Configure(kConfigUnmanagedSharedConnected)); | 454 EXPECT_TRUE(Configure(kConfigUnmanagedSharedConnected)); |
424 EXPECT_TRUE(Configure(kConfigManagedSharedConnectable)); | 455 EXPECT_TRUE(Configure(kConfigManagedSharedConnectable)); |
425 test_manager_client_->SetBestServiceToConnect("wifi1"); | 456 test_manager_client_->SetBestServiceToConnect("wifi1"); |
426 | 457 |
427 // User login and certificate loading shouldn't trigger any change until the | 458 // User login and certificate loading shouldn't trigger any change until the |
428 // policy is loaded. | 459 // policy is loaded. |
429 LoginToRegularUser(); | 460 LoginToRegularUser(); |
430 StartCertLoader(); | 461 StartCertLoader(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 // Applying the user policy after login would usually trigger connecting to | 502 // Applying the user policy after login would usually trigger connecting to |
472 // the 'best' network. But the manual connect prevents this. | 503 // the 'best' network. But the manual connect prevents this. |
473 SetupPolicy(std::string(), // no network configs | 504 SetupPolicy(std::string(), // no network configs |
474 base::DictionaryValue(), // no global config | 505 base::DictionaryValue(), // no global config |
475 true); // load as user policy | 506 true); // load as user policy |
476 EXPECT_EQ(shill::kStateOnline, GetServiceState("wifi0")); | 507 EXPECT_EQ(shill::kStateOnline, GetServiceState("wifi0")); |
477 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); | 508 EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); |
478 } | 509 } |
479 | 510 |
480 } // namespace chromeos | 511 } // namespace chromeos |
OLD | NEW |