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..31221f7a15653dbb183be13f33ab69561d2e62ca 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 */, false /* has_connected_to_host */); |
| + |
| + network_state_handler()->AddTetherNetworkState( |
| + kTetherNetworkGuid2, "tetherNetworkName2" /* name */, |
| + "tetherNetworkCarrier2" /* carrier */, 100 /* full battery */, |
| + 100 /* full signal strength */, false /* has_connected_to_host */); |
| + |
| wifi_hotspot_connector_ = base::WrapUnique(new WifiHotspotConnector( |
| network_state_handler(), test_network_connect_.get())); |
| @@ -201,6 +217,27 @@ 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 VerifyNetworkNotAssociated(const std::string& guid) { |
| + const NetworkState* network_state = |
| + network_state_handler()->GetNetworkStateFromGuid(guid); |
| + ASSERT_TRUE(network_state); |
| + // EXPECT_TRUE(network_state->tether_guid().empty()); |
|
Kyle Horimoto
2017/05/03 01:53:34
Use this, delete the line below.
lesliewatkins
2017/05/03 22:00:24
Done.
|
| + EXPECT_EQ(network_state->tether_guid(), std::string()); |
| + } |
| + |
| void WifiConnectionCallback(const std::string& wifi_guid) { |
| connection_callback_responses_.push_back(wifi_guid); |
| } |
| @@ -221,7 +258,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 +278,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 +289,11 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_AnotherNetworkBecomesConnectable) { |
| // Another network becomes connectable. This should not cause the connection |
| // to start. |
| NotifyConnectable(other_wifi_service_path_); |
| + VerifyNetworkNotAssociated(wifi_guid); |
| + std::string other_wifi_guid = network_state_handler() |
| + ->GetNetworkState(other_wifi_service_path_) |
| + ->guid(); |
| + VerifyNetworkNotAssociated(other_wifi_guid); |
| EXPECT_EQ("", test_network_connect_->network_id_to_connect()); |
| // Timeout timer fires. |
| @@ -263,7 +305,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 +315,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 +329,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 +339,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 +352,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 +361,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 +375,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 +388,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 +406,7 @@ TEST_F(WifiHotspotConnectorTest, |
| // First network becomes connectable. |
| NotifyConnectable(service_path1); |
| + VerifyNetworkNotAssociated(wifi_guid1); |
|
Kyle Horimoto
2017/05/03 01:53:33
You can move this to just below the "EXPECT_FALSE(
lesliewatkins
2017/05/03 22:00:24
Done.
|
| // A connection should not have started to that GUID. |
| EXPECT_EQ("", test_network_connect_->network_id_to_connect()); |
| @@ -368,6 +414,59 @@ 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))); |
| + |
| + // Disassocciate first network from Tether network. |
|
Kyle Horimoto
2017/05/03 01:53:33
nit: The way you word this makes it seem like the
lesliewatkins
2017/05/03 22:00:24
Done.
|
| + VerifyNetworkNotAssociated(kTetherNetworkGuid); |
| + VerifyNetworkNotAssociated(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()); |