Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: chrome/installer/util/work_item_unittest.cc

Issue 1882923003: Add best-effort/allow rollback flags on WorkItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simple_list_tests
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
grt (UTC plus 2) 2016/04/27 17:29:17 add a test to check that best_effort and allow_rol
fdoray 2016/05/02 20:10:00 Done.
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 EXPECT_CALL(item_success, DoImpl()).WillOnce(Return(true));
29 EXPECT_TRUE(item_success.Do());
30 }
31
32 {
33 StrictMockWorkItem item_failure;
34 EXPECT_CALL(item_failure, DoImpl()).WillOnce(Return(false));
35 EXPECT_FALSE(item_failure.Do());
36 }
37 }
38
39 // Verify that Do() calls DoImpl() and returns true for a best-effort WorkItem.
40 TEST(WorkItemTest, DoBestEffort) {
41 {
42 StrictMockWorkItem item_success;
43 item_success.set_best_effort(true);
44 EXPECT_CALL(item_success, DoImpl()).WillOnce(Return(true));
45 EXPECT_TRUE(item_success.Do());
46 }
47
48 {
49 StrictMockWorkItem item_failure;
50 item_failure.set_best_effort(true);
51 EXPECT_CALL(item_failure, DoImpl()).WillOnce(Return(false));
52 EXPECT_TRUE(item_failure.Do());
53 testing::Mock::VerifyAndClearExpectations(&item_failure);
54 }
55 }
56
57 // Verify that Rollback() calls RollbackImpl() for a WorkItem that allows
58 // rollback.
59 TEST(WorkItemTest, Rollback) {
60 StrictMockWorkItem item;
61 EXPECT_CALL(item, DoImpl()).WillOnce(Return(true));
62 item.Do();
63 testing::Mock::VerifyAndClearExpectations(&item);
grt (UTC plus 2) 2016/04/27 17:29:17 rather than doing this, use InSequence to assert t
fdoray 2016/05/02 20:10:00 Done.
64 EXPECT_CALL(item, RollbackImpl());
65 item.Rollback();
66 }
67
68 // Verify that Rollback() doesn't call RollbackImpl() for a WorkItem that
69 // doesn't allow rollback.
70 TEST(WorkItemTest, RollbackNotAllowed) {
71 StrictMockWorkItem item;
72 item.set_allow_rollback(false);
73 EXPECT_CALL(item, DoImpl()).WillOnce(Return(true));
74 item.Do();
75 testing::Mock::VerifyAndClearExpectations(&item);
grt (UTC plus 2) 2016/04/27 17:29:17 here, too
fdoray 2016/05/02 20:10:00 I don't need InSequence here because I have a sing
76 item.Rollback();
77 }
OLDNEW
« chrome/installer/util/work_item_list.cc ('K') | « chrome/installer/util/work_item_list_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698