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..8a33beab6525b4365a164087de6abc0c8f75b90c 100644 |
--- a/chromeos/components/tether/wifi_hotspot_connector_unittest.cc |
+++ b/chromeos/components/tether/wifi_hotspot_connector_unittest.cc |
@@ -13,6 +13,7 @@ |
#include "base/test/scoped_task_environment.h" |
#include "base/timer/mock_timer.h" |
#include "base/values.h" |
+#include "chromeos/components/tether/fake_active_host.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "chromeos/dbus/shill_device_client.h" |
#include "chromeos/dbus/shill_service_client.h" |
@@ -36,6 +37,9 @@ const char kPassword[] = "password"; |
const char kOtherWifiServiceGuid[] = "otherWifiServiceGuid"; |
+const char kDeviceId[] = "deviceId"; |
+const char kTetherNetworkGuid[] = "tetherNetworkGuid"; |
+ |
std::string CreateConfigurationJsonString(const std::string& guid) { |
std::stringstream ss; |
ss << "{" |
@@ -116,12 +120,25 @@ 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)); |
+ fake_active_host_ = base::MakeUnique<FakeActiveHost>(); |
+ |
+ network_state_handler()->AddTetherNetworkState( |
+ kTetherNetworkGuid, "", /* name */ |
Kyle Horimoto
2017/04/27 01:28:08
Add the comment before the comma: "" /* name */,
lesliewatkins
2017/04/28 21:30:43
Done.
I believe 'git cl format' is the culprit fo
|
+ "", /* carrier */ |
+ 100, /* full battery */ |
+ 100 /* full signal strength */); |
+ |
+ fake_active_host_->SetActiveHostConnecting(kDeviceId, kTetherNetworkGuid); |
wifi_hotspot_connector_ = base::WrapUnique(new WifiHotspotConnector( |
- network_state_handler(), test_network_connect_.get())); |
+ network_state_handler(), test_network_connect_.get(), |
+ fake_active_host_.get())); |
mock_timer_ = new base::MockTimer(true /* retain_user_task */, |
false /* is_repeating */); |
@@ -201,6 +218,27 @@ class WifiHotspotConnectorTest : public NetworkStateTest { |
return wifi_guid; |
} |
+ void VerifyTetherAndWifiNetworkAssociation(const std::string& wifi_guid) { |
+ const NetworkState* wifi_network_state = |
+ network_state_handler()->GetNetworkStateFromGuid(wifi_guid); |
+ ASSERT_TRUE(wifi_network_state); |
+ EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(), |
+ wifi_network_state->tether_guid()); |
+ |
+ const NetworkState* tether_network_state = |
+ network_state_handler()->GetNetworkStateFromGuid( |
+ fake_active_host_->GetTetherNetworkGuid()); |
Kyle Horimoto
2017/04/27 01:28:08
Note: To get the tether GUID once you change from
lesliewatkins
2017/04/28 21:30:43
I ended up added a second parameter to VerifyTethe
|
+ ASSERT_TRUE(tether_network_state); |
+ EXPECT_EQ(wifi_guid, tether_network_state->tether_guid()); |
+ } |
+ |
+ void VerifyTetherAndWifiNetworkNotAssociated(const std::string& wifi_guid) { |
Kyle Horimoto
2017/04/27 01:28:08
You aren't verifying anything about a tether netwo
lesliewatkins
2017/04/28 21:30:43
Done.
|
+ 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); |
} |
@@ -214,6 +252,7 @@ class WifiHotspotConnectorTest : public NetworkStateTest { |
std::unique_ptr<TestNetworkConnect> test_network_connect_; |
std::unique_ptr<WifiHotspotConnector> wifi_hotspot_connector_; |
+ std::unique_ptr<FakeActiveHost> fake_active_host_; |
private: |
DISALLOW_COPY_AND_ASSIGN(WifiHotspotConnectorTest); |
@@ -252,6 +291,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_AnotherNetworkBecomesConnectable) { |
// Another network becomes connectable. This should not cause the connection |
// to start. |
NotifyConnectable(other_wifi_service_path_); |
+ VerifyTetherAndWifiNetworkNotAssociated(wifi_guid); |
Kyle Horimoto
2017/04/27 01:28:08
Also verify that the network associated with other
lesliewatkins
2017/04/28 21:30:43
Done.
|
EXPECT_EQ("", test_network_connect_->network_id_to_connect()); |
// Timeout timer fires. |
@@ -273,6 +313,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_CannotConnectToNetwork) { |
// Network becomes connectable. |
NotifyConnectable(test_network_connect_->last_service_path_created()); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid); |
EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); |
// Network connection does not occur. |
@@ -296,6 +337,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_Success) { |
// Network becomes connectable. |
NotifyConnectable(test_network_connect_->last_service_path_created()); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid); |
EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); |
EXPECT_EQ(0u, connection_callback_responses_.size()); |
@@ -317,6 +359,7 @@ TEST_F(WifiHotspotConnectorTest, TestConnect_Success_EmptyPassword) { |
// Network becomes connectable. |
NotifyConnectable(test_network_connect_->last_service_path_created()); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid); |
EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); |
EXPECT_EQ(0u, connection_callback_responses_.size()); |
@@ -361,6 +404,7 @@ TEST_F(WifiHotspotConnectorTest, |
// First network becomes connectable. |
NotifyConnectable(service_path1); |
+ VerifyTetherAndWifiNetworkNotAssociated(wifi_guid1); |
// A connection should not have started to that GUID. |
EXPECT_EQ("", test_network_connect_->network_id_to_connect()); |
@@ -368,6 +412,7 @@ TEST_F(WifiHotspotConnectorTest, |
// Second network becomes connectable. |
NotifyConnectable(service_path2); |
+ VerifyTetherAndWifiNetworkAssociation(wifi_guid2); |
EXPECT_EQ(wifi_guid2, test_network_connect_->network_id_to_connect()); |
EXPECT_EQ(1u, connection_callback_responses_.size()); |