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_disconnector.h" | 5 #include "chromeos/components/tether/tether_disconnector_impl.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" |
11 #include "chromeos/components/tether/fake_active_host.h" | 11 #include "chromeos/components/tether/fake_active_host.h" |
12 #include "chromeos/components/tether/fake_ble_connection_manager.h" | 12 #include "chromeos/components/tether/fake_ble_connection_manager.h" |
13 #include "chromeos/components/tether/fake_network_configuration_remover.h" | 13 #include "chromeos/components/tether/fake_network_configuration_remover.h" |
14 #include "chromeos/components/tether/fake_tether_host_fetcher.h" | 14 #include "chromeos/components/tether/fake_tether_host_fetcher.h" |
15 #include "chromeos/components/tether/fake_wifi_hotspot_connector.h" | 15 #include "chromeos/components/tether/fake_wifi_hotspot_connector.h" |
16 #include "chromeos/components/tether/mock_tether_host_response_recorder.h" | 16 #include "chromeos/components/tether/mock_tether_host_response_recorder.h" |
| 17 #include "chromeos/components/tether/pref_names.h" |
17 #include "chromeos/components/tether/tether_connector.h" | 18 #include "chromeos/components/tether/tether_connector.h" |
18 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
19 #include "chromeos/network/network_connection_handler.h" | 20 #include "chromeos/network/network_connection_handler.h" |
20 #include "chromeos/network/network_state.h" | 21 #include "chromeos/network/network_state.h" |
21 #include "chromeos/network/network_state_handler.h" | 22 #include "chromeos/network/network_state_handler.h" |
22 #include "chromeos/network/network_state_test.h" | 23 #include "chromeos/network/network_state_test.h" |
23 #include "components/cryptauth/remote_device.h" | 24 #include "components/cryptauth/remote_device.h" |
24 #include "components/cryptauth/remote_device_test_util.h" | 25 #include "components/cryptauth/remote_device_test_util.h" |
| 26 #include "components/prefs/testing_pref_service.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" | 29 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
28 | 30 |
29 namespace chromeos { | 31 namespace chromeos { |
30 | 32 |
31 namespace tether { | 33 namespace tether { |
32 | 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 const char kSuccessResult[] = "success"; | 37 const char kSuccessResult[] = "success"; |
36 | 38 |
37 const char kWifiNetworkGuid[] = "wifiNetworkGuid"; | 39 const char kWifiNetworkGuid[] = "wifiNetworkGuid"; |
38 | 40 |
39 std::string CreateConnectedWifiConfigurationJsonString() { | 41 std::string CreateConnectedWifiConfigurationJsonString( |
| 42 const std::string& wifi_network_guid) { |
40 std::stringstream ss; | 43 std::stringstream ss; |
41 ss << "{" | 44 ss << "{" |
42 << " \"GUID\": \"" << kWifiNetworkGuid << "\"," | 45 << " \"GUID\": \"" << wifi_network_guid << "\"," |
43 << " \"Type\": \"" << shill::kTypeWifi << "\"," | 46 << " \"Type\": \"" << shill::kTypeWifi << "\"," |
44 << " \"State\": \"" << shill::kStateOnline << "\"" | 47 << " \"State\": \"" << shill::kStateOnline << "\"" |
45 << "}"; | 48 << "}"; |
46 return ss.str(); | 49 return ss.str(); |
47 } | 50 } |
48 | 51 |
49 class TestNetworkConnectionHandler : public NetworkConnectionHandler { | 52 class TestNetworkConnectionHandler : public NetworkConnectionHandler { |
50 public: | 53 public: |
51 explicit TestNetworkConnectionHandler(base::Closure disconnect_callback) | 54 explicit TestNetworkConnectionHandler(base::Closure disconnect_callback) |
52 : disconnect_callback_(disconnect_callback) {} | 55 : disconnect_callback_(disconnect_callback) {} |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 created_operations_.push_back(operation); | 174 created_operations_.push_back(operation); |
172 return base::WrapUnique(operation); | 175 return base::WrapUnique(operation); |
173 } | 176 } |
174 | 177 |
175 private: | 178 private: |
176 std::vector<FakeDisconnectTetheringOperation*> created_operations_; | 179 std::vector<FakeDisconnectTetheringOperation*> created_operations_; |
177 }; | 180 }; |
178 | 181 |
179 } // namespace | 182 } // namespace |
180 | 183 |
181 class TetherDisconnectorTest : public NetworkStateTest { | 184 class TetherDisconnectorImplTest : public NetworkStateTest { |
182 public: | 185 public: |
183 TetherDisconnectorTest() | 186 TetherDisconnectorImplTest() |
184 : test_devices_(cryptauth::GenerateTestRemoteDevices(2u)) {} | 187 : test_devices_(cryptauth::GenerateTestRemoteDevices(2u)) {} |
185 ~TetherDisconnectorTest() override {} | 188 ~TetherDisconnectorImplTest() override {} |
186 | 189 |
187 void SetUp() override { | 190 void SetUp() override { |
188 DBusThreadManager::Initialize(); | 191 DBusThreadManager::Initialize(); |
189 NetworkStateTest::SetUp(); | 192 NetworkStateTest::SetUp(); |
190 | 193 |
| 194 should_run_disconnect_callbacks_synchronously_ = true; |
191 should_disconnect_successfully_ = true; | 195 should_disconnect_successfully_ = true; |
192 | 196 |
193 test_network_connection_handler_ = | 197 test_network_connection_handler_ = |
194 base::WrapUnique(new TestNetworkConnectionHandler(base::Bind( | 198 base::WrapUnique(new TestNetworkConnectionHandler(base::Bind( |
195 &TetherDisconnectorTest::OnNetworkConnectionManagerDisconnect, | 199 &TetherDisconnectorImplTest::OnNetworkConnectionManagerDisconnect, |
196 base::Unretained(this)))); | 200 base::Unretained(this)))); |
197 fake_active_host_ = base::MakeUnique<FakeActiveHost>(); | 201 fake_active_host_ = base::MakeUnique<FakeActiveHost>(); |
198 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); | 202 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); |
199 fake_network_configuration_remover_ = | 203 fake_network_configuration_remover_ = |
200 base::MakeUnique<FakeNetworkConfigurationRemover>(); | 204 base::MakeUnique<FakeNetworkConfigurationRemover>(); |
201 test_tether_connector_ = base::WrapUnique(new TestTetherConnector()); | 205 test_tether_connector_ = base::WrapUnique(new TestTetherConnector()); |
202 device_id_tether_network_guid_map_ = | 206 device_id_tether_network_guid_map_ = |
203 base::MakeUnique<DeviceIdTetherNetworkGuidMap>(); | 207 base::MakeUnique<DeviceIdTetherNetworkGuidMap>(); |
204 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>( | 208 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>( |
205 test_devices_, true /* synchronously_reply_with_results */); | 209 test_devices_, true /* synchronously_reply_with_results */); |
| 210 test_pref_service_ = base::MakeUnique<TestingPrefServiceSimple>(); |
206 | 211 |
207 fake_operation_factory_ = | 212 fake_operation_factory_ = |
208 base::WrapUnique(new FakeDisconnectTetheringOperationFactory()); | 213 base::WrapUnique(new FakeDisconnectTetheringOperationFactory()); |
209 DisconnectTetheringOperation::Factory::SetInstanceForTesting( | 214 DisconnectTetheringOperation::Factory::SetInstanceForTesting( |
210 fake_operation_factory_.get()); | 215 fake_operation_factory_.get()); |
211 | 216 |
212 SetUpTetherNetworks(); | 217 SetUpTetherNetworks(); |
213 | 218 |
214 tether_disconnector_ = base::MakeUnique<TetherDisconnector>( | 219 TetherDisconnectorImpl::RegisterPrefs(test_pref_service_->registry()); |
| 220 tether_disconnector_ = base::MakeUnique<TetherDisconnectorImpl>( |
215 test_network_connection_handler_.get(), network_state_handler(), | 221 test_network_connection_handler_.get(), network_state_handler(), |
216 fake_active_host_.get(), fake_ble_connection_manager_.get(), | 222 fake_active_host_.get(), fake_ble_connection_manager_.get(), |
217 fake_network_configuration_remover_.get(), test_tether_connector_.get(), | 223 fake_network_configuration_remover_.get(), test_tether_connector_.get(), |
218 device_id_tether_network_guid_map_.get(), | 224 device_id_tether_network_guid_map_.get(), |
219 fake_tether_host_fetcher_.get()); | 225 fake_tether_host_fetcher_.get(), test_pref_service_.get()); |
220 } | 226 } |
221 | 227 |
222 void TearDown() override { | 228 void TearDown() override { |
| 229 tether_disconnector_.reset(); |
223 ShutdownNetworkState(); | 230 ShutdownNetworkState(); |
224 NetworkStateTest::TearDown(); | 231 NetworkStateTest::TearDown(); |
225 DBusThreadManager::Shutdown(); | 232 DBusThreadManager::Shutdown(); |
226 } | 233 } |
227 | 234 |
228 std::string GetTetherNetworkGuid(const std::string& device_id) { | 235 std::string GetTetherNetworkGuid(const std::string& device_id) { |
229 return device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( | 236 return device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( |
230 device_id); | 237 device_id); |
231 } | 238 } |
232 | 239 |
233 void SetUpTetherNetworks() { | 240 void SetUpTetherNetworks() { |
234 network_state_handler()->SetTetherTechnologyState( | 241 network_state_handler()->SetTetherTechnologyState( |
235 NetworkStateHandler::TECHNOLOGY_ENABLED); | 242 NetworkStateHandler::TECHNOLOGY_ENABLED); |
236 | 243 |
237 // Add a tether network corresponding to both of the test devices. These | 244 // Add a tether network corresponding to both of the test devices. These |
238 // networks are expected to be added already before | 245 // networks are expected to be added already before |
239 // TetherDisconnector::DisconnectFromNetwork() is called. | 246 // TetherDisconnectorImpl::DisconnectFromNetwork() is called. |
240 network_state_handler()->AddTetherNetworkState( | 247 network_state_handler()->AddTetherNetworkState( |
241 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 248 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
242 "TetherNetworkName1", "TetherNetworkCarrier1", | 249 "TetherNetworkName1", "TetherNetworkCarrier1", |
243 85 /* battery_percentage */, 75 /* signal_strength */, | 250 85 /* battery_percentage */, 75 /* signal_strength */, |
244 true /* has_connected_to_host */); | 251 true /* has_connected_to_host */); |
245 network_state_handler()->AddTetherNetworkState( | 252 network_state_handler()->AddTetherNetworkState( |
246 GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), | 253 GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), |
247 "TetherNetworkName2", "TetherNetworkCarrier2", | 254 "TetherNetworkName2", "TetherNetworkCarrier2", |
248 90 /* battery_percentage */, 50 /* signal_strength */, | 255 90 /* battery_percentage */, 50 /* signal_strength */, |
249 true /* has_connected_to_host */); | 256 true /* has_connected_to_host */); |
250 } | 257 } |
251 | 258 |
252 void SimulateConnectionToWifiNetwork() { | 259 void SimulateConnectionToWifiNetwork() { |
253 wifi_service_path_ = | 260 wifi_service_path_ = ConfigureService( |
254 ConfigureService(CreateConnectedWifiConfigurationJsonString()); | 261 CreateConnectedWifiConfigurationJsonString(kWifiNetworkGuid)); |
255 EXPECT_FALSE(wifi_service_path_.empty()); | 262 EXPECT_FALSE(wifi_service_path_.empty()); |
256 } | 263 } |
257 | 264 |
258 void SuccessCallback() { disconnection_result_ = kSuccessResult; } | 265 void SuccessCallback() { disconnection_result_ = kSuccessResult; } |
259 | 266 |
260 void ErrorCallback(const std::string& error_name) { | 267 void ErrorCallback(const std::string& error_name) { |
261 disconnection_result_ = error_name; | 268 disconnection_result_ = error_name; |
262 } | 269 } |
263 | 270 |
264 void CallDisconnect(const std::string& tether_network_guid) { | 271 void CallDisconnect(const std::string& tether_network_guid) { |
265 tether_disconnector_->DisconnectFromNetwork( | 272 tether_disconnector_->DisconnectFromNetwork( |
266 tether_network_guid, | 273 tether_network_guid, |
267 base::Bind(&TetherDisconnectorTest::SuccessCallback, | 274 base::Bind(&TetherDisconnectorImplTest::SuccessCallback, |
268 base::Unretained(this)), | 275 base::Unretained(this)), |
269 base::Bind(&TetherDisconnectorTest::ErrorCallback, | 276 base::Bind(&TetherDisconnectorImplTest::ErrorCallback, |
270 base::Unretained(this))); | 277 base::Unretained(this))); |
271 } | 278 } |
272 | 279 |
273 // This function is called by | 280 // This function is called by |
274 // TestNetworkConnectionHandler::DisconnectFromNetwork(). | 281 // TestNetworkConnectionHandler::DisconnectFromNetwork(). |
275 void OnNetworkConnectionManagerDisconnect() { | 282 void OnNetworkConnectionManagerDisconnect() { |
276 EXPECT_EQ(wifi_service_path_, | 283 EXPECT_EQ(wifi_service_path_, |
277 test_network_connection_handler_->last_disconnect_service_path()); | 284 test_network_connection_handler_->last_disconnect_service_path()); |
278 | 285 |
279 if (should_disconnect_successfully_) { | 286 if (should_disconnect_successfully_) { |
280 SetServiceProperty(wifi_service_path_, shill::kStateProperty, | 287 SetServiceProperty(wifi_service_path_, shill::kStateProperty, |
281 base::Value(shill::kStateIdle)); | 288 base::Value(shill::kStateIdle)); |
| 289 } |
| 290 |
| 291 if (should_run_disconnect_callbacks_synchronously_) { |
| 292 // Before the callbacks are invoked, the network configuration should not |
| 293 // yet have been cleared, and the disconnecting GUID should still be in |
| 294 // prefs. |
| 295 EXPECT_TRUE( |
| 296 fake_network_configuration_remover_->last_removed_wifi_network_guid() |
| 297 .empty()); |
| 298 EXPECT_FALSE(GetDisconnectingWifiGuidFromPrefs().empty()); |
| 299 |
| 300 if (should_disconnect_successfully_) { |
| 301 EXPECT_FALSE( |
| 302 test_network_connection_handler_->last_disconnect_success_callback() |
| 303 .is_null()); |
| 304 test_network_connection_handler_->last_disconnect_success_callback() |
| 305 .Run(); |
| 306 } else { |
| 307 EXPECT_FALSE( |
| 308 test_network_connection_handler_->last_disconnect_error_callback() |
| 309 .is_null()); |
| 310 network_handler::RunErrorCallback( |
| 311 test_network_connection_handler_->last_disconnect_error_callback(), |
| 312 wifi_service_path_, |
| 313 NetworkConnectionHandler::kErrorDisconnectFailed, |
| 314 "" /* error_detail */); |
| 315 } |
| 316 |
| 317 // Now that the callbacks have been invoked, both the network |
| 318 // configuration and the disconnecting GUID should have cleared. |
282 EXPECT_FALSE( | 319 EXPECT_FALSE( |
283 test_network_connection_handler_->last_disconnect_success_callback() | 320 fake_network_configuration_remover_->last_removed_wifi_network_guid() |
284 .is_null()); | 321 .empty()); |
285 test_network_connection_handler_->last_disconnect_success_callback() | 322 EXPECT_TRUE(GetDisconnectingWifiGuidFromPrefs().empty()); |
286 .Run(); | |
287 } else { | |
288 EXPECT_FALSE( | |
289 test_network_connection_handler_->last_disconnect_error_callback() | |
290 .is_null()); | |
291 network_handler::RunErrorCallback( | |
292 test_network_connection_handler_->last_disconnect_error_callback(), | |
293 wifi_service_path_, NetworkConnectionHandler::kErrorDisconnectFailed, | |
294 "" /* error_detail */); | |
295 } | 323 } |
296 } | 324 } |
297 | 325 |
298 std::string GetResultAndReset() { | 326 std::string GetResultAndReset() { |
299 std::string result; | 327 std::string result; |
300 result.swap(disconnection_result_); | 328 result.swap(disconnection_result_); |
301 return result; | 329 return result; |
302 } | 330 } |
303 | 331 |
| 332 std::string GetDisconnectingWifiGuidFromPrefs() { |
| 333 return test_pref_service_->GetString(prefs::kDisconnectingWifiNetworkGuid); |
| 334 } |
| 335 |
304 const std::vector<cryptauth::RemoteDevice> test_devices_; | 336 const std::vector<cryptauth::RemoteDevice> test_devices_; |
305 const base::MessageLoop message_loop_; | 337 const base::MessageLoop message_loop_; |
306 | 338 |
307 std::unique_ptr<TestNetworkConnectionHandler> | 339 std::unique_ptr<TestNetworkConnectionHandler> |
308 test_network_connection_handler_; | 340 test_network_connection_handler_; |
309 std::unique_ptr<FakeActiveHost> fake_active_host_; | 341 std::unique_ptr<FakeActiveHost> fake_active_host_; |
310 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; | 342 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; |
311 std::unique_ptr<FakeNetworkConfigurationRemover> | 343 std::unique_ptr<FakeNetworkConfigurationRemover> |
312 fake_network_configuration_remover_; | 344 fake_network_configuration_remover_; |
313 std::unique_ptr<TestTetherConnector> test_tether_connector_; | 345 std::unique_ptr<TestTetherConnector> test_tether_connector_; |
314 // TODO(hansberry): Use a fake for this when a real mapping scheme is created. | 346 // TODO(hansberry): Use a fake for this when a real mapping scheme is created. |
315 std::unique_ptr<DeviceIdTetherNetworkGuidMap> | 347 std::unique_ptr<DeviceIdTetherNetworkGuidMap> |
316 device_id_tether_network_guid_map_; | 348 device_id_tether_network_guid_map_; |
317 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_; | 349 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_; |
| 350 std::unique_ptr<TestingPrefServiceSimple> test_pref_service_; |
318 | 351 |
319 std::unique_ptr<FakeDisconnectTetheringOperationFactory> | 352 std::unique_ptr<FakeDisconnectTetheringOperationFactory> |
320 fake_operation_factory_; | 353 fake_operation_factory_; |
321 | 354 |
322 std::string wifi_service_path_; | 355 std::string wifi_service_path_; |
323 std::string disconnection_result_; | 356 std::string disconnection_result_; |
| 357 bool should_run_disconnect_callbacks_synchronously_; |
324 bool should_disconnect_successfully_; | 358 bool should_disconnect_successfully_; |
325 | 359 |
326 std::unique_ptr<TetherDisconnector> tether_disconnector_; | 360 std::unique_ptr<TetherDisconnectorImpl> tether_disconnector_; |
327 | 361 |
328 private: | 362 private: |
329 DISALLOW_COPY_AND_ASSIGN(TetherDisconnectorTest); | 363 DISALLOW_COPY_AND_ASSIGN(TetherDisconnectorImplTest); |
330 }; | 364 }; |
331 | 365 |
332 TEST_F(TetherDisconnectorTest, DisconnectWhenAlreadyDisconnected) { | 366 TEST_F(TetherDisconnectorImplTest, DisconnectWhenAlreadyDisconnected) { |
333 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 367 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
334 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); | 368 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); |
335 | 369 |
336 // Should still be disconnected. | 370 // Should still be disconnected. |
337 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 371 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
338 fake_active_host_->GetActiveHostStatus()); | 372 fake_active_host_->GetActiveHostStatus()); |
339 } | 373 } |
340 | 374 |
341 TEST_F(TetherDisconnectorTest, DisconnectWhenOtherDeviceConnected) { | 375 TEST_F(TetherDisconnectorImplTest, DisconnectWhenOtherDeviceConnected) { |
| 376 wifi_service_path_ = ConfigureService( |
| 377 CreateConnectedWifiConfigurationJsonString("otherWifiNetworkGuid")); |
342 fake_active_host_->SetActiveHostConnected( | 378 fake_active_host_->SetActiveHostConnected( |
343 test_devices_[1].GetDeviceId(), | 379 test_devices_[1].GetDeviceId(), |
344 GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), | 380 GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), |
345 "otherWifiNetworkGuid"); | 381 "otherWifiNetworkGuid"); |
346 | 382 |
347 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 383 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
348 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); | 384 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); |
349 | 385 |
350 // Should still be connected to the other host. | 386 // Should still be connected to the other host. |
351 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTED, | 387 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTED, |
352 fake_active_host_->GetActiveHostStatus()); | 388 fake_active_host_->GetActiveHostStatus()); |
353 EXPECT_EQ(test_devices_[1].GetDeviceId(), | 389 EXPECT_EQ(test_devices_[1].GetDeviceId(), |
354 fake_active_host_->GetActiveHostDeviceId()); | 390 fake_active_host_->GetActiveHostDeviceId()); |
355 } | 391 } |
356 | 392 |
357 TEST_F(TetherDisconnectorTest, DisconnectWhenConnecting_CancelFails) { | 393 TEST_F(TetherDisconnectorImplTest, DisconnectWhenConnecting_CancelFails) { |
358 fake_active_host_->SetActiveHostConnecting( | 394 fake_active_host_->SetActiveHostConnecting( |
359 test_devices_[0].GetDeviceId(), | 395 test_devices_[0].GetDeviceId(), |
360 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 396 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
361 test_tether_connector_->set_should_cancel_successfully(false); | 397 test_tether_connector_->set_should_cancel_successfully(false); |
362 | 398 |
363 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 399 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
364 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, | 400 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, |
365 GetResultAndReset()); | 401 GetResultAndReset()); |
366 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 402 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
367 test_tether_connector_->last_canceled_tether_network_guid()); | 403 test_tether_connector_->last_canceled_tether_network_guid()); |
368 | 404 |
369 // Note: This test does not check the active host's status because it will be | 405 // Note: This test does not check the active host's status because it will be |
370 // changed by TetherConnector. | 406 // changed by TetherConnector. |
371 } | 407 } |
372 | 408 |
373 TEST_F(TetherDisconnectorTest, DisconnectWhenConnecting_CancelSucceeds) { | 409 TEST_F(TetherDisconnectorImplTest, DisconnectWhenConnecting_CancelSucceeds) { |
374 fake_active_host_->SetActiveHostConnecting( | 410 fake_active_host_->SetActiveHostConnecting( |
375 test_devices_[0].GetDeviceId(), | 411 test_devices_[0].GetDeviceId(), |
376 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 412 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
377 test_tether_connector_->set_should_cancel_successfully(true); | 413 test_tether_connector_->set_should_cancel_successfully(true); |
378 | 414 |
379 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 415 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
380 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 416 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
381 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 417 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
382 test_tether_connector_->last_canceled_tether_network_guid()); | 418 test_tether_connector_->last_canceled_tether_network_guid()); |
383 | 419 |
384 // Note: This test does not check the active host's status because it will be | 420 // Note: This test does not check the active host's status because it will be |
385 // changed by TetherConnector. | 421 // changed by TetherConnector. |
386 } | 422 } |
387 | 423 |
388 TEST_F(TetherDisconnectorTest, DisconnectWhenConnected_NotActuallyConnected) { | 424 TEST_F(TetherDisconnectorImplTest, |
| 425 DisconnectWhenConnected_NotActuallyConnected) { |
389 fake_active_host_->SetActiveHostConnected( | 426 fake_active_host_->SetActiveHostConnected( |
390 test_devices_[0].GetDeviceId(), | 427 test_devices_[0].GetDeviceId(), |
391 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 428 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
392 "nonExistentWifiGuid"); | 429 "nonExistentWifiGuid"); |
393 | 430 |
394 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 431 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
395 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, | 432 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, |
396 GetResultAndReset()); | 433 GetResultAndReset()); |
397 | 434 |
398 // Should be disconnected. | 435 // Should be disconnected. |
399 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 436 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
400 fake_active_host_->GetActiveHostStatus()); | 437 fake_active_host_->GetActiveHostStatus()); |
401 } | 438 } |
402 | 439 |
403 TEST_F(TetherDisconnectorTest, | 440 TEST_F(TetherDisconnectorImplTest, |
404 DisconnectWhenConnected_WifiConnectionFails_CannotFetchHost) { | 441 DisconnectWhenConnected_WifiDisconnectionFails_CannotFetchHost) { |
405 fake_active_host_->SetActiveHostConnected( | 442 fake_active_host_->SetActiveHostConnected( |
406 test_devices_[0].GetDeviceId(), | 443 test_devices_[0].GetDeviceId(), |
407 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); | 444 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); |
408 SimulateConnectionToWifiNetwork(); | 445 SimulateConnectionToWifiNetwork(); |
409 | 446 |
410 // Remove hosts from |fake_tether_host_fetcher_|; this will cause the fetcher | 447 // Remove hosts from |fake_tether_host_fetcher_|; this will cause the fetcher |
411 // to return a null RemoteDevice. | 448 // to return a null RemoteDevice. |
412 fake_tether_host_fetcher_->SetTetherHosts( | 449 fake_tether_host_fetcher_->SetTetherHosts( |
413 std::vector<cryptauth::RemoteDevice>()); | 450 std::vector<cryptauth::RemoteDevice>()); |
414 | 451 |
415 should_disconnect_successfully_ = false; | 452 should_disconnect_successfully_ = false; |
416 | 453 |
417 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 454 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
418 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, | 455 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, |
419 GetResultAndReset()); | 456 GetResultAndReset()); |
420 | 457 |
421 // The Wi-Fi network should still be connected since disconnection failed. | 458 // The Wi-Fi network should still be connected since disconnection failed. |
422 EXPECT_EQ( | 459 EXPECT_EQ( |
423 shill::kStateOnline, | 460 shill::kStateOnline, |
424 GetServiceStringProperty(wifi_service_path_, shill::kStateProperty)); | 461 GetServiceStringProperty(wifi_service_path_, shill::kStateProperty)); |
425 | 462 |
426 // Should not have created any operations since the fetch failed. | 463 // Should not have created any operations since the fetch failed. |
427 EXPECT_TRUE(fake_operation_factory_->created_operations().empty()); | 464 EXPECT_TRUE(fake_operation_factory_->created_operations().empty()); |
428 | 465 |
429 // Should be disconnected. | 466 // Should be disconnected. |
430 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 467 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
431 fake_active_host_->GetActiveHostStatus()); | 468 fake_active_host_->GetActiveHostStatus()); |
432 } | 469 } |
433 | 470 |
434 TEST_F(TetherDisconnectorTest, | 471 TEST_F(TetherDisconnectorImplTest, |
435 DisconnectWhenConnected_WifiConnectionSucceeds_CannotFetchHost) { | 472 DisconnectWhenConnected_WifiDisconnectionSucceeds_CannotFetchHost) { |
436 fake_active_host_->SetActiveHostConnected( | 473 fake_active_host_->SetActiveHostConnected( |
437 test_devices_[0].GetDeviceId(), | 474 test_devices_[0].GetDeviceId(), |
438 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); | 475 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); |
439 SimulateConnectionToWifiNetwork(); | 476 SimulateConnectionToWifiNetwork(); |
440 | 477 |
441 // Remove hosts from |fake_tether_host_fetcher_|; this will cause the fetcher | 478 // Remove hosts from |fake_tether_host_fetcher_|; this will cause the fetcher |
442 // to return a null RemoteDevice. | 479 // to return a null RemoteDevice. |
443 fake_tether_host_fetcher_->SetTetherHosts( | 480 fake_tether_host_fetcher_->SetTetherHosts( |
444 std::vector<cryptauth::RemoteDevice>()); | 481 std::vector<cryptauth::RemoteDevice>()); |
445 | 482 |
446 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 483 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
447 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 484 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
448 | 485 |
449 // The Wi-Fi network should be disconnected since disconnection failed. | 486 // The Wi-Fi network should be disconnected. |
450 EXPECT_EQ(shill::kStateIdle, GetServiceStringProperty(wifi_service_path_, | 487 EXPECT_EQ(shill::kStateIdle, GetServiceStringProperty(wifi_service_path_, |
451 shill::kStateProperty)); | 488 shill::kStateProperty)); |
452 | 489 |
453 // Should not have created any operations since the fetch failed. | 490 // Should not have created any operations since the fetch failed. |
454 EXPECT_TRUE(fake_operation_factory_->created_operations().empty()); | 491 EXPECT_TRUE(fake_operation_factory_->created_operations().empty()); |
455 | 492 |
456 // Should be disconnected. | 493 // Should be disconnected. |
457 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 494 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
458 fake_active_host_->GetActiveHostStatus()); | 495 fake_active_host_->GetActiveHostStatus()); |
459 } | 496 } |
460 | 497 |
461 TEST_F(TetherDisconnectorTest, | 498 TEST_F(TetherDisconnectorImplTest, |
462 DisconnectWhenConnected_WifiConnectionFails_OperationFails) { | 499 DisconnectWhenConnected_WifiDisconnectionFails_OperationFails) { |
463 fake_active_host_->SetActiveHostConnected( | 500 fake_active_host_->SetActiveHostConnected( |
464 test_devices_[0].GetDeviceId(), | 501 test_devices_[0].GetDeviceId(), |
465 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); | 502 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); |
466 SimulateConnectionToWifiNetwork(); | 503 SimulateConnectionToWifiNetwork(); |
467 | 504 |
468 should_disconnect_successfully_ = false; | 505 should_disconnect_successfully_ = false; |
469 | 506 |
470 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 507 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
471 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, | 508 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, |
472 GetResultAndReset()); | 509 GetResultAndReset()); |
473 | 510 |
474 // The Wi-Fi network should still be connected since disconnection failed. | 511 // The Wi-Fi network should still be connected since disconnection failed. |
475 EXPECT_EQ( | 512 EXPECT_EQ( |
476 shill::kStateOnline, | 513 shill::kStateOnline, |
477 GetServiceStringProperty(wifi_service_path_, shill::kStateProperty)); | 514 GetServiceStringProperty(wifi_service_path_, shill::kStateProperty)); |
478 | 515 |
479 // Fail the operation. | 516 // Fail the operation. |
480 ASSERT_EQ(1u, fake_operation_factory_->created_operations().size()); | 517 ASSERT_EQ(1u, fake_operation_factory_->created_operations().size()); |
481 EXPECT_EQ( | 518 EXPECT_EQ( |
482 test_devices_[0], | 519 test_devices_[0], |
483 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); | 520 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); |
484 fake_operation_factory_->created_operations()[0]->NotifyFinished( | 521 fake_operation_factory_->created_operations()[0]->NotifyFinished( |
485 false /* success */); | 522 false /* success */); |
486 | 523 |
487 // Should be disconnected. | 524 // Should be disconnected. |
488 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 525 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
489 fake_active_host_->GetActiveHostStatus()); | 526 fake_active_host_->GetActiveHostStatus()); |
490 } | 527 } |
491 | 528 |
492 TEST_F(TetherDisconnectorTest, | 529 TEST_F(TetherDisconnectorImplTest, |
493 DisconnectWhenConnected_WifiConnectionSucceeds_OperationFails) { | 530 DisconnectWhenConnected_WifiDisconnectionSucceeds_OperationFails) { |
494 fake_active_host_->SetActiveHostConnected( | 531 fake_active_host_->SetActiveHostConnected( |
495 test_devices_[0].GetDeviceId(), | 532 test_devices_[0].GetDeviceId(), |
496 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); | 533 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); |
497 SimulateConnectionToWifiNetwork(); | 534 SimulateConnectionToWifiNetwork(); |
498 | 535 |
499 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 536 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
500 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 537 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
501 | 538 |
502 // The Wi-Fi network should be disconnected since disconnection failed. | 539 // The Wi-Fi network should be disconnected. |
503 EXPECT_EQ(shill::kStateIdle, GetServiceStringProperty(wifi_service_path_, | 540 EXPECT_EQ(shill::kStateIdle, GetServiceStringProperty(wifi_service_path_, |
504 shill::kStateProperty)); | 541 shill::kStateProperty)); |
505 | 542 |
506 ASSERT_EQ(1u, fake_operation_factory_->created_operations().size()); | 543 ASSERT_EQ(1u, fake_operation_factory_->created_operations().size()); |
507 EXPECT_EQ( | 544 EXPECT_EQ( |
508 test_devices_[0], | 545 test_devices_[0], |
509 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); | 546 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); |
510 fake_operation_factory_->created_operations()[0]->NotifyFinished( | 547 fake_operation_factory_->created_operations()[0]->NotifyFinished( |
511 false /* success */); | 548 false /* success */); |
512 | 549 |
513 // Should be disconnected. | 550 // Should be disconnected. |
514 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 551 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
515 fake_active_host_->GetActiveHostStatus()); | 552 fake_active_host_->GetActiveHostStatus()); |
516 } | 553 } |
517 | 554 |
518 TEST_F(TetherDisconnectorTest, | 555 TEST_F(TetherDisconnectorImplTest, |
519 DisconnectWhenConnected_WifiConnectionFails_OperationSucceeds) { | 556 DisconnectWhenConnected_WifiDisconnectionFails_OperationSucceeds) { |
520 fake_active_host_->SetActiveHostConnected( | 557 fake_active_host_->SetActiveHostConnected( |
521 test_devices_[0].GetDeviceId(), | 558 test_devices_[0].GetDeviceId(), |
522 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); | 559 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); |
523 SimulateConnectionToWifiNetwork(); | 560 SimulateConnectionToWifiNetwork(); |
524 | 561 |
525 should_disconnect_successfully_ = false; | 562 should_disconnect_successfully_ = false; |
526 | 563 |
527 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 564 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
528 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, | 565 EXPECT_EQ(NetworkConnectionHandler::kErrorDisconnectFailed, |
529 GetResultAndReset()); | 566 GetResultAndReset()); |
530 | 567 |
531 // The Wi-Fi network should still be connected since disconnection failed. | 568 // The Wi-Fi network should still be connected since disconnection failed. |
532 EXPECT_EQ( | 569 EXPECT_EQ( |
533 shill::kStateOnline, | 570 shill::kStateOnline, |
534 GetServiceStringProperty(wifi_service_path_, shill::kStateProperty)); | 571 GetServiceStringProperty(wifi_service_path_, shill::kStateProperty)); |
535 | 572 |
536 // Fail the operation. | 573 // Fail the operation. |
537 ASSERT_EQ(1u, fake_operation_factory_->created_operations().size()); | 574 ASSERT_EQ(1u, fake_operation_factory_->created_operations().size()); |
538 EXPECT_EQ( | 575 EXPECT_EQ( |
539 test_devices_[0], | 576 test_devices_[0], |
540 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); | 577 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); |
541 fake_operation_factory_->created_operations()[0]->NotifyFinished( | 578 fake_operation_factory_->created_operations()[0]->NotifyFinished( |
542 true /* success */); | 579 true /* success */); |
543 | 580 |
544 // Should be disconnected. | 581 // Should be disconnected. |
545 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 582 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
546 fake_active_host_->GetActiveHostStatus()); | 583 fake_active_host_->GetActiveHostStatus()); |
547 } | 584 } |
548 | 585 |
549 TEST_F(TetherDisconnectorTest, | 586 TEST_F(TetherDisconnectorImplTest, |
550 DisconnectWhenConnected_WifiConnectionSucceeds_OperationSucceeds) { | 587 DisconnectWhenConnected_WifiDisconnectionSucceeds_OperationSucceeds) { |
551 fake_active_host_->SetActiveHostConnected( | 588 fake_active_host_->SetActiveHostConnected( |
552 test_devices_[0].GetDeviceId(), | 589 test_devices_[0].GetDeviceId(), |
553 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); | 590 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); |
554 SimulateConnectionToWifiNetwork(); | 591 SimulateConnectionToWifiNetwork(); |
555 | 592 |
556 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 593 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
557 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 594 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
558 | 595 |
559 // The Wi-Fi network should be disconnected since disconnection failed. | 596 // The Wi-Fi network should be disconnected. |
560 EXPECT_EQ(shill::kStateIdle, GetServiceStringProperty(wifi_service_path_, | 597 EXPECT_EQ(shill::kStateIdle, GetServiceStringProperty(wifi_service_path_, |
561 shill::kStateProperty)); | 598 shill::kStateProperty)); |
562 | 599 |
563 ASSERT_EQ(1u, fake_operation_factory_->created_operations().size()); | 600 ASSERT_EQ(1u, fake_operation_factory_->created_operations().size()); |
564 EXPECT_EQ( | 601 EXPECT_EQ( |
565 test_devices_[0], | 602 test_devices_[0], |
566 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); | 603 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); |
567 fake_operation_factory_->created_operations()[0]->NotifyFinished( | 604 fake_operation_factory_->created_operations()[0]->NotifyFinished( |
568 true /* success */); | 605 true /* success */); |
569 | 606 |
570 // Should be disconnected. | 607 // Should be disconnected. |
571 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 608 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
572 fake_active_host_->GetActiveHostStatus()); | 609 fake_active_host_->GetActiveHostStatus()); |
573 } | 610 } |
574 | 611 |
575 TEST_F(TetherDisconnectorTest, | 612 TEST_F(TetherDisconnectorImplTest, |
576 DisconnectWhenConnected_DestroyBeforeOperationComplete) { | 613 DisconnectWhenConnected_DestroyBeforeOperationComplete) { |
577 fake_active_host_->SetActiveHostConnected( | 614 fake_active_host_->SetActiveHostConnected( |
578 test_devices_[0].GetDeviceId(), | 615 test_devices_[0].GetDeviceId(), |
579 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); | 616 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); |
580 SimulateConnectionToWifiNetwork(); | 617 SimulateConnectionToWifiNetwork(); |
581 | 618 |
582 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 619 CallDisconnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
583 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 620 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
584 | 621 |
585 // Stop the test here, before the operation responds in any way. This test | 622 // Stop the test here, before the operation responds in any way. This test |
586 // ensures that TetherDisconnector properly removes existing listeners if it | 623 // ensures that TetherDisconnectorImpl properly removes existing listeners |
587 // is destroyed while there are still active operations. | 624 // if it is destroyed while there are still active operations. |
| 625 } |
| 626 |
| 627 TEST_F(TetherDisconnectorImplTest, DisconnectsWhenDestructorCalled) { |
| 628 // For this test, do not synchronously reply with results. This echos what |
| 629 // actually happens when a TetherDisconnectorImpl is deleted. |
| 630 should_run_disconnect_callbacks_synchronously_ = false; |
| 631 fake_tether_host_fetcher_->set_synchronously_reply_with_results(false); |
| 632 |
| 633 fake_active_host_->SetActiveHostConnected( |
| 634 test_devices_[0].GetDeviceId(), |
| 635 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), kWifiNetworkGuid); |
| 636 SimulateConnectionToWifiNetwork(); |
| 637 |
| 638 // Destroy the object, which should result in a disconnection. |
| 639 tether_disconnector_.reset(); |
| 640 |
| 641 // Because the object is destroyed before the disconnection callback occurs, |
| 642 // no result should have been able to be set. |
| 643 EXPECT_EQ(std::string(), GetResultAndReset()); |
| 644 |
| 645 // The Wi-Fi network should be disconnected. |
| 646 EXPECT_EQ(shill::kStateIdle, GetServiceStringProperty(wifi_service_path_, |
| 647 shill::kStateProperty)); |
| 648 |
| 649 // Because the fetcher does not synchronously reply with results, |
| 650 // |tether_disconnector_| should be deleted before any operations can be |
| 651 // created. |
| 652 EXPECT_TRUE(fake_operation_factory_->created_operations().empty()); |
| 653 |
| 654 // Should be disconnected. |
| 655 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
| 656 fake_active_host_->GetActiveHostStatus()); |
| 657 |
| 658 // Because the disconnection did not fully complete, the configuration should |
| 659 // not yet have been cleaned up, and prefs should still contain the |
| 660 // disconnecting Wi-Fi GUID. |
| 661 EXPECT_TRUE( |
| 662 fake_network_configuration_remover_->last_removed_wifi_network_guid() |
| 663 .empty()); |
| 664 EXPECT_EQ(kWifiNetworkGuid, GetDisconnectingWifiGuidFromPrefs()); |
| 665 |
| 666 // Now, create a new TetherDisconnectorImpl instance. This should clean up |
| 667 // the previous disconnection attempt. |
| 668 tether_disconnector_ = base::MakeUnique<TetherDisconnectorImpl>( |
| 669 test_network_connection_handler_.get(), network_state_handler(), |
| 670 fake_active_host_.get(), fake_ble_connection_manager_.get(), |
| 671 fake_network_configuration_remover_.get(), test_tether_connector_.get(), |
| 672 device_id_tether_network_guid_map_.get(), fake_tether_host_fetcher_.get(), |
| 673 test_pref_service_.get()); |
| 674 EXPECT_EQ( |
| 675 kWifiNetworkGuid, |
| 676 fake_network_configuration_remover_->last_removed_wifi_network_guid()); |
| 677 EXPECT_TRUE(GetDisconnectingWifiGuidFromPrefs().empty()); |
588 } | 678 } |
589 | 679 |
590 } // namespace tether | 680 } // namespace tether |
591 | 681 |
592 } // namespace chromeos | 682 } // namespace chromeos |
OLD | NEW |