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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/task.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_unittest.cc
diff --git a/base/task_unittest.cc b/base/task_unittest.cc
index e0cb659cf094c01db34730189989efef07a243d2..d7d31fa47b2eace0011df618f4ed34c3b7d01a45 100644
--- a/base/task_unittest.cc
+++ b/base/task_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/task.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -107,4 +108,30 @@ TEST(TaskTest, TestScopedTaskRunnerManualRun) {
EXPECT_TRUE(was_deleted);
}
+void Increment(int* value) {
+ (*value)++;
+}
+
+TEST(TaskTest, TestScopedClosureRunnerExitScope) {
+ int run_count = 0;
+ {
+ base::ScopedClosureRunner runner(base::Bind(Increment, &run_count));
+ EXPECT_EQ(0, run_count);
+ }
+ EXPECT_EQ(1, run_count);
+}
+
+TEST(TaskTest, TestScopedClosureRunnerRelease) {
+ int run_count = 0;
+ base::Closure c;
+ {
+ base::ScopedClosureRunner runner(base::Bind(Increment, &run_count));
+ c = runner.Release();
+ EXPECT_EQ(0, run_count);
+ }
+ EXPECT_EQ(0, run_count);
+ c.Run();
+ EXPECT_EQ(1, run_count);
+}
+
} // namespace
« 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