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..b30fe3de85662af98e7e269c6a8cd604a55c85f7 |
--- /dev/null |
+++ b/chrome/installer/util/work_item_unittest.cc |
@@ -0,0 +1,77 @@ |
+// 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 |
+ |
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.
|
+// Verify that Do() calls DoImpl() and returns its return value for a |
+// non-best-effort WorkItem. |
+TEST(WorkItemTest, Do) { |
+ { |
+ StrictMockWorkItem item_success; |
+ EXPECT_CALL(item_success, DoImpl()).WillOnce(Return(true)); |
+ EXPECT_TRUE(item_success.Do()); |
+ } |
+ |
+ { |
+ StrictMockWorkItem item_failure; |
+ 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_CALL(item_success, DoImpl()).WillOnce(Return(true)); |
+ EXPECT_TRUE(item_success.Do()); |
+ } |
+ |
+ { |
+ StrictMockWorkItem item_failure; |
+ item_failure.set_best_effort(true); |
+ 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 that allows |
+// rollback. |
+TEST(WorkItemTest, Rollback) { |
+ StrictMockWorkItem item; |
+ EXPECT_CALL(item, DoImpl()).WillOnce(Return(true)); |
+ item.Do(); |
+ 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.
|
+ EXPECT_CALL(item, RollbackImpl()); |
+ item.Rollback(); |
+} |
+ |
+// Verify that Rollback() doesn't call RollbackImpl() for a WorkItem that |
+// doesn't allow rollback. |
+TEST(WorkItemTest, RollbackNotAllowed) { |
+ StrictMockWorkItem item; |
+ item.set_allow_rollback(false); |
+ EXPECT_CALL(item, DoImpl()).WillOnce(Return(true)); |
+ item.Do(); |
+ 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
|
+ item.Rollback(); |
+} |