| OLD | NEW |
| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/test/test_browser_thread.h" | 10 #include "content/test/test_browser_thread.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 scoped_ptr<BrowserThreadImpl> ui_thread_; | 85 scoped_ptr<BrowserThreadImpl> ui_thread_; |
| 86 scoped_ptr<BrowserThreadImpl> file_thread_; | 86 scoped_ptr<BrowserThreadImpl> file_thread_; |
| 87 // It's kind of ugly to make this mutable - solely so we can post the Quit | 87 // It's kind of ugly to make this mutable - solely so we can post the Quit |
| 88 // Task from Release(). This should be fixed. | 88 // Task from Release(). This should be fixed. |
| 89 mutable MessageLoop loop_; | 89 mutable MessageLoop loop_; |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 TEST_F(BrowserThreadTest, PostTask) { | 92 TEST_F(BrowserThreadTest, PostTask) { |
| 93 BrowserThread::PostTask( | 93 BrowserThread::PostTask( |
| 94 BrowserThread::FILE, FROM_HERE, | 94 BrowserThread::FILE, FROM_HERE, |
| 95 NewRunnableFunction(&BasicFunction, MessageLoop::current())); | 95 base::Bind(&BasicFunction, MessageLoop::current())); |
| 96 MessageLoop::current()->Run(); | 96 MessageLoop::current()->Run(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST_F(BrowserThreadTest, Release) { | 99 TEST_F(BrowserThreadTest, Release) { |
| 100 BrowserThread::ReleaseSoon(BrowserThread::UI, FROM_HERE, this); | 100 BrowserThread::ReleaseSoon(BrowserThread::UI, FROM_HERE, this); |
| 101 MessageLoop::current()->Run(); | 101 MessageLoop::current()->Run(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 TEST_F(BrowserThreadTest, TaskToNonExistentThreadIsDeleted) { | 104 TEST_F(BrowserThreadTest, TaskToNonExistentThreadIsDeleted) { |
| 105 bool deleted = false; | 105 bool deleted = false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 117 MessageLoop::current()->Run(); | 117 MessageLoop::current()->Run(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 TEST_F(BrowserThreadTest, NotReleasedIfTargetThreadNonExistent) { | 120 TEST_F(BrowserThreadTest, NotReleasedIfTargetThreadNonExistent) { |
| 121 scoped_refptr<NeverDeleted> test(new NeverDeleted()); | 121 scoped_refptr<NeverDeleted> test(new NeverDeleted()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxy) { | 124 TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxy) { |
| 125 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = | 125 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
| 126 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); | 126 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); |
| 127 message_loop_proxy->PostTask(FROM_HERE, | 127 message_loop_proxy->PostTask( |
| 128 NewRunnableFunction(&BasicFunction, | 128 FROM_HERE, base::Bind(&BasicFunction, MessageLoop::current())); |
| 129 MessageLoop::current())); | |
| 130 MessageLoop::current()->Run(); | 129 MessageLoop::current()->Run(); |
| 131 } | 130 } |
| 132 | 131 |
| 133 TEST_F(BrowserThreadTest, ReleaseViaMessageLoopProxy) { | 132 TEST_F(BrowserThreadTest, ReleaseViaMessageLoopProxy) { |
| 134 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = | 133 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
| 135 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 134 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 136 message_loop_proxy->ReleaseSoon(FROM_HERE, this); | 135 message_loop_proxy->ReleaseSoon(FROM_HERE, this); |
| 137 MessageLoop::current()->Run(); | 136 MessageLoop::current()->Run(); |
| 138 } | 137 } |
| 139 | 138 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 179 } |
| 181 bool deleted = false; | 180 bool deleted = false; |
| 182 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = | 181 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
| 183 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 182 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 184 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); | 183 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); |
| 185 EXPECT_FALSE(ret); | 184 EXPECT_FALSE(ret); |
| 186 EXPECT_TRUE(deleted); | 185 EXPECT_TRUE(deleted); |
| 187 } | 186 } |
| 188 | 187 |
| 189 } | 188 } |
| OLD | NEW |