Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / installer / util / callback_work_item_unittest.cc
blob0c4a531b139b5dabde266c5a3200ec8d1b785d12
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.
5 #include "base/bind.h"
6 #include "chrome/installer/util/callback_work_item.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace {
11 // A callback that always fails (returns false).
12 bool TestFailureCallback(const CallbackWorkItem& work_item) {
13 return false;
16 } // namespace
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());
25 namespace {
27 enum TestCallbackState {
28 TCS_UNDEFINED,
29 TCS_CALLED_FORWARD,
30 TCS_CALLED_ROLLBACK,
33 // A callback that sets |state| according to whether it is rolling forward or
34 // backward.
35 bool TestForwardBackwardCallback(TestCallbackState* state,
36 const CallbackWorkItem& work_item) {
37 *state = work_item.IsRollback() ? TCS_CALLED_ROLLBACK : TCS_CALLED_FORWARD;
38 return true;
41 } // namespace
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);
52 work_item.Rollback();
53 EXPECT_EQ(TCS_CALLED_ROLLBACK, state);