Commit c13891c7 authored by Sorin Jianu's avatar Sorin Jianu Committed by Commit Bot

Fix UpdateState comparison for invalid version.

Change-Id: I64808b274438776fe3c6ce94a27bcf43b84a6639
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2278305
Commit-Queue: Sorin Jianu <sorin@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784533}
parent 777b7cb1
...@@ -88,8 +88,11 @@ std::ostream& operator<<(std::ostream& os, ...@@ -88,8 +88,11 @@ std::ostream& operator<<(std::ostream& os,
bool operator==(const UpdateService::UpdateState& lhs, bool operator==(const UpdateService::UpdateState& lhs,
const UpdateService::UpdateState& rhs) { const UpdateService::UpdateState& rhs) {
return lhs.app_id == rhs.app_id && lhs.state == rhs.state && const bool versions_equal =
lhs.next_version == rhs.next_version && (lhs.next_version.IsValid() && rhs.next_version.IsValid() &&
lhs.next_version == rhs.next_version) ||
(!lhs.next_version.IsValid() && !rhs.next_version.IsValid());
return versions_equal && lhs.app_id == rhs.app_id && lhs.state == rhs.state &&
lhs.downloaded_bytes == rhs.downloaded_bytes && lhs.downloaded_bytes == rhs.downloaded_bytes &&
lhs.total_bytes == rhs.total_bytes && lhs.total_bytes == rhs.total_bytes &&
lhs.install_progress == rhs.total_bytes && lhs.install_progress == rhs.total_bytes &&
......
...@@ -11,9 +11,17 @@ namespace updater { ...@@ -11,9 +11,17 @@ namespace updater {
TEST(UnitTestUtil, UpdateServiceState) { TEST(UnitTestUtil, UpdateServiceState) {
UpdateService::UpdateState state1; UpdateService::UpdateState state1;
state1.next_version = base::Version("1.0");
UpdateService::UpdateState state2 = state1; UpdateService::UpdateState state2 = state1;
// Ignore version in the comparison, if both versions are not set.
EXPECT_EQ(state1, state2);
state1.next_version = base::Version("1.0");
EXPECT_NE(state1, state2);
state2.next_version = base::Version("1.0");
EXPECT_EQ(state1, state2); EXPECT_EQ(state1, state2);
state2.state = UpdateService::UpdateState::State::kUpdateError; state2.state = UpdateService::UpdateState::State::kUpdateError;
EXPECT_NE(state1, state2); EXPECT_NE(state1, state2);
EXPECT_STREQ(::testing::PrintToString(state1).c_str(), EXPECT_STREQ(::testing::PrintToString(state1).c_str(),
......
...@@ -112,12 +112,17 @@ class UpdateService : public base::RefCountedThreadSafe<UpdateService> { ...@@ -112,12 +112,17 @@ class UpdateService : public base::RefCountedThreadSafe<UpdateService> {
std::string app_id; std::string app_id;
State state = State::kUnknown; State state = State::kUnknown;
// The version is initialized only after an update check has completed, and
// an update is available.
base::Version next_version; base::Version next_version;
int64_t downloaded_bytes = -1; // -1 means that the byte count is unknown. int64_t downloaded_bytes = -1; // -1 means that the byte count is unknown.
int64_t total_bytes = -1; int64_t total_bytes = -1;
int install_progress = -1; // -1 means that the progress is unknown. // A value in the range [0, 100] if the install progress is known, or -1
// if the install progress is not available or it could not be computed.
int install_progress = -1;
ErrorCategory error_category = ErrorCategory::kNone; ErrorCategory error_category = ErrorCategory::kNone;
int error_code = 0; int error_code = 0;
......
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