PM: Policy for checking whether an update can start.
This policy is based on existing logic found in the following locations
through the current update engine code base:
- UpdateAttempter::CalculateUpdateParams(), which applies various device
policy attributes and sets the update params.
- UpdateAttempter::CalculateScatteringParams(), called by the former for
deciding the scatter wait period for the current update. Calls
UpdateAttempter::GenerateNewWaitingPeriod() to compute a new wait
period.
- OmahaRequestAction::IsWallClockBasedWaitingSatisfied() and
OmahaRequestAction::IsUpdateCheckCountBasedWaitingSatisfied, which
check whether a scattering derived wait period has elapsed and whether
a check threshold counter was satisfied, respectively.
- UpdateAttempter::CalculateP2PParams() and
P2PManagerImpl::IsP2PEnabled(), which decide whether P2P can be used.
- PayloadState::ComputeCandidateUrls(), where there's logic for deciding
whether HTTP downloads are allowed.
Note that this policy request is based on two others. One is the public
UpdateCheckAllowed(), whose positive return value invalidates the
current update attempt. The second is a private policy
UpdateScattering() that decides whether the current update attempt is
subject to scattering.
BUG=chromium:358323
TEST=Unit tests.
Change-Id: I889a3d1c10e1722585fdc1aa87fb6f9d627b60c7
Reviewed-on: https://chromium-review.googlesource.com/198781
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/policy_manager/policy_manager_unittest.cc b/policy_manager/policy_manager_unittest.cc
index 5272bcd..89da2a4 100644
--- a/policy_manager/policy_manager_unittest.cc
+++ b/policy_manager/policy_manager_unittest.cc
@@ -9,6 +9,7 @@
#include <base/bind.h>
#include <base/memory/scoped_ptr.h>
+#include <base/time/time.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -22,6 +23,8 @@
using base::Bind;
using base::Callback;
+using base::Time;
+using base::TimeDelta;
using chromeos_update_engine::FakeClock;
using std::pair;
using std::string;
@@ -30,6 +33,24 @@
using testing::StrictMock;
using testing::_;
+namespace {
+
+// Generates a fixed timestamp for use in faking the current time.
+Time FixedTime() {
+ Time::Exploded now_exp;
+ now_exp.year = 2014;
+ now_exp.month = 3;
+ now_exp.day_of_week = 2;
+ now_exp.day_of_month = 18;
+ now_exp.hour = 8;
+ now_exp.minute = 5;
+ now_exp.second = 33;
+ now_exp.millisecond = 675;
+ return Time::FromLocalExploded(now_exp);
+}
+
+} // namespace
+
namespace chromeos_policy_manager {
class PmPolicyManagerTest : public ::testing::Test {
@@ -77,19 +98,23 @@
// Tests that policy requests are completed successfully. It is important that
// this tests cover all policy requests as defined in Policy.
-TEST_F(PmPolicyManagerTest, PolicyRequestCallUpdateDownloadAndApplyAllowed) {
- bool result;
- EXPECT_EQ(EvalStatus::kSucceeded,
- pmut_->PolicyRequest(&Policy::UpdateDownloadAndApplyAllowed,
- &result));
-}
-
TEST_F(PmPolicyManagerTest, PolicyRequestCallUpdateCheckAllowed) {
UpdateCheckParams result;
EXPECT_EQ(EvalStatus::kSucceeded, pmut_->PolicyRequest(
&Policy::UpdateCheckAllowed, &result));
}
+TEST_F(PmPolicyManagerTest, PolicyRequestCallUpdateCanStart) {
+ const UpdateState update_state = {
+ FixedTime(), 1, TimeDelta::FromSeconds(15), TimeDelta::FromSeconds(60),
+ 4, 2, 8
+ };
+ UpdateCanStartResult result;
+ EXPECT_EQ(EvalStatus::kSucceeded,
+ pmut_->PolicyRequest(&Policy::UpdateCanStart, &result, true,
+ update_state));
+}
+
TEST_F(PmPolicyManagerTest, PolicyRequestCallsDefaultOnError) {
pmut_->set_policy(new FailingPolicy());