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

Side by Side Diff: mojo/edk/system/channel_manager_unittest.cc

Issue 1651183003: Make PlatformChannelPair "dumb". (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/edk/system/channel_manager.h" 5 #include "mojo/edk/system/channel_manager.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 ChannelManager channel_manager_; 62 ChannelManager channel_manager_;
63 63
64 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManagerTest); 64 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManagerTest);
65 }; 65 };
66 66
67 TEST_F(ChannelManagerTest, Basic) { 67 TEST_F(ChannelManagerTest, Basic) {
68 embedder::PlatformChannelPair channel_pair; 68 embedder::PlatformChannelPair channel_pair;
69 69
70 const ChannelId id = 1; 70 const ChannelId id = 1;
71 RefPtr<MessagePipeDispatcher> d = channel_manager().CreateChannelOnIOThread( 71 RefPtr<MessagePipeDispatcher> d = channel_manager().CreateChannelOnIOThread(
72 id, channel_pair.PassServerHandle()); 72 id, channel_pair.handle0.Pass());
73 73
74 RefPtr<Channel> ch = channel_manager().GetChannel(id); 74 RefPtr<Channel> ch = channel_manager().GetChannel(id);
75 EXPECT_TRUE(ch); 75 EXPECT_TRUE(ch);
76 // |ChannelManager| should have a ref. 76 // |ChannelManager| should have a ref.
77 EXPECT_FALSE(ch->HasOneRef()); 77 EXPECT_FALSE(ch->HasOneRef());
78 78
79 channel_manager().WillShutdownChannel(id); 79 channel_manager().WillShutdownChannel(id);
80 // |ChannelManager| should still have a ref. 80 // |ChannelManager| should still have a ref.
81 EXPECT_FALSE(ch->HasOneRef()); 81 EXPECT_FALSE(ch->HasOneRef());
82 82
83 channel_manager().ShutdownChannelOnIOThread(id); 83 channel_manager().ShutdownChannelOnIOThread(id);
84 // |ChannelManager| should have given up its ref. 84 // |ChannelManager| should have given up its ref.
85 EXPECT_TRUE(ch->HasOneRef()); 85 EXPECT_TRUE(ch->HasOneRef());
86 86
87 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 87 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
88 } 88 }
89 89
90 TEST_F(ChannelManagerTest, TwoChannels) { 90 TEST_F(ChannelManagerTest, TwoChannels) {
91 embedder::PlatformChannelPair channel_pair; 91 embedder::PlatformChannelPair channel_pair;
92 92
93 const ChannelId id1 = 1; 93 const ChannelId id1 = 1;
94 RefPtr<MessagePipeDispatcher> d1 = channel_manager().CreateChannelOnIOThread( 94 RefPtr<MessagePipeDispatcher> d1 = channel_manager().CreateChannelOnIOThread(
95 id1, channel_pair.PassServerHandle()); 95 id1, channel_pair.handle0.Pass());
96 96
97 const ChannelId id2 = 2; 97 const ChannelId id2 = 2;
98 RefPtr<MessagePipeDispatcher> d2 = channel_manager().CreateChannelOnIOThread( 98 RefPtr<MessagePipeDispatcher> d2 = channel_manager().CreateChannelOnIOThread(
99 id2, channel_pair.PassClientHandle()); 99 id2, channel_pair.handle1.Pass());
100 100
101 RefPtr<Channel> ch1 = channel_manager().GetChannel(id1); 101 RefPtr<Channel> ch1 = channel_manager().GetChannel(id1);
102 EXPECT_TRUE(ch1); 102 EXPECT_TRUE(ch1);
103 103
104 RefPtr<Channel> ch2 = channel_manager().GetChannel(id2); 104 RefPtr<Channel> ch2 = channel_manager().GetChannel(id2);
105 EXPECT_TRUE(ch2); 105 EXPECT_TRUE(ch2);
106 106
107 // Calling |WillShutdownChannel()| multiple times (on |id1|) is okay. 107 // Calling |WillShutdownChannel()| multiple times (on |id1|) is okay.
108 channel_manager().WillShutdownChannel(id1); 108 channel_manager().WillShutdownChannel(id1);
109 channel_manager().WillShutdownChannel(id1); 109 channel_manager().WillShutdownChannel(id1);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 std::function<void()> quit_closure_; 164 std::function<void()> quit_closure_;
165 165
166 MOJO_DISALLOW_COPY_AND_ASSIGN(OtherThread); 166 MOJO_DISALLOW_COPY_AND_ASSIGN(OtherThread);
167 }; 167 };
168 168
169 TEST_F(ChannelManagerTest, CallsFromOtherThread) { 169 TEST_F(ChannelManagerTest, CallsFromOtherThread) {
170 embedder::PlatformChannelPair channel_pair; 170 embedder::PlatformChannelPair channel_pair;
171 171
172 const ChannelId id = 1; 172 const ChannelId id = 1;
173 RefPtr<MessagePipeDispatcher> d = channel_manager().CreateChannelOnIOThread( 173 RefPtr<MessagePipeDispatcher> d = channel_manager().CreateChannelOnIOThread(
174 id, channel_pair.PassServerHandle()); 174 id, channel_pair.handle0.Pass());
175 175
176 OtherThread thread(task_runner().Clone(), &channel_manager(), id, 176 OtherThread thread(task_runner().Clone(), &channel_manager(), id,
177 [this]() { message_loop()->QuitNow(); }); 177 [this]() { message_loop()->QuitNow(); });
178 thread.Start(); 178 thread.Start();
179 message_loop()->Run(); 179 message_loop()->Run();
180 thread.Join(); 180 thread.Join();
181 181
182 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 182 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
183 } 183 }
184 184
185 // TODO(vtl): Test |CreateChannelWithoutBootstrapOnIOThread()|. (This will 185 // TODO(vtl): Test |CreateChannelWithoutBootstrapOnIOThread()|. (This will
186 // require additional functionality in |Channel|.) 186 // require additional functionality in |Channel|.)
187 187
188 } // namespace 188 } // namespace
189 } // namespace system 189 } // namespace system
190 } // namespace mojo 190 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_channel_pair_unittest.cc ('k') | mojo/edk/system/channel_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698