update_engine: Update unit tests to use unique_ptr for PolicyProvider
The class policy::PolicyProvider from libbrillo has been updated
to accept unique_ptr instead of raw pointer for constructor.
This CL updates the tests to use the new constructor.
The changes in PolicyProvider contructor come from CL
https://chromium-review.googlesource.com/c/aosp/platform/external/libbrillo/+/674935
BUG=chromium:764337
TEST=cros_workon_make --board=${BOARD} chromeos-base/update_engine --test
CQ-DEPEND=CL:674935, CL:819250, CL:819353
Change-Id: I5537cfe9a88053193fbe8b0b6d844c59df148fc9
Reviewed-on: https://chromium-review.googlesource.com/819412
Commit-Ready: Igor <[email protected]>
Tested-by: Igor <[email protected]>
Reviewed-by: Amin Hassani <[email protected]>
Reviewed-by: Sen Jiang <[email protected]>
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index ef84c1b..06c82c9 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -372,10 +372,11 @@
// Expect that the device policy is loaded by the UpdateAttempter at some
// point by calling RefreshDevicePolicy.
- policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy();
- attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy));
+ auto device_policy = std::make_unique<policy::MockDevicePolicy>();
EXPECT_CALL(*device_policy, LoadPolicy())
.Times(testing::AtLeast(1)).WillRepeatedly(Return(true));
+ attempter_.policy_provider_.reset(
+ new policy::PolicyProvider(std::move(device_policy)));
{
InSequence s;
@@ -414,11 +415,23 @@
void UpdateAttempterTest::RollbackTestStart(
bool enterprise_rollback, bool valid_slot) {
// Create a device policy so that we can change settings.
- policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy();
- attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy));
-
+ auto device_policy = std::make_unique<policy::MockDevicePolicy>();
EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true));
- fake_system_state_.set_device_policy(device_policy);
+ fake_system_state_.set_device_policy(device_policy.get());
+ if (enterprise_rollback) {
+ // We return an empty owner as this is an enterprise.
+ EXPECT_CALL(*device_policy, GetOwner(_)).WillRepeatedly(
+ DoAll(SetArgPointee<0>(string("")),
+ Return(true)));
+ } else {
+ // We return a fake owner as this is an owned consumer device.
+ EXPECT_CALL(*device_policy, GetOwner(_)).WillRepeatedly(
+ DoAll(SetArgPointee<0>(string("[email protected]")),
+ Return(true)));
+ }
+
+ attempter_.policy_provider_.reset(
+ new policy::PolicyProvider(std::move(device_policy)));
if (valid_slot) {
BootControlInterface::Slot rollback_slot = 1;
@@ -436,18 +449,6 @@
is_rollback_allowed = true;
}
- if (enterprise_rollback) {
- // We return an empty owner as this is an enterprise.
- EXPECT_CALL(*device_policy, GetOwner(_)).WillRepeatedly(
- DoAll(SetArgPointee<0>(string("")),
- Return(true)));
- } else {
- // We return a fake owner as this is an owned consumer device.
- EXPECT_CALL(*device_policy, GetOwner(_)).WillRepeatedly(
- DoAll(SetArgPointee<0>(string("[email protected]")),
- Return(true)));
- }
-
if (is_rollback_allowed) {
InSequence s;
for (size_t i = 0; i < arraysize(kRollbackActionTypes); ++i) {
@@ -718,17 +719,18 @@
void UpdateAttempterTest::ReadScatterFactorFromPolicyTestStart() {
int64_t scatter_factor_in_seconds = 36000;
- policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy();
- attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy));
-
+ auto device_policy = std::make_unique<policy::MockDevicePolicy>();
EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true));
- fake_system_state_.set_device_policy(device_policy);
+ fake_system_state_.set_device_policy(device_policy.get());
EXPECT_CALL(*device_policy, GetScatterFactorInSeconds(_))
.WillRepeatedly(DoAll(
SetArgPointee<0>(scatter_factor_in_seconds),
Return(true)));
+ attempter_.policy_provider_.reset(
+ new policy::PolicyProvider(std::move(device_policy)));
+
attempter_.Update("", "", "", "", false, false);
EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds());
@@ -756,17 +758,18 @@
int64_t scatter_factor_in_seconds = 10;
- policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy();
- attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy));
-
+ auto device_policy = std::make_unique<policy::MockDevicePolicy>();
EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true));
- fake_system_state_.set_device_policy(device_policy);
+ fake_system_state_.set_device_policy(device_policy.get());
EXPECT_CALL(*device_policy, GetScatterFactorInSeconds(_))
.WillRepeatedly(DoAll(
SetArgPointee<0>(scatter_factor_in_seconds),
Return(true)));
+ attempter_.policy_provider_.reset(
+ new policy::PolicyProvider(std::move(device_policy)));
+
attempter_.Update("", "", "", "", false, false);
EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds());
@@ -815,17 +818,18 @@
// otherwise.
int64_t scatter_factor_in_seconds = 50;
- policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy();
- attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy));
-
+ auto device_policy = std::make_unique<policy::MockDevicePolicy>();
EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true));
- fake_system_state_.set_device_policy(device_policy);
+ fake_system_state_.set_device_policy(device_policy.get());
EXPECT_CALL(*device_policy, GetScatterFactorInSeconds(_))
.WillRepeatedly(DoAll(
SetArgPointee<0>(scatter_factor_in_seconds),
Return(true)));
+ attempter_.policy_provider_.reset(
+ new policy::PolicyProvider(std::move(device_policy)));
+
// Trigger an interactive check so we can test that scattering is disabled.
attempter_.Update("", "", "", "", false, true);
EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds());