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

Side by Side Diff: base/task_unittest.cc

Issue 7062042: 1;2305;0cRevert 86971 - Move media library AutoTaskRunner to base and rename ScopedTaskRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/task.cc ('k') | content/renderer/media/video_capture_impl.h » ('j') | 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/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/task.h" 6 #include "base/task.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace { 9 namespace {
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 TEST(TaskTest, TestCancelInDestructor) { 43 TEST(TaskTest, TestCancelInDestructor) {
44 // Intentionally not using a scoped_refptr for cancel_in_destructor. 44 // Intentionally not using a scoped_refptr for cancel_in_destructor.
45 CancelInDestructor* cancel_in_destructor = new CancelInDestructor(); 45 CancelInDestructor* cancel_in_destructor = new CancelInDestructor();
46 cancel_in_destructor->Start(); 46 cancel_in_destructor->Start();
47 CancelableTask* cancelable_task = cancel_in_destructor->cancelable_task(); 47 CancelableTask* cancelable_task = cancel_in_destructor->cancelable_task();
48 ASSERT_TRUE(cancelable_task); 48 ASSERT_TRUE(cancelable_task);
49 delete cancelable_task; 49 delete cancelable_task;
50 } 50 }
51 51
52 class DoneTask : public Task {
53 public:
54 DoneTask(int* run_count, bool* was_deleted)
55 : run_count_(run_count), was_deleted_(was_deleted) {
56 }
57 virtual ~DoneTask() {
58 *was_deleted_ = true;
59 }
60
61 virtual void Run() {
62 ++(*run_count_);
63 }
64
65 int* run_count_;
66 bool* was_deleted_;
67 };
68
69 TEST(TaskTest, TestScopedTaskRunnerExitScope) {
70 int run_count = 0;
71 bool was_deleted = false;
72 {
73 base::ScopedTaskRunner runner(new DoneTask(&run_count, &was_deleted));
74 EXPECT_EQ(0, run_count);
75 }
76 EXPECT_EQ(1, run_count);
77 EXPECT_TRUE(was_deleted);
78 }
79
80 TEST(TaskTest, TestScopedTaskRunnerRelease) {
81 int run_count = 0;
82 bool was_deleted = false;
83 {
84 base::ScopedTaskRunner runner(new DoneTask(&run_count, &was_deleted));
85 delete runner.Release();
86 EXPECT_TRUE(was_deleted);
87 }
88 EXPECT_EQ(0, run_count);
89 }
90
91 TEST(TaskTest, TestScopedTaskRunnerManualRun) {
92 int run_count = 0;
93 Task* done_task = NULL;
94 bool was_deleted = false;
95 {
96 base::ScopedTaskRunner runner(new DoneTask(&run_count, &was_deleted));
97 done_task = runner.Release();
98 EXPECT_TRUE(NULL != done_task);
99 EXPECT_FALSE(was_deleted);
100 EXPECT_EQ(0, run_count);
101 done_task->Run();
102 EXPECT_FALSE(was_deleted);
103 EXPECT_EQ(1, run_count);
104 }
105 EXPECT_EQ(1, run_count);
106 delete done_task;
107 EXPECT_TRUE(was_deleted);
108 }
109
110 } // namespace 52 } // namespace
OLDNEW
« 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