Commit 7efce453 authored by Mila Green's avatar Mila Green Committed by Chromium LUCI CQ

Updater: Fix cross-casts enum class error results

Bug: 1159537
Change-Id: I5595f6fc3fb3efa7cd76175820dbd84d3d1f93fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595976Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Commit-Queue: Mila Green <milagreen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838134}
parent 6d590c57
......@@ -309,6 +309,7 @@ if (is_win || is_mac) {
"test/integration_tests.cc",
"test/integration_tests.h",
"unittest_util_unittest.cc",
"update_service_unittest.cc",
"updater_unittest.cc",
]
......
......@@ -37,7 +37,7 @@ namespace updater {
template <typename T>
struct EnumTraits {};
// Returns an optional value of an enun type T if the conversion from an
// Returns an optional value of an enum type T if the conversion from an
// integral type V is safe, meaning that |v| is within the bounds of the enum.
// The enum type must be annotated with traits to specify the lower and upper
// bounds of the enum values.
......
......@@ -46,12 +46,12 @@ class UpdateService : public base::RefCountedThreadSafe<UpdateService> {
// such as a task failed to post, or allocation of a resource failed.
kServiceFailed = 4,
// An error handling the update check occurred.
kUpdateCheckFailed = 5,
// This value indicates that required metadata associated with the
// application was not available for any reason.
kAppNotFound = 5,
// An error handling the update check occurred.
kUpdateCheckFailed = 6,
kAppNotFound = 6,
// A function argument was invalid.
kInvalidArgument = 7,
......@@ -59,11 +59,10 @@ class UpdateService : public base::RefCountedThreadSafe<UpdateService> {
// This server is not the active server.
kInactive = 8,
// Change the EnumTraits class in this file when adding new values.
// IPC connection to the remote process failed for some reason.
kIPCConnectionFailed = 9,
// Change the traits class in this file when adding new values.
// Update EnumTraits<UpdateService::Result> when adding new values.
};
// Run time errors are organized in specific categories to indicate the
......@@ -76,7 +75,7 @@ class UpdateService : public base::RefCountedThreadSafe<UpdateService> {
kInstall = 3,
kService = 4,
kUpdateCheck = 5,
// Change the traits class in this file when adding new values.
// Update EnumTraits<UpdateService::ErrorCategory> when adding new values.
};
struct UpdateState {
......@@ -115,7 +114,8 @@ class UpdateService : public base::RefCountedThreadSafe<UpdateService> {
// halted and the state will not change.
kUpdateError = 8,
// Change the traits class in this file when adding new values.
// Update EnumTraits<UpdateService::UpdateState::State> when adding new
// values.
};
UpdateState();
......@@ -222,7 +222,7 @@ template <>
struct EnumTraits<UpdateService::Result> {
using Result = UpdateService::Result;
static constexpr Result first_elem = Result::kSuccess;
static constexpr Result last_elem = Result::kInactive;
static constexpr Result last_elem = Result::kIPCConnectionFailed;
};
template <>
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/updater/update_service.h"
#include "components/update_client/update_client_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
// Tests value parity between UpdateService::Result and UpdateService::Result.
TEST(UpdateServiceTest, ResultEnumTest) {
EXPECT_EQ(static_cast<int>(updater::UpdateService::Result::kSuccess),
static_cast<int>(update_client::Error::NONE));
EXPECT_EQ(static_cast<int>(updater::UpdateService::Result::kUpdateInProgress),
static_cast<int>(update_client::Error::UPDATE_IN_PROGRESS));
EXPECT_EQ(static_cast<int>(updater::UpdateService::Result::kUpdateCanceled),
static_cast<int>(update_client::Error::UPDATE_CANCELED));
EXPECT_EQ(static_cast<int>(updater::UpdateService::Result::kRetryLater),
static_cast<int>(update_client::Error::RETRY_LATER));
EXPECT_EQ(static_cast<int>(updater::UpdateService::Result::kServiceFailed),
static_cast<int>(update_client::Error::SERVICE_ERROR));
EXPECT_EQ(
static_cast<int>(updater::UpdateService::Result::kUpdateCheckFailed),
static_cast<int>(update_client::Error::UPDATE_CHECK_ERROR));
EXPECT_EQ(static_cast<int>(updater::UpdateService::Result::kAppNotFound),
static_cast<int>(update_client::Error::CRX_NOT_FOUND));
EXPECT_EQ(static_cast<int>(updater::UpdateService::Result::kInvalidArgument),
static_cast<int>(update_client::Error::INVALID_ARGUMENT));
}
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