OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/installer/util/work_item.h" | |
6 | |
7 #include "testing/gmock/include/gmock/gmock.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace { | |
11 | |
12 class MockWorkItem : public WorkItem { | |
13 public: | |
14 MOCK_METHOD0(DoImpl, bool()); | |
15 MOCK_METHOD0(RollbackImpl, void()); | |
16 }; | |
17 | |
18 using StrictMockWorkItem = testing::StrictMock<MockWorkItem>; | |
19 using testing::Return; | |
20 | |
21 } // namespace | |
22 | |
23 // Verify that Do() calls DoImpl() and returns its return value for a | |
24 // non-best-effort WorkItem. | |
25 TEST(WorkItemTest, Do) { | |
26 { | |
27 StrictMockWorkItem item_success; | |
28 item_success.set_best_effort(false); | |
29 EXPECT_CALL(item_success, DoImpl()).WillOnce(Return(true)); | |
30 EXPECT_TRUE(item_success.Do()); | |
31 } | |
32 | |
33 { | |
34 StrictMockWorkItem item_failure; | |
35 item_failure.set_best_effort(false); | |
36 EXPECT_CALL(item_failure, DoImpl()).WillOnce(Return(false)); | |
37 EXPECT_FALSE(item_failure.Do()); | |
38 } | |
39 } | |
40 | |
41 // Verify that Do() calls DoImpl() and returns true for a best-effort WorkItem. | |
42 TEST(WorkItemTest, DoBestEffort) { | |
43 { | |
44 StrictMockWorkItem item_success; | |
45 item_success.set_best_effort(true); | |
46 EXPECT_CALL(item_success, DoImpl()).WillOnce(Return(true)); | |
47 EXPECT_TRUE(item_success.Do()); | |
48 } | |
49 | |
50 { | |
51 StrictMockWorkItem item_failure; | |
52 item_failure.set_best_effort(true); | |
53 EXPECT_CALL(item_failure, DoImpl()).WillOnce(Return(false)); | |
54 EXPECT_TRUE(item_failure.Do()); | |
55 testing::Mock::VerifyAndClearExpectations(&item_failure); | |
56 } | |
57 } | |
58 | |
59 // Verify that Rollback() calls RollbackImpl() for a WorkItem with rollback | |
60 // enabled. | |
61 TEST(WorkItemTest, Rollback) { | |
62 StrictMockWorkItem item; | |
63 item.set_rollback_enabled(true); | |
64 EXPECT_TRUE(item.rollback_enabled()); | |
65 | |
66 { | |
67 testing::InSequence s; | |
68 EXPECT_CALL(item, DoImpl()).WillOnce(Return(true)); | |
69 EXPECT_CALL(item, RollbackImpl()); | |
70 } | |
71 | |
72 item.Do(); | |
73 item.Rollback(); | |
74 } | |
75 | |
76 // Verify that Rollback() doesn't call RollbackImpl() for a WorkItem with | |
77 // rollback disabled. | |
78 TEST(WorkItemTest, RollbackNotAllowed) { | |
79 StrictMockWorkItem item; | |
80 item.set_rollback_enabled(false); | |
81 | |
82 EXPECT_CALL(item, DoImpl()).WillOnce(Return(true)); | |
83 | |
84 item.Do(); | |
85 item.Rollback(); | |
86 } | |
87 | |
88 // Verify that the default value of the "best-effort" flag is false and that the | |
89 // setter works. | |
90 TEST(WorkItemTest, BestEffortDefaultValueAndSetter) { | |
91 MockWorkItem work_item; | |
92 EXPECT_FALSE(work_item.best_effort()); | |
93 work_item.set_best_effort(true); | |
94 EXPECT_TRUE(work_item.best_effort()); | |
95 } | |
96 | |
97 // Verify that the default value of the "enable rollback" flag is true and that | |
98 // the setter works. | |
99 TEST(WorkItemTest, EnableRollbackDefaultValueAndSetter) { | |
100 MockWorkItem work_item; | |
101 EXPECT_TRUE(work_item.rollback_enabled()); | |
102 work_item.set_rollback_enabled(false); | |
103 EXPECT_FALSE(work_item.rollback_enabled()); | |
104 } | |
OLD | NEW |