1 //
2 // Copyright (C) 2018 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/update_boot_flags_action.h"
18 
19 #include <memory>
20 #include <utility>
21 
22 #include <base/bind.h>
23 #include <gtest/gtest.h>
24 
25 #include "update_engine/fake_system_state.h"
26 
27 namespace chromeos_update_engine {
28 
29 class UpdateBootFlagsActionTest : public ::testing::Test {
30  public:
31   FakeSystemState fake_system_state_;
32 };
33 
TEST_F(UpdateBootFlagsActionTest,SimpleTest)34 TEST_F(UpdateBootFlagsActionTest, SimpleTest) {
35   auto boot_control = fake_system_state_.fake_boot_control();
36   auto action = std::make_unique<UpdateBootFlagsAction>(boot_control);
37   ActionProcessor processor;
38   processor.EnqueueAction(std::move(action));
39 
40   EXPECT_FALSE(UpdateBootFlagsAction::updated_boot_flags_);
41   EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
42   processor.StartProcessing();
43   EXPECT_TRUE(UpdateBootFlagsAction::updated_boot_flags_);
44   EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
45 }
46 
TEST_F(UpdateBootFlagsActionTest,DoubleActionTest)47 TEST_F(UpdateBootFlagsActionTest, DoubleActionTest) {
48   // Reset the static flags.
49   UpdateBootFlagsAction::updated_boot_flags_ = false;
50   UpdateBootFlagsAction::is_running_ = false;
51 
52   auto boot_control = fake_system_state_.fake_boot_control();
53   auto action1 = std::make_unique<UpdateBootFlagsAction>(boot_control);
54   auto action2 = std::make_unique<UpdateBootFlagsAction>(boot_control);
55   ActionProcessor processor1, processor2;
56   processor1.EnqueueAction(std::move(action1));
57   processor2.EnqueueAction(std::move(action2));
58 
59   EXPECT_FALSE(UpdateBootFlagsAction::updated_boot_flags_);
60   EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
61   processor1.StartProcessing();
62   EXPECT_TRUE(UpdateBootFlagsAction::updated_boot_flags_);
63   EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
64   processor2.StartProcessing();
65   EXPECT_TRUE(UpdateBootFlagsAction::updated_boot_flags_);
66   EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
67 }
68 
69 }  // namespace chromeos_update_engine
70