Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: base/task_unittest.cc

Issue 8120015: Add ScopedClosureRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unittests Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/task.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « base/task.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698