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

Side by Side Diff: base/message_loop_proxy_impl_unittest.cc

Issue 13333003: Create a new base/message_loop directory and move the message_loop_proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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/message_loop_proxy_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/message_loop_proxy_impl.h"
6
7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h"
11 #include "base/threading/thread.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h"
14
15
16 class MessageLoopProxyImplTest : public testing::Test {
17 public:
18 void Release() const {
19 AssertOnIOThread();
20 Quit();
21 }
22
23 void Quit() const {
24 loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure());
25 }
26
27 void AssertOnIOThread() const {
28 ASSERT_TRUE(io_thread_->message_loop_proxy()->BelongsToCurrentThread());
29 ASSERT_EQ(io_thread_->message_loop_proxy(),
30 base::MessageLoopProxy::current());
31 }
32
33 void AssertOnFileThread() const {
34 ASSERT_TRUE(file_thread_->message_loop_proxy()->BelongsToCurrentThread());
35 ASSERT_EQ(file_thread_->message_loop_proxy(),
36 base::MessageLoopProxy::current());
37 }
38
39 protected:
40 virtual void SetUp() OVERRIDE {
41 io_thread_.reset(new base::Thread("MessageLoopProxyImplTest_IO"));
42 file_thread_.reset(new base::Thread("MessageLoopProxyImplTest_File"));
43 io_thread_->Start();
44 file_thread_->Start();
45 }
46
47 virtual void TearDown() OVERRIDE {
48 io_thread_->Stop();
49 file_thread_->Stop();
50 }
51
52 static void BasicFunction(MessageLoopProxyImplTest* test) {
53 test->AssertOnFileThread();
54 test->Quit();
55 }
56
57 static void AssertNotRun() {
58 FAIL() << "Callback Should not get executed.";
59 }
60
61 class DeletedOnFile {
62 public:
63 explicit DeletedOnFile(MessageLoopProxyImplTest* test) : test_(test) {}
64
65 ~DeletedOnFile() {
66 test_->AssertOnFileThread();
67 test_->Quit();
68 }
69
70 private:
71 MessageLoopProxyImplTest* test_;
72 };
73
74 scoped_ptr<base::Thread> io_thread_;
75 scoped_ptr<base::Thread> file_thread_;
76
77 private:
78 mutable MessageLoop loop_;
79 };
80
81 TEST_F(MessageLoopProxyImplTest, Release) {
82 EXPECT_TRUE(io_thread_->message_loop_proxy()->ReleaseSoon(FROM_HERE, this));
83 MessageLoop::current()->Run();
84 }
85
86 TEST_F(MessageLoopProxyImplTest, Delete) {
87 DeletedOnFile* deleted_on_file = new DeletedOnFile(this);
88 EXPECT_TRUE(file_thread_->message_loop_proxy()->DeleteSoon(
89 FROM_HERE, deleted_on_file));
90 MessageLoop::current()->Run();
91 }
92
93 TEST_F(MessageLoopProxyImplTest, PostTask) {
94 EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
95 FROM_HERE, base::Bind(&MessageLoopProxyImplTest::BasicFunction,
96 base::Unretained(this))));
97 MessageLoop::current()->Run();
98 }
99
100 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) {
101 scoped_ptr<base::Thread> test_thread(
102 new base::Thread("MessageLoopProxyImplTest_Dummy"));
103 test_thread->Start();
104 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
105 test_thread->message_loop_proxy();
106 test_thread->Stop();
107
108 bool ret = message_loop_proxy->PostTask(
109 FROM_HERE,
110 base::Bind(&MessageLoopProxyImplTest::AssertNotRun));
111 EXPECT_FALSE(ret);
112 }
113
114 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadIsDeleted) {
115 scoped_refptr<base::MessageLoopProxy> message_loop_proxy;
116 {
117 scoped_ptr<base::Thread> test_thread(
118 new base::Thread("MessageLoopProxyImplTest_Dummy"));
119 test_thread->Start();
120 message_loop_proxy = test_thread->message_loop_proxy();
121 }
122 bool ret = message_loop_proxy->PostTask(
123 FROM_HERE,
124 base::Bind(&MessageLoopProxyImplTest::AssertNotRun));
125 EXPECT_FALSE(ret);
126 }
OLDNEW
« no previous file with comments | « base/message_loop_proxy_impl.cc ('k') | base/message_loop_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698