update_engine: Add staging to update_attempter and omaha_request
Modify update_attempter and omaha_request so that they take the user's
staging settings into account. This includes:
* Turning off scattering if staging is on.
* Preserving scattering values if staging is off.
* Setting staging related persisted values if staging is on.
* Deleting the corresponding persisted values if staging is off.
* Making omaha use the max wait time for staging as its max scatter
period if staging is on.
* Add the corresponding unittests for this.
BUG=chromium:858621
TEST=cros_workon_make update_engine --test
Change-Id: I501f90d9e195b5ceef61d3eac67ab52051793ae9
Reviewed-on: https://chromium-review.googlesource.com/1141217
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Adolfo Higueros <adokar@google.com>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index 63bb170..1e0ad6d 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -1336,6 +1336,42 @@
EXPECT_TRUE(response.update_exists);
}
+TEST_F(OmahaRequestActionTest, StagingTurnedOnCausesScattering) {
+ // If staging is on, the value for max days to scatter should be ignored, and
+ // staging's scatter value should be used.
+ OmahaResponse response;
+ request_params_.set_wall_clock_based_wait_enabled(true);
+ request_params_.set_waiting_period(TimeDelta::FromDays(6));
+ request_params_.set_update_check_count_wait_enabled(false);
+
+ ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsWallClockStagingWaitPeriod, 6));
+ // This should not prevent scattering due to staging.
+ fake_update_response_.max_days_to_scatter = "0";
+ ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(),
+ -1,
+ false, // ping_only
+ ErrorCode::kOmahaUpdateDeferredPerPolicy,
+ metrics::CheckResult::kUpdateAvailable,
+ metrics::CheckReaction::kDeferring,
+ metrics::DownloadErrorCode::kUnset,
+ &response,
+ nullptr));
+ EXPECT_FALSE(response.update_exists);
+
+ // Interactive updates should not be affected.
+ request_params_.set_interactive(true);
+ ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(),
+ -1,
+ false, // ping_only
+ ErrorCode::kSuccess,
+ metrics::CheckResult::kUpdateAvailable,
+ metrics::CheckReaction::kUpdating,
+ metrics::DownloadErrorCode::kUnset,
+ &response,
+ nullptr));
+ EXPECT_TRUE(response.update_exists);
+}
+
TEST_F(OmahaRequestActionTest, CohortsArePersisted) {
OmahaResponse response;
fake_update_response_.include_cohorts = true;