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

Unified Diff: chromeos/components/tether/tether_connector_unittest.cc

Issue 2949343002: Tether: record each type of host connection result. (Closed)
Patch Set: Fix crash. 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/components/tether/tether_connector_unittest.cc
diff --git a/chromeos/components/tether/tether_connector_unittest.cc b/chromeos/components/tether/tether_connector_unittest.cc
index 31e1755564e102381ce70b65edd1bff757549f1e..d4a2513e7658b4e7ff755d76d43b53110d0d4274 100644
--- a/chromeos/components/tether/tether_connector_unittest.cc
+++ b/chromeos/components/tether/tether_connector_unittest.cc
@@ -14,6 +14,7 @@
#include "chromeos/components/tether/fake_notification_presenter.h"
#include "chromeos/components/tether/fake_tether_host_fetcher.h"
#include "chromeos/components/tether/fake_wifi_hotspot_connector.h"
+#include "chromeos/components/tether/mock_host_connection_metrics_logger.h"
#include "chromeos/components/tether/mock_tether_host_response_recorder.h"
#include "chromeos/components/tether/tether_connector.h"
#include "chromeos/dbus/dbus_thread_manager.h"
@@ -27,6 +28,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
+using testing::StrictMock;
+
namespace chromeos {
namespace tether {
@@ -146,6 +149,8 @@ class TetherConnectorTest : public NetworkStateTest {
fake_host_scan_cache_ = base::MakeUnique<FakeHostScanCache>();
fake_notification_presenter_ =
base::MakeUnique<FakeNotificationPresenter>();
+ mock_host_connection_metrics_logger_ =
+ base::WrapUnique(new StrictMock<MockHostConnectionMetricsLogger>);
result_.clear();
@@ -155,7 +160,8 @@ class TetherConnectorTest : public NetworkStateTest {
fake_ble_connection_manager_.get(),
mock_tether_host_response_recorder_.get(),
device_id_tether_network_guid_map_.get(), fake_host_scan_cache_.get(),
- fake_notification_presenter_.get()));
+ fake_notification_presenter_.get(),
+ mock_host_connection_metrics_logger_.get()));
SetUpTetherNetworks();
}
@@ -231,6 +237,58 @@ class TetherConnectorTest : public NetworkStateTest {
base::Unretained(this)));
}
+ void VerifyConnectTetheringOperationFails(
+ ConnectTetheringResponse_ResponseCode response_code,
+ bool setup_required,
+ HostConnectionMetricsLogger::ConnectionToHostResult expected_event_type) {
+ EXPECT_CALL(*mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(expected_event_type));
+
+ EXPECT_FALSE(
+ fake_notification_presenter_->is_setup_required_notification_shown());
+
+ // test_devices_[0] does not require first-time setup, but test_devices_[1]
+ // does require first-time setup. See SetUpTetherNetworks().
+ cryptauth::RemoteDevice test_device = test_devices_[setup_required ? 1 : 0];
+
+ CallConnect(GetTetherNetworkGuid(test_device.GetDeviceId()));
+ EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
+ fake_active_host_->GetActiveHostStatus());
+ EXPECT_EQ(test_device.GetDeviceId(),
+ fake_active_host_->GetActiveHostDeviceId());
+ EXPECT_EQ(GetTetherNetworkGuid(test_device.GetDeviceId()),
+ fake_active_host_->GetTetherNetworkGuid());
+ EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty());
+
+ EXPECT_EQ(
+ setup_required,
+ fake_notification_presenter_->is_setup_required_notification_shown());
+
+ fake_tether_host_fetcher_->InvokePendingCallbacks();
+
+ EXPECT_EQ(
+ setup_required,
+ fake_notification_presenter_->is_setup_required_notification_shown());
+ EXPECT_EQ(
+ setup_required,
+ fake_operation_factory_->created_operations()[0]->setup_required());
+
+ // Simulate a failed connection attempt (either the host cannot provide
+ // tethering at this time or a timeout occurs).
+ EXPECT_EQ(1u, fake_operation_factory_->created_operations().size());
+ fake_operation_factory_->created_operations()[0]->SendFailedResponse(
+ response_code);
+
+ EXPECT_FALSE(
+ fake_notification_presenter_->is_setup_required_notification_shown());
+
+ // The failure should have resulted in the host being disconnected.
+ EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED,
+ fake_active_host_->GetActiveHostStatus());
+ EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed,
+ GetResultAndReset());
+ }
+
std::string GetResultAndReset() {
std::string result;
result.swap(result_);
@@ -252,6 +310,8 @@ class TetherConnectorTest : public NetworkStateTest {
device_id_tether_network_guid_map_;
std::unique_ptr<FakeHostScanCache> fake_host_scan_cache_;
std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_;
+ std::unique_ptr<StrictMock<MockHostConnectionMetricsLogger>>
+ mock_host_connection_metrics_logger_;
std::string result_;
@@ -262,6 +322,12 @@ class TetherConnectorTest : public NetworkStateTest {
};
TEST_F(TetherConnectorTest, TestCannotFetchDevice) {
+ EXPECT_CALL(
+ *mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_INTERNAL_ERROR));
+
// Base64-encoded version of "nonexistentDeviceId".
const char kNonexistentDeviceId[] = "bm9uZXhpc3RlbnREZXZpY2VJZA==";
@@ -283,6 +349,12 @@ TEST_F(TetherConnectorTest, TestCannotFetchDevice) {
}
TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) {
+ EXPECT_CALL(
+ *mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER));
+
CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
fake_active_host_->GetActiveHostStatus());
@@ -308,60 +380,61 @@ TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) {
GetResultAndReset());
}
-TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails) {
- CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
- EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
- fake_active_host_->GetActiveHostStatus());
- EXPECT_EQ(test_devices_[0].GetDeviceId(),
- fake_active_host_->GetActiveHostDeviceId());
- EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()),
- fake_active_host_->GetTetherNetworkGuid());
- EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty());
-
- fake_tether_host_fetcher_->InvokePendingCallbacks();
-
- // Simulate a failed connection attempt (either the host cannot provide
- // tethering at this time or a timeout occurs).
- EXPECT_EQ(1u, fake_operation_factory_->created_operations().size());
- EXPECT_FALSE(
- fake_operation_factory_->created_operations()[0]->setup_required());
- fake_operation_factory_->created_operations()[0]->SendFailedResponse(
+TEST_F(TetherConnectorTest,
+ TestConnectTetheringOperationFails_SetupNotRequired) {
+ VerifyConnectTetheringOperationFails(
ConnectTetheringResponse_ResponseCode::
- ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR);
-
- // The failure should have resulted in the host being disconnected.
- EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED,
- fake_active_host_->GetActiveHostStatus());
- EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset());
+ ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR,
+ false /* setup_required */,
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR);
}
TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails_SetupRequired) {
- EXPECT_FALSE(
- fake_notification_presenter_->is_setup_required_notification_shown());
-
- CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()));
-
- EXPECT_TRUE(
- fake_notification_presenter_->is_setup_required_notification_shown());
-
- fake_tether_host_fetcher_->InvokePendingCallbacks();
-
- EXPECT_TRUE(
- fake_notification_presenter_->is_setup_required_notification_shown());
- EXPECT_TRUE(
- fake_operation_factory_->created_operations()[0]->setup_required());
+ VerifyConnectTetheringOperationFails(
+ ConnectTetheringResponse_ResponseCode::
+ ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR,
+ true /* setup_required */,
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_UNKNOWN_ERROR);
+}
- fake_operation_factory_->created_operations()[0]->SendFailedResponse(
+TEST_F(TetherConnectorTest,
+ TestConnectTetheringOperationFails_ProvisioningFailed) {
+ VerifyConnectTetheringOperationFails(
ConnectTetheringResponse_ResponseCode::
- ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR);
+ ConnectTetheringResponse_ResponseCode_PROVISIONING_FAILED,
+ false /* setup_required */,
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_PROVISIONING_FAILED);
+}
- EXPECT_FALSE(
- fake_notification_presenter_->is_setup_required_notification_shown());
+TEST_F(TetherConnectorTest,
+ TestConnectTetheringOperationFails_TetheringTimeout_SetupNotRequired) {
+ VerifyConnectTetheringOperationFails(
+ ConnectTetheringResponse_ResponseCode::
+ ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT,
+ false /* setup_required */,
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_NOT_REQUIRED);
+}
- EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset());
+TEST_F(TetherConnectorTest,
+ TestConnectTetheringOperationFails_TetheringTimeout_SetupRequired) {
+ VerifyConnectTetheringOperationFails(
+ ConnectTetheringResponse_ResponseCode::
+ ConnectTetheringResponse_ResponseCode_TETHERING_TIMEOUT,
+ true /* setup_required */,
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_REQUIRED);
}
TEST_F(TetherConnectorTest, TestConnectingToWifiFails) {
+ EXPECT_CALL(*mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_TIMEOUT));
+
CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
fake_active_host_->GetActiveHostStatus());
@@ -398,6 +471,12 @@ TEST_F(TetherConnectorTest, TestConnectingToWifiFails) {
}
TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) {
+ EXPECT_CALL(
+ *mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER));
+
CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
fake_active_host_->GetActiveHostStatus());
@@ -428,6 +507,11 @@ TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) {
}
TEST_F(TetherConnectorTest, TestSuccessfulConnection) {
+ EXPECT_CALL(*mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_SUCCESS));
+
CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
fake_active_host_->GetActiveHostStatus());
@@ -472,6 +556,11 @@ TEST_F(TetherConnectorTest, TestSuccessfulConnection) {
}
TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) {
+ EXPECT_CALL(*mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_SUCCESS));
+
EXPECT_FALSE(
fake_notification_presenter_->is_setup_required_notification_shown());
@@ -503,6 +592,12 @@ TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) {
TEST_F(TetherConnectorTest,
TestNewConnectionAttemptDuringFetch_DifferentDevice) {
+ EXPECT_CALL(
+ *mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER));
+
CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
// Instead of invoking the pending callbacks on |fake_tether_host_fetcher_|,
@@ -524,6 +619,12 @@ TEST_F(TetherConnectorTest,
TEST_F(TetherConnectorTest,
TestNewConnectionAttemptDuringOperation_DifferentDevice) {
+ EXPECT_CALL(
+ *mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER));
+
CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
fake_active_host_->GetActiveHostStatus());
@@ -576,6 +677,12 @@ TEST_F(TetherConnectorTest,
TEST_F(TetherConnectorTest,
TestNewConnectionAttemptDuringWifiConnection_DifferentDevice) {
+ EXPECT_CALL(
+ *mock_host_connection_metrics_logger_,
+ RecordConnectionToHostResult(
+ HostConnectionMetricsLogger::ConnectionToHostResult::
+ CONNECTION_RESULT_FAILURE_CLIENT_CONNECTION_CANCELED_BY_USER));
+
CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
fake_active_host_->GetActiveHostStatus());
« no previous file with comments | « chromeos/components/tether/tether_connector.cc ('k') | chromeos/components/tether/tether_disconnector_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698