Chromium Code Reviews| 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..ab257c3cc0cc42967ca8dd2c8d454584afeae991 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,21 @@ 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, "" /* name */, "" /* carrier */, |
|
Kyle Horimoto
2017/04/28 22:07:29
nit: Pass a name like "tetherNetworkName1" instead
lesliewatkins
2017/04/29 00:57:54
Done.
|
| + 100 /* full battery */, 100 /* full signal strength */); |
| + |
| + network_state_handler()->AddTetherNetworkState( |
| + kTetherNetworkGuid2, "" /* name */, "" /* carrier */, |
| + 100 /* full battery */, 100 /* full signal strength */); |
| + |
| wifi_hotspot_connector_ = base::WrapUnique(new WifiHotspotConnector( |
| network_state_handler(), test_network_connect_.get())); |
| @@ -201,6 +215,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 +255,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 +275,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 +286,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 +302,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 +312,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 +326,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 +336,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 +349,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_Success) { |
| TEST_F(WifiHotspotConnectorTest, TestConnect_Success_EmptyPassword) { |
| wifi_hotspot_connector_->ConnectToWifiHotspot( |
| - std::string(kSsid), "", |
| + std::string(kSsid), "", kTetherNetworkGuid, |
|
Kyle Horimoto
2017/04/28 22:07:29
nit: Add /* password */ after "".
lesliewatkins
2017/04/29 00:57:54
Done.
|
| base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, |
| base::Unretained(this))); |
| @@ -317,6 +358,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 +372,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 +385,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 +403,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,9 +411,58 @@ 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))); |
| + |
| + 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()); |
| + // The original connection attempt should have gotten a "" response. |
|
Kyle Horimoto
2017/04/28 22:07:29
Move this up to right after the second ConnectToWi
lesliewatkins
2017/04/29 00:57:54
Done.
|
| + EXPECT_EQ(1u, connection_callback_responses_.size()); |
| + EXPECT_EQ("", connection_callback_responses_[0]); |
| + |
| // Connection to network successful. |
| NotifyConnected(service_path2); |
| EXPECT_EQ(2u, connection_callback_responses_.size()); |