OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "base/bind.h" |
5 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
6 #include "base/task.h" | 7 #include "base/task.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 | 9 |
9 namespace { | 10 namespace { |
10 | 11 |
11 class CancelInDestructor : public base::RefCounted<CancelInDestructor> { | 12 class CancelInDestructor : public base::RefCounted<CancelInDestructor> { |
12 public: | 13 public: |
13 CancelInDestructor() : cancelable_task_(NULL) {} | 14 CancelInDestructor() : cancelable_task_(NULL) {} |
14 | 15 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 EXPECT_EQ(0, run_count); | 101 EXPECT_EQ(0, run_count); |
101 done_task->Run(); | 102 done_task->Run(); |
102 EXPECT_FALSE(was_deleted); | 103 EXPECT_FALSE(was_deleted); |
103 EXPECT_EQ(1, run_count); | 104 EXPECT_EQ(1, run_count); |
104 } | 105 } |
105 EXPECT_EQ(1, run_count); | 106 EXPECT_EQ(1, run_count); |
106 delete done_task; | 107 delete done_task; |
107 EXPECT_TRUE(was_deleted); | 108 EXPECT_TRUE(was_deleted); |
108 } | 109 } |
109 | 110 |
| 111 void Increment(int* value) { |
| 112 (*value)++; |
| 113 } |
| 114 |
| 115 TEST(TaskTest, TestScopedClosureRunnerExitScope) { |
| 116 int run_count = 0; |
| 117 { |
| 118 base::ScopedClosureRunner runner(base::Bind(Increment, &run_count)); |
| 119 EXPECT_EQ(0, run_count); |
| 120 } |
| 121 EXPECT_EQ(1, run_count); |
| 122 } |
| 123 |
| 124 TEST(TaskTest, TestScopedClosureRunnerRelease) { |
| 125 int run_count = 0; |
| 126 base::Closure c; |
| 127 { |
| 128 base::ScopedClosureRunner runner(base::Bind(Increment, &run_count)); |
| 129 c = runner.Release(); |
| 130 EXPECT_EQ(0, run_count); |
| 131 } |
| 132 EXPECT_EQ(0, run_count); |
| 133 c.Run(); |
| 134 EXPECT_EQ(1, run_count); |
| 135 } |
| 136 |
110 } // namespace | 137 } // namespace |
OLD | NEW |