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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 224 |
219 void CallConnect(const std::string& tether_network_guid) { | 225 void CallConnect(const std::string& tether_network_guid) { |
220 tether_connector_->ConnectToNetwork( | 226 tether_connector_->ConnectToNetwork( |
221 tether_network_guid, | 227 tether_network_guid, |
222 base::Bind(&TetherConnectorTest::SuccessCallback, | 228 base::Bind(&TetherConnectorTest::SuccessCallback, |
223 base::Unretained(this)), | 229 base::Unretained(this)), |
224 base::Bind(&TetherConnectorTest::ErrorCallback, | 230 base::Bind(&TetherConnectorTest::ErrorCallback, |
225 base::Unretained(this))); | 231 base::Unretained(this))); |
226 } | 232 } |
227 | 233 |
| 234 void VerifyConnectTetheringOperationFails( |
| 235 ConnectTetheringResponse_ResponseCode response_code, |
| 236 bool setup_required, |
| 237 HostConnectionMetricsLogger::ConnectionToHostResult expected_event_type) { |
| 238 EXPECT_CALL(*mock_host_connection_metrics_logger_, |
| 239 RecordConnectionToHostResult(expected_event_type)); |
| 240 |
| 241 EXPECT_FALSE( |
| 242 fake_notification_presenter_->is_setup_required_notification_shown()); |
| 243 |
| 244 // test_devices_[0] does not require first-time setup, but test_devices_[1] |
| 245 // does require first-time setup. See SetUpTetherNetworks(). |
| 246 cryptauth::RemoteDevice test_device = test_devices_[setup_required ? 1 : 0]; |
| 247 |
| 248 CallConnect(GetTetherNetworkGuid(test_device.GetDeviceId())); |
| 249 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
| 250 fake_active_host_->GetActiveHostStatus()); |
| 251 EXPECT_EQ(test_device.GetDeviceId(), |
| 252 fake_active_host_->GetActiveHostDeviceId()); |
| 253 EXPECT_EQ(GetTetherNetworkGuid(test_device.GetDeviceId()), |
| 254 fake_active_host_->GetTetherNetworkGuid()); |
| 255 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
| 256 |
| 257 EXPECT_EQ( |
| 258 setup_required, |
| 259 fake_notification_presenter_->is_setup_required_notification_shown()); |
| 260 |
| 261 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
| 262 |
| 263 EXPECT_EQ( |
| 264 setup_required, |
| 265 fake_notification_presenter_->is_setup_required_notification_shown()); |
| 266 EXPECT_EQ( |
| 267 setup_required, |
| 268 fake_operation_factory_->created_operations()[0]->setup_required()); |
| 269 |
| 270 // Simulate a failed connection attempt (either the host cannot provide |
| 271 // tethering at this time or a timeout occurs). |
| 272 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
| 273 fake_operation_factory_->created_operations()[0]->SendFailedResponse( |
| 274 response_code); |
| 275 |
| 276 EXPECT_FALSE( |
| 277 fake_notification_presenter_->is_setup_required_notification_shown()); |
| 278 |
| 279 // The failure should have resulted in the host being disconnected. |
| 280 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
| 281 fake_active_host_->GetActiveHostStatus()); |
| 282 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, |
| 283 GetResultAndReset()); |
| 284 } |
| 285 |
228 std::string GetResultAndReset() { | 286 std::string GetResultAndReset() { |
229 std::string result; | 287 std::string result; |
230 result.swap(result_); | 288 result.swap(result_); |
231 return result; | 289 return result; |
232 } | 290 } |
233 | 291 |
234 const std::vector<cryptauth::RemoteDevice> test_devices_; | 292 const std::vector<cryptauth::RemoteDevice> test_devices_; |
235 const base::MessageLoop message_loop_; | 293 const base::MessageLoop message_loop_; |
236 | 294 |
237 std::unique_ptr<FakeConnectTetheringOperationFactory> fake_operation_factory_; | 295 std::unique_ptr<FakeConnectTetheringOperationFactory> fake_operation_factory_; |
238 std::unique_ptr<FakeWifiHotspotConnector> fake_wifi_hotspot_connector_; | 296 std::unique_ptr<FakeWifiHotspotConnector> fake_wifi_hotspot_connector_; |
239 std::unique_ptr<FakeActiveHost> fake_active_host_; | 297 std::unique_ptr<FakeActiveHost> fake_active_host_; |
240 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_; | 298 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_; |
241 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; | 299 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; |
242 std::unique_ptr<MockTetherHostResponseRecorder> | 300 std::unique_ptr<MockTetherHostResponseRecorder> |
243 mock_tether_host_response_recorder_; | 301 mock_tether_host_response_recorder_; |
244 // TODO(hansberry): Use a fake for this when a real mapping scheme is created. | 302 // TODO(hansberry): Use a fake for this when a real mapping scheme is created. |
245 std::unique_ptr<DeviceIdTetherNetworkGuidMap> | 303 std::unique_ptr<DeviceIdTetherNetworkGuidMap> |
246 device_id_tether_network_guid_map_; | 304 device_id_tether_network_guid_map_; |
247 std::unique_ptr<FakeHostScanCache> fake_host_scan_cache_; | 305 std::unique_ptr<FakeHostScanCache> fake_host_scan_cache_; |
248 std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_; | 306 std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_; |
| 307 std::unique_ptr<StrictMock<MockHostConnectionMetricsLogger>> |
| 308 mock_host_connection_metrics_logger_; |
249 | 309 |
250 std::string result_; | 310 std::string result_; |
251 | 311 |
252 std::unique_ptr<TetherConnector> tether_connector_; | 312 std::unique_ptr<TetherConnector> tether_connector_; |
253 | 313 |
254 private: | 314 private: |
255 DISALLOW_COPY_AND_ASSIGN(TetherConnectorTest); | 315 DISALLOW_COPY_AND_ASSIGN(TetherConnectorTest); |
256 }; | 316 }; |
257 | 317 |
258 TEST_F(TetherConnectorTest, TestCannotFetchDevice) { | 318 TEST_F(TetherConnectorTest, TestCannotFetchDevice) { |
| 319 EXPECT_CALL( |
| 320 *mock_host_connection_metrics_logger_, |
| 321 RecordConnectionToHostResult( |
| 322 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 323 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_INTERNAL_ERROR)); |
| 324 |
259 // Base64-encoded version of "nonexistentDeviceId". | 325 // Base64-encoded version of "nonexistentDeviceId". |
260 const char kNonexistentDeviceId[] = "bm9uZXhpc3RlbnREZXZpY2VJZA=="; | 326 const char kNonexistentDeviceId[] = "bm9uZXhpc3RlbnREZXZpY2VJZA=="; |
261 | 327 |
262 CallConnect(GetTetherNetworkGuid(kNonexistentDeviceId)); | 328 CallConnect(GetTetherNetworkGuid(kNonexistentDeviceId)); |
263 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 329 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
264 fake_active_host_->GetActiveHostStatus()); | 330 fake_active_host_->GetActiveHostStatus()); |
265 EXPECT_EQ(kNonexistentDeviceId, fake_active_host_->GetActiveHostDeviceId()); | 331 EXPECT_EQ(kNonexistentDeviceId, fake_active_host_->GetActiveHostDeviceId()); |
266 EXPECT_EQ(GetTetherNetworkGuid(kNonexistentDeviceId), | 332 EXPECT_EQ(GetTetherNetworkGuid(kNonexistentDeviceId), |
267 fake_active_host_->GetTetherNetworkGuid()); | 333 fake_active_host_->GetTetherNetworkGuid()); |
268 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 334 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
269 | 335 |
270 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 336 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
271 | 337 |
272 // Since an invalid device ID was used, no connection should have been | 338 // Since an invalid device ID was used, no connection should have been |
273 // started. | 339 // started. |
274 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 340 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
275 fake_active_host_->GetActiveHostStatus()); | 341 fake_active_host_->GetActiveHostStatus()); |
276 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); | 342 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); |
277 } | 343 } |
278 | 344 |
279 TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) { | 345 TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) { |
| 346 EXPECT_CALL( |
| 347 *mock_host_connection_metrics_logger_, |
| 348 RecordConnectionToHostResult( |
| 349 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 350 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 351 |
280 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 352 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
281 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 353 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
282 fake_active_host_->GetActiveHostStatus()); | 354 fake_active_host_->GetActiveHostStatus()); |
283 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 355 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
284 fake_active_host_->GetActiveHostDeviceId()); | 356 fake_active_host_->GetActiveHostDeviceId()); |
285 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 357 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
286 fake_active_host_->GetTetherNetworkGuid()); | 358 fake_active_host_->GetTetherNetworkGuid()); |
287 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 359 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
288 | 360 |
289 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 361 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
290 | 362 |
291 // Simulate a failed connection attempt (either the host cannot provide | 363 // Simulate a failed connection attempt (either the host cannot provide |
292 // tethering at this time or a timeout occurs). | 364 // tethering at this time or a timeout occurs). |
293 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | 365 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
294 EXPECT_FALSE( | 366 EXPECT_FALSE( |
295 fake_operation_factory_->created_operations()[0]->setup_required()); | 367 fake_operation_factory_->created_operations()[0]->setup_required()); |
296 tether_connector_->CancelConnectionAttempt( | 368 tether_connector_->CancelConnectionAttempt( |
297 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 369 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
298 | 370 |
299 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 371 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
300 fake_active_host_->GetActiveHostStatus()); | 372 fake_active_host_->GetActiveHostStatus()); |
301 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, | 373 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, |
302 GetResultAndReset()); | 374 GetResultAndReset()); |
303 } | 375 } |
304 | 376 |
305 TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails) { | 377 TEST_F(TetherConnectorTest, |
| 378 TestConnectTetheringOperationFails_SetupNotRequired) { |
| 379 VerifyConnectTetheringOperationFails( |
| 380 ConnectTetheringResponse_ResponseCode:: |
| 381 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, |
| 382 false /* setup_required */, |
| 383 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 384 CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR); |
| 385 } |
| 386 |
| 387 TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails_SetupRequired) { |
| 388 VerifyConnectTetheringOperationFails( |
| 389 ConnectTetheringResponse_ResponseCode:: |
| 390 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, |
| 391 true /* setup_required */, |
| 392 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 393 CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR); |
| 394 } |
| 395 |
| 396 TEST_F(TetherConnectorTest, |
| 397 TestConnectTetheringOperationFails_ProvisioningFailed) { |
| 398 VerifyConnectTetheringOperationFails( |
| 399 ConnectTetheringResponse_ResponseCode:: |
| 400 ConnectTetheringResponse_ResponseCode_PROVISIONING_FAILED, |
| 401 false /* setup_required */, |
| 402 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 403 CONNECTION_RESULT_PROVISIONING_FAILED); |
| 404 } |
| 405 |
| 406 TEST_F(TetherConnectorTest, |
| 407 TestConnectTetheringOperationFails_TetheringTimeout_SetupNotRequired) { |
| 408 VerifyConnectTetheringOperationFails( |
| 409 ConnectTetheringResponse_ResponseCode:: |
| 410 ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT, |
| 411 false /* setup_required */, |
| 412 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 413 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_NOT
_REQUIRED); |
| 414 } |
| 415 |
| 416 TEST_F(TetherConnectorTest, |
| 417 TestConnectTetheringOperationFails_TetheringTimeout_SetupRequired) { |
| 418 VerifyConnectTetheringOperationFails( |
| 419 ConnectTetheringResponse_ResponseCode:: |
| 420 ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT, |
| 421 true /* setup_required */, |
| 422 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 423 CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_REQ
UIRED); |
| 424 } |
| 425 |
| 426 TEST_F(TetherConnectorTest, TestConnectingToWifiFails) { |
| 427 EXPECT_CALL(*mock_host_connection_metrics_logger_, |
| 428 RecordConnectionToHostResult( |
| 429 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 430 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_TIMEOUT)); |
| 431 |
306 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 432 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
307 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 433 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
308 fake_active_host_->GetActiveHostStatus()); | 434 fake_active_host_->GetActiveHostStatus()); |
309 EXPECT_EQ(test_devices_[0].GetDeviceId(), | |
310 fake_active_host_->GetActiveHostDeviceId()); | |
311 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | |
312 fake_active_host_->GetTetherNetworkGuid()); | |
313 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | |
314 | |
315 fake_tether_host_fetcher_->InvokePendingCallbacks(); | |
316 | |
317 // Simulate a failed connection attempt (either the host cannot provide | |
318 // tethering at this time or a timeout occurs). | |
319 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | |
320 EXPECT_FALSE( | |
321 fake_operation_factory_->created_operations()[0]->setup_required()); | |
322 fake_operation_factory_->created_operations()[0]->SendFailedResponse( | |
323 ConnectTetheringResponse_ResponseCode:: | |
324 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR); | |
325 | |
326 // The failure should have resulted in the host being disconnected. | |
327 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | |
328 fake_active_host_->GetActiveHostStatus()); | |
329 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); | |
330 } | |
331 | |
332 TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails_SetupRequired) { | |
333 EXPECT_FALSE( | |
334 fake_notification_presenter_->is_setup_required_notification_shown()); | |
335 | |
336 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); | |
337 | |
338 EXPECT_TRUE( | |
339 fake_notification_presenter_->is_setup_required_notification_shown()); | |
340 | |
341 fake_tether_host_fetcher_->InvokePendingCallbacks(); | |
342 | |
343 EXPECT_TRUE( | |
344 fake_notification_presenter_->is_setup_required_notification_shown()); | |
345 EXPECT_TRUE( | |
346 fake_operation_factory_->created_operations()[0]->setup_required()); | |
347 | |
348 fake_operation_factory_->created_operations()[0]->SendFailedResponse( | |
349 ConnectTetheringResponse_ResponseCode:: | |
350 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR); | |
351 | |
352 EXPECT_FALSE( | |
353 fake_notification_presenter_->is_setup_required_notification_shown()); | |
354 | |
355 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); | |
356 } | |
357 | |
358 TEST_F(TetherConnectorTest, TestConnectingToWifiFails) { | |
359 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | |
360 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | |
361 fake_active_host_->GetActiveHostStatus()); | |
362 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 435 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
363 fake_active_host_->GetActiveHostDeviceId()); | 436 fake_active_host_->GetActiveHostDeviceId()); |
364 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 437 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
365 fake_active_host_->GetTetherNetworkGuid()); | 438 fake_active_host_->GetTetherNetworkGuid()); |
366 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 439 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
367 | 440 |
368 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 441 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
369 | 442 |
370 // Receive a successful response. We should still be connecting. | 443 // Receive a successful response. We should still be connecting. |
371 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | 444 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
(...skipping 13 matching lines...) Expand all Loading... |
385 fake_wifi_hotspot_connector_->most_recent_tether_network_guid()); | 458 fake_wifi_hotspot_connector_->most_recent_tether_network_guid()); |
386 fake_wifi_hotspot_connector_->CallMostRecentCallback(""); | 459 fake_wifi_hotspot_connector_->CallMostRecentCallback(""); |
387 | 460 |
388 // The failure should have resulted in the host being disconnected. | 461 // The failure should have resulted in the host being disconnected. |
389 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 462 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
390 fake_active_host_->GetActiveHostStatus()); | 463 fake_active_host_->GetActiveHostStatus()); |
391 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); | 464 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); |
392 } | 465 } |
393 | 466 |
394 TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) { | 467 TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) { |
| 468 EXPECT_CALL( |
| 469 *mock_host_connection_metrics_logger_, |
| 470 RecordConnectionToHostResult( |
| 471 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 472 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 473 |
395 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 474 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
396 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 475 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
397 fake_active_host_->GetActiveHostStatus()); | 476 fake_active_host_->GetActiveHostStatus()); |
398 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 477 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
399 fake_active_host_->GetActiveHostDeviceId()); | 478 fake_active_host_->GetActiveHostDeviceId()); |
400 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 479 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
401 fake_active_host_->GetTetherNetworkGuid()); | 480 fake_active_host_->GetTetherNetworkGuid()); |
402 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 481 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
403 | 482 |
404 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 483 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
(...skipping 10 matching lines...) Expand all Loading... |
415 tether_connector_->CancelConnectionAttempt( | 494 tether_connector_->CancelConnectionAttempt( |
416 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 495 GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
417 | 496 |
418 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, | 497 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, |
419 fake_active_host_->GetActiveHostStatus()); | 498 fake_active_host_->GetActiveHostStatus()); |
420 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, | 499 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, |
421 GetResultAndReset()); | 500 GetResultAndReset()); |
422 } | 501 } |
423 | 502 |
424 TEST_F(TetherConnectorTest, TestSuccessfulConnection) { | 503 TEST_F(TetherConnectorTest, TestSuccessfulConnection) { |
| 504 EXPECT_CALL(*mock_host_connection_metrics_logger_, |
| 505 RecordConnectionToHostResult( |
| 506 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 507 CONNECTION_RESULT_SUCCESS)); |
| 508 |
425 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 509 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
426 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 510 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
427 fake_active_host_->GetActiveHostStatus()); | 511 fake_active_host_->GetActiveHostStatus()); |
428 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 512 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
429 fake_active_host_->GetActiveHostDeviceId()); | 513 fake_active_host_->GetActiveHostDeviceId()); |
430 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 514 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
431 fake_active_host_->GetTetherNetworkGuid()); | 515 fake_active_host_->GetTetherNetworkGuid()); |
432 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 516 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
433 EXPECT_FALSE( | 517 EXPECT_FALSE( |
434 fake_notification_presenter_->is_setup_required_notification_shown()); | 518 fake_notification_presenter_->is_setup_required_notification_shown()); |
(...skipping 24 matching lines...) Expand all Loading... |
459 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 543 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
460 fake_active_host_->GetActiveHostDeviceId()); | 544 fake_active_host_->GetActiveHostDeviceId()); |
461 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 545 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
462 fake_active_host_->GetTetherNetworkGuid()); | 546 fake_active_host_->GetTetherNetworkGuid()); |
463 EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid()); | 547 EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid()); |
464 | 548 |
465 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 549 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
466 } | 550 } |
467 | 551 |
468 TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) { | 552 TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) { |
| 553 EXPECT_CALL(*mock_host_connection_metrics_logger_, |
| 554 RecordConnectionToHostResult( |
| 555 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 556 CONNECTION_RESULT_SUCCESS)); |
| 557 |
469 EXPECT_FALSE( | 558 EXPECT_FALSE( |
470 fake_notification_presenter_->is_setup_required_notification_shown()); | 559 fake_notification_presenter_->is_setup_required_notification_shown()); |
471 | 560 |
472 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); | 561 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); |
473 | 562 |
474 EXPECT_TRUE( | 563 EXPECT_TRUE( |
475 fake_notification_presenter_->is_setup_required_notification_shown()); | 564 fake_notification_presenter_->is_setup_required_notification_shown()); |
476 | 565 |
477 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 566 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
478 | 567 |
(...skipping 11 matching lines...) Expand all Loading... |
490 SuccessfullyJoinWifiNetwork(); | 579 SuccessfullyJoinWifiNetwork(); |
491 | 580 |
492 EXPECT_FALSE( | 581 EXPECT_FALSE( |
493 fake_notification_presenter_->is_setup_required_notification_shown()); | 582 fake_notification_presenter_->is_setup_required_notification_shown()); |
494 | 583 |
495 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 584 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
496 } | 585 } |
497 | 586 |
498 TEST_F(TetherConnectorTest, | 587 TEST_F(TetherConnectorTest, |
499 TestNewConnectionAttemptDuringFetch_DifferentDevice) { | 588 TestNewConnectionAttemptDuringFetch_DifferentDevice) { |
| 589 EXPECT_CALL( |
| 590 *mock_host_connection_metrics_logger_, |
| 591 RecordConnectionToHostResult( |
| 592 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 593 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 594 |
500 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 595 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
501 | 596 |
502 // Instead of invoking the pending callbacks on |fake_tether_host_fetcher_|, | 597 // Instead of invoking the pending callbacks on |fake_tether_host_fetcher_|, |
503 // attempt another connection attempt, this time to another device. | 598 // attempt another connection attempt, this time to another device. |
504 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); | 599 CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); |
505 // The first connection attempt should have resulted in a connect canceled | 600 // The first connection attempt should have resulted in a connect canceled |
506 // error. | 601 // error. |
507 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, | 602 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, |
508 GetResultAndReset()); | 603 GetResultAndReset()); |
509 | 604 |
510 // Now invoke the callbacks. An operation should have been created for the | 605 // Now invoke the callbacks. An operation should have been created for the |
511 // device 1, not device 0. | 606 // device 1, not device 0. |
512 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 607 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
513 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | 608 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
514 EXPECT_EQ( | 609 EXPECT_EQ( |
515 test_devices_[1], | 610 test_devices_[1], |
516 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); | 611 fake_operation_factory_->created_operations()[0]->GetRemoteDevice()); |
517 } | 612 } |
518 | 613 |
519 TEST_F(TetherConnectorTest, | 614 TEST_F(TetherConnectorTest, |
520 TestNewConnectionAttemptDuringOperation_DifferentDevice) { | 615 TestNewConnectionAttemptDuringOperation_DifferentDevice) { |
| 616 EXPECT_CALL( |
| 617 *mock_host_connection_metrics_logger_, |
| 618 RecordConnectionToHostResult( |
| 619 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 620 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 621 |
521 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 622 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
522 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 623 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
523 fake_active_host_->GetActiveHostStatus()); | 624 fake_active_host_->GetActiveHostStatus()); |
524 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 625 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
525 fake_active_host_->GetActiveHostDeviceId()); | 626 fake_active_host_->GetActiveHostDeviceId()); |
526 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), | 627 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), |
527 fake_active_host_->GetTetherNetworkGuid()); | 628 fake_active_host_->GetTetherNetworkGuid()); |
528 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 629 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
529 | 630 |
530 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 631 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 fake_operation_factory_->created_operations()[1]->SendSuccessfulResponse( | 664 fake_operation_factory_->created_operations()[1]->SendSuccessfulResponse( |
564 kSsid, kPassword); | 665 kSsid, kPassword); |
565 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); | 666 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); |
566 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); | 667 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); |
567 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(), | 668 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(), |
568 fake_wifi_hotspot_connector_->most_recent_tether_network_guid()); | 669 fake_wifi_hotspot_connector_->most_recent_tether_network_guid()); |
569 } | 670 } |
570 | 671 |
571 TEST_F(TetherConnectorTest, | 672 TEST_F(TetherConnectorTest, |
572 TestNewConnectionAttemptDuringWifiConnection_DifferentDevice) { | 673 TestNewConnectionAttemptDuringWifiConnection_DifferentDevice) { |
| 674 EXPECT_CALL( |
| 675 *mock_host_connection_metrics_logger_, |
| 676 RecordConnectionToHostResult( |
| 677 HostConnectionMetricsLogger::ConnectionToHostResult:: |
| 678 CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER)); |
| 679 |
573 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); | 680 CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); |
574 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, | 681 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, |
575 fake_active_host_->GetActiveHostStatus()); | 682 fake_active_host_->GetActiveHostStatus()); |
576 EXPECT_EQ(test_devices_[0].GetDeviceId(), | 683 EXPECT_EQ(test_devices_[0].GetDeviceId(), |
577 fake_active_host_->GetActiveHostDeviceId()); | 684 fake_active_host_->GetActiveHostDeviceId()); |
578 | 685 |
579 fake_tether_host_fetcher_->InvokePendingCallbacks(); | 686 fake_tether_host_fetcher_->InvokePendingCallbacks(); |
580 | 687 |
581 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); | 688 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); |
582 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse( | 689 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse( |
(...skipping 22 matching lines...) Expand all Loading... |
605 EXPECT_EQ(test_devices_[1].GetDeviceId(), | 712 EXPECT_EQ(test_devices_[1].GetDeviceId(), |
606 fake_active_host_->GetActiveHostDeviceId()); | 713 fake_active_host_->GetActiveHostDeviceId()); |
607 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), | 714 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), |
608 fake_active_host_->GetTetherNetworkGuid()); | 715 fake_active_host_->GetTetherNetworkGuid()); |
609 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); | 716 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); |
610 } | 717 } |
611 | 718 |
612 } // namespace tether | 719 } // namespace tether |
613 | 720 |
614 } // namespace chromeos | 721 } // namespace chromeos |
OLD | NEW |