Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 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 "update_engine/excluder_chromeos.h" |
| 18 | |
| 19 | #include <memory> |
| 20 | |
| 21 | #include <base/files/file_util.h> |
| 22 | #include <base/files/scoped_temp_dir.h> |
| 23 | #include <gtest/gtest.h> |
| 24 | |
| 25 | #include "update_engine/common/prefs.h" |
| 26 | |
| 27 | using std::string; |
| 28 | using std::unique_ptr; |
| 29 | |
| 30 | namespace chromeos_update_engine { |
| 31 | |
Tianjie | d60dc39 | 2020-07-29 11:27:35 -0700 | [diff] [blame] | 32 | constexpr char kFakeHash[] = |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 33 | "71ff43d76e2488e394e46872f5b066cc25e394c2c3e3790dd319517883b33db1"; |
| 34 | |
| 35 | class ExcluderChromeOSTest : public ::testing::Test { |
| 36 | protected: |
| 37 | void SetUp() override { |
| 38 | ASSERT_TRUE(tempdir_.CreateUniqueTempDir()); |
| 39 | ASSERT_TRUE(base::PathExists(tempdir_.GetPath())); |
| 40 | ASSERT_TRUE(prefs_.Init(tempdir_.GetPath())); |
| 41 | excluder_ = std::make_unique<ExcluderChromeOS>(&prefs_); |
| 42 | } |
| 43 | |
| 44 | base::ScopedTempDir tempdir_; |
| 45 | Prefs prefs_; |
| 46 | unique_ptr<ExcluderChromeOS> excluder_; |
| 47 | }; |
| 48 | |
| 49 | TEST_F(ExcluderChromeOSTest, ExclusionCheck) { |
Tianjie | d60dc39 | 2020-07-29 11:27:35 -0700 | [diff] [blame] | 50 | EXPECT_FALSE(excluder_->IsExcluded(kFakeHash)); |
| 51 | EXPECT_TRUE(excluder_->Exclude(kFakeHash)); |
| 52 | EXPECT_TRUE(excluder_->IsExcluded(kFakeHash)); |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | TEST_F(ExcluderChromeOSTest, ResetFlow) { |
| 56 | EXPECT_TRUE(excluder_->Exclude("abc")); |
Tianjie | d60dc39 | 2020-07-29 11:27:35 -0700 | [diff] [blame] | 57 | EXPECT_TRUE(excluder_->Exclude(kFakeHash)); |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 58 | EXPECT_TRUE(excluder_->IsExcluded("abc")); |
Tianjie | d60dc39 | 2020-07-29 11:27:35 -0700 | [diff] [blame] | 59 | EXPECT_TRUE(excluder_->IsExcluded(kFakeHash)); |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 60 | |
| 61 | EXPECT_TRUE(excluder_->Reset()); |
| 62 | EXPECT_FALSE(excluder_->IsExcluded("abc")); |
Tianjie | d60dc39 | 2020-07-29 11:27:35 -0700 | [diff] [blame] | 63 | EXPECT_FALSE(excluder_->IsExcluded(kFakeHash)); |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace chromeos_update_engine |