Commit 79965d1c authored by Kartik Hegde's avatar Kartik Hegde Committed by Commit Bot

cros_healthd: Add DnsResolverPresent routine

Add the DnsResolverPresent routine to the ServiceConnection.

BUG=chromium:956783
TEST=1) chromeos_unittests --gtest_filter=CrosHealthdServiceConnectionTest.*
2) unit_tests --gtest_filter=DeviceCommandRunRoutineJobTest*
3) Applied DnsResolverPresent changes and successfully ran the
DnsResolverPresent routine on a DUT (verified using cros-health-tool diag
--action=run_routine --routine=dns_resolver_prsent).

Change-Id: Iad19c4ab6eb9391bcc4a9410288e90f838446073
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2344807Reviewed-by: default avatarPaul Moy <pmoy@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarOleh Lamzin <lamzin@google.com>
Commit-Queue: Kartik Hegde <khegde@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817786}
parent e5725605
...@@ -530,6 +530,15 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback, ...@@ -530,6 +530,15 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback,
std::move(failed_callback))); std::move(failed_callback)));
break; break;
} }
case chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::
kDnsResolverPresent: {
chromeos::cros_healthd::ServiceConnection::GetInstance()
->RunDnsResolverPresentRoutine(base::BindOnce(
&DeviceCommandRunRoutineJob::OnCrosHealthdResponseReceived,
weak_ptr_factory_.GetWeakPtr(), std::move(succeeded_callback),
std::move(failed_callback)));
break;
}
} }
} }
......
...@@ -1331,4 +1331,63 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunSignalStrengthRoutineSuccess) { ...@@ -1331,4 +1331,63 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunSignalStrengthRoutineSuccess) {
}))); })));
} }
// Note that the gateway can be pinged routine has no parameters, so we only
// need to test that it can be run successfully.
TEST_F(DeviceCommandRunRoutineJobTest, RunGatewayCanBePingedRoutineSuccess) {
auto run_routine_response =
chromeos::cros_healthd::mojom::RunRoutineResponse::New(kId, kStatus);
chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY);
EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kGatewayCanBePinged,
std::move(params_dict),
base::BindLambdaForTesting([](RemoteCommandJob* job) {
EXPECT_EQ(job->status(), RemoteCommandJob::SUCCEEDED);
std::unique_ptr<std::string> payload = job->GetResultPayload();
EXPECT_TRUE(payload);
EXPECT_EQ(CreateSuccessPayload(kId, kStatus), *payload);
})));
}
// Note that the has secure WiFi connection routine has no parameters, so we
// only need to test that it can be run successfully.
TEST_F(DeviceCommandRunRoutineJobTest,
RunHasSecureWiFiConnectionRoutineSuccess) {
auto run_routine_response =
chromeos::cros_healthd::mojom::RunRoutineResponse::New(kId, kStatus);
chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY);
EXPECT_TRUE(RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::
kHasSecureWiFiConnection,
std::move(params_dict),
base::BindLambdaForTesting([](RemoteCommandJob* job) {
EXPECT_EQ(job->status(), RemoteCommandJob::SUCCEEDED);
std::unique_ptr<std::string> payload =
job->GetResultPayload();
EXPECT_TRUE(payload);
EXPECT_EQ(CreateSuccessPayload(kId, kStatus), *payload);
})));
}
// Note that the DNS resolver present routine has no parameters, so we only need
// to test that it can be run successfully.
TEST_F(DeviceCommandRunRoutineJobTest, RunDnsResolverPresentRoutineSuccess) {
auto run_routine_response =
chromeos::cros_healthd::mojom::RunRoutineResponse::New(kId, kStatus);
chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY);
EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDnsResolverPresent,
std::move(params_dict),
base::BindLambdaForTesting([](RemoteCommandJob* job) {
EXPECT_EQ(job->status(), RemoteCommandJob::SUCCEEDED);
std::unique_ptr<std::string> payload = job->GetResultPayload();
EXPECT_TRUE(payload);
EXPECT_EQ(CreateSuccessPayload(kId, kStatus), *payload);
})));
}
} // namespace policy } // namespace policy
...@@ -227,6 +227,11 @@ void FakeCrosHealthdService::RunHasSecureWiFiConnectionRoutine( ...@@ -227,6 +227,11 @@ void FakeCrosHealthdService::RunHasSecureWiFiConnectionRoutine(
std::move(callback).Run(run_routine_response_.Clone()); std::move(callback).Run(run_routine_response_.Clone());
} }
void FakeCrosHealthdService::RunDnsResolverPresentRoutine(
RunDnsResolverPresentRoutineCallback callback) {
std::move(callback).Run(run_routine_response_.Clone());
}
void FakeCrosHealthdService::AddBluetoothObserver( void FakeCrosHealthdService::AddBluetoothObserver(
mojom::CrosHealthdBluetoothObserverPtr observer) { mojom::CrosHealthdBluetoothObserverPtr observer) {
bluetooth_observers_.Add(observer.PassInterface()); bluetooth_observers_.Add(observer.PassInterface());
......
...@@ -106,6 +106,8 @@ class FakeCrosHealthdService final ...@@ -106,6 +106,8 @@ class FakeCrosHealthdService final
RunGatewayCanBePingedRoutineCallback callback) override; RunGatewayCanBePingedRoutineCallback callback) override;
void RunHasSecureWiFiConnectionRoutine( void RunHasSecureWiFiConnectionRoutine(
RunHasSecureWiFiConnectionRoutineCallback callback) override; RunHasSecureWiFiConnectionRoutineCallback callback) override;
void RunDnsResolverPresentRoutine(
RunDnsResolverPresentRoutineCallback callback) override;
// CrosHealthdEventService overrides: // CrosHealthdEventService overrides:
void AddBluetoothObserver( void AddBluetoothObserver(
......
...@@ -116,6 +116,9 @@ class ServiceConnectionImpl : public ServiceConnection { ...@@ -116,6 +116,9 @@ class ServiceConnectionImpl : public ServiceConnection {
void RunHasSecureWiFiConnectionRoutine( void RunHasSecureWiFiConnectionRoutine(
mojom::CrosHealthdDiagnosticsService:: mojom::CrosHealthdDiagnosticsService::
RunHasSecureWiFiConnectionRoutineCallback callback) override; RunHasSecureWiFiConnectionRoutineCallback callback) override;
void RunDnsResolverPresentRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsResolverPresentRoutineCallback
callback) override;
void AddBluetoothObserver( void AddBluetoothObserver(
mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer)
override; override;
...@@ -401,6 +404,15 @@ void ServiceConnectionImpl::RunHasSecureWiFiConnectionRoutine( ...@@ -401,6 +404,15 @@ void ServiceConnectionImpl::RunHasSecureWiFiConnectionRoutine(
std::move(callback)); std::move(callback));
} }
void ServiceConnectionImpl::RunDnsResolverPresentRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsResolverPresentRoutineCallback
callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdDiagnosticsServiceIfNeeded();
cros_healthd_diagnostics_service_->RunDnsResolverPresentRoutine(
std::move(callback));
}
void ServiceConnectionImpl::AddBluetoothObserver( void ServiceConnectionImpl::AddBluetoothObserver(
mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) { mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......
...@@ -207,6 +207,13 @@ class ServiceConnection { ...@@ -207,6 +207,13 @@ class ServiceConnection {
mojom::CrosHealthdDiagnosticsService:: mojom::CrosHealthdDiagnosticsService::
RunHasSecureWiFiConnectionRoutineCallback callback) = 0; RunHasSecureWiFiConnectionRoutineCallback callback) = 0;
// Requests that cros_healthd runs DNS resolver present routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunDnsResolverPresentRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsResolverPresentRoutineCallback
callback) = 0;
// Subscribes to cros_healthd's Bluetooth-related events. See // Subscribes to cros_healthd's Bluetooth-related events. See
// src/chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom for // src/chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom for
// details. // details.
......
...@@ -575,6 +575,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunHasSecureWiFiConnectionRoutine) { ...@@ -575,6 +575,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunHasSecureWiFiConnectionRoutine) {
run_loop.Run(); run_loop.Run();
} }
// Test that we can run the DNS resolver present routine.
TEST_F(CrosHealthdServiceConnectionTest, RunDnsResolverPresentRoutine) {
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
base::RunLoop run_loop;
ServiceConnection::GetInstance()->RunDnsResolverPresentRoutine(
base::BindLambdaForTesting([&](mojom::RunRoutineResponsePtr response) {
EXPECT_EQ(response, MakeRunRoutineResponse());
run_loop.Quit();
}));
run_loop.Run();
}
// Test that we can add a Bluetooth observer. // Test that we can add a Bluetooth observer.
TEST_F(CrosHealthdServiceConnectionTest, AddBluetoothObserver) { TEST_F(CrosHealthdServiceConnectionTest, AddBluetoothObserver) {
MockCrosHealthdBluetoothObserver observer; MockCrosHealthdBluetoothObserver observer;
......
...@@ -347,6 +347,16 @@ interface CrosHealthdDiagnosticsService { ...@@ -347,6 +347,16 @@ interface CrosHealthdDiagnosticsService {
// * |response| - contains a unique identifier and status for the created // * |response| - contains a unique identifier and status for the created
// routine. // routine.
RunHasSecureWiFiConnectionRoutine() => (RunRoutineResponse response); RunHasSecureWiFiConnectionRoutine() => (RunRoutineResponse response);
// Requests that the DnsResolverPresent routine is created and started on the
// platform. This routine checks whether a DNS resolver is available to the
// browser. This routine is only available if GetAvailableRoutines returned
// kDnsResolverPresent.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunDnsResolverPresentRoutine() => (RunRoutineResponse response);
}; };
// Event interface exposed by the cros_healthd daemon. // Event interface exposed by the cros_healthd daemon.
......
...@@ -35,6 +35,7 @@ enum DiagnosticRoutineEnum { ...@@ -35,6 +35,7 @@ enum DiagnosticRoutineEnum {
kSignalStrength = 16, kSignalStrength = 16,
kGatewayCanBePinged = 17, kGatewayCanBePinged = 17,
kHasSecureWiFiConnection = 18, kHasSecureWiFiConnection = 18,
kDnsResolverPresent = 19,
}; };
// Enumeration of the possible DiskRead routine's command type // Enumeration of the possible DiskRead routine's command type
......
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