blob: dba77e47f3702018206821fffd28d939c0effc0d [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
Tianjied60dc392020-07-29 11:27:35 -070032constexpr char kFakeHash[] =
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070033 "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) {
Tianjied60dc392020-07-29 11:27:35 -070050 EXPECT_FALSE(excluder_->IsExcluded(kFakeHash));
51 EXPECT_TRUE(excluder_->Exclude(kFakeHash));
52 EXPECT_TRUE(excluder_->IsExcluded(kFakeHash));
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070053}
54
55TEST_F(ExcluderChromeOSTest, ResetFlow) {
56 EXPECT_TRUE(excluder_->Exclude("abc"));
Tianjied60dc392020-07-29 11:27:35 -070057 EXPECT_TRUE(excluder_->Exclude(kFakeHash));
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070058 EXPECT_TRUE(excluder_->IsExcluded("abc"));
Tianjied60dc392020-07-29 11:27:35 -070059 EXPECT_TRUE(excluder_->IsExcluded(kFakeHash));
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070060
61 EXPECT_TRUE(excluder_->Reset());
62 EXPECT_FALSE(excluder_->IsExcluded("abc"));
Tianjied60dc392020-07-29 11:27:35 -070063 EXPECT_FALSE(excluder_->IsExcluded(kFakeHash));
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070064}
65
66} // namespace chromeos_update_engine