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

Side by Side Diff: base/message_loop_proxy_impl_unittest.cc

Issue 3869003: Const-ify RefCountedThreadSafe::AddRef and Release. (Closed)
Patch Set: actually remove the cast Created 10 years, 2 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
« no previous file with comments | « base/message_loop_proxy_impl.cc ('k') | base/ref_counted.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) 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_impl.h" 6 #include "base/message_loop_proxy_impl.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/thread.h" 8 #include "base/thread.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h" 10 #include "testing/platform_test.h"
11 11
12 12
13 class MessageLoopProxyImplTest : public testing::Test { 13 class MessageLoopProxyImplTest : public testing::Test {
14 public: 14 public:
15 void Release() { 15 void Release() const {
16 AssertOnIOThread(); 16 AssertOnIOThread();
17 Quit(); 17 Quit();
18 } 18 }
19 19
20 void Quit() { 20 void Quit() const {
21 loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); 21 loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask);
22 } 22 }
23 23
24 void AssertOnIOThread() { 24 void AssertOnIOThread() const {
25 ASSERT_TRUE(io_thread_->message_loop_proxy()->BelongsToCurrentThread()); 25 ASSERT_TRUE(io_thread_->message_loop_proxy()->BelongsToCurrentThread());
26 } 26 }
27 27
28 void AssertOnFileThread() { 28 void AssertOnFileThread() const {
29 ASSERT_TRUE(file_thread_->message_loop_proxy()->BelongsToCurrentThread()); 29 ASSERT_TRUE(file_thread_->message_loop_proxy()->BelongsToCurrentThread());
30 } 30 }
31 31
32 protected: 32 protected:
33 virtual void SetUp() { 33 virtual void SetUp() {
34 io_thread_.reset(new base::Thread("MessageLoopProxyImplTest_IO")); 34 io_thread_.reset(new base::Thread("MessageLoopProxyImplTest_IO"));
35 file_thread_.reset(new base::Thread("MessageLoopProxyImplTest_File")); 35 file_thread_.reset(new base::Thread("MessageLoopProxyImplTest_File"));
36 io_thread_->Start(); 36 io_thread_->Start();
37 file_thread_->Start(); 37 file_thread_->Start();
38 } 38 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 73
74 private: 74 private:
75 MessageLoopProxyImplTest* test_; 75 MessageLoopProxyImplTest* test_;
76 }; 76 };
77 77
78 scoped_ptr<base::Thread> io_thread_; 78 scoped_ptr<base::Thread> io_thread_;
79 scoped_ptr<base::Thread> file_thread_; 79 scoped_ptr<base::Thread> file_thread_;
80 80
81 private: 81 private:
82 MessageLoop loop_; 82 mutable MessageLoop loop_;
83 }; 83 };
84 84
85 85
86 TEST_F(MessageLoopProxyImplTest, PostTask) { 86 TEST_F(MessageLoopProxyImplTest, PostTask) {
87 EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask( 87 EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
88 FROM_HERE, NewRunnableFunction(&BasicFunction, this))); 88 FROM_HERE, NewRunnableFunction(&BasicFunction, this)));
89 MessageLoop::current()->Run(); 89 MessageLoop::current()->Run();
90 } 90 }
91 91
92 TEST_F(MessageLoopProxyImplTest, Release) { 92 TEST_F(MessageLoopProxyImplTest, Release) {
(...skipping 30 matching lines...) Expand all
123 new base::Thread("MessageLoopProxyImplTest_Dummy")); 123 new base::Thread("MessageLoopProxyImplTest_Dummy"));
124 test_thread->Start(); 124 test_thread->Start();
125 message_loop_proxy = test_thread->message_loop_proxy(); 125 message_loop_proxy = test_thread->message_loop_proxy();
126 } 126 }
127 bool deleted = false; 127 bool deleted = false;
128 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); 128 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted));
129 EXPECT_FALSE(ret); 129 EXPECT_FALSE(ret);
130 EXPECT_TRUE(deleted); 130 EXPECT_TRUE(deleted);
131 } 131 }
132 132
OLDNEW
« no previous file with comments | « base/message_loop_proxy_impl.cc ('k') | base/ref_counted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698