Support IsDeltaPayload per <package>.
Mixed full and delta payloads are now supported for multi-payload.
Bug: 36252799
Test: update_engine_unittests
Change-Id: Ic519f8399579c714a65ba9f9f948a389fcc249ed
(cherry picked from commit 4928112f8635f7a5b583171640aee2bda690ba34)
diff --git a/payload_state_unittest.cc b/payload_state_unittest.cc
index 6366a7e..4546180 100644
--- a/payload_state_unittest.cc
+++ b/payload_state_unittest.cc
@@ -61,6 +61,7 @@
static void SetupPayloadStateWith2Urls(string hash,
bool http_enabled,
+ bool is_delta_payload,
PayloadState* payload_state,
OmahaResponse* response) {
response->packages.clear();
@@ -68,7 +69,8 @@
.size = 523456789,
.metadata_size = 558123,
.metadata_signature = "metasign",
- .hash = hash});
+ .hash = hash,
+ .is_delta = is_delta_payload});
response->max_failure_count_per_url = 3;
payload_state->SetResponse(*response);
string stored_response_sign = payload_state->GetResponseSignature();
@@ -88,13 +90,13 @@
" Sha256 Hash = %s\n"
" Metadata Size = 558123\n"
" Metadata Signature = metasign\n"
+ " Is Delta = %d\n"
"%s"
- "Is Delta Payload = %d\n"
"Max Failure Count Per Url = %d\n"
"Disable Payload Backoff = %d\n",
hash.c_str(),
+ response->packages[0].is_delta,
(http_enabled ? expected_urls_both : expected_url_https_only).c_str(),
- response->is_delta_payload,
response->max_failure_count_per_url,
response->disable_payload_backoff);
EXPECT_EQ(expected_response_sign, stored_response_sign);
@@ -131,7 +133,6 @@
payload_state.SetResponse(response);
string stored_response_sign = payload_state.GetResponseSignature();
string expected_response_sign =
- "Is Delta Payload = 0\n"
"Max Failure Count Per Url = 0\n"
"Disable Payload Backoff = 0\n";
EXPECT_EQ(expected_response_sign, stored_response_sign);
@@ -183,9 +184,9 @@
" Sha256 Hash = hash\n"
" Metadata Size = 58123\n"
" Metadata Signature = msign\n"
+ " Is Delta = 0\n"
" NumURLs = 1\n"
" Candidate Url0 = https://single.url.test\n"
- "Is Delta Payload = 0\n"
"Max Failure Count Per Url = 0\n"
"Disable Payload Backoff = 0\n";
EXPECT_EQ(expected_response_sign, stored_response_sign);
@@ -235,10 +236,10 @@
" Sha256 Hash = rhash\n"
" Metadata Size = 558123\n"
" Metadata Signature = metasign\n"
+ " Is Delta = 0\n"
" NumURLs = 2\n"
" Candidate Url0 = http://multiple.url.test\n"
" Candidate Url1 = https://multiple.url.test\n"
- "Is Delta Payload = 0\n"
"Max Failure Count Per Url = 0\n"
"Disable Payload Backoff = 0\n";
EXPECT_EQ(expected_response_sign, stored_response_sign);
@@ -282,7 +283,8 @@
// This does a SetResponse which causes all the states to be set to 0 for
// the first time.
- SetupPayloadStateWith2Urls("Hash1235", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash1235", true, false, &payload_state, &response);
EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
// Verify that on the first error, the URL index advances to 1.
@@ -315,7 +317,8 @@
.Times(AnyNumber());
// Set the first response.
- SetupPayloadStateWith2Urls("Hash5823", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash5823", true, false, &payload_state, &response);
EXPECT_EQ(1, payload_state.GetNumResponsesSeen());
// Advance the URL index to 1 by faking an error.
@@ -325,7 +328,8 @@
EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
// Now, slightly change the response and set it again.
- SetupPayloadStateWith2Urls("Hash8225", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8225", true, false, &payload_state, &response);
EXPECT_EQ(2, payload_state.GetNumResponsesSeen());
// Fake an error again.
@@ -334,7 +338,8 @@
EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
// Return a third different response.
- SetupPayloadStateWith2Urls("Hash9999", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash9999", true, false, &payload_state, &response);
EXPECT_EQ(3, payload_state.GetNumResponsesSeen());
// Make sure the url index was reset to 0 because of the new response.
@@ -405,7 +410,8 @@
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash5873", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash5873", true, false, &payload_state, &response);
EXPECT_EQ(1, payload_state.GetNumResponsesSeen());
// This should advance the URL index.
@@ -484,7 +490,8 @@
EXPECT_TRUE(payload_state.ShouldBackoffDownload());
// Now, slightly change the response and set it again.
- SetupPayloadStateWith2Urls("Hash8532", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8532", true, false, &payload_state, &response);
EXPECT_EQ(2, payload_state.GetNumResponsesSeen());
// Make sure the url index was reset to 0 because of the new response.
@@ -498,7 +505,6 @@
TEST(PayloadStateTest, PayloadAttemptNumberIncreasesOnSuccessfulFullDownload) {
OmahaResponse response;
- response.is_delta_payload = false;
PayloadState payload_state;
FakeSystemState fake_system_state;
NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
@@ -524,7 +530,8 @@
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8593", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8593", true, false, &payload_state, &response);
// This should just advance the payload attempt number;
EXPECT_EQ(0, payload_state.GetPayloadAttemptNumber());
@@ -539,7 +546,6 @@
TEST(PayloadStateTest, PayloadAttemptNumberIncreasesOnSuccessfulDeltaDownload) {
OmahaResponse response;
- response.is_delta_payload = true;
PayloadState payload_state;
FakeSystemState fake_system_state;
NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
@@ -564,7 +570,7 @@
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8593", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls("Hash8593", true, true, &payload_state, &response);
// This should just advance the payload attempt number;
EXPECT_EQ(0, payload_state.GetPayloadAttemptNumber());
@@ -583,7 +589,8 @@
FakeSystemState fake_system_state;
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash4427", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash4427", true, false, &payload_state, &response);
// Generate enough events to advance URL index, failure count and
// payload attempt number all to 1.
@@ -619,7 +626,8 @@
// response was different. We want to specifically test that even if the
// response is same, we should reset the state if we find it corrupted.
EXPECT_TRUE(payload_state.Initialize(&fake_system_state2));
- SetupPayloadStateWith2Urls("Hash4427", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash4427", true, false, &payload_state, &response);
// Make sure all counters get reset to 0 because of the corrupted URL index
// we supplied above.
@@ -632,7 +640,6 @@
TEST(PayloadStateTest, NoBackoffInteractiveChecks) {
OmahaResponse response;
- response.is_delta_payload = false;
PayloadState payload_state;
FakeSystemState fake_system_state;
OmahaRequestParams params(&fake_system_state);
@@ -640,7 +647,8 @@
fake_system_state.set_request_params(¶ms);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash6437", true, false, &payload_state, &response);
// Simulate two failures (enough to cause payload backoff) and check
// again that we're ready to re-download without any backoff as this is
@@ -655,7 +663,6 @@
TEST(PayloadStateTest, NoBackoffForP2PUpdates) {
OmahaResponse response;
- response.is_delta_payload = false;
PayloadState payload_state;
FakeSystemState fake_system_state;
OmahaRequestParams params(&fake_system_state);
@@ -663,7 +670,8 @@
fake_system_state.set_request_params(¶ms);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash6437", true, false, &payload_state, &response);
// Simulate two failures (enough to cause payload backoff) and check
// again that we're ready to re-download without any backoff as this is
@@ -686,12 +694,11 @@
TEST(PayloadStateTest, NoBackoffForDeltaPayloads) {
OmahaResponse response;
- response.is_delta_payload = true;
PayloadState payload_state;
FakeSystemState fake_system_state;
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls("Hash6437", true, true, &payload_state, &response);
// Simulate a successful download and see that we're ready to download
// again without any backoff as this is a delta payload.
@@ -731,12 +738,12 @@
TEST(PayloadStateTest, BackoffPeriodsAreInCorrectRange) {
OmahaResponse response;
- response.is_delta_payload = false;
PayloadState payload_state;
FakeSystemState fake_system_state;
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8939", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8939", true, false, &payload_state, &response);
CheckPayloadBackoffState(&payload_state, 1, TimeDelta::FromDays(1));
CheckPayloadBackoffState(&payload_state, 2, TimeDelta::FromDays(2));
@@ -757,7 +764,8 @@
FakeSystemState fake_system_state;
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8939", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8939", true, false, &payload_state, &response);
// Simulate a successful download and see that we are ready to download
// again without any backoff.
@@ -785,7 +793,8 @@
uint64_t http_total = 0;
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash3286", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash3286", true, false, &payload_state, &response);
EXPECT_EQ(1, payload_state.GetNumResponsesSeen());
// Simulate a previous attempt with in order to set an initial non-zero value
@@ -802,7 +811,8 @@
// Change the response hash so as to simulate a new response which will
// reset the current bytes downloaded, but not the total bytes downloaded.
- SetupPayloadStateWith2Urls("Hash9904", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash9904", true, false, &payload_state, &response);
EXPECT_EQ(2, payload_state.GetNumResponsesSeen());
// First, simulate successful download of a few bytes over HTTP.
@@ -904,7 +914,8 @@
FakeSystemState fake_system_state;
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash3286", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash3286", true, false, &payload_state, &response);
// Simulate progress in order to mark HTTP as one of the sources used.
uint64_t num_bytes = 42 * 1000 * 1000;
@@ -935,7 +946,8 @@
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
// Set the first response.
- SetupPayloadStateWith2Urls("Hash5823", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash5823", true, false, &payload_state, &response);
uint64_t num_bytes = 10000;
payload_state.DownloadProgress(num_bytes);
@@ -1052,7 +1064,8 @@
// Check that durations are correct for a successful update where
// time has advanced 7 seconds on the wall clock and 4 seconds on
// the monotonic clock.
- SetupPayloadStateWith2Urls("Hash8593", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8593", true, false, &payload_state, &response);
fake_clock.SetWallclockTime(Time::FromInternalValue(8000000));
fake_clock.SetMonotonicTime(Time::FromInternalValue(6000000));
payload_state.UpdateSucceeded();
@@ -1060,7 +1073,8 @@
EXPECT_EQ(payload_state.GetUpdateDurationUptime().InMicroseconds(), 4000000);
// Check that durations are reset when a new response comes in.
- SetupPayloadStateWith2Urls("Hash8594", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8594", true, false, &payload_state, &response);
EXPECT_EQ(payload_state.GetUpdateDuration().InMicroseconds(), 0);
EXPECT_EQ(payload_state.GetUpdateDurationUptime().InMicroseconds(), 0);
@@ -1109,7 +1123,8 @@
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
// Make the update succeed.
- SetupPayloadStateWith2Urls("Hash8593", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8593", true, false, &payload_state, &response);
payload_state.UpdateSucceeded();
// Check that the marker was written.
@@ -1251,7 +1266,8 @@
.WillRepeatedly(Return(false));
// Set the first response.
- SetupPayloadStateWith2Urls("Hash8433", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8433", true, false, &payload_state, &response);
// Check that we use the HTTP URL since there is no value set for allowing
// http.
@@ -1262,7 +1278,8 @@
.WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(true)));
// Reset state and set again.
- SetupPayloadStateWith2Urls("Hash8433", false, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8433", false, false, &payload_state, &response);
// Check that we skip the HTTP URL and use only the HTTPS url.
EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
@@ -1276,7 +1293,8 @@
EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
// Now, slightly change the response and set it again.
- SetupPayloadStateWith2Urls("Hash2399", false, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash2399", false, false, &payload_state, &response);
// Check that we still skip the HTTP URL and use only the HTTPS url.
EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
@@ -1292,7 +1310,8 @@
// so that we can test that the state is reset not because of the
// hash but because of the policy change which results in candidate url
// list change.
- SetupPayloadStateWith2Urls("Hash2399", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash2399", true, false, &payload_state, &response);
// Check that we use the HTTP URL now and the failure count is reset.
EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
@@ -1308,12 +1327,11 @@
TEST(PayloadStateTest, PayloadTypeMetricWhenTypeIsDelta) {
OmahaResponse response;
- response.is_delta_payload = true;
PayloadState payload_state;
FakeSystemState fake_system_state;
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls("Hash6437", true, true, &payload_state, &response);
// Simulate a successful download and update.
payload_state.DownloadComplete();
@@ -1334,7 +1352,7 @@
fake_system_state.set_request_params(¶ms);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls("Hash6437", true, true, &payload_state, &response);
payload_state.DownloadComplete();
@@ -1349,12 +1367,12 @@
TEST(PayloadStateTest, PayloadTypeMetricWhenTypeIsForcedFull) {
OmahaResponse response;
- response.is_delta_payload = false;
PayloadState payload_state;
FakeSystemState fake_system_state;
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash6437", true, false, &payload_state, &response);
// Mock the request to a request where the delta was disabled.
OmahaRequestParams params(&fake_system_state);
@@ -1377,12 +1395,12 @@
TEST(PayloadStateTest, PayloadTypeMetricWhenTypeIsFull) {
OmahaResponse response;
- response.is_delta_payload = false;
PayloadState payload_state;
FakeSystemState fake_system_state;
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash6437", true, false, &payload_state, &response);
// Mock the request to a request where the delta is enabled, although the
// result is full.
@@ -1412,7 +1430,8 @@
fake_system_state.set_prefs(&fake_prefs);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash3141", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash3141", true, false, &payload_state, &response);
// Simulate a successful download and update.
payload_state.DownloadComplete();
@@ -1454,7 +1473,8 @@
fake_boot_control->SetCurrentSlot(0);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash3141", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash3141", true, false, &payload_state, &response);
// Simulate a successful download and update.
payload_state.DownloadComplete();
@@ -1483,7 +1503,8 @@
fake_system_state.set_prefs(&fake_prefs);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash3141", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash3141", true, false, &payload_state, &response);
// Simulate a successful download and update.
payload_state.DownloadComplete();
@@ -1525,7 +1546,8 @@
fake_system_state.set_prefs(&fake_prefs);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8593", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8593", true, false, &payload_state, &response);
// Should allow exactly kMaxP2PAttempts...
for (int n = 0; n < kMaxP2PAttempts; n++) {
@@ -1547,7 +1569,8 @@
fake_system_state.set_clock(&fake_clock);
fake_system_state.set_prefs(&fake_prefs);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8593", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8593", true, false, &payload_state, &response);
// Set the clock to 1 second.
Time epoch = Time::FromInternalValue(1000000);
@@ -1590,7 +1613,8 @@
fake_system_state.set_prefs(&fake_prefs);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8593", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8593", true, false, &payload_state, &response);
Time null_time = Time();
EXPECT_EQ(null_time, payload_state.GetP2PFirstAttemptTimestamp());
@@ -1606,7 +1630,8 @@
fake_system_state.set_clock(&fake_clock);
fake_system_state.set_prefs(&fake_prefs);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8593", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8593", true, false, &payload_state, &response);
// Set the clock to something known.
Time time = Time::FromInternalValue(12345);
@@ -1635,7 +1660,8 @@
fake_system_state.set_prefs(&fake_prefs);
EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8593", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash8593", true, false, &payload_state, &response);
// Set the clock to something known.
Time time = Time::FromInternalValue(12345);
@@ -1647,7 +1673,8 @@
EXPECT_EQ(time, payload_state.GetP2PFirstAttemptTimestamp());
// Set a new response...
- SetupPayloadStateWith2Urls("Hash9904", true, &payload_state, &response);
+ SetupPayloadStateWith2Urls(
+ "Hash9904", true, false, &payload_state, &response);
// ... and check that it clears the P2P state vars.
Time null_time = Time();