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
3 // found in the LICENSE file.
6 #include "chrome/installer/util/callback_work_item.h"
7 #include "testing/gtest/include/gtest/gtest.h"
11 // A callback that always fails (returns false).
12 bool TestFailureCallback(const CallbackWorkItem
& work_item
) {
18 // Test that the work item returns false when a callback returns failure.
19 TEST(CallbackWorkItemTest
, TestFailure
) {
20 CallbackWorkItem
work_item(base::Bind(&TestFailureCallback
));
22 EXPECT_FALSE(work_item
.Do());
27 enum TestCallbackState
{
33 // A callback that sets |state| according to whether it is rolling forward or
35 bool TestForwardBackwardCallback(TestCallbackState
* state
,
36 const CallbackWorkItem
& work_item
) {
37 *state
= work_item
.IsRollback() ? TCS_CALLED_ROLLBACK
: TCS_CALLED_FORWARD
;
43 // Test that the callback is invoked correclty during Do() and Rollback().
44 TEST(CallbackWorkItemTest
, TestForwardBackward
) {
45 TestCallbackState state
= TCS_UNDEFINED
;
47 CallbackWorkItem
work_item(base::Bind(&TestForwardBackwardCallback
, &state
));
49 EXPECT_TRUE(work_item
.Do());
50 EXPECT_EQ(TCS_CALLED_FORWARD
, state
);
53 EXPECT_EQ(TCS_CALLED_ROLLBACK
, state
);