• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2020 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include <memory>
18 
19 #include "update_engine/update_manager/minimum_version_policy_impl.h"
20 #include "update_engine/update_manager/policy_test_utils.h"
21 
22 using chromeos_update_engine::ErrorCode;
23 using chromeos_update_engine::InstallPlan;
24 
25 namespace {
26 
27 const char* kInvalidVersion = "13315.woops.12";
28 const char* kOldVersion = "13315.60.12";
29 const char* kNewVersion = "13315.60.15";
30 
31 }  // namespace
32 
33 namespace chromeos_update_manager {
34 
35 class UmMinimumVersionPolicyImplTest : public UmPolicyTestBase {
36  protected:
UmMinimumVersionPolicyImplTest()37   UmMinimumVersionPolicyImplTest() {
38     policy_ = std::make_unique<MinimumVersionPolicyImpl>();
39   }
40 
SetCurrentVersion(const std::string & version)41   void SetCurrentVersion(const std::string& version) {
42     fake_state_.system_provider()->var_chromeos_version()->reset(
43         new base::Version(version));
44   }
45 
SetMinimumVersion(const std::string & version)46   void SetMinimumVersion(const std::string& version) {
47     fake_state_.device_policy_provider()->var_device_minimum_version()->reset(
48         new base::Version(version));
49   }
50 
TestPolicy(const EvalStatus & expected_status)51   void TestPolicy(const EvalStatus& expected_status) {
52     InstallPlan install_plan;
53     ErrorCode result;
54     ExpectPolicyStatus(
55         expected_status, &Policy::UpdateCanBeApplied, &result, &install_plan);
56     if (expected_status == EvalStatus::kSucceeded)
57       EXPECT_EQ(result, ErrorCode::kSuccess);
58   }
59 };
60 
TEST_F(UmMinimumVersionPolicyImplTest,ContinueWhenCurrentVersionIsNotSet)61 TEST_F(UmMinimumVersionPolicyImplTest, ContinueWhenCurrentVersionIsNotSet) {
62   SetMinimumVersion(kNewVersion);
63 
64   TestPolicy(EvalStatus::kContinue);
65 }
66 
TEST_F(UmMinimumVersionPolicyImplTest,ContinueWhenCurrentVersionIsInvalid)67 TEST_F(UmMinimumVersionPolicyImplTest, ContinueWhenCurrentVersionIsInvalid) {
68   SetCurrentVersion(kInvalidVersion);
69   SetMinimumVersion(kNewVersion);
70 
71   TestPolicy(EvalStatus::kContinue);
72 }
73 
TEST_F(UmMinimumVersionPolicyImplTest,ContinueWhenMinumumVersionIsNotSet)74 TEST_F(UmMinimumVersionPolicyImplTest, ContinueWhenMinumumVersionIsNotSet) {
75   SetCurrentVersion(kOldVersion);
76 
77   TestPolicy(EvalStatus::kContinue);
78 }
79 
TEST_F(UmMinimumVersionPolicyImplTest,ContinueWhenMinumumVersionIsInvalid)80 TEST_F(UmMinimumVersionPolicyImplTest, ContinueWhenMinumumVersionIsInvalid) {
81   SetCurrentVersion(kOldVersion);
82   SetMinimumVersion(kInvalidVersion);
83 
84   TestPolicy(EvalStatus::kContinue);
85 }
86 
TEST_F(UmMinimumVersionPolicyImplTest,ContinueWhenCurrentVersionIsGreaterThanMinimumVersion)87 TEST_F(UmMinimumVersionPolicyImplTest,
88        ContinueWhenCurrentVersionIsGreaterThanMinimumVersion) {
89   SetCurrentVersion(kNewVersion);
90   SetMinimumVersion(kOldVersion);
91 
92   TestPolicy(EvalStatus::kContinue);
93 }
94 
TEST_F(UmMinimumVersionPolicyImplTest,ContinueWhenCurrentVersionIsEqualToMinimumVersion)95 TEST_F(UmMinimumVersionPolicyImplTest,
96        ContinueWhenCurrentVersionIsEqualToMinimumVersion) {
97   SetCurrentVersion(kNewVersion);
98   SetMinimumVersion(kNewVersion);
99 
100   TestPolicy(EvalStatus::kContinue);
101 }
102 
TEST_F(UmMinimumVersionPolicyImplTest,SuccessWhenCurrentVersionIsLessThanMinimumVersion)103 TEST_F(UmMinimumVersionPolicyImplTest,
104        SuccessWhenCurrentVersionIsLessThanMinimumVersion) {
105   SetCurrentVersion(kOldVersion);
106   SetMinimumVersion(kNewVersion);
107 
108   TestPolicy(EvalStatus::kSucceeded);
109 }
110 
111 }  // namespace chromeos_update_manager
112