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

Unified Diff: base/task_unittest.cc

Issue 7062013: Move media library AutoTaskRunner to base and rename ScopedTaskRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add innocuous but critical BASE_API modifier to ScopedTaskRunner declaration. Created 9 years, 7 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') | content/renderer/media/video_capture_impl.h » ('j') | 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 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
« no previous file with comments | « base/task.cc ('k') | content/renderer/media/video_capture_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698