OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/installer/util/work_item_list.h" | 5 #include "chrome/installer/util/work_item_list.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "chrome/installer/util/work_item.h" | 10 #include "chrome/installer/util/work_item.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 // Create the mock work items. | 22 // Create the mock work items. |
23 std::unique_ptr<StrictMockWorkItem> item1(new StrictMockWorkItem); | 23 std::unique_ptr<StrictMockWorkItem> item1(new StrictMockWorkItem); |
24 std::unique_ptr<StrictMockWorkItem> item2(new StrictMockWorkItem); | 24 std::unique_ptr<StrictMockWorkItem> item2(new StrictMockWorkItem); |
25 std::unique_ptr<StrictMockWorkItem> item3(new StrictMockWorkItem); | 25 std::unique_ptr<StrictMockWorkItem> item3(new StrictMockWorkItem); |
26 | 26 |
27 { | 27 { |
28 // Expect all three items to be done in order then undone. | 28 // Expect all three items to be done in order then undone. |
29 InSequence s; | 29 InSequence s; |
30 | 30 |
31 EXPECT_CALL(*item1, DoImpl()).WillOnce(Return(true)); | 31 EXPECT_CALL(*item1, Do()).WillOnce(Return(true)); |
32 EXPECT_CALL(*item2, DoImpl()).WillOnce(Return(true)); | 32 EXPECT_CALL(*item2, Do()).WillOnce(Return(true)); |
33 EXPECT_CALL(*item3, DoImpl()).WillOnce(Return(true)); | 33 EXPECT_CALL(*item3, Do()).WillOnce(Return(true)); |
34 EXPECT_CALL(*item3, RollbackImpl()); | 34 EXPECT_CALL(*item3, Rollback()); |
35 EXPECT_CALL(*item2, RollbackImpl()); | 35 EXPECT_CALL(*item2, Rollback()); |
36 EXPECT_CALL(*item1, RollbackImpl()); | 36 EXPECT_CALL(*item1, Rollback()); |
37 } | 37 } |
38 | 38 |
39 // Add the items to the list. | 39 // Add the items to the list. |
40 list->AddWorkItem(item1.release()); | 40 list->AddWorkItem(item1.release()); |
41 list->AddWorkItem(item2.release()); | 41 list->AddWorkItem(item2.release()); |
42 list->AddWorkItem(item3.release()); | 42 list->AddWorkItem(item3.release()); |
43 | 43 |
44 // Do and rollback the list. | 44 // Do and rollback the list. |
45 EXPECT_TRUE(list->Do()); | 45 EXPECT_TRUE(list->Do()); |
46 list->Rollback(); | 46 list->Rollback(); |
47 } | 47 } |
48 | 48 |
49 // Execute a WorkItemList. Fail in the middle. Rollback what has been done. | 49 // Execute a WorkItemList. Fail in the middle. Rollback what has been done. |
50 TEST(WorkItemListTest, ExecutionFailAndRollback) { | 50 TEST(WorkItemListTest, ExecutionFailAndRollback) { |
51 std::unique_ptr<WorkItemList> list(WorkItem::CreateWorkItemList()); | 51 std::unique_ptr<WorkItemList> list(WorkItem::CreateWorkItemList()); |
52 | 52 |
53 // Create the mock work items. | 53 // Create the mock work items. |
54 std::unique_ptr<StrictMockWorkItem> item1(new StrictMockWorkItem); | 54 std::unique_ptr<StrictMockWorkItem> item1(new StrictMockWorkItem); |
55 std::unique_ptr<StrictMockWorkItem> item2(new StrictMockWorkItem); | 55 std::unique_ptr<StrictMockWorkItem> item2(new StrictMockWorkItem); |
56 std::unique_ptr<StrictMockWorkItem> item3(new StrictMockWorkItem); | 56 std::unique_ptr<StrictMockWorkItem> item3(new StrictMockWorkItem); |
57 | 57 |
58 { | 58 { |
59 // Expect the two first work items to be done in order then undone. | 59 // Expect the two first work items to be done in order then undone. |
60 InSequence s; | 60 InSequence s; |
61 | 61 |
62 EXPECT_CALL(*item1, DoImpl()).WillOnce(Return(true)); | 62 EXPECT_CALL(*item1, Do()).WillOnce(Return(true)); |
63 EXPECT_CALL(*item2, DoImpl()).WillOnce(Return(false)); | 63 EXPECT_CALL(*item2, Do()).WillOnce(Return(false)); |
64 EXPECT_CALL(*item2, RollbackImpl()); | 64 EXPECT_CALL(*item2, Rollback()); |
65 EXPECT_CALL(*item1, RollbackImpl()); | 65 EXPECT_CALL(*item1, Rollback()); |
66 } | 66 } |
67 | 67 |
68 // Add the items to the list. | 68 // Add the items to the list. |
69 list->AddWorkItem(item1.release()); | 69 list->AddWorkItem(item1.release()); |
70 list->AddWorkItem(item2.release()); | 70 list->AddWorkItem(item2.release()); |
71 list->AddWorkItem(item3.release()); | 71 list->AddWorkItem(item3.release()); |
72 | 72 |
73 // Do and rollback the list. | 73 // Do and rollback the list. |
74 EXPECT_FALSE(list->Do()); | 74 EXPECT_FALSE(list->Do()); |
75 list->Rollback(); | 75 list->Rollback(); |
76 } | 76 } |
OLD | NEW |