blob: a8c14b39a910108c2dec2f06db3d336de706ef3f [file] [log] [blame]
Jae Hoon Kim38de3b12020-04-29 19:41:23 -07001//
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
27using std::string;
28using std::unique_ptr;
29
30namespace chromeos_update_engine {
31
32constexpr char kDummyHash[] =
33 "71ff43d76e2488e394e46872f5b066cc25e394c2c3e3790dd319517883b33db1";
34
35class 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
49TEST_F(ExcluderChromeOSTest, ExclusionCheck) {
50 EXPECT_FALSE(excluder_->IsExcluded(kDummyHash));
51 EXPECT_TRUE(excluder_->Exclude(kDummyHash));
52 EXPECT_TRUE(excluder_->IsExcluded(kDummyHash));
53}
54
55TEST_F(ExcluderChromeOSTest, ResetFlow) {
56 EXPECT_TRUE(excluder_->Exclude("abc"));
57 EXPECT_TRUE(excluder_->Exclude(kDummyHash));
58 EXPECT_TRUE(excluder_->IsExcluded("abc"));
59 EXPECT_TRUE(excluder_->IsExcluded(kDummyHash));
60
61 EXPECT_TRUE(excluder_->Reset());
62 EXPECT_FALSE(excluder_->IsExcluded("abc"));
63 EXPECT_FALSE(excluder_->IsExcluded(kDummyHash));
64}
65
66} // namespace chromeos_update_engine