OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/components/tether/tether_connector.h" | 5 #include "chromeos/components/tether/tether_connector.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "chromeos/components/tether/connect_tethering_operation.h" | 9 #include "chromeos/components/tether/connect_tethering_operation.h" |
10 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" | 10 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 "TetherNetworkName2", "TetherNetworkCarrier2", | 190 "TetherNetworkName2", "TetherNetworkCarrier2", |
191 90 /* battery_percentage */, 50 /* signal_strength */, | 191 90 /* battery_percentage */, 50 /* signal_strength */, |
192 true /* has_connected_to_host */); | 192 true /* has_connected_to_host */); |
193 } | 193 } |
194 | 194 |
195 void SuccessfullyJoinWifiNetwork() { | 195 void SuccessfullyJoinWifiNetwork() { |
196 ConfigureService(CreateWifiConfigurationJsonString()); | 196 ConfigureService(CreateWifiConfigurationJsonString()); |
197 fake_wifi_hotspot_connector_->CallMostRecentCallback(kWifiNetworkGuid); | 197 fake_wifi_hotspot_connector_->CallMostRecentCallback(kWifiNetworkGuid); |
198 } | 198 } |
199 | 199 |
200 void VerifyTetherAndWifiNetworkAssociation( | |
201 const std::string& tether_network_guid) { | |
202 const NetworkState* tether_network_state = | |
203 network_state_handler()->GetNetworkStateFromGuid(tether_network_guid); | |
204 EXPECT_TRUE(tether_network_state); | |
205 EXPECT_EQ(kWifiNetworkGuid, tether_network_state->tether_guid()); | |
206 | |
207 const NetworkState* wifi_network_state = | |
208 network_state_handler()->GetNetworkStateFromGuid(kWifiNetworkGuid); | |
209 EXPECT_TRUE(wifi_network_state); | |
210 EXPECT_EQ(tether_network_guid, wifi_network_state->tether_guid()); | |
211 } | |
212 | |
213 void SuccessCallback() { result_ = kSuccessResult; } | 200 void SuccessCallback() { result_ = kSuccessResult; } |
214 | 201 |
215 void ErrorCallback(const std::string& error_name, | 202 void ErrorCallback(const std::string& error_name, |
216 std::unique_ptr<base::DictionaryValue> error_data) { | 203 std::unique_ptr<base::DictionaryValue> error_data) { |
217 result_ = error_name; | 204 result_ = error_name; |
218 } | 205 } |
219 | 206 |
220 void CallTetherDelegate(const std::string& tether_network_guid) { | 207 void CallTetherDelegate(const std::string& tether_network_guid) { |
221 test_network_connection_handler_->CallTetherDelegate( | 208 test_network_connection_handler_->CallTetherDelegate( |
222 tether_network_guid, | 209 tether_network_guid, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 340 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
354 fake_active_host_->GetActiveHostStatus()); | 341 fake_active_host_->GetActiveHostStatus()); |
355 | 342 |
356 // |fake_wifi_hotspot_connector_| should have received the SSID and password | 343 // |fake_wifi_hotspot_connector_| should have received the SSID and password |
357 // above. Verify this, then return the GUID corresponding to the connected | 344 // above. Verify this, then return the GUID corresponding to the connected |
358 // Wi-Fi network. | 345 // Wi-Fi network. |
359 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); | 346 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); |
360 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); | 347 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); |
361 SuccessfullyJoinWifiNetwork(); | 348 SuccessfullyJoinWifiNetwork(); |
362 | 349 |
363 // The active host should now be connected, and the tether and Wi-Fi networks | 350 // The active host should now be connected. |
364 // should be associated. | |
365 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTED, | 351 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTED, |
366 fake_active_host_->GetActiveHostStatus()); | 352 fake_active_host_->GetActiveHostStatus()); |
367 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 353 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
368 fake_active_host_->GetActiveHostDeviceId()); | 354 fake_active_host_->GetActiveHostDeviceId()); |
369 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 355 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
370 fake_active_host_->GetTetherNetworkGuid()); | 356 fake_active_host_->GetTetherNetworkGuid()); |
371 EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid()); | 357 EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid()); |
372 VerifyTetherAndWifiNetworkAssociation( | 358 |
373 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | |
374 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 359 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
375 } | 360 } |
376 | 361 |
377 TEST_F(TetherConnectorTest, | 362 TEST_F(TetherConnectorTest, |
378 TestNewConnectionAttemptDuringFetch_DifferentDevice) { | 363 TestNewConnectionAttemptDuringFetch_DifferentDevice) { |
379 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 364 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
380 | 365 |
381 // Instead of invoking the pending callbacks on |fake_tether_host_fetcher_|, | 366 // Instead of invoking the pending callbacks on |fake_tether_host_fetcher_|, |
382 // attempt another connection attempt, this time to another device. | 367 // attempt another connection attempt, this time to another device. |
383 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); | 368 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 EXPECT_EQ(test_devices_[1].GetDeviceId(), | 463 EXPECT_EQ(test_devices_[1].GetDeviceId(), |
479 fake_active_host_->GetActiveHostDeviceId()); | 464 fake_active_host_->GetActiveHostDeviceId()); |
480 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), | 465 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), |
481 fake_active_host_->GetTetherNetworkGuid()); | 466 fake_active_host_->GetTetherNetworkGuid()); |
482 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 467 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
483 } | 468 } |
484 | 469 |
485 } // namespace tether | 470 } // namespace tether |
486 | 471 |
487 } // namespace chromeos | 472 } // namespace chromeos |
OLD | NEW |