Commit bd0741d0 authored by Paul Moy's avatar Paul Moy Committed by Commit Bot

remote_commands: descriptively name test arguments

Instead of using magic numbers for test arguments, name
them according to their function, e.g. kPositiveInt.
This makes it clear what the number represents.

Bug: chromium:1066251
Change-Id: Ie9525667d4fe62dcd0c61f39250f61cb9fc70fe0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134504
Commit-Queue: Paul Moy <pmoy@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756373}
parent e931a171
...@@ -78,11 +78,19 @@ constexpr char kMaximumDischargePercentAllowedFieldName[] = ...@@ -78,11 +78,19 @@ constexpr char kMaximumDischargePercentAllowedFieldName[] =
// Dummy values to populate cros_healthd's RunRoutineResponse. // Dummy values to populate cros_healthd's RunRoutineResponse.
constexpr uint32_t kId = 11; constexpr uint32_t kId = 11;
constexpr chromeos::cros_healthd::mojom::DiagnosticRoutineStatusEnum kStatus = constexpr auto kStatus =
chromeos::cros_healthd::mojom::DiagnosticRoutineStatusEnum::kRunning; chromeos::cros_healthd::mojom::DiagnosticRoutineStatusEnum::kRunning;
constexpr RemoteCommandJob::UniqueIDType kUniqueID = 987123; constexpr RemoteCommandJob::UniqueIDType kUniqueID = 987123;
constexpr int kPositiveInt = 8789;
constexpr int kNegativeInt = -231;
constexpr auto kValidAcPowerStatusEnum =
chromeos::cros_healthd::mojom::AcPowerStatusEnum::kConnected;
constexpr char kValidExpectedAcPowerType[] = "power_type";
constexpr auto kValidDiskReadRoutineTypeEnum =
chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum::kLinearRead;
em::RemoteCommand GenerateCommandProto( em::RemoteCommand GenerateCommandProto(
RemoteCommandJob::UniqueIDType unique_id, RemoteCommandJob::UniqueIDType unique_id,
base::TimeDelta age_of_command, base::TimeDelta age_of_command,
...@@ -214,19 +222,18 @@ bool DeviceCommandRunRoutineJobTest::RunJob( ...@@ -214,19 +222,18 @@ bool DeviceCommandRunRoutineJobTest::RunJob(
} }
TEST_F(DeviceCommandRunRoutineJobTest, InvalidRoutineEnumInCommandPayload) { TEST_F(DeviceCommandRunRoutineJobTest, InvalidRoutineEnumInCommandPayload) {
constexpr auto kInvalidRoutineEnum = static_cast<
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum>(
std::numeric_limits<std::underlying_type<
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum>::type>::max());
auto job = std::make_unique<DeviceCommandRunRoutineJob>(); auto job = std::make_unique<DeviceCommandRunRoutineJob>();
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
EXPECT_FALSE(job->Init( EXPECT_FALSE(job->Init(
base::TimeTicks::Now(), base::TimeTicks::Now(),
GenerateCommandProto( GenerateCommandProto(kUniqueID, base::TimeTicks::Now() - test_start_time_,
kUniqueID, base::TimeTicks::Now() - test_start_time_, base::TimeDelta::FromSeconds(30),
base::TimeDelta::FromSeconds(30), /*terminate_upon_input=*/false, kInvalidRoutineEnum,
/*terminate_upon_input=*/false, std::move(params_dict)),
static_cast<chromeos::cros_healthd::mojom::DiagnosticRoutineEnum>(
std::numeric_limits<std::underlying_type<
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum>::type>::
max()),
std::move(params_dict)),
nullptr)); nullptr));
EXPECT_EQ(kUniqueID, job->unique_id()); EXPECT_EQ(kUniqueID, job->unique_id());
...@@ -252,15 +259,15 @@ TEST_F(DeviceCommandRunRoutineJobTest, CommandPayloadMissingRoutine) { ...@@ -252,15 +259,15 @@ TEST_F(DeviceCommandRunRoutineJobTest, CommandPayloadMissingRoutine) {
// Test that not including a parameters dictionary causes the routine // Test that not including a parameters dictionary causes the routine
// initialization to fail. // initialization to fail.
TEST_F(DeviceCommandRunRoutineJobTest, CommandPayloadMissingParamDict) { TEST_F(DeviceCommandRunRoutineJobTest, CommandPayloadMissingParamDict) {
constexpr auto kValidRoutineEnum =
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kSmartctlCheck;
auto job = std::make_unique<DeviceCommandRunRoutineJob>(); auto job = std::make_unique<DeviceCommandRunRoutineJob>();
EXPECT_FALSE(job->Init( EXPECT_FALSE(job->Init(
base::TimeTicks::Now(), base::TimeTicks::Now(),
GenerateCommandProto( GenerateCommandProto(kUniqueID, base::TimeTicks::Now() - test_start_time_,
kUniqueID, base::TimeTicks::Now() - test_start_time_, base::TimeDelta::FromSeconds(30),
base::TimeDelta::FromSeconds(30), /*terminate_upon_input=*/false, kValidRoutineEnum,
/*terminate_upon_input=*/false, /*params=*/base::nullopt),
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kSmartctlCheck,
/*params=*/base::nullopt),
nullptr)); nullptr));
EXPECT_EQ(kUniqueID, job->unique_id()); EXPECT_EQ(kUniqueID, job->unique_id());
...@@ -273,8 +280,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineSuccess) { ...@@ -273,8 +280,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLowMahFieldName, /*low_mah=*/90812); params_dict.SetIntKey(kLowMahFieldName, kPositiveInt);
params_dict.SetIntKey(kHighMahFieldName, /*high_mah=*/986909); params_dict.SetIntKey(kHighMahFieldName, kPositiveInt);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity,
std::move(params_dict), std::move(params_dict),
...@@ -290,7 +297,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineSuccess) { ...@@ -290,7 +297,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineSuccess) {
// routine to fail. // routine to fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineMissingLowMah) { TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineMissingLowMah) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kHighMahFieldName, /*high_mah=*/986909); params_dict.SetIntKey(kHighMahFieldName, kPositiveInt);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity,
std::move(params_dict), std::move(params_dict),
...@@ -307,7 +314,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineMissingLowMah) { ...@@ -307,7 +314,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineMissingLowMah) {
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunBatteryCapacityRoutineMissingHighMah) { RunBatteryCapacityRoutineMissingHighMah) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLowMahFieldName, /*low_mah=*/90812); params_dict.SetIntKey(kLowMahFieldName, kPositiveInt);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity,
std::move(params_dict), std::move(params_dict),
...@@ -323,8 +330,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -323,8 +330,8 @@ TEST_F(DeviceCommandRunRoutineJobTest,
// fail. // fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineInvalidLowMah) { TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineInvalidLowMah) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLowMahFieldName, /*low_mah=*/-1); params_dict.SetIntKey(kLowMahFieldName, kNegativeInt);
params_dict.SetIntKey(kHighMahFieldName, /*high_mah=*/986909); params_dict.SetIntKey(kHighMahFieldName, kPositiveInt);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity,
std::move(params_dict), std::move(params_dict),
...@@ -341,8 +348,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineInvalidLowMah) { ...@@ -341,8 +348,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryCapacityRoutineInvalidLowMah) {
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunBatteryCapacityRoutineInvalidHighMah) { RunBatteryCapacityRoutineInvalidHighMah) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLowMahFieldName, /*low_mah=*/90812); params_dict.SetIntKey(kLowMahFieldName, kPositiveInt);
params_dict.SetIntKey(kHighMahFieldName, /*high_mah=*/-1); params_dict.SetIntKey(kHighMahFieldName, kNegativeInt);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity,
std::move(params_dict), std::move(params_dict),
...@@ -360,10 +367,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryHealthRoutineSuccess) { ...@@ -360,10 +367,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryHealthRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kMaximumCycleCountFieldName, params_dict.SetIntKey(kMaximumCycleCountFieldName, kPositiveInt);
/*maximum_cycle_count=*/12); params_dict.SetIntKey(kPercentBatteryWearAllowedFieldName, kPositiveInt);
params_dict.SetIntKey(kPercentBatteryWearAllowedFieldName,
/*percent_battery_wear_allowed=*/78);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth,
std::move(params_dict), std::move(params_dict),
...@@ -380,8 +385,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryHealthRoutineSuccess) { ...@@ -380,8 +385,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryHealthRoutineSuccess) {
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunBatteryHealthRoutineMissingMaximumCycleCount) { RunBatteryHealthRoutineMissingMaximumCycleCount) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kPercentBatteryWearAllowedFieldName, params_dict.SetIntKey(kPercentBatteryWearAllowedFieldName, kPositiveInt);
/*percent_battery_wear_allowed=*/78);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth,
std::move(params_dict), std::move(params_dict),
...@@ -398,8 +402,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -398,8 +402,7 @@ TEST_F(DeviceCommandRunRoutineJobTest,
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunBatteryHealthRoutineMissingPercentBatteryWearAllowed) { RunBatteryHealthRoutineMissingPercentBatteryWearAllowed) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kMaximumCycleCountFieldName, params_dict.SetIntKey(kMaximumCycleCountFieldName, kPositiveInt);
/*maximum_cycle_count=*/12);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth,
std::move(params_dict), std::move(params_dict),
...@@ -416,10 +419,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -416,10 +419,8 @@ TEST_F(DeviceCommandRunRoutineJobTest,
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunBatteryHealthRoutineInvalidMaximumCycleCount) { RunBatteryHealthRoutineInvalidMaximumCycleCount) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kMaximumCycleCountFieldName, params_dict.SetIntKey(kMaximumCycleCountFieldName, kNegativeInt);
/*maximum_cycle_count=*/-1); params_dict.SetIntKey(kPercentBatteryWearAllowedFieldName, kPositiveInt);
params_dict.SetIntKey(kPercentBatteryWearAllowedFieldName,
/*percent_battery_wear_allowed=*/78);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth,
std::move(params_dict), std::move(params_dict),
...@@ -436,10 +437,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -436,10 +437,8 @@ TEST_F(DeviceCommandRunRoutineJobTest,
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunBatteryHealthRoutineInvalidPercentBatteryWearAllowed) { RunBatteryHealthRoutineInvalidPercentBatteryWearAllowed) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kMaximumCycleCountFieldName, params_dict.SetIntKey(kMaximumCycleCountFieldName, kPositiveInt);
/*maximum_cycle_count=*/12); params_dict.SetIntKey(kPercentBatteryWearAllowedFieldName, kNegativeInt);
params_dict.SetIntKey(kPercentBatteryWearAllowedFieldName,
/*percent_battery_wear_allowed=*/-1);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth,
std::move(params_dict), std::move(params_dict),
...@@ -457,8 +456,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunUrandomRoutineSuccess) { ...@@ -457,8 +456,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunUrandomRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
/*length_seconds=*/2342);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kUrandom, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kUrandom,
std::move(params_dict), std::move(params_dict),
...@@ -489,8 +487,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunUrandomRoutineMissingLengthSeconds) { ...@@ -489,8 +487,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunUrandomRoutineMissingLengthSeconds) {
// fail. // fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunUrandomRoutineInvalidLengthSeconds) { TEST_F(DeviceCommandRunRoutineJobTest, RunUrandomRoutineInvalidLengthSeconds) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kNegativeInt);
/*length_seconds=*/-1);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kUrandom, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kUrandom,
std::move(params_dict), std::move(params_dict),
...@@ -528,12 +525,10 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunAcPowerRoutineSuccess) { ...@@ -528,12 +525,10 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunAcPowerRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey( params_dict.SetIntKey(kExpectedStatusFieldName,
kExpectedStatusFieldName, static_cast<int>(kValidAcPowerStatusEnum));
/*expected_status=*/static_cast<int>(
chromeos::cros_healthd::mojom::AcPowerStatusEnum::kConnected));
params_dict.SetStringKey(kExpectedPowerTypeFieldName, params_dict.SetStringKey(kExpectedPowerTypeFieldName,
/*expected_power_type=*/"power_type"); kValidExpectedAcPowerType);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kAcPower, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kAcPower,
std::move(params_dict), std::move(params_dict),
...@@ -554,10 +549,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -554,10 +549,8 @@ TEST_F(DeviceCommandRunRoutineJobTest,
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey( params_dict.SetIntKey(kExpectedStatusFieldName,
kExpectedStatusFieldName, static_cast<int>(kValidAcPowerStatusEnum));
/*expected_status=*/static_cast<int>(
chromeos::cros_healthd::mojom::AcPowerStatusEnum::kConnected));
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kAcPower, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kAcPower,
std::move(params_dict), std::move(params_dict),
...@@ -574,7 +567,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -574,7 +567,7 @@ TEST_F(DeviceCommandRunRoutineJobTest,
TEST_F(DeviceCommandRunRoutineJobTest, RunAcPowerRoutineMissingExpectedStatus) { TEST_F(DeviceCommandRunRoutineJobTest, RunAcPowerRoutineMissingExpectedStatus) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetStringKey(kExpectedPowerTypeFieldName, params_dict.SetStringKey(kExpectedPowerTypeFieldName,
/*expected_power_type=*/"power_type"); kValidExpectedAcPowerType);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kAcPower, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kAcPower,
std::move(params_dict), std::move(params_dict),
...@@ -589,15 +582,15 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunAcPowerRoutineMissingExpectedStatus) { ...@@ -589,15 +582,15 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunAcPowerRoutineMissingExpectedStatus) {
// Test that an invalid value for the expectedStatus parameter causes the AC // Test that an invalid value for the expectedStatus parameter causes the AC
// power routine to fail. // power routine to fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunAcPowerRoutineInvalidExpectedStatus) { TEST_F(DeviceCommandRunRoutineJobTest, RunAcPowerRoutineInvalidExpectedStatus) {
base::Value params_dict(base::Value::Type::DICTIONARY); constexpr auto kInvalidAcPowerStatusEnum =
auto expected_status =
static_cast<chromeos::cros_healthd::mojom::AcPowerStatusEnum>( static_cast<chromeos::cros_healthd::mojom::AcPowerStatusEnum>(
std::numeric_limits<std::underlying_type< std::numeric_limits<std::underlying_type<
chromeos::cros_healthd::mojom::AcPowerStatusEnum>::type>::max()); chromeos::cros_healthd::mojom::AcPowerStatusEnum>::type>::max());
base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kExpectedStatusFieldName, params_dict.SetIntKey(kExpectedStatusFieldName,
static_cast<int>(expected_status)); static_cast<int>(kInvalidAcPowerStatusEnum));
params_dict.SetStringKey(kExpectedPowerTypeFieldName, params_dict.SetStringKey(kExpectedPowerTypeFieldName,
/*expected_power_type=*/"power_type"); kValidExpectedAcPowerType);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kAcPower, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kAcPower,
std::move(params_dict), std::move(params_dict),
...@@ -615,8 +608,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunCpuCacheRoutineSuccess) { ...@@ -615,8 +608,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunCpuCacheRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
/*length_seconds=*/2342);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kCpuCache, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kCpuCache,
std::move(params_dict), std::move(params_dict),
...@@ -647,8 +639,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunCpuCacheRoutineMissingLengthSeconds) { ...@@ -647,8 +639,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunCpuCacheRoutineMissingLengthSeconds) {
// fail. // fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunCpuCacheRoutineInvalidLengthSeconds) { TEST_F(DeviceCommandRunRoutineJobTest, RunCpuCacheRoutineInvalidLengthSeconds) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kNegativeInt);
/*length_seconds=*/-1);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kCpuCache, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kCpuCache,
std::move(params_dict), std::move(params_dict),
...@@ -666,8 +657,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunCpuStressRoutineSuccess) { ...@@ -666,8 +657,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunCpuStressRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
/*length_seconds=*/2342);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kCpuStress, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kCpuStress,
std::move(params_dict), std::move(params_dict),
...@@ -700,8 +690,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -700,8 +690,7 @@ TEST_F(DeviceCommandRunRoutineJobTest,
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunCpuStressRoutineInvalidLengthSeconds) { RunCpuStressRoutineInvalidLengthSeconds) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kNegativeInt);
/*length_seconds=*/-1);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kCpuStress, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kCpuStress,
std::move(params_dict), std::move(params_dict),
...@@ -719,8 +708,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunFloatingPointAccuracyRoutineSuccess) { ...@@ -719,8 +708,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunFloatingPointAccuracyRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
/*length_seconds=*/2342);
EXPECT_TRUE(RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum:: EXPECT_TRUE(RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::
kFloatingPointAccuracy, kFloatingPointAccuracy,
std::move(params_dict), std::move(params_dict),
...@@ -755,8 +743,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -755,8 +743,7 @@ TEST_F(DeviceCommandRunRoutineJobTest,
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunFloatingPointAccuracyRoutineInvalidLengthSeconds) { RunFloatingPointAccuracyRoutineInvalidLengthSeconds) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kNegativeInt);
/*length_seconds=*/-1);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum:: RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::
kFloatingPointAccuracy, kFloatingPointAccuracy,
...@@ -775,8 +762,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunNvmeWearLevelRoutineSuccess) { ...@@ -775,8 +762,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunNvmeWearLevelRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kWearLevelThresholdFieldName, params_dict.SetIntKey(kWearLevelThresholdFieldName, kPositiveInt);
/*wear_level_threshold=*/50);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kNvmeWearLevel, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kNvmeWearLevel,
std::move(params_dict), std::move(params_dict),
...@@ -809,8 +795,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -809,8 +795,7 @@ TEST_F(DeviceCommandRunRoutineJobTest,
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunNvmeWearLevelRoutineInvalidWearLevelThreshold) { RunNvmeWearLevelRoutineInvalidWearLevelThreshold) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kWearLevelThresholdFieldName, params_dict.SetIntKey(kWearLevelThresholdFieldName, kNegativeInt);
/*wear_level_threshold=*/-1);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kNvmeWearLevel, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kNvmeWearLevel,
std::move(params_dict), std::move(params_dict),
...@@ -823,15 +808,15 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -823,15 +808,15 @@ TEST_F(DeviceCommandRunRoutineJobTest,
} }
TEST_F(DeviceCommandRunRoutineJobTest, RunNvmeSelfTestRoutineSuccess) { TEST_F(DeviceCommandRunRoutineJobTest, RunNvmeSelfTestRoutineSuccess) {
constexpr auto kValidNvmeSelfTestTypeEnum =
chromeos::cros_healthd::mojom::NvmeSelfTestTypeEnum::kShortSelfTest;
auto run_routine_response = auto run_routine_response =
chromeos::cros_healthd::mojom::RunRoutineResponse::New(kId, kStatus); chromeos::cros_healthd::mojom::RunRoutineResponse::New(kId, kStatus);
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey( params_dict.SetIntKey(kNvmeSelfTestTypeFieldName,
kNvmeSelfTestTypeFieldName, static_cast<int>(kValidNvmeSelfTestTypeEnum));
/*nvme_self_test_type=*/static_cast<int>(
chromeos::cros_healthd::mojom::NvmeSelfTestTypeEnum::kShortSelfTest));
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kNvmeSelfTest, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kNvmeSelfTest,
std::move(params_dict), std::move(params_dict),
...@@ -863,11 +848,13 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -863,11 +848,13 @@ TEST_F(DeviceCommandRunRoutineJobTest,
// self test routine to fail. // self test routine to fail.
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunNvmeSelfTestRoutineInvalidSelfTestType) { RunNvmeSelfTestRoutineInvalidSelfTestType) {
constexpr auto kInvalidNvmeSelfTestTypeEnum = static_cast<
chromeos::cros_healthd::mojom::NvmeSelfTestTypeEnum>(
std::numeric_limits<std::underlying_type<
chromeos::cros_healthd::mojom::NvmeSelfTestTypeEnum>::type>::max());
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
auto nvme_self_test_type = std::numeric_limits<std::underlying_type<
chromeos::cros_healthd::mojom::NvmeSelfTestTypeEnum>::type>::max();
params_dict.SetIntKey(kNvmeSelfTestTypeFieldName, params_dict.SetIntKey(kNvmeSelfTestTypeFieldName,
static_cast<int>(nvme_self_test_type)); static_cast<int>(kInvalidNvmeSelfTestTypeEnum));
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kNvmeSelfTest, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kNvmeSelfTest,
std::move(params_dict), std::move(params_dict),
...@@ -886,14 +873,10 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineSuccess) { ...@@ -886,14 +873,10 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey( params_dict.SetIntKey(kTypeFieldName,
kTypeFieldName, static_cast<int>(kValidDiskReadRoutineTypeEnum));
/*type=*/static_cast<int>( params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum::kLinearRead)); params_dict.SetIntKey(kFileSizeMbFieldName, kPositiveInt);
params_dict.SetIntKey(kLengthSecondsFieldName,
/*length_seconds=*/2342);
params_dict.SetIntKey(kFileSizeMbFieldName,
/*file_size_mb=*/512);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead,
std::move(params_dict), std::move(params_dict),
...@@ -909,10 +892,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineSuccess) { ...@@ -909,10 +892,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineSuccess) {
// fail. // fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingType) { TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingType) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
/*length_seconds=*/2342); params_dict.SetIntKey(kFileSizeMbFieldName, kPositiveInt);
params_dict.SetIntKey(kFileSizeMbFieldName,
/*file_size_mb=*/512);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead,
std::move(params_dict), std::move(params_dict),
...@@ -928,12 +909,9 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingType) { ...@@ -928,12 +909,9 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingType) {
// routine to fail. // routine to fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingLengthSeconds) { TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingLengthSeconds) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey( params_dict.SetIntKey(kTypeFieldName,
kTypeFieldName, static_cast<int>(kValidDiskReadRoutineTypeEnum));
/*type=*/static_cast<int>( params_dict.SetIntKey(kFileSizeMbFieldName, kPositiveInt);
chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum::kLinearRead));
params_dict.SetIntKey(kFileSizeMbFieldName,
/*file_size_mb=*/512);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead,
std::move(params_dict), std::move(params_dict),
...@@ -949,12 +927,9 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingLengthSeconds) { ...@@ -949,12 +927,9 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingLengthSeconds) {
// to fail. // to fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingFileSizeMb) { TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingFileSizeMb) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey( params_dict.SetIntKey(kTypeFieldName,
kTypeFieldName, static_cast<int>(kValidDiskReadRoutineTypeEnum));
/*type=*/static_cast<int>( params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum::kLinearRead));
params_dict.SetIntKey(kLengthSecondsFieldName,
/*length_seconds=*/2342);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead,
std::move(params_dict), std::move(params_dict),
...@@ -969,17 +944,16 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingFileSizeMb) { ...@@ -969,17 +944,16 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineMissingFileSizeMb) {
// Test that an invalid value for the type parameter causes the disk read // Test that an invalid value for the type parameter causes the disk read
// routine to fail. // routine to fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidType) { TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidType) {
base::Value params_dict(base::Value::Type::DICTIONARY); constexpr auto kInvalidDiskReadRoutineTypeEnum =
auto type =
static_cast<chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum>( static_cast<chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum>(
std::numeric_limits<std::underlying_type< std::numeric_limits<std::underlying_type<
chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum>::type>:: chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum>::type>::
max()); max());
params_dict.SetIntKey(kTypeFieldName, static_cast<int>(type)); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kTypeFieldName,
/*length_seconds=*/2342); static_cast<int>(kInvalidDiskReadRoutineTypeEnum));
params_dict.SetIntKey(kFileSizeMbFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
/*file_size_mb=*/512); params_dict.SetIntKey(kFileSizeMbFieldName, kPositiveInt);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead,
std::move(params_dict), std::move(params_dict),
...@@ -995,14 +969,10 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidType) { ...@@ -995,14 +969,10 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidType) {
// read routine to fail. // read routine to fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidLengthSeconds) { TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidLengthSeconds) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey( params_dict.SetIntKey(kTypeFieldName,
kTypeFieldName, static_cast<int>(kValidDiskReadRoutineTypeEnum));
/*type=*/static_cast<int>( params_dict.SetIntKey(kLengthSecondsFieldName, kNegativeInt);
chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum::kLinearRead)); params_dict.SetIntKey(kFileSizeMbFieldName, kPositiveInt);
params_dict.SetIntKey(kLengthSecondsFieldName,
/*length_seconds=*/-1);
params_dict.SetIntKey(kFileSizeMbFieldName,
/*file_size_mb=*/512);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead,
std::move(params_dict), std::move(params_dict),
...@@ -1018,14 +988,10 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidLengthSeconds) { ...@@ -1018,14 +988,10 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidLengthSeconds) {
// routine to fail. // routine to fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidFileSizeMb) { TEST_F(DeviceCommandRunRoutineJobTest, RunDiskReadRoutineInvalidFileSizeMb) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey( params_dict.SetIntKey(kTypeFieldName,
kTypeFieldName, static_cast<int>(kValidDiskReadRoutineTypeEnum));
/*type=*/static_cast<int>( params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
chromeos::cros_healthd::mojom::DiskReadRoutineTypeEnum::kLinearRead)); params_dict.SetIntKey(kFileSizeMbFieldName, kNegativeInt);
params_dict.SetIntKey(kLengthSecondsFieldName,
/*length_seconds=*/2342);
params_dict.SetIntKey(kFileSizeMbFieldName,
/*file_size_mb=*/-1);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead,
std::move(params_dict), std::move(params_dict),
...@@ -1044,10 +1010,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineSuccess) { ...@@ -1044,10 +1010,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
/*length_seconds=*/2342); params_dict.SetIntKey(kMaxNumFieldName, kPositiveInt);
params_dict.SetIntKey(kMaxNumFieldName,
/*max_num=*/100000);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch,
std::move(params_dict), std::move(params_dict),
...@@ -1064,8 +1028,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineSuccess) { ...@@ -1064,8 +1028,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineSuccess) {
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunPrimeSearchRoutineMissingLengthSeconds) { RunPrimeSearchRoutineMissingLengthSeconds) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kMaxNumFieldName, params_dict.SetIntKey(kMaxNumFieldName, kPositiveInt);
/*max_num=*/100000);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch,
std::move(params_dict), std::move(params_dict),
...@@ -1081,8 +1044,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -1081,8 +1044,7 @@ TEST_F(DeviceCommandRunRoutineJobTest,
// fail. // fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineMissingMaxNum) { TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineMissingMaxNum) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
/*length_seconds=*/2342);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch,
std::move(params_dict), std::move(params_dict),
...@@ -1099,10 +1061,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineMissingMaxNum) { ...@@ -1099,10 +1061,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineMissingMaxNum) {
TEST_F(DeviceCommandRunRoutineJobTest, TEST_F(DeviceCommandRunRoutineJobTest,
RunPrimeSearchRoutineInvalidLengthSeconds) { RunPrimeSearchRoutineInvalidLengthSeconds) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kNegativeInt);
/*length_seconds=*/-1); params_dict.SetIntKey(kMaxNumFieldName, kPositiveInt);
params_dict.SetIntKey(kMaxNumFieldName,
/*max_num=*/100000);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch,
std::move(params_dict), std::move(params_dict),
...@@ -1118,10 +1078,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -1118,10 +1078,8 @@ TEST_F(DeviceCommandRunRoutineJobTest,
// routine to fail. // routine to fail.
TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineInvalidMaxNum) { TEST_F(DeviceCommandRunRoutineJobTest, RunPrimeSearchRoutineInvalidMaxNum) {
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
/*length_seconds=*/2342); params_dict.SetIntKey(kMaxNumFieldName, kNegativeInt);
params_dict.SetIntKey(kMaxNumFieldName,
/*max_num=*/-1);
EXPECT_TRUE( EXPECT_TRUE(
RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch, RunJob(chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch,
std::move(params_dict), std::move(params_dict),
...@@ -1139,9 +1097,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryDischargeRoutineSuccess) { ...@@ -1139,9 +1097,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, RunBatteryDischargeRoutineSuccess) {
chromeos::cros_healthd::FakeCrosHealthdClient::Get() chromeos::cros_healthd::FakeCrosHealthdClient::Get()
->SetRunRoutineResponseForTesting(run_routine_response); ->SetRunRoutineResponseForTesting(run_routine_response);
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, /*length_seconds=*/10); params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
params_dict.SetIntKey(kMaximumDischargePercentAllowedFieldName, params_dict.SetIntKey(kMaximumDischargePercentAllowedFieldName, kPositiveInt);
/*maximum_discharge_percent_allowed=*/76);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge,
std::move(params_dict), std::move(params_dict),
...@@ -1158,8 +1115,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -1158,8 +1115,7 @@ TEST_F(DeviceCommandRunRoutineJobTest,
// Test that leaving out the lengthSeconds parameter causes the routine to // Test that leaving out the lengthSeconds parameter causes the routine to
// fail. // fail.
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kMaximumDischargePercentAllowedFieldName, params_dict.SetIntKey(kMaximumDischargePercentAllowedFieldName, kPositiveInt);
/*maximum_discharge_percent_allowed=*/76);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge,
std::move(params_dict), std::move(params_dict),
...@@ -1176,7 +1132,7 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -1176,7 +1132,7 @@ TEST_F(DeviceCommandRunRoutineJobTest,
// Test that leaving out the maximumDischargePercentAllowed parameter causes // Test that leaving out the maximumDischargePercentAllowed parameter causes
// the routine to fail. // the routine to fail.
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, /*length_seconds=*/10); params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge,
std::move(params_dict), std::move(params_dict),
...@@ -1192,9 +1148,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -1192,9 +1148,8 @@ TEST_F(DeviceCommandRunRoutineJobTest,
RunBatteryDischargeRoutineInvalidLengthSeconds) { RunBatteryDischargeRoutineInvalidLengthSeconds) {
// Test that a negative lengthSeconds parameter causes the routine to fail. // Test that a negative lengthSeconds parameter causes the routine to fail.
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, /*length_seconds=*/-10); params_dict.SetIntKey(kLengthSecondsFieldName, kNegativeInt);
params_dict.SetIntKey(kMaximumDischargePercentAllowedFieldName, params_dict.SetIntKey(kMaximumDischargePercentAllowedFieldName, kPositiveInt);
/*maximum_discharge_percent_allowed=*/76);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge,
std::move(params_dict), std::move(params_dict),
...@@ -1211,9 +1166,8 @@ TEST_F(DeviceCommandRunRoutineJobTest, ...@@ -1211,9 +1166,8 @@ TEST_F(DeviceCommandRunRoutineJobTest,
// Test that a negative maximumDischargePercentAllowed parameter causes the // Test that a negative maximumDischargePercentAllowed parameter causes the
// routine to fail. // routine to fail.
base::Value params_dict(base::Value::Type::DICTIONARY); base::Value params_dict(base::Value::Type::DICTIONARY);
params_dict.SetIntKey(kLengthSecondsFieldName, /*length_seconds=*/10); params_dict.SetIntKey(kLengthSecondsFieldName, kPositiveInt);
params_dict.SetIntKey(kMaximumDischargePercentAllowedFieldName, params_dict.SetIntKey(kMaximumDischargePercentAllowedFieldName, kNegativeInt);
/*maximum_discharge_percent_allowed=*/-76);
EXPECT_TRUE(RunJob( EXPECT_TRUE(RunJob(
chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge, chromeos::cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge,
std::move(params_dict), std::move(params_dict),
......
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