Index: base/task_unittest.cc |
diff --git a/base/task_unittest.cc b/base/task_unittest.cc |
index 25c201d267b801c0008c2a3074b4fd84755fc253..e0cb659cf094c01db34730189989efef07a243d2 100644 |
--- a/base/task_unittest.cc |
+++ b/base/task_unittest.cc |
@@ -49,4 +49,62 @@ TEST(TaskTest, TestCancelInDestructor) { |
delete cancelable_task; |
} |
+class DoneTask : public Task { |
+ public: |
+ DoneTask(int* run_count, bool* was_deleted) |
+ : run_count_(run_count), was_deleted_(was_deleted) { |
+ } |
+ virtual ~DoneTask() { |
+ *was_deleted_ = true; |
+ } |
+ |
+ virtual void Run() { |
+ ++(*run_count_); |
+ } |
+ |
+ int* run_count_; |
+ bool* was_deleted_; |
+}; |
+ |
+TEST(TaskTest, TestScopedTaskRunnerExitScope) { |
+ int run_count = 0; |
+ bool was_deleted = false; |
+ { |
+ base::ScopedTaskRunner runner(new DoneTask(&run_count, &was_deleted)); |
+ EXPECT_EQ(0, run_count); |
+ } |
+ EXPECT_EQ(1, run_count); |
+ EXPECT_TRUE(was_deleted); |
+} |
+ |
+TEST(TaskTest, TestScopedTaskRunnerRelease) { |
+ int run_count = 0; |
+ bool was_deleted = false; |
+ { |
+ base::ScopedTaskRunner runner(new DoneTask(&run_count, &was_deleted)); |
+ delete runner.Release(); |
+ EXPECT_TRUE(was_deleted); |
+ } |
+ EXPECT_EQ(0, run_count); |
+} |
+ |
+TEST(TaskTest, TestScopedTaskRunnerManualRun) { |
+ int run_count = 0; |
+ Task* done_task = NULL; |
+ bool was_deleted = false; |
+ { |
+ base::ScopedTaskRunner runner(new DoneTask(&run_count, &was_deleted)); |
+ done_task = runner.Release(); |
+ EXPECT_TRUE(NULL != done_task); |
+ EXPECT_FALSE(was_deleted); |
+ EXPECT_EQ(0, run_count); |
+ done_task->Run(); |
+ EXPECT_FALSE(was_deleted); |
+ EXPECT_EQ(1, run_count); |
+ } |
+ EXPECT_EQ(1, run_count); |
+ delete done_task; |
+ EXPECT_TRUE(was_deleted); |
+} |
+ |
} // namespace |