Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: chromeos/components/tether/tether_connector_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698