Commit de4ffadb authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Tether] Show the "connection to host failed" notification when a Tether...

[CrOS Tether] Show the "connection to host failed" notification when a Tether connection attempt fails.

The notification is removed when it is clicked or when a new connection attempt
is started.

Bug: 672263, 734241
Change-Id: I985554345796b953c166024e4bcddf141703591f
Reviewed-on: https://chromium-review.googlesource.com/575526Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487312}
parent 665ee257
...@@ -60,6 +60,7 @@ void TetherConnector::ConnectToNetwork( ...@@ -60,6 +60,7 @@ void TetherConnector::ConnectToNetwork(
PA_LOG(INFO) << "Attempting to connect to network with GUID " PA_LOG(INFO) << "Attempting to connect to network with GUID "
<< tether_network_guid << "."; << tether_network_guid << ".";
notification_presenter_->RemoveConnectionToHostFailedNotification();
const std::string device_id = const std::string device_id =
device_id_tether_network_guid_map_->GetDeviceIdForTetherNetworkGuid( device_id_tether_network_guid_map_->GetDeviceIdForTetherNetworkGuid(
...@@ -244,6 +245,13 @@ void TetherConnector::SetConnectionFailed( ...@@ -244,6 +245,13 @@ void TetherConnector::SetConnectionFailed(
host_connection_metrics_logger_->RecordConnectionToHostResult( host_connection_metrics_logger_->RecordConnectionToHostResult(
connection_to_host_result); connection_to_host_result);
if (error_name == NetworkConnectionHandler::kErrorConnectFailed) {
// Only show notification if the error is kErrorConnectFailed. Other error
// names (e.g., kErrorConnectCanceled) are a result of user interaction and
// should not result in any error UI.
notification_presenter_->NotifyConnectionToHostFailed();
}
} }
void TetherConnector::SetConnectionSucceeded( void TetherConnector::SetConnectionSucceeded(
......
...@@ -287,6 +287,8 @@ class TetherConnectorTest : public NetworkStateTest { ...@@ -287,6 +287,8 @@ class TetherConnectorTest : public NetworkStateTest {
fake_active_host_->GetActiveHostStatus()); fake_active_host_->GetActiveHostStatus());
EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed,
GetResultAndReset()); GetResultAndReset());
EXPECT_TRUE(fake_notification_presenter_
->is_connection_failed_notification_shown());
} }
std::string GetResultAndReset() { std::string GetResultAndReset() {
...@@ -346,6 +348,8 @@ TEST_F(TetherConnectorTest, TestCannotFetchDevice) { ...@@ -346,6 +348,8 @@ TEST_F(TetherConnectorTest, TestCannotFetchDevice) {
EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED,
fake_active_host_->GetActiveHostStatus()); fake_active_host_->GetActiveHostStatus());
EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset());
EXPECT_TRUE(
fake_notification_presenter_->is_connection_failed_notification_shown());
} }
TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) { TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) {
...@@ -378,6 +382,8 @@ TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) { ...@@ -378,6 +382,8 @@ TEST_F(TetherConnectorTest, TestCancelWhileOperationActive) {
fake_active_host_->GetActiveHostStatus()); fake_active_host_->GetActiveHostStatus());
EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled,
GetResultAndReset()); GetResultAndReset());
EXPECT_FALSE(
fake_notification_presenter_->is_connection_failed_notification_shown());
} }
TEST_F(TetherConnectorTest, TEST_F(TetherConnectorTest,
...@@ -429,6 +435,17 @@ TEST_F(TetherConnectorTest, ...@@ -429,6 +435,17 @@ TEST_F(TetherConnectorTest,
CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_REQUIRED); CONNECTION_RESULT_FAILURE_TETHERING_TIMED_OUT_FIRST_TIME_SETUP_WAS_REQUIRED);
} }
TEST_F(TetherConnectorTest,
ConnectionToHostFailedNotificationRemovedWhenConnectionStarts) {
// Start with the "connection to host failed" notification showing.
fake_notification_presenter_->NotifyConnectionToHostFailed();
// Starting a connection should result in it being removed.
CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
EXPECT_FALSE(
fake_notification_presenter_->is_connection_failed_notification_shown());
}
TEST_F(TetherConnectorTest, TestConnectingToWifiFails) { TEST_F(TetherConnectorTest, TestConnectingToWifiFails) {
EXPECT_CALL(*mock_host_connection_metrics_logger_, EXPECT_CALL(*mock_host_connection_metrics_logger_,
RecordConnectionToHostResult( RecordConnectionToHostResult(
...@@ -468,6 +485,8 @@ TEST_F(TetherConnectorTest, TestConnectingToWifiFails) { ...@@ -468,6 +485,8 @@ TEST_F(TetherConnectorTest, TestConnectingToWifiFails) {
EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED,
fake_active_host_->GetActiveHostStatus()); fake_active_host_->GetActiveHostStatus());
EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset());
EXPECT_TRUE(
fake_notification_presenter_->is_connection_failed_notification_shown());
} }
TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) { TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) {
...@@ -504,6 +523,8 @@ TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) { ...@@ -504,6 +523,8 @@ TEST_F(TetherConnectorTest, TestCancelWhileConnectingToWifi) {
fake_active_host_->GetActiveHostStatus()); fake_active_host_->GetActiveHostStatus());
EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled,
GetResultAndReset()); GetResultAndReset());
EXPECT_FALSE(
fake_notification_presenter_->is_connection_failed_notification_shown());
} }
TEST_F(TetherConnectorTest, TestSuccessfulConnection) { TEST_F(TetherConnectorTest, TestSuccessfulConnection) {
...@@ -553,6 +574,8 @@ TEST_F(TetherConnectorTest, TestSuccessfulConnection) { ...@@ -553,6 +574,8 @@ TEST_F(TetherConnectorTest, TestSuccessfulConnection) {
EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid()); EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid());
EXPECT_EQ(kSuccessResult, GetResultAndReset()); EXPECT_EQ(kSuccessResult, GetResultAndReset());
EXPECT_FALSE(
fake_notification_presenter_->is_connection_failed_notification_shown());
} }
TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) { TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) {
...@@ -588,6 +611,8 @@ TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) { ...@@ -588,6 +611,8 @@ TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) {
fake_notification_presenter_->is_setup_required_notification_shown()); fake_notification_presenter_->is_setup_required_notification_shown());
EXPECT_EQ(kSuccessResult, GetResultAndReset()); EXPECT_EQ(kSuccessResult, GetResultAndReset());
EXPECT_FALSE(
fake_notification_presenter_->is_connection_failed_notification_shown());
} }
TEST_F(TetherConnectorTest, TEST_F(TetherConnectorTest,
...@@ -607,6 +632,8 @@ TEST_F(TetherConnectorTest, ...@@ -607,6 +632,8 @@ TEST_F(TetherConnectorTest,
// error. // error.
EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled,
GetResultAndReset()); GetResultAndReset());
EXPECT_FALSE(
fake_notification_presenter_->is_connection_failed_notification_shown());
// Now invoke the callbacks. An operation should have been created for the // Now invoke the callbacks. An operation should have been created for the
// device 1, not device 0. // device 1, not device 0.
...@@ -645,6 +672,8 @@ TEST_F(TetherConnectorTest, ...@@ -645,6 +672,8 @@ TEST_F(TetherConnectorTest,
// error. // error.
EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled,
GetResultAndReset()); GetResultAndReset());
EXPECT_FALSE(
fake_notification_presenter_->is_connection_failed_notification_shown());
fake_tether_host_fetcher_->InvokePendingCallbacks(); fake_tether_host_fetcher_->InvokePendingCallbacks();
// Now, the active host should be the second device. // Now, the active host should be the second device.
...@@ -708,6 +737,8 @@ TEST_F(TetherConnectorTest, ...@@ -708,6 +737,8 @@ TEST_F(TetherConnectorTest,
// error. // error.
EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled,
GetResultAndReset()); GetResultAndReset());
EXPECT_FALSE(
fake_notification_presenter_->is_connection_failed_notification_shown());
fake_tether_host_fetcher_->InvokePendingCallbacks(); fake_tether_host_fetcher_->InvokePendingCallbacks();
// Connect successfully to the first Wi-Fi network. Even though a temporary // Connect successfully to the first Wi-Fi network. Even though a temporary
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment