Remove use of deprecated SkImage::getTexture() from gl_renderer.cc
[chromium-blink-merge.git] / media / base / callback_holder_unittest.cc
blobe06a930ed334ca1c1de1042aab7e1327f3720ae8
1 // Copyright 2013 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 "media/base/callback_holder.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace media {
11 static void SetBool(bool* var) {
12 DCHECK(!*var);
13 *var = true;
16 static void CopyVar(int var1, int* var2) {
17 DCHECK_NE(var1, *var2);
18 *var2 = var1;
21 TEST(CallbackHolderTest, SetAfterHold_Closure) {
22 CallbackHolder<base::Closure> cb;
23 EXPECT_TRUE(cb.IsNull());
25 cb.HoldCallback();
27 bool closure_called = false;
28 cb.SetCallback(base::Bind(&SetBool, &closure_called));
29 EXPECT_FALSE(cb.IsNull());
31 cb.RunOrHold();
32 EXPECT_FALSE(closure_called);
34 EXPECT_FALSE(cb.IsNull());
35 cb.RunHeldCallback();
36 EXPECT_TRUE(cb.IsNull());
37 EXPECT_TRUE(closure_called);
40 TEST(CallbackHolderTest, HoldAfterSet_Closure) {
41 CallbackHolder<base::Closure> cb;
42 EXPECT_TRUE(cb.IsNull());
44 bool closure_called = false;
45 cb.SetCallback(base::Bind(&SetBool, &closure_called));
46 EXPECT_FALSE(cb.IsNull());
48 cb.HoldCallback();
50 cb.RunOrHold();
51 EXPECT_FALSE(closure_called);
52 EXPECT_FALSE(cb.IsNull());
53 cb.RunHeldCallback();
54 EXPECT_TRUE(cb.IsNull());
55 EXPECT_TRUE(closure_called);
58 TEST(CallbackHolderTest, NotHold_Closure) {
59 CallbackHolder<base::Closure> cb;
60 EXPECT_TRUE(cb.IsNull());
62 bool closure_called = false;
63 cb.SetCallback(base::Bind(&SetBool, &closure_called));
64 EXPECT_FALSE(cb.IsNull());
66 cb.RunOrHold();
67 EXPECT_TRUE(cb.IsNull());
68 EXPECT_TRUE(closure_called);
71 TEST(CallbackHolderTest, SetAfterHold_Callback) {
72 CallbackHolder<base::Callback<void(int, int*)> > cb;
73 EXPECT_TRUE(cb.IsNull());
75 cb.HoldCallback();
77 cb.SetCallback(base::Bind(&CopyVar));
78 EXPECT_FALSE(cb.IsNull());
80 int var1 = 100;
81 int var2 = 0;
82 cb.RunOrHold(var1, &var2);
83 EXPECT_FALSE(cb.IsNull());
84 EXPECT_NE(var1, var2);
86 cb.RunHeldCallback();
87 EXPECT_TRUE(cb.IsNull());
88 EXPECT_EQ(var1, var2);
91 TEST(CallbackHolderTest, HoldAfterSet_Callback) {
92 CallbackHolder<base::Callback<void(int, int*)> > cb;
93 EXPECT_TRUE(cb.IsNull());
95 cb.SetCallback(base::Bind(&CopyVar));
96 EXPECT_FALSE(cb.IsNull());
98 cb.HoldCallback();
100 int var1 = 100;
101 int var2 = 0;
102 cb.RunOrHold(var1, &var2);
103 EXPECT_FALSE(cb.IsNull());
104 EXPECT_NE(var1, var2);
106 cb.RunHeldCallback();
107 EXPECT_TRUE(cb.IsNull());
108 EXPECT_EQ(var1, var2);
111 TEST(CallbackHolderTest, NotHold_Callback) {
112 CallbackHolder<base::Callback<void(int, int*)> > cb;
113 EXPECT_TRUE(cb.IsNull());
115 cb.SetCallback(base::Bind(&CopyVar));
116 EXPECT_FALSE(cb.IsNull());
118 int var1 = 100;
119 int var2 = 0;
120 cb.RunOrHold(var1, &var2);
121 EXPECT_TRUE(cb.IsNull());
122 EXPECT_EQ(var1, var2);
125 } // namespace media