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

Side by Side Diff: base/message_loop_proxy_impl_unittest.cc

Issue 9086002: base::Bind: Remove Task. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fix. Created 8 years, 11 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/message_loop_proxy_impl.cc ('k') | base/task.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/message_loop_proxy_impl.h" 5 #include "base/message_loop_proxy_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 static void BasicFunction(MessageLoopProxyImplTest* test) { 52 static void BasicFunction(MessageLoopProxyImplTest* test) {
53 test->AssertOnFileThread(); 53 test->AssertOnFileThread();
54 test->Quit(); 54 test->Quit();
55 } 55 }
56 56
57 static void AssertNotRun() { 57 static void AssertNotRun() {
58 FAIL() << "Callback Should not get executed."; 58 FAIL() << "Callback Should not get executed.";
59 } 59 }
60 60
61 class DummyTask : public Task {
62 public:
63 explicit DummyTask(bool* deleted) : deleted_(deleted) { }
64 ~DummyTask() {
65 *deleted_ = true;
66 }
67
68 void Run() {
69 FAIL();
70 }
71
72 private:
73 bool* deleted_;
74 };
75
76 class DeletedOnFile { 61 class DeletedOnFile {
77 public: 62 public:
78 explicit DeletedOnFile(MessageLoopProxyImplTest* test) : test_(test) {} 63 explicit DeletedOnFile(MessageLoopProxyImplTest* test) : test_(test) {}
79 64
80 ~DeletedOnFile() { 65 ~DeletedOnFile() {
81 test_->AssertOnFileThread(); 66 test_->AssertOnFileThread();
82 test_->Quit(); 67 test_->Quit();
83 } 68 }
84 69
85 private: 70 private:
(...skipping 12 matching lines...) Expand all
98 MessageLoop::current()->Run(); 83 MessageLoop::current()->Run();
99 } 84 }
100 85
101 TEST_F(MessageLoopProxyImplTest, Delete) { 86 TEST_F(MessageLoopProxyImplTest, Delete) {
102 DeletedOnFile* deleted_on_file = new DeletedOnFile(this); 87 DeletedOnFile* deleted_on_file = new DeletedOnFile(this);
103 EXPECT_TRUE(file_thread_->message_loop_proxy()->DeleteSoon( 88 EXPECT_TRUE(file_thread_->message_loop_proxy()->DeleteSoon(
104 FROM_HERE, deleted_on_file)); 89 FROM_HERE, deleted_on_file));
105 MessageLoop::current()->Run(); 90 MessageLoop::current()->Run();
106 } 91 }
107 92
108 TEST_F(MessageLoopProxyImplTest, LegacyPostTaskAfterThreadExits) {
109 scoped_ptr<base::Thread> test_thread(
110 new base::Thread("MessageLoopProxyImplTest_Dummy"));
111 test_thread->Start();
112 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
113 test_thread->message_loop_proxy();
114 test_thread->Stop();
115
116 bool deleted = false;
117 bool ret = message_loop_proxy->PostTask(
118 FROM_HERE, new DummyTask(&deleted));
119 EXPECT_FALSE(ret);
120 EXPECT_TRUE(deleted);
121 }
122
123 TEST_F(MessageLoopProxyImplTest, LegacyPostTaskAfterThreadIsDeleted) {
124 scoped_refptr<base::MessageLoopProxy> message_loop_proxy;
125 {
126 scoped_ptr<base::Thread> test_thread(
127 new base::Thread("MessageLoopProxyImplTest_Dummy"));
128 test_thread->Start();
129 message_loop_proxy = test_thread->message_loop_proxy();
130 }
131 bool deleted = false;
132 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted));
133 EXPECT_FALSE(ret);
134 EXPECT_TRUE(deleted);
135 }
136
137 TEST_F(MessageLoopProxyImplTest, PostTask) { 93 TEST_F(MessageLoopProxyImplTest, PostTask) {
138 EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask( 94 EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
139 FROM_HERE, base::Bind(&MessageLoopProxyImplTest::BasicFunction, 95 FROM_HERE, base::Bind(&MessageLoopProxyImplTest::BasicFunction,
140 base::Unretained(this)))); 96 base::Unretained(this))));
141 MessageLoop::current()->Run(); 97 MessageLoop::current()->Run();
142 } 98 }
143 99
144 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) { 100 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) {
145 scoped_ptr<base::Thread> test_thread( 101 scoped_ptr<base::Thread> test_thread(
146 new base::Thread("MessageLoopProxyImplTest_Dummy")); 102 new base::Thread("MessageLoopProxyImplTest_Dummy"));
(...skipping 14 matching lines...) Expand all
161 scoped_ptr<base::Thread> test_thread( 117 scoped_ptr<base::Thread> test_thread(
162 new base::Thread("MessageLoopProxyImplTest_Dummy")); 118 new base::Thread("MessageLoopProxyImplTest_Dummy"));
163 test_thread->Start(); 119 test_thread->Start();
164 message_loop_proxy = test_thread->message_loop_proxy(); 120 message_loop_proxy = test_thread->message_loop_proxy();
165 } 121 }
166 bool ret = message_loop_proxy->PostTask( 122 bool ret = message_loop_proxy->PostTask(
167 FROM_HERE, 123 FROM_HERE,
168 base::Bind(&MessageLoopProxyImplTest::AssertNotRun)); 124 base::Bind(&MessageLoopProxyImplTest::AssertNotRun));
169 EXPECT_FALSE(ret); 125 EXPECT_FALSE(ret);
170 } 126 }
OLDNEW
« no previous file with comments | « base/message_loop_proxy_impl.cc ('k') | base/task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698