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

Side by Side Diff: content/browser/browser_thread_unittest.cc

Issue 8340028: Salient parts of http://codereview.chromium.org/8392042/ (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « content/browser/browser_thread_impl.cc ('k') | content/browser/child_process_launcher.cc » ('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/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.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/test/test_browser_thread.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
12 13
14 namespace content {
15
13 class BrowserThreadTest : public testing::Test { 16 class BrowserThreadTest : public testing::Test {
14 public: 17 public:
15 void Release() const { 18 void Release() const {
16 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 19 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
17 loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); 20 loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask);
18 } 21 }
19 22
20 protected: 23 protected:
21 virtual void SetUp() { 24 virtual void SetUp() {
22 ui_thread_.reset(new BrowserThread(BrowserThread::UI)); 25 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI));
23 file_thread_.reset(new BrowserThread(BrowserThread::FILE)); 26 file_thread_.reset(new BrowserThreadImpl(BrowserThread::FILE));
24 ui_thread_->Start(); 27 ui_thread_->Start();
25 file_thread_->Start(); 28 file_thread_->Start();
26 } 29 }
27 30
28 virtual void TearDown() { 31 virtual void TearDown() {
29 ui_thread_->Stop(); 32 ui_thread_->Stop();
30 file_thread_->Stop(); 33 file_thread_->Stop();
31 } 34 }
32 35
33 static void BasicFunction(MessageLoop* message_loop) { 36 static void BasicFunction(MessageLoop* message_loop) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 class NeverDeleted 75 class NeverDeleted
73 : public base::RefCountedThreadSafe< 76 : public base::RefCountedThreadSafe<
74 NeverDeleted, BrowserThread::DeleteOnWebKitThread> { 77 NeverDeleted, BrowserThread::DeleteOnWebKitThread> {
75 public: 78 public:
76 ~NeverDeleted() { 79 ~NeverDeleted() {
77 CHECK(false); 80 CHECK(false);
78 } 81 }
79 }; 82 };
80 83
81 private: 84 private:
82 scoped_ptr<BrowserThread> ui_thread_; 85 scoped_ptr<BrowserThreadImpl> ui_thread_;
83 scoped_ptr<BrowserThread> file_thread_; 86 scoped_ptr<BrowserThreadImpl> file_thread_;
84 // 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
85 // Task from Release(). This should be fixed. 88 // Task from Release(). This should be fixed.
86 mutable MessageLoop loop_; 89 mutable MessageLoop loop_;
87 }; 90 };
88 91
89 TEST_F(BrowserThreadTest, PostTask) { 92 TEST_F(BrowserThreadTest, PostTask) {
90 BrowserThread::PostTask( 93 BrowserThread::PostTask(
91 BrowserThread::FILE, FROM_HERE, 94 BrowserThread::FILE, FROM_HERE,
92 NewRunnableFunction(&BasicFunction, MessageLoop::current())); 95 NewRunnableFunction(&BasicFunction, MessageLoop::current()));
93 MessageLoop::current()->Run(); 96 MessageLoop::current()->Run();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 152
150 TEST_F(BrowserThreadTest, TaskToNonExistentThreadIsDeletedViaMessageLoopProxy) { 153 TEST_F(BrowserThreadTest, TaskToNonExistentThreadIsDeletedViaMessageLoopProxy) {
151 bool deleted = false; 154 bool deleted = false;
152 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = 155 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
153 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT); 156 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT);
154 message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); 157 message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted));
155 EXPECT_TRUE(deleted); 158 EXPECT_TRUE(deleted);
156 } 159 }
157 160
158 TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxyAfterThreadExits) { 161 TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxyAfterThreadExits) {
159 scoped_ptr<BrowserThread> io_thread(new BrowserThread(BrowserThread::IO)); 162 scoped_ptr<BrowserThreadImpl> io_thread(
163 new BrowserThreadImpl(BrowserThread::IO));
160 io_thread->Start(); 164 io_thread->Start();
161 io_thread->Stop(); 165 io_thread->Stop();
162 166
163 bool deleted = false; 167 bool deleted = false;
164 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = 168 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
165 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 169 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
166 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); 170 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted));
167 EXPECT_FALSE(ret); 171 EXPECT_FALSE(ret);
168 EXPECT_TRUE(deleted); 172 EXPECT_TRUE(deleted);
169 } 173 }
170 174
171 TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxyAfterThreadIsDeleted) { 175 TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxyAfterThreadIsDeleted) {
172 { 176 {
173 scoped_ptr<BrowserThread> io_thread(new BrowserThread(BrowserThread::IO)); 177 scoped_ptr<BrowserThreadImpl> io_thread(
178 new BrowserThreadImpl(BrowserThread::IO));
174 io_thread->Start(); 179 io_thread->Start();
175 } 180 }
176 bool deleted = false; 181 bool deleted = false;
177 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = 182 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
178 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 183 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
179 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); 184 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted));
180 EXPECT_FALSE(ret); 185 EXPECT_FALSE(ret);
181 EXPECT_TRUE(deleted); 186 EXPECT_TRUE(deleted);
182 } 187 }
188
189 }
OLDNEW
« no previous file with comments | « content/browser/browser_thread_impl.cc ('k') | content/browser/child_process_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698