Commit 89b2f828 authored by Kartik Hegde's avatar Kartik Hegde Committed by Commit Bot

cros_healthd: Add CaptivePortal routine

Add the CaptivePortal routine to the ServiceConnection.

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

Change-Id: I8eb98621bdfde9efc53357ba05f04affce614139
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2477523Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarPaul Moy <pmoy@chromium.org>
Commit-Queue: Kartik Hegde <khegde@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824968}
parent d92a59f5
...@@ -518,6 +518,14 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback, ...@@ -518,6 +518,14 @@ void DeviceCommandRunRoutineJob::RunImpl(CallbackWithResult succeeded_callback,
std::move(failed_callback))); std::move(failed_callback)));
break; break;
} }
case chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kCaptivePortal: {
chromeos::cros_healthd::ServiceConnection::GetInstance()
->RunCaptivePortalRoutine(base::BindOnce(
&DeviceCommandRunRoutineJob::OnCrosHealthdResponseReceived,
weak_ptr_factory_.GetWeakPtr(), std::move(succeeded_callback),
std::move(failed_callback)));
break;
}
} }
} }
......
...@@ -1279,4 +1279,23 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDnsResolutionRoutineSuccess) { ...@@ -1279,4 +1279,23 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDnsResolutionRoutineSuccess) {
}))); })));
} }
// Note that the captive portal routine has no parameters, so we only need to
// test that it can be run successfully.
TEST_F(DeviceCommandRunRoutineJobTest, RunCaptivePortalRoutineSuccess) {
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::kCaptivePortal,
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
...@@ -238,6 +238,11 @@ void FakeCrosHealthdService::RunDnsResolutionRoutine( ...@@ -238,6 +238,11 @@ void FakeCrosHealthdService::RunDnsResolutionRoutine(
std::move(callback).Run(run_routine_response_.Clone()); std::move(callback).Run(run_routine_response_.Clone());
} }
void FakeCrosHealthdService::RunCaptivePortalRoutine(
RunCaptivePortalRoutineCallback 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());
......
...@@ -107,6 +107,8 @@ class FakeCrosHealthdService final ...@@ -107,6 +107,8 @@ class FakeCrosHealthdService final
void RunDnsLatencyRoutine(RunDnsLatencyRoutineCallback callback) override; void RunDnsLatencyRoutine(RunDnsLatencyRoutineCallback callback) override;
void RunDnsResolutionRoutine( void RunDnsResolutionRoutine(
RunDnsResolutionRoutineCallback callback) override; RunDnsResolutionRoutineCallback callback) override;
void RunCaptivePortalRoutine(
RunCaptivePortalRoutineCallback callback) override;
// CrosHealthdEventService overrides: // CrosHealthdEventService overrides:
void AddBluetoothObserver( void AddBluetoothObserver(
......
...@@ -121,6 +121,9 @@ class ServiceConnectionImpl : public ServiceConnection { ...@@ -121,6 +121,9 @@ class ServiceConnectionImpl : public ServiceConnection {
void RunDnsResolutionRoutine( void RunDnsResolutionRoutine(
mojom::CrosHealthdDiagnosticsService::RunDnsResolutionRoutineCallback mojom::CrosHealthdDiagnosticsService::RunDnsResolutionRoutineCallback
callback) override; callback) override;
void RunCaptivePortalRoutine(
mojom::CrosHealthdDiagnosticsService::RunCaptivePortalRoutineCallback
callback) override;
void AddBluetoothObserver( void AddBluetoothObserver(
mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer) mojo::PendingRemote<mojom::CrosHealthdBluetoothObserver> pending_observer)
override; override;
...@@ -428,6 +431,15 @@ void ServiceConnectionImpl::RunDnsResolutionRoutine( ...@@ -428,6 +431,15 @@ void ServiceConnectionImpl::RunDnsResolutionRoutine(
std::move(callback)); std::move(callback));
} }
void ServiceConnectionImpl::RunCaptivePortalRoutine(
mojom::CrosHealthdDiagnosticsService::RunCaptivePortalRoutineCallback
callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindCrosHealthdDiagnosticsServiceIfNeeded();
cros_healthd_diagnostics_service_->RunCaptivePortalRoutine(
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_);
......
...@@ -224,6 +224,13 @@ class ServiceConnection { ...@@ -224,6 +224,13 @@ class ServiceConnection {
mojom::CrosHealthdDiagnosticsService::RunDnsResolutionRoutineCallback mojom::CrosHealthdDiagnosticsService::RunDnsResolutionRoutineCallback
callback) = 0; callback) = 0;
// Requests that cros_healthd runs the captive portal routine. See
// src/chromeos/service/cros_healthd/public/mojom/cros_healthd.mojom for
// details.
virtual void RunCaptivePortalRoutine(
mojom::CrosHealthdDiagnosticsService::RunCaptivePortalRoutineCallback
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.
......
...@@ -612,6 +612,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunDnsResolutionRoutine) { ...@@ -612,6 +612,19 @@ TEST_F(CrosHealthdServiceConnectionTest, RunDnsResolutionRoutine) {
run_loop.Run(); run_loop.Run();
} }
// Test that we can run the captive portal routine.
TEST_F(CrosHealthdServiceConnectionTest, RunCaptivePortalRoutine) {
auto response = MakeRunRoutineResponse();
FakeCrosHealthdClient::Get()->SetRunRoutineResponseForTesting(response);
base::RunLoop run_loop;
ServiceConnection::GetInstance()->RunCaptivePortalRoutine(
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;
......
...@@ -369,6 +369,16 @@ interface CrosHealthdDiagnosticsService { ...@@ -369,6 +369,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.
RunDnsResolutionRoutine() => (RunRoutineResponse response); RunDnsResolutionRoutine() => (RunRoutineResponse response);
// Requests that the CaptivePortal routine is created and started on the
// platform. This routine checks whether the internet connection is behind
// a captive portal. This routine is only available if GetAvailableRoutines
// returned kCaptivePortal.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunCaptivePortalRoutine() => (RunRoutineResponse response);
}; };
// Event interface exposed by the cros_healthd daemon. // Event interface exposed by the cros_healthd daemon.
......
...@@ -38,6 +38,7 @@ enum DiagnosticRoutineEnum { ...@@ -38,6 +38,7 @@ enum DiagnosticRoutineEnum {
kDnsResolverPresent = 19, kDnsResolverPresent = 19,
kDnsLatency = 20, kDnsLatency = 20,
kDnsResolution = 21, kDnsResolution = 21,
kCaptivePortal = 22,
}; };
// 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