Index: chrome/installer/util/work_item_unittest.cc |
diff --git a/chrome/installer/util/work_item_unittest.cc b/chrome/installer/util/work_item_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..815f3669eef5fbc7484f08fa2421a3c6340bbd21 |
--- /dev/null |
+++ b/chrome/installer/util/work_item_unittest.cc |
@@ -0,0 +1,101 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/installer/util/work_item.h" |
+ |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace { |
+ |
+class MockWorkItem : public WorkItem { |
+ public: |
+ MOCK_METHOD0(DoImpl, bool()); |
+ MOCK_METHOD0(RollbackImpl, void()); |
+}; |
+ |
+using StrictMockWorkItem = testing::StrictMock<MockWorkItem>; |
+using testing::Return; |
+ |
+} // namespace |
+ |
+// Verify that Do() calls DoImpl() and returns its return value for a |
+// non-best-effort WorkItem. |
+TEST(WorkItemTest, Do) { |
+ { |
+ StrictMockWorkItem item_success; |
+ item_success.set_best_effort(false); |
+ EXPECT_FALSE(item_success.best_effort()); |
grt (UTC plus 2)
2016/05/06 18:39:13
rather than checking that the setter worked in eac
fdoray
2016/05/10 18:35:32
Done.
|
+ EXPECT_CALL(item_success, DoImpl()).WillOnce(Return(true)); |
+ EXPECT_TRUE(item_success.Do()); |
+ } |
+ |
+ { |
+ StrictMockWorkItem item_failure; |
+ item_failure.set_best_effort(false); |
+ EXPECT_FALSE(item_failure.best_effort()); |
+ EXPECT_CALL(item_failure, DoImpl()).WillOnce(Return(false)); |
+ EXPECT_FALSE(item_failure.Do()); |
+ } |
+} |
+ |
+// Verify that Do() calls DoImpl() and returns true for a best-effort WorkItem. |
+TEST(WorkItemTest, DoBestEffort) { |
+ { |
+ StrictMockWorkItem item_success; |
+ item_success.set_best_effort(true); |
+ EXPECT_TRUE(item_success.best_effort()); |
+ EXPECT_CALL(item_success, DoImpl()).WillOnce(Return(true)); |
+ EXPECT_TRUE(item_success.Do()); |
+ } |
+ |
+ { |
+ StrictMockWorkItem item_failure; |
+ item_failure.set_best_effort(true); |
+ EXPECT_TRUE(item_failure.best_effort()); |
+ EXPECT_CALL(item_failure, DoImpl()).WillOnce(Return(false)); |
+ EXPECT_TRUE(item_failure.Do()); |
+ testing::Mock::VerifyAndClearExpectations(&item_failure); |
+ } |
+} |
+ |
+// Verify that Rollback() calls RollbackImpl() for a WorkItem with rollback |
+// enabled. |
+TEST(WorkItemTest, Rollback) { |
+ StrictMockWorkItem item; |
+ item.set_rollback_enabled(true); |
+ EXPECT_TRUE(item.rollback_enabled()); |
+ |
+ { |
+ testing::InSequence s; |
+ EXPECT_CALL(item, DoImpl()).WillOnce(Return(true)); |
+ EXPECT_CALL(item, RollbackImpl()); |
+ } |
+ |
+ item.Do(); |
+ item.Rollback(); |
+} |
+ |
+// Verify that Rollback() doesn't call RollbackImpl() for a WorkItem with |
+// rollback disabled. |
+TEST(WorkItemTest, RollbackNotAllowed) { |
+ StrictMockWorkItem item; |
+ item.set_rollback_enabled(false); |
+ EXPECT_FALSE(item.rollback_enabled()); |
+ |
+ EXPECT_CALL(item, DoImpl()).WillOnce(Return(true)); |
+ |
+ item.Do(); |
+ item.Rollback(); |
+} |
+ |
+// Verify that the default value of the "best-effort" flag is false. |
+TEST(WorkItemTest, BestEffortDefaultValue) { |
+ EXPECT_FALSE(MockWorkItem().best_effort()); |
+} |
+ |
+// Verify that the default value of the "enable rollback" flag is true. |
+TEST(WorkItemTest, EnableRollbackDefaultValue) { |
+ EXPECT_TRUE(MockWorkItem().rollback_enabled()); |
+} |