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

Side by Side Diff: mojo/public/cpp/bindings/tests/connector_unittest.cc

Issue 328713004: Mojo: Use the MessagePipe creation helper whenever possible/reasonable in tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "mojo/public/cpp/bindings/lib/connector.h" 8 #include "mojo/public/cpp/bindings/lib/connector.h"
9 #include "mojo/public/cpp/bindings/lib/message_builder.h" 9 #include "mojo/public/cpp/bindings/lib/message_builder.h"
10 #include "mojo/public/cpp/bindings/lib/message_queue.h" 10 #include "mojo/public/cpp/bindings/lib/message_queue.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 173
174 // Still not observed. 174 // Still not observed.
175 EXPECT_FALSE(connector0.encountered_error()); 175 EXPECT_FALSE(connector0.encountered_error());
176 176
177 // Spin the RunLoop, and then we should start observing the closed pipe. 177 // Spin the RunLoop, and then we should start observing the closed pipe.
178 PumpMessages(); 178 PumpMessages();
179 179
180 EXPECT_TRUE(connector0.encountered_error()); 180 EXPECT_TRUE(connector0.encountered_error());
181 } 181 }
182 182
183 // Enable this test once MojoWriteMessage supports passing handles.
184 TEST_F(ConnectorTest, MessageWithHandles) { 183 TEST_F(ConnectorTest, MessageWithHandles) {
185 internal::Connector connector0(handle0_.Pass()); 184 internal::Connector connector0(handle0_.Pass());
186 internal::Connector connector1(handle1_.Pass()); 185 internal::Connector connector1(handle1_.Pass());
187 186
188 const char kText[] = "hello world"; 187 const char kText[] = "hello world";
189 188
190 Message message1; 189 Message message1;
191 AllocMessage(kText, &message1); 190 AllocMessage(kText, &message1);
192 191
193 ScopedMessagePipeHandle handles[2]; 192 MessagePipe pipe;
194 CreateMessagePipe(&handles[0], &handles[1]); 193 message1.mutable_handles()->push_back(pipe.handle0.release());
195 message1.mutable_handles()->push_back(handles[0].release());
196 194
197 connector0.Accept(&message1); 195 connector0.Accept(&message1);
198 196
199 // The message should have been transferred, releasing the handles. 197 // The message should have been transferred, releasing the handles.
200 EXPECT_TRUE(message1.handles()->empty()); 198 EXPECT_TRUE(message1.handles()->empty());
201 199
202 MessageAccumulator accumulator; 200 MessageAccumulator accumulator;
203 connector1.set_incoming_receiver(&accumulator); 201 connector1.set_incoming_receiver(&accumulator);
204 202
205 PumpMessages(); 203 PumpMessages();
(...skipping 10 matching lines...) Expand all
216 214
217 // Now send a message to the transferred handle and confirm it's sent through 215 // Now send a message to the transferred handle and confirm it's sent through
218 // to the orginal pipe. 216 // to the orginal pipe.
219 // TODO(vtl): Do we need a better way of "downcasting" the handle types? 217 // TODO(vtl): Do we need a better way of "downcasting" the handle types?
220 ScopedMessagePipeHandle smph; 218 ScopedMessagePipeHandle smph;
221 smph.reset(MessagePipeHandle(message_received.handles()->front().value())); 219 smph.reset(MessagePipeHandle(message_received.handles()->front().value()));
222 message_received.mutable_handles()->front() = Handle(); 220 message_received.mutable_handles()->front() = Handle();
223 // |smph| now owns this handle. 221 // |smph| now owns this handle.
224 222
225 internal::Connector connector_received(smph.Pass()); 223 internal::Connector connector_received(smph.Pass());
226 internal::Connector connector_original(handles[1].Pass()); 224 internal::Connector connector_original(pipe.handle1.Pass());
227 225
228 Message message2; 226 Message message2;
229 AllocMessage(kText, &message2); 227 AllocMessage(kText, &message2);
230 228
231 connector_received.Accept(&message2); 229 connector_received.Accept(&message2);
232 connector_original.set_incoming_receiver(&accumulator); 230 connector_original.set_incoming_receiver(&accumulator);
233 PumpMessages(); 231 PumpMessages();
234 232
235 ASSERT_FALSE(accumulator.IsEmpty()); 233 ASSERT_FALSE(accumulator.IsEmpty());
236 234
237 accumulator.Pop(&message_received); 235 accumulator.Pop(&message_received);
238 236
239 EXPECT_EQ( 237 EXPECT_EQ(
240 std::string(kText), 238 std::string(kText),
241 std::string(reinterpret_cast<const char*>(message_received.payload()))); 239 std::string(reinterpret_cast<const char*>(message_received.payload())));
242 } 240 }
243 241
244 } // namespace 242 } // namespace
245 } // namespace test 243 } // namespace test
246 } // namespace mojo 244 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/array_unittest.cc ('k') | mojo/public/cpp/bindings/tests/handle_passing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698