OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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.h" | 5 #include "base/message_loop.h" |
6 #include "base/message_loop_proxy.h" | 6 #include "base/message_loop_proxy.h" |
7 #include "chrome/browser/chrome_thread.h" | 7 #include "chrome/browser/chrome_thread.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "testing/platform_test.h" | 9 #include "testing/platform_test.h" |
10 | 10 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 new DeletedOnFile(MessageLoop::current())); | 105 new DeletedOnFile(MessageLoop::current())); |
106 } | 106 } |
107 MessageLoop::current()->Run(); | 107 MessageLoop::current()->Run(); |
108 } | 108 } |
109 | 109 |
110 TEST_F(ChromeThreadTest, NotReleasedIfTargetThreadNonExistent) { | 110 TEST_F(ChromeThreadTest, NotReleasedIfTargetThreadNonExistent) { |
111 scoped_refptr<NeverDeleted> test(new NeverDeleted()); | 111 scoped_refptr<NeverDeleted> test(new NeverDeleted()); |
112 } | 112 } |
113 | 113 |
114 TEST_F(ChromeThreadTest, PostTaskViaMessageLoopProxy) { | 114 TEST_F(ChromeThreadTest, PostTaskViaMessageLoopProxy) { |
115 scoped_refptr<MessageLoopProxy> message_loop_proxy = | 115 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
116 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE); | 116 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE); |
117 message_loop_proxy->PostTask(FROM_HERE, | 117 message_loop_proxy->PostTask(FROM_HERE, |
118 NewRunnableFunction(&BasicFunction, | 118 NewRunnableFunction(&BasicFunction, |
119 MessageLoop::current())); | 119 MessageLoop::current())); |
120 MessageLoop::current()->Run(); | 120 MessageLoop::current()->Run(); |
121 } | 121 } |
122 | 122 |
123 TEST_F(ChromeThreadTest, ReleaseViaMessageLoopProxy) { | 123 TEST_F(ChromeThreadTest, ReleaseViaMessageLoopProxy) { |
124 scoped_refptr<MessageLoopProxy> message_loop_proxy = | 124 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
125 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::UI); | 125 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::UI); |
126 message_loop_proxy->ReleaseSoon(FROM_HERE, this); | 126 message_loop_proxy->ReleaseSoon(FROM_HERE, this); |
127 MessageLoop::current()->Run(); | 127 MessageLoop::current()->Run(); |
128 } | 128 } |
129 | 129 |
130 TEST_F(ChromeThreadTest, TaskToNonExistentThreadIsDeletedViaMessageLoopProxy) { | 130 TEST_F(ChromeThreadTest, TaskToNonExistentThreadIsDeletedViaMessageLoopProxy) { |
131 bool deleted = false; | 131 bool deleted = false; |
132 scoped_refptr<MessageLoopProxy> message_loop_proxy = | 132 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
133 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::WEBKIT); | 133 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::WEBKIT); |
134 message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); | 134 message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); |
135 EXPECT_TRUE(deleted); | 135 EXPECT_TRUE(deleted); |
136 } | 136 } |
137 | 137 |
138 TEST_F(ChromeThreadTest, PostTaskViaMessageLoopProxyAfterThreadExits) { | 138 TEST_F(ChromeThreadTest, PostTaskViaMessageLoopProxyAfterThreadExits) { |
139 scoped_ptr<ChromeThread> io_thread(new ChromeThread(ChromeThread::IO)); | 139 scoped_ptr<ChromeThread> io_thread(new ChromeThread(ChromeThread::IO)); |
140 io_thread->Start(); | 140 io_thread->Start(); |
141 io_thread->Stop(); | 141 io_thread->Stop(); |
142 | 142 |
143 bool deleted = false; | 143 bool deleted = false; |
144 scoped_refptr<MessageLoopProxy> message_loop_proxy = | 144 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
145 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); | 145 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); |
146 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); | 146 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); |
147 EXPECT_FALSE(ret); | 147 EXPECT_FALSE(ret); |
148 EXPECT_TRUE(deleted); | 148 EXPECT_TRUE(deleted); |
149 } | 149 } |
150 | 150 |
151 TEST_F(ChromeThreadTest, PostTaskViaMessageLoopProxyAfterThreadIsDeleted) { | 151 TEST_F(ChromeThreadTest, PostTaskViaMessageLoopProxyAfterThreadIsDeleted) { |
152 { | 152 { |
153 scoped_ptr<ChromeThread> io_thread(new ChromeThread(ChromeThread::IO)); | 153 scoped_ptr<ChromeThread> io_thread(new ChromeThread(ChromeThread::IO)); |
154 io_thread->Start(); | 154 io_thread->Start(); |
155 } | 155 } |
156 bool deleted = false; | 156 bool deleted = false; |
157 scoped_refptr<MessageLoopProxy> message_loop_proxy = | 157 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
158 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); | 158 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); |
159 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); | 159 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); |
160 EXPECT_FALSE(ret); | 160 EXPECT_FALSE(ret); |
161 EXPECT_TRUE(deleted); | 161 EXPECT_TRUE(deleted); |
162 } | 162 } |
163 | 163 |
OLD | NEW |