Index: chromeos/components/tether/wifi_hotspot_connector_unittest.cc |
diff --git a/chromeos/components/tether/wifi_hotspot_connector_unittest.cc b/chromeos/components/tether/wifi_hotspot_connector_unittest.cc |
index 3eb687d6a6e2df885e019b53c7135fbc6896192b..0f72dcaa4f62a640ae1a6093b57ca344b8f4b7d5 100644 |
--- a/chromeos/components/tether/wifi_hotspot_connector_unittest.cc |
+++ b/chromeos/components/tether/wifi_hotspot_connector_unittest.cc |
@@ -36,6 +36,9 @@ const char kPassword[] = "password"; |
const char kOtherWifiServiceGuid[] = "otherWifiServiceGuid"; |
+const char kTetherNetworkGuid[] = "tetherNetworkGuid"; |
+const char kTetherNetworkGuid2[] = "tetherNetworkGuid2"; |
+ |
std::string CreateConfigurationJsonString(const std::string& guid) { |
std::stringstream ss; |
ss << "{" |
@@ -116,10 +119,23 @@ class WifiHotspotConnectorTest : public NetworkStateTest { |
DBusThreadManager::Initialize(); |
NetworkStateTest::SetUp(); |
+ network_state_handler()->SetTetherTechnologyState( |
+ NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED); |
+ |
SetUpShillState(); |
test_network_connect_ = base::WrapUnique(new TestNetworkConnect(this)); |
+ network_state_handler()->AddTetherNetworkState( |
+ kTetherNetworkGuid, "tetherNetworkName" /* name */, |
+ "tetherNetworkCarrier" /* carrier */, 100 /* full battery */, |
+ 100 /* full signal strength */); |
+ |
+ network_state_handler()->AddTetherNetworkState( |
+ kTetherNetworkGuid2, "tetherNetworkName2" /* name */, |
+ "tetherNetworkCarrier2" /* carrier */, 100 /* full battery */, |
+ 100 /* full signal strength */); |
+ |
wifi_hotspot_connector_ = base::WrapUnique(new WifiHotspotConnector( |
network_state_handler(), test_network_connect_.get())); |
@@ -201,6 +217,26 @@ class WifiHotspotConnectorTest : public NetworkStateTest { |
return wifi_guid; |
} |
+ void VerifyTetherAndWifiNetworkAssociation(const std::string& wifi_guid, |
+ const std::string& tether_guid) { |
+ const NetworkState* wifi_network_state = |
+ network_state_handler()->GetNetworkStateFromGuid(wifi_guid); |
+ ASSERT_TRUE(wifi_network_state); |
+ EXPECT_EQ(tether_guid, wifi_network_state->tether_guid()); |
+ |
+ const NetworkState* tether_network_state = |
+ network_state_handler()->GetNetworkStateFromGuid(tether_guid); |
+ ASSERT_TRUE(tether_network_state); |
+ EXPECT_EQ(wifi_guid, tether_network_state->tether_guid()); |
+ } |
+ |
+ void VerifyWifiNetworkNotAssociated(const std::string& wifi_guid) { |
+ const NetworkState* wifi_network_state = |
+ network_state_handler()->GetNetworkStateFromGuid(wifi_guid); |
+ ASSERT_TRUE(wifi_network_state); |
+ EXPECT_TRUE(wifi_network_state->tether_guid().empty()); |
+ } |
+ |
void WifiConnectionCallback(const std::string& wifi_guid) { |
connection_callback_responses_.push_back(wifi_guid); |
} |
@@ -221,7 +257,7 @@ class WifiHotspotConnectorTest : public NetworkStateTest { |
TEST_F(WifiHotspotConnectorTest, TestConnect_NetworkDoesNotBecomeConnectable) { |
wifi_hotspot_connector_->ConnectToWifiHotspot( |
- std::string(kSsid), std::string(kPassword), |
+ std::string(kSsid), std::string(kPassword), kTetherNetworkGuid, |
base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
base::Unretained(this))); |
@@ -241,7 +277,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_NetworkDoesNotBecomeConnectable) { |
TEST_F(WifiHotspotConnectorTest, TestConnect_AnotherNetworkBecomesConnectable) { |
wifi_hotspot_connector_->ConnectToWifiHotspot( |
- std::string(kSsid), std::string(kPassword), |
+ std::string(kSsid), std::string(kPassword), kTetherNetworkGuid, |
base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
base::Unretained(this))); |
@@ -252,6 +288,11 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_AnotherNetworkBecomesConnectable) { |
// Another network becomes connectable. This should not cause the connection |
// to start. |
NotifyConnectable(other_wifi_service_path_); |
+ VerifyWifiNetworkNotAssociated(wifi_guid); |
+ std::string other_wifi_guid = network_state_handler() |
+ ->GetNetworkState(other_wifi_service_path_) |
+ ->guid(); |
+ VerifyWifiNetworkNotAssociated(other_wifi_guid); |
EXPECT_EQ("", test_network_connect_->network_id_to_connect()); |
// Timeout timer fires. |
@@ -263,7 +304,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_AnotherNetworkBecomesConnectable) { |
TEST_F(WifiHotspotConnectorTest, TestConnect_CannotConnectToNetwork) { |
wifi_hotspot_connector_->ConnectToWifiHotspot( |
- std::string(kSsid), std::string(kPassword), |
+ std::string(kSsid), std::string(kPassword), kTetherNetworkGuid, |
base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
base::Unretained(this))); |
@@ -273,6 +314,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_CannotConnectToNetwork) { |
// Network becomes connectable. |
NotifyConnectable(test_network_connect_->last_service_path_created()); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid, kTetherNetworkGuid); |
EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); |
// Network connection does not occur. |
@@ -286,7 +328,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_CannotConnectToNetwork) { |
TEST_F(WifiHotspotConnectorTest, TestConnect_Success) { |
wifi_hotspot_connector_->ConnectToWifiHotspot( |
- std::string(kSsid), std::string(kPassword), |
+ std::string(kSsid), std::string(kPassword), kTetherNetworkGuid, |
base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
base::Unretained(this))); |
@@ -296,6 +338,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_Success) { |
// Network becomes connectable. |
NotifyConnectable(test_network_connect_->last_service_path_created()); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid, kTetherNetworkGuid); |
EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); |
EXPECT_EQ(0u, connection_callback_responses_.size()); |
@@ -308,7 +351,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_Success) { |
TEST_F(WifiHotspotConnectorTest, TestConnect_Success_EmptyPassword) { |
wifi_hotspot_connector_->ConnectToWifiHotspot( |
- std::string(kSsid), "", |
+ std::string(kSsid), "" /* password */, kTetherNetworkGuid, |
base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
base::Unretained(this))); |
@@ -317,6 +360,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_Success_EmptyPassword) { |
// Network becomes connectable. |
NotifyConnectable(test_network_connect_->last_service_path_created()); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid, kTetherNetworkGuid); |
EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); |
EXPECT_EQ(0u, connection_callback_responses_.size()); |
@@ -330,7 +374,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_Success_EmptyPassword) { |
TEST_F(WifiHotspotConnectorTest, |
TestConnect_SecondConnectionWhileWaitingForFirstToBecomeConnectable) { |
wifi_hotspot_connector_->ConnectToWifiHotspot( |
- "ssid1", "password1", |
+ "ssid1", "password1", "tetherNetworkGuid1", |
base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
base::Unretained(this))); |
@@ -343,7 +387,7 @@ TEST_F(WifiHotspotConnectorTest, |
// Before network becomes connectable, start the new connection. |
EXPECT_EQ(0u, connection_callback_responses_.size()); |
wifi_hotspot_connector_->ConnectToWifiHotspot( |
- "ssid2", "password2", |
+ "ssid2", "password2", kTetherNetworkGuid2, |
base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
base::Unretained(this))); |
@@ -361,6 +405,7 @@ TEST_F(WifiHotspotConnectorTest, |
// First network becomes connectable. |
NotifyConnectable(service_path1); |
+ VerifyWifiNetworkNotAssociated(wifi_guid1); |
// A connection should not have started to that GUID. |
EXPECT_EQ("", test_network_connect_->network_id_to_connect()); |
@@ -368,6 +413,60 @@ TEST_F(WifiHotspotConnectorTest, |
// Second network becomes connectable. |
NotifyConnectable(service_path2); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid2, kTetherNetworkGuid2); |
+ EXPECT_EQ(wifi_guid2, test_network_connect_->network_id_to_connect()); |
+ EXPECT_EQ(1u, connection_callback_responses_.size()); |
+ |
+ // Connection to network successful. |
+ NotifyConnected(service_path2); |
+ EXPECT_EQ(2u, connection_callback_responses_.size()); |
+ EXPECT_EQ(wifi_guid2, connection_callback_responses_[1]); |
+ VerifyTimerStopped(); |
+} |
+ |
+TEST_F(WifiHotspotConnectorTest, |
+ TestConnect_SecondConnectionWhileWaitingForFirstToConnect) { |
+ wifi_hotspot_connector_->ConnectToWifiHotspot( |
+ "ssid1", "password1", kTetherNetworkGuid, |
+ base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
+ base::Unretained(this))); |
+ |
+ std::string wifi_guid1 = VerifyLastConfiguration("ssid1", "password1"); |
+ EXPECT_FALSE(wifi_guid1.empty()); |
+ std::string service_path1 = |
+ test_network_connect_->last_service_path_created(); |
+ EXPECT_FALSE(service_path1.empty()); |
+ |
+ // First network becomes connectable. |
+ NotifyConnectable(service_path1); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid1, kTetherNetworkGuid); |
+ |
+ // After network becomes connectable, request a connection to second network. |
+ wifi_hotspot_connector_->ConnectToWifiHotspot( |
+ "ssid2", "password2", kTetherNetworkGuid2, |
+ base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
+ base::Unretained(this))); |
+ |
+ // Disasocciate first network from Tether network. |
+ network_state_handler()->DisassociateTetherNetworkStateWithWifiNetwork( |
+ kTetherNetworkGuid); |
+ VerifyWifiNetworkNotAssociated(wifi_guid1); |
+ |
+ // The original connection attempt should have gotten a "" response. |
+ EXPECT_EQ(1u, connection_callback_responses_.size()); |
+ EXPECT_EQ("", connection_callback_responses_[0]); |
+ |
+ std::string wifi_guid2 = VerifyLastConfiguration("ssid2", "password2"); |
+ EXPECT_FALSE(wifi_guid2.empty()); |
+ std::string service_path2 = |
+ test_network_connect_->last_service_path_created(); |
+ EXPECT_FALSE(service_path2.empty()); |
+ |
+ EXPECT_NE(service_path1, service_path2); |
+ |
+ // Second network becomes connectable. |
+ NotifyConnectable(service_path2); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid2, kTetherNetworkGuid2); |
EXPECT_EQ(wifi_guid2, test_network_connect_->network_id_to_connect()); |
EXPECT_EQ(1u, connection_callback_responses_.size()); |