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" |
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_host_scan_cache.h" | 13 #include "chromeos/components/tether/fake_host_scan_cache.h" |
14 #include "chromeos/components/tether/fake_notification_presenter.h" | 14 #include "chromeos/components/tether/fake_notification_presenter.h" |
15 #include "chromeos/components/tether/fake_tether_host_fetcher.h" | 15 #include "chromeos/components/tether/fake_tether_host_fetcher.h" |
16 #include "chromeos/components/tether/fake_wifi_hotspot_connector.h" | 16 #include "chromeos/components/tether/fake_wifi_hotspot_connector.h" |
| 17 #include "chromeos/components/tether/mock_host_connection_metrics_logger.h" |
17 #include "chromeos/components/tether/mock_tether_host_response_recorder.h" | 18 #include "chromeos/components/tether/mock_tether_host_response_recorder.h" |
18 #include "chromeos/components/tether/tether_connector.h" | 19 #include "chromeos/components/tether/tether_connector.h" |
19 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
20 #include "chromeos/network/network_connection_handler.h" | 21 #include "chromeos/network/network_connection_handler.h" |
21 #include "chromeos/network/network_state.h" | 22 #include "chromeos/network/network_state.h" |
22 #include "chromeos/network/network_state_handler.h" | 23 #include "chromeos/network/network_state_handler.h" |
23 #include "chromeos/network/network_state_test.h" | 24 #include "chromeos/network/network_state_test.h" |
24 #include "components/cryptauth/remote_device.h" | 25 #include "components/cryptauth/remote_device.h" |
25 #include "components/cryptauth/remote_device_test_util.h" | 26 #include "components/cryptauth/remote_device_test_util.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" | 29 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
29 | 30 |
| 31 using testing::StrictMock; |
| 32 |
30 namespace chromeos { | 33 namespace chromeos { |
31 | 34 |
32 namespace tether { | 35 namespace tether { |
33 | 36 |
34 namespace { | 37 namespace { |
35 | 38 |
36 const char kSuccessResult[] = "success"; | 39 const char kSuccessResult[] = "success"; |
37 | 40 |
38 const char kSsid[] = "ssid"; | 41 const char kSsid[] = "ssid"; |
39 const char kPassword[] = "password"; | 42 const char kPassword[] = "password"; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>( | 142 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>( |
140 test_devices_, false /* synchronously_reply_with_results */); | 143 test_devices_, false /* synchronously_reply_with_results */); |
141 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); | 144 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); |
142 mock_tether_host_response_recorder_ = | 145 mock_tether_host_response_recorder_ = |
143 base::MakeUnique<MockTetherHostResponseRecorder>(); | 146 base::MakeUnique<MockTetherHostResponseRecorder>(); |
144 device_id_tether_network_guid_map_ = | 147 device_id_tether_network_guid_map_ = |
145 base::MakeUnique<DeviceIdTetherNetworkGuidMap>(); | 148 base::MakeUnique<DeviceIdTetherNetworkGuidMap>(); |
146 fake_host_scan_cache_ = base::MakeUnique<FakeHostScanCache>(); | 149 fake_host_scan_cache_ = base::MakeUnique<FakeHostScanCache>(); |
147 fake_notification_presenter_ = | 150 fake_notification_presenter_ = |
148 base::MakeUnique<FakeNotificationPresenter>(); | 151 base::MakeUnique<FakeNotificationPresenter>(); |
| 152 mock_host_connection_metrics_logger_ = |
| 153 base::WrapUnique(new StrictMock<MockHostConnectionMetricsLogger>); |
149 | 154 |
150 result_.clear(); | 155 result_.clear(); |
151 | 156 |
152 tether_connector_ = base::WrapUnique(new TetherConnector( | 157 tether_connector_ = base::WrapUnique(new TetherConnector( |
153 network_state_handler(), fake_wifi_hotspot_connector_.get(), | 158 network_state_handler(), fake_wifi_hotspot_connector_.get(), |
154 fake_active_host_.get(), fake_tether_host_fetcher_.get(), | 159 fake_active_host_.get(), fake_tether_host_fetcher_.get(), |
155 fake_ble_connection_manager_.get(), | 160 fake_ble_connection_manager_.get(), |
156 mock_tether_host_response_recorder_.get(), | 161 mock_tether_host_response_recorder_.get(), |
157 device_id_tether_network_guid_map_.get(), fake_host_scan_cache_.get(), | 162 device_id_tether_network_guid_map_.get(), fake_host_scan_cache_.get(), |
158 fake_notification_presenter_.get())); | 163 fake_notification_presenter_.get(), |
| 164 mock_host_connection_metrics_logger_.get())); |
159 | 165 |
160 SetUpTetherNetworks(); | 166 SetUpTetherNetworks(); |
161 } | 167 } |
162 | 168 |
163 void TearDown() override { | 169 void TearDown() override { |
164 // Must delete |fake_wifi_hotspot_connector_| before NetworkStateHandler is | 170 // Must delete |fake_wifi_hotspot_connector_| before NetworkStateHandler is |
165 // destroyed to ensure that NetworkStateHandler has zero observers by the | 171 // destroyed to ensure that NetworkStateHandler has zero observers by the |
166 // time it reaches its destructor. | 172 // time it reaches its destructor. |
167 fake_wifi_hotspot_connector_.reset(); | 173 fake_wifi_hotspot_connector_.reset(); |
168 | 174 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 230 |
225 void CallConnect(const std::string& tether_network_guid) { | 231 void CallConnect(const std::string& tether_network_guid) { |
226 tether_connector_->ConnectToNetwork( | 232 tether_connector_->ConnectToNetwork( |
227 tether_network_guid, | 233 tether_network_guid, |
228 base::Bind(&TetherConnectorTest::SuccessCallback, | 234 base::Bind(&TetherConnectorTest::SuccessCallback, |
229 base::Unretained(this)), | 235 base::Unretained(this)), |
230 base::Bind(&TetherConnectorTest::ErrorCallback, | 236 base::Bind(&TetherConnectorTest::ErrorCallback, |
231 base::Unretained(this))); | 237 base::Unretained(this))); |
232 } | 238 } |
233 | 239 |
| 240 void VerifyConnectTetheringOperationFails( |
| 241 ConnectTetheringResponse_ResponseCode response_code, |
| 242 bool setup_required, |
| 243 HostConnectionMetricsLogger::ConnectionToHostResult expected_event_type) { |
| 244 EXPECT_CALL(*mock_host_connection_metrics_logger_, |
| 245 RecordConnectionToHostResult(expected_event_type)); |
| 246 |
| 247 EXPECT_FALSE( |
| 248 fake_notification_presenter_->is_setup_required_notification_shown()); |
| 249 |
| 250 // test_devices_[0] does not require first-time setup, but test_devices_[1] |
| 251 // does require first-time setup. See SetUpTetherNetworks(). |
| 252 cryptauth::RemoteDevice test_device = test_devices_[setup_required ? 1 : 0]; |
| 253 |
| 254 CallConnect(GetTetherNetworkGuid(test_device.GetDeviceId())); |
| 255 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
| 256 fake_active_host_->GetActiveHostStatus()); |
| 257 EXPECT_EQ(test_device.GetDeviceId(), |
| 258 fake_active_host_->GetActiveHostDeviceId()); |
| 259 EXPECT_EQ(GetTetherNetworkGuid(test_device.GetDeviceId()), |
| 260 fake_active_host_->GetTetherNetworkGuid()); |
| 261 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
| 262 |
| 263 EXPECT_EQ( |
| 264 setup_required, |
| 265 fake_notification_presenter_->is_setup_required_notification_shown()); |
| 266 |
| 267 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
| 268 |
| 269 EXPECT_EQ( |
| 270 setup_required, |
| 271 fake_notification_presenter_->is_setup_required_notification_shown()); |
| 272 EXPECT_EQ( |
| 273 setup_required, |
| 274 fake_operation_factory_->created_operations()[0]->setup_required()); |
| 275 |
| 276 // Simulate a failed connection attempt (either the host cannot provide |
| 277 // tethering at this time or a timeout occurs). |
| 278 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
| 279 fake_operation_factory_->created_operations()[0]->SendFailedResponse( |
| 280 response_code); |
| 281 |
| 282 EXPECT_FALSE( |
| 283 fake_notification_presenter_->is_setup_required_notification_shown()); |
| 284 |
| 285 // The failure should have resulted in the host being disconnected. |
| 286 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
| 287 fake_active_host_->GetActiveHostStatus()); |
| 288 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, |
| 289 GetResultAndReset()); |
| 290 } |
| 291 |
234 std::string GetResultAndReset() { | 292 std::string GetResultAndReset() { |
235 std::string result; | 293 std::string result; |
236 result.swap(result_); | 294 result.swap(result_); |
237 return result; | 295 return result; |
238 } | 296 } |
239 | 297 |
240 const std::vector<cryptauth::RemoteDevice> test_devices_; | 298 const std::vector<cryptauth::RemoteDevice> test_devices_; |
241 const base::MessageLoop message_loop_; | 299 const base::MessageLoop message_loop_; |
242 | 300 |
243 std::unique_ptr<FakeConnectTetheringOperationFactory> fake_operation_factory_; | 301 std::unique_ptr<FakeConnectTetheringOperationFactory> fake_operation_factory_; |
244 std::unique_ptr<FakeWifiHotspotConnector> fake_wifi_hotspot_connector_; | 302 std::unique_ptr<FakeWifiHotspotConnector> fake_wifi_hotspot_connector_; |
245 std::unique_ptr<FakeActiveHost> fake_active_host_; | 303 std::unique_ptr<FakeActiveHost> fake_active_host_; |
246 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_; | 304 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_; |
247 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; | 305 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; |
248 std::unique_ptr<MockTetherHostResponseRecorder> | 306 std::unique_ptr<MockTetherHostResponseRecorder> |
249 mock_tether_host_response_recorder_; | 307 mock_tether_host_response_recorder_; |
250 // TODO(hansberry): Use a fake for this when a real mapping scheme is created. | 308 // TODO(hansberry): Use a fake for this when a real mapping scheme is created. |
251 std::unique_ptr<DeviceIdTetherNetworkGuidMap> | 309 std::unique_ptr<DeviceIdTetherNetworkGuidMap> |
252 device_id_tether_network_guid_map_; | 310 device_id_tether_network_guid_map_; |
253 std::unique_ptr<FakeHostScanCache> fake_host_scan_cache_; | 311 std::unique_ptr<FakeHostScanCache> fake_host_scan_cache_; |
254 std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_; | 312 std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_; |
| 313 std::unique_ptr<StrictMock<MockHostConnectionMetricsLogger>> |
| 314 mock_host_connection_metrics_logger_; |
255 | 315 |
256 std::string result_; | 316 std::string result_; |
257 | 317 |
258 std::unique_ptr<TetherConnector> tether_connector_; | 318 std::unique_ptr<TetherConnector> tether_connector_; |
259 | 319 |
260 private: | 320 private: |
261 DISALLOW_COPY_AND_ASSIGN(TetherConnectorTest); | 321 DISALLOW_COPY_AND_ASSIGN(TetherConnectorTest); |
262 }; | 322 }; |
263 | 323 |
264 TEST_F(TetherConnectorTest, TestCannotFetchDevice) { | 324 TEST_F(TetherConnectorTest, TestCannotFetchDevice) { |
| 325 EXPECT_CALL( |
| 326 *mock_host_connection_metrics_logger_, |
| 327 RecordConnectionToHostResult( |
| 328 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 329 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_INTERNAL_ERROR)); |
| 330 |
265 // Base64-encoded version of "nonexistentDeviceId". | 331 // Base64-encoded version of "nonexistentDeviceId". |
266 const char kNonexistentDeviceId[] = "bm9uZXhpc3RlbnREZXZpY2VJZA=="; | 332 const char kNonexistentDeviceId[] = "bm9uZXhpc3RlbnREZXZpY2VJZA=="; |
267 | 333 |
268 CallConnect(GetTetherNetworkGuid(kNonexistentDeviceId)); | 334 CallConnect(GetTetherNetworkGuid(kNonexistentDeviceId)); |
269 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 335 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
270 fake_active_host_->GetActiveHostStatus()); | 336 fake_active_host_->GetActiveHostStatus()); |
271 EXPECT_EQ(kNonexistentDeviceId, fake_active_host_->GetActiveHostDeviceId()); | 337 EXPECT_EQ(kNonexistentDeviceId, fake_active_host_->GetActiveHostDeviceId()); |
272 EXPECT_EQ(GetTetherNetworkGuid(kNonexistentDeviceId), | 338 EXPECT_EQ(GetTetherNetworkGuid(kNonexistentDeviceId), |
273 fake_active_host_->GetTetherNetworkGuid()); | 339 fake_active_host_->GetTetherNetworkGuid()); |
274 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 340 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
275 | 341 |
276 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 342 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
277 | 343 |
278 // Since an invalid device ID was used, no connection should have been | 344 // Since an invalid device ID was used, no connection should have been |
279 // started. | 345 // started. |
280 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 346 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
281 fake_active_host_->GetActiveHostStatus()); | 347 fake_active_host_->GetActiveHostStatus()); |
282 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); | 348 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); |
283 } | 349 } |
284 | 350 |
285 TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) { | 351 TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) { |
| 352 EXPECT_CALL( |
| 353 *mock_host_connection_metrics_logger_, |
| 354 RecordConnectionToHostResult( |
| 355 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 356 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 357 |
286 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 358 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
287 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 359 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
288 fake_active_host_->GetActiveHostStatus()); | 360 fake_active_host_->GetActiveHostStatus()); |
289 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 361 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
290 fake_active_host_->GetActiveHostDeviceId()); | 362 fake_active_host_->GetActiveHostDeviceId()); |
291 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 363 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
292 fake_active_host_->GetTetherNetworkGuid()); | 364 fake_active_host_->GetTetherNetworkGuid()); |
293 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 365 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
294 | 366 |
295 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 367 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
296 | 368 |
297 // Simulate a failed connection attempt (either the host cannot provide | 369 // Simulate a failed connection attempt (either the host cannot provide |
298 // tethering at this time or a timeout occurs). | 370 // tethering at this time or a timeout occurs). |
299 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | 371 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
300 EXPECT_FALSE( | 372 EXPECT_FALSE( |
301 fake_operation_factory_->created_operations()[0]->setup_required()); | 373 fake_operation_factory_->created_operations()[0]->setup_required()); |
302 tether_connector_->CancelConnectionAttempt( | 374 tether_connector_->CancelConnectionAttempt( |
303 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 375 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
304 | 376 |
305 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 377 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
306 fake_active_host_->GetActiveHostStatus()); | 378 fake_active_host_->GetActiveHostStatus()); |
307 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, | 379 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, |
308 GetResultAndReset()); | 380 GetResultAndReset()); |
309 } | 381 } |
310 | 382 |
311 TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails) { | 383 TEST_F(TetherConnectorTest, |
| 384 TestConnectTetheringOperationFails_SetupNotRequired) { |
| 385 VerifyConnectTetheringOperationFails( |
| 386 ConnectTetheringResponse_ResponseCode:: |
| 387 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, |
| 388 false /* setup_required */, |
| 389 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 390 CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR); |
| 391 } |
| 392 |
| 393 TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails_SetupRequired) { |
| 394 VerifyConnectTetheringOperationFails( |
| 395 ConnectTetheringResponse_ResponseCode:: |
| 396 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, |
| 397 true /* setup_required */, |
| 398 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 399 CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR); |
| 400 } |
| 401 |
| 402 TEST_F(TetherConnectorTest, |
| 403 TestConnectTetheringOperationFails_ProvisioningFailed) { |
| 404 VerifyConnectTetheringOperationFails( |
| 405 ConnectTetheringResponse_ResponseCode:: |
| 406 ConnectTetheringResponse_ResponseCode_PROVISIONING_FAILED, |
| 407 false /* setup_required */, |
| 408 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 409 CONNECTION_RESULT_PROVISIONING_FAILED); |
| 410 } |
| 411 |
| 412 TEST_F(TetherConnectorTest, |
| 413 TestConnectTetheringOperationFails_TetheringTimeout_SetupNotRequired) { |
| 414 VerifyConnectTetheringOperationFails( |
| 415 ConnectTetheringResponse_ResponseCode:: |
| 416 ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT, |
| 417 false /* setup_required */, |
| 418 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 419 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_NOT
_REQUIRED); |
| 420 } |
| 421 |
| 422 TEST_F(TetherConnectorTest, |
| 423 TestConnectTetheringOperationFails_TetheringTimeout_SetupRequired) { |
| 424 VerifyConnectTetheringOperationFails( |
| 425 ConnectTetheringResponse_ResponseCode:: |
| 426 ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT, |
| 427 true /* setup_required */, |
| 428 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 429 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_REQ
UIRED); |
| 430 } |
| 431 |
| 432 TEST_F(TetherConnectorTest, TestConnectingToWifiFails) { |
| 433 EXPECT_CALL(*mock_host_connection_metrics_logger_, |
| 434 RecordConnectionToHostResult( |
| 435 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 436 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_TIMEOUT)); |
| 437 |
312 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 438 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
313 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 439 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
314 fake_active_host_->GetActiveHostStatus()); | 440 fake_active_host_->GetActiveHostStatus()); |
315 EXPECT_EQ(test_devices_[0].GetDeviceId(), | |
316 fake_active_host_->GetActiveHostDeviceId()); | |
317 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | |
318 fake_active_host_->GetTetherNetworkGuid()); | |
319 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | |
320 | |
321 fake_tether_host_fetcher_->InvokePendingCallbacks(); | |
322 | |
323 // Simulate a failed connection attempt (either the host cannot provide | |
324 // tethering at this time or a timeout occurs). | |
325 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | |
326 EXPECT_FALSE( | |
327 fake_operation_factory_->created_operations()[0]->setup_required()); | |
328 fake_operation_factory_->created_operations()[0]->SendFailedResponse( | |
329 ConnectTetheringResponse_ResponseCode:: | |
330 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR); | |
331 | |
332 // The failure should have resulted in the host being disconnected. | |
333 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | |
334 fake_active_host_->GetActiveHostStatus()); | |
335 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); | |
336 } | |
337 | |
338 TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails_SetupRequired) { | |
339 EXPECT_FALSE( | |
340 fake_notification_presenter_->is_setup_required_notification_shown()); | |
341 | |
342 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); | |
343 | |
344 EXPECT_TRUE( | |
345 fake_notification_presenter_->is_setup_required_notification_shown()); | |
346 | |
347 fake_tether_host_fetcher_->InvokePendingCallbacks(); | |
348 | |
349 EXPECT_TRUE( | |
350 fake_notification_presenter_->is_setup_required_notification_shown()); | |
351 EXPECT_TRUE( | |
352 fake_operation_factory_->created_operations()[0]->setup_required()); | |
353 | |
354 fake_operation_factory_->created_operations()[0]->SendFailedResponse( | |
355 ConnectTetheringResponse_ResponseCode:: | |
356 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR); | |
357 | |
358 EXPECT_FALSE( | |
359 fake_notification_presenter_->is_setup_required_notification_shown()); | |
360 | |
361 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); | |
362 } | |
363 | |
364 TEST_F(TetherConnectorTest, TestConnectingToWifiFails) { | |
365 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | |
366 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | |
367 fake_active_host_->GetActiveHostStatus()); | |
368 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 441 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
369 fake_active_host_->GetActiveHostDeviceId()); | 442 fake_active_host_->GetActiveHostDeviceId()); |
370 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 443 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
371 fake_active_host_->GetTetherNetworkGuid()); | 444 fake_active_host_->GetTetherNetworkGuid()); |
372 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 445 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
373 | 446 |
374 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 447 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
375 | 448 |
376 // Receive a successful response. We should still be connecting. | 449 // Receive a successful response. We should still be connecting. |
377 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | 450 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
(...skipping 13 matching lines...) Expand all Loading... |
391 fake_wifi_hotspot_connector_->most_recent_tether_network_guid()); | 464 fake_wifi_hotspot_connector_->most_recent_tether_network_guid()); |
392 fake_wifi_hotspot_connector_->CallMostRecentCallback(""); | 465 fake_wifi_hotspot_connector_->CallMostRecentCallback(""); |
393 | 466 |
394 // The failure should have resulted in the host being disconnected. | 467 // The failure should have resulted in the host being disconnected. |
395 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 468 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
396 fake_active_host_->GetActiveHostStatus()); | 469 fake_active_host_->GetActiveHostStatus()); |
397 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); | 470 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); |
398 } | 471 } |
399 | 472 |
400 TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) { | 473 TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) { |
| 474 EXPECT_CALL( |
| 475 *mock_host_connection_metrics_logger_, |
| 476 RecordConnectionToHostResult( |
| 477 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 478 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 479 |
401 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 480 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
402 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 481 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
403 fake_active_host_->GetActiveHostStatus()); | 482 fake_active_host_->GetActiveHostStatus()); |
404 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 483 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
405 fake_active_host_->GetActiveHostDeviceId()); | 484 fake_active_host_->GetActiveHostDeviceId()); |
406 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 485 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
407 fake_active_host_->GetTetherNetworkGuid()); | 486 fake_active_host_->GetTetherNetworkGuid()); |
408 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 487 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
409 | 488 |
410 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 489 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
(...skipping 10 matching lines...) Expand all Loading... |
421 tether_connector_->CancelConnectionAttempt( | 500 tether_connector_->CancelConnectionAttempt( |
422 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 501 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
423 | 502 |
424 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 503 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
425 fake_active_host_->GetActiveHostStatus()); | 504 fake_active_host_->GetActiveHostStatus()); |
426 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, | 505 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, |
427 GetResultAndReset()); | 506 GetResultAndReset()); |
428 } | 507 } |
429 | 508 |
430 TEST_F(TetherConnectorTest, TestSuccessfulConnection) { | 509 TEST_F(TetherConnectorTest, TestSuccessfulConnection) { |
| 510 EXPECT_CALL(*mock_host_connection_metrics_logger_, |
| 511 RecordConnectionToHostResult( |
| 512 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 513 CONNECTION_RESULT_SUCCESS)); |
| 514 |
431 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 515 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
432 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 516 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
433 fake_active_host_->GetActiveHostStatus()); | 517 fake_active_host_->GetActiveHostStatus()); |
434 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 518 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
435 fake_active_host_->GetActiveHostDeviceId()); | 519 fake_active_host_->GetActiveHostDeviceId()); |
436 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 520 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
437 fake_active_host_->GetTetherNetworkGuid()); | 521 fake_active_host_->GetTetherNetworkGuid()); |
438 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 522 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
439 EXPECT_FALSE( | 523 EXPECT_FALSE( |
440 fake_notification_presenter_->is_setup_required_notification_shown()); | 524 fake_notification_presenter_->is_setup_required_notification_shown()); |
(...skipping 24 matching lines...) Expand all Loading... |
465 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 549 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
466 fake_active_host_->GetActiveHostDeviceId()); | 550 fake_active_host_->GetActiveHostDeviceId()); |
467 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 551 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
468 fake_active_host_->GetTetherNetworkGuid()); | 552 fake_active_host_->GetTetherNetworkGuid()); |
469 EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid()); | 553 EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid()); |
470 | 554 |
471 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 555 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
472 } | 556 } |
473 | 557 |
474 TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) { | 558 TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) { |
| 559 EXPECT_CALL(*mock_host_connection_metrics_logger_, |
| 560 RecordConnectionToHostResult( |
| 561 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 562 CONNECTION_RESULT_SUCCESS)); |
| 563 |
475 EXPECT_FALSE( | 564 EXPECT_FALSE( |
476 fake_notification_presenter_->is_setup_required_notification_shown()); | 565 fake_notification_presenter_->is_setup_required_notification_shown()); |
477 | 566 |
478 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); | 567 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); |
479 | 568 |
480 EXPECT_TRUE( | 569 EXPECT_TRUE( |
481 fake_notification_presenter_->is_setup_required_notification_shown()); | 570 fake_notification_presenter_->is_setup_required_notification_shown()); |
482 | 571 |
483 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 572 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
484 | 573 |
(...skipping 11 matching lines...) Expand all Loading... |
496 SuccessfullyJoinWifiNetwork(); | 585 SuccessfullyJoinWifiNetwork(); |
497 | 586 |
498 EXPECT_FALSE( | 587 EXPECT_FALSE( |
499 fake_notification_presenter_->is_setup_required_notification_shown()); | 588 fake_notification_presenter_->is_setup_required_notification_shown()); |
500 | 589 |
501 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 590 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
502 } | 591 } |
503 | 592 |
504 TEST_F(TetherConnectorTest, | 593 TEST_F(TetherConnectorTest, |
505 TestNewConnectionAttemptDuringFetch_DifferentDevice) { | 594 TestNewConnectionAttemptDuringFetch_DifferentDevice) { |
| 595 EXPECT_CALL( |
| 596 *mock_host_connection_metrics_logger_, |
| 597 RecordConnectionToHostResult( |
| 598 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 599 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 600 |
506 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 601 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
507 | 602 |
508 // Instead of invoking the pending callbacks on |fake_tether_host_fetcher_|, | 603 // Instead of invoking the pending callbacks on |fake_tether_host_fetcher_|, |
509 // attempt another connection attempt, this time to another device. | 604 // attempt another connection attempt, this time to another device. |
510 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); | 605 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); |
511 // The first connection attempt should have resulted in a connect canceled | 606 // The first connection attempt should have resulted in a connect canceled |
512 // error. | 607 // error. |
513 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, | 608 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, |
514 GetResultAndReset()); | 609 GetResultAndReset()); |
515 | 610 |
516 // Now invoke the callbacks. An operation should have been created for the | 611 // Now invoke the callbacks. An operation should have been created for the |
517 // device 1, not device 0. | 612 // device 1, not device 0. |
518 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 613 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
519 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | 614 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
520 EXPECT_EQ( | 615 EXPECT_EQ( |
521 test_devices_[1], | 616 test_devices_[1], |
522 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); | 617 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); |
523 } | 618 } |
524 | 619 |
525 TEST_F(TetherConnectorTest, | 620 TEST_F(TetherConnectorTest, |
526 TestNewConnectionAttemptDuringOperation_DifferentDevice) { | 621 TestNewConnectionAttemptDuringOperation_DifferentDevice) { |
| 622 EXPECT_CALL( |
| 623 *mock_host_connection_metrics_logger_, |
| 624 RecordConnectionToHostResult( |
| 625 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 626 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 627 |
527 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 628 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
528 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 629 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
529 fake_active_host_->GetActiveHostStatus()); | 630 fake_active_host_->GetActiveHostStatus()); |
530 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 631 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
531 fake_active_host_->GetActiveHostDeviceId()); | 632 fake_active_host_->GetActiveHostDeviceId()); |
532 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 633 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
533 fake_active_host_->GetTetherNetworkGuid()); | 634 fake_active_host_->GetTetherNetworkGuid()); |
534 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 635 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
535 | 636 |
536 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 637 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 fake_operation_factory_->created_operations()[1]->SendSuccessfulResponse( | 670 fake_operation_factory_->created_operations()[1]->SendSuccessfulResponse( |
570 kSsid, kPassword); | 671 kSsid, kPassword); |
571 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); | 672 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); |
572 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); | 673 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); |
573 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(), | 674 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(), |
574 fake_wifi_hotspot_connector_->most_recent_tether_network_guid()); | 675 fake_wifi_hotspot_connector_->most_recent_tether_network_guid()); |
575 } | 676 } |
576 | 677 |
577 TEST_F(TetherConnectorTest, | 678 TEST_F(TetherConnectorTest, |
578 TestNewConnectionAttemptDuringWifiConnection_DifferentDevice) { | 679 TestNewConnectionAttemptDuringWifiConnection_DifferentDevice) { |
| 680 EXPECT_CALL( |
| 681 *mock_host_connection_metrics_logger_, |
| 682 RecordConnectionToHostResult( |
| 683 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 684 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 685 |
579 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 686 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
580 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 687 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
581 fake_active_host_->GetActiveHostStatus()); | 688 fake_active_host_->GetActiveHostStatus()); |
582 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 689 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
583 fake_active_host_->GetActiveHostDeviceId()); | 690 fake_active_host_->GetActiveHostDeviceId()); |
584 | 691 |
585 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 692 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
586 | 693 |
587 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | 694 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
588 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse( | 695 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse( |
(...skipping 22 matching lines...) Expand all Loading... |
611 EXPECT_EQ(test_devices_[1].GetDeviceId(), | 718 EXPECT_EQ(test_devices_[1].GetDeviceId(), |
612 fake_active_host_->GetActiveHostDeviceId()); | 719 fake_active_host_->GetActiveHostDeviceId()); |
613 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), | 720 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), |
614 fake_active_host_->GetTetherNetworkGuid()); | 721 fake_active_host_->GetTetherNetworkGuid()); |
615 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 722 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
616 } | 723 } |
617 | 724 |
618 } // namespace tether | 725 } // namespace tether |
619 | 726 |
620 } // namespace chromeos | 727 } // namespace chromeos |
OLD | NEW |