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

Side by Side Diff: base/message_loop_proxy_impl_unittest.cc

Issue 7316015: Support Closure in ALL the loops! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed nit and rebased. Created 9 years, 5 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"
6
7 #include "base/bind.h"
5 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h" 9 #include "base/message_loop.h"
7 #include "base/message_loop_proxy_impl.h"
8 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
11 13
12 14
13 class MessageLoopProxyImplTest : public testing::Test { 15 class MessageLoopProxyImplTest : public testing::Test {
14 public: 16 public:
15 void Release() const { 17 void Release() const {
16 AssertOnIOThread(); 18 AssertOnIOThread();
17 Quit(); 19 Quit();
(...skipping 22 matching lines...) Expand all
40 virtual void TearDown() { 42 virtual void TearDown() {
41 io_thread_->Stop(); 43 io_thread_->Stop();
42 file_thread_->Stop(); 44 file_thread_->Stop();
43 } 45 }
44 46
45 static void BasicFunction(MessageLoopProxyImplTest* test) { 47 static void BasicFunction(MessageLoopProxyImplTest* test) {
46 test->AssertOnFileThread(); 48 test->AssertOnFileThread();
47 test->Quit(); 49 test->Quit();
48 } 50 }
49 51
52 static void AssertNotRun() {
53 FAIL() << "Callback Should not get executed.";
54 }
55
50 class DummyTask : public Task { 56 class DummyTask : public Task {
51 public: 57 public:
52 explicit DummyTask(bool* deleted) : deleted_(deleted) { } 58 explicit DummyTask(bool* deleted) : deleted_(deleted) { }
53 ~DummyTask() { 59 ~DummyTask() {
54 *deleted_ = true; 60 *deleted_ = true;
55 } 61 }
56 62
57 void Run() { 63 void Run() {
58 FAIL(); 64 FAIL();
59 } 65 }
(...skipping 16 matching lines...) Expand all
76 }; 82 };
77 83
78 scoped_ptr<base::Thread> io_thread_; 84 scoped_ptr<base::Thread> io_thread_;
79 scoped_ptr<base::Thread> file_thread_; 85 scoped_ptr<base::Thread> file_thread_;
80 86
81 private: 87 private:
82 mutable MessageLoop loop_; 88 mutable MessageLoop loop_;
83 }; 89 };
84 90
85 91
86 TEST_F(MessageLoopProxyImplTest, PostTask) { 92 TEST_F(MessageLoopProxyImplTest, LegacyPostTask) {
87 EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask( 93 EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
88 FROM_HERE, NewRunnableFunction(&BasicFunction, this))); 94 FROM_HERE, NewRunnableFunction(&BasicFunction, this)));
89 MessageLoop::current()->Run(); 95 MessageLoop::current()->Run();
90 } 96 }
91 97
92 TEST_F(MessageLoopProxyImplTest, Release) { 98 TEST_F(MessageLoopProxyImplTest, Release) {
93 EXPECT_TRUE(io_thread_->message_loop_proxy()->ReleaseSoon(FROM_HERE, this)); 99 EXPECT_TRUE(io_thread_->message_loop_proxy()->ReleaseSoon(FROM_HERE, this));
94 MessageLoop::current()->Run(); 100 MessageLoop::current()->Run();
95 } 101 }
96 102
97 TEST_F(MessageLoopProxyImplTest, Delete) { 103 TEST_F(MessageLoopProxyImplTest, Delete) {
98 DeletedOnFile* deleted_on_file = new DeletedOnFile(this); 104 DeletedOnFile* deleted_on_file = new DeletedOnFile(this);
99 EXPECT_TRUE(file_thread_->message_loop_proxy()->DeleteSoon( 105 EXPECT_TRUE(file_thread_->message_loop_proxy()->DeleteSoon(
100 FROM_HERE, deleted_on_file)); 106 FROM_HERE, deleted_on_file));
101 MessageLoop::current()->Run(); 107 MessageLoop::current()->Run();
102 } 108 }
103 109
104 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) { 110 TEST_F(MessageLoopProxyImplTest, LegacyPostTaskAfterThreadExits) {
105 scoped_ptr<base::Thread> test_thread( 111 scoped_ptr<base::Thread> test_thread(
106 new base::Thread("MessageLoopProxyImplTest_Dummy")); 112 new base::Thread("MessageLoopProxyImplTest_Dummy"));
107 test_thread->Start(); 113 test_thread->Start();
108 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = 114 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
109 test_thread->message_loop_proxy(); 115 test_thread->message_loop_proxy();
110 test_thread->Stop(); 116 test_thread->Stop();
111 117
112 bool deleted = false; 118 bool deleted = false;
113 bool ret = message_loop_proxy->PostTask( 119 bool ret = message_loop_proxy->PostTask(
114 FROM_HERE, new DummyTask(&deleted)); 120 FROM_HERE, new DummyTask(&deleted));
115 EXPECT_FALSE(ret); 121 EXPECT_FALSE(ret);
116 EXPECT_TRUE(deleted); 122 EXPECT_TRUE(deleted);
117 } 123 }
118 124
119 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadIsDeleted) { 125 TEST_F(MessageLoopProxyImplTest, LegacyPostTaskAfterThreadIsDeleted) {
120 scoped_refptr<base::MessageLoopProxy> message_loop_proxy; 126 scoped_refptr<base::MessageLoopProxy> message_loop_proxy;
121 { 127 {
122 scoped_ptr<base::Thread> test_thread( 128 scoped_ptr<base::Thread> test_thread(
123 new base::Thread("MessageLoopProxyImplTest_Dummy")); 129 new base::Thread("MessageLoopProxyImplTest_Dummy"));
124 test_thread->Start(); 130 test_thread->Start();
125 message_loop_proxy = test_thread->message_loop_proxy(); 131 message_loop_proxy = test_thread->message_loop_proxy();
126 } 132 }
127 bool deleted = false; 133 bool deleted = false;
128 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); 134 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted));
129 EXPECT_FALSE(ret); 135 EXPECT_FALSE(ret);
130 EXPECT_TRUE(deleted); 136 EXPECT_TRUE(deleted);
131 } 137 }
132 138
139 TEST_F(MessageLoopProxyImplTest, PostTask) {
140 EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
141 FROM_HERE, base::Bind(&MessageLoopProxyImplTest::BasicFunction,
142 base::Unretained(this))));
143 MessageLoop::current()->Run();
144 }
145
146 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) {
147 scoped_ptr<base::Thread> test_thread(
148 new base::Thread("MessageLoopProxyImplTest_Dummy"));
149 test_thread->Start();
150 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
151 test_thread->message_loop_proxy();
152 test_thread->Stop();
153
154 bool ret = message_loop_proxy->PostTask(
155 FROM_HERE,
156 base::Bind(&MessageLoopProxyImplTest::AssertNotRun));
157 EXPECT_FALSE(ret);
158 }
159
160 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadIsDeleted) {
161 scoped_refptr<base::MessageLoopProxy> message_loop_proxy;
162 {
163 scoped_ptr<base::Thread> test_thread(
164 new base::Thread("MessageLoopProxyImplTest_Dummy"));
165 test_thread->Start();
166 message_loop_proxy = test_thread->message_loop_proxy();
167 }
168 bool ret = message_loop_proxy->PostTask(
169 FROM_HERE,
170 base::Bind(&MessageLoopProxyImplTest::AssertNotRun));
171 EXPECT_FALSE(ret);
172 }
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