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

Side by Side Diff: mojo/edk/embedder/embedder_unittest.cc

Issue 728043002: Revert of Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | « mojo/edk/embedder/embedder_internal.h ('k') | mojo/edk/embedder/entrypoints.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 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/embedder/embedder.h" 5 #include "mojo/edk/embedder/embedder.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 21 matching lines...) Expand all
32 // pipe on this channel; it is up to the caller to close this handle. 32 // pipe on this channel; it is up to the caller to close this handle.
33 // Note: The I/O thread must outlive this object (and its message loop must 33 // Note: The I/O thread must outlive this object (and its message loop must
34 // continue pumping messages while this object is alive). 34 // continue pumping messages while this object is alive).
35 ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner, 35 ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner,
36 ScopedPlatformHandle platform_handle) 36 ScopedPlatformHandle platform_handle)
37 : io_thread_task_runner_(io_thread_task_runner), 37 : io_thread_task_runner_(io_thread_task_runner),
38 bootstrap_message_pipe_(MOJO_HANDLE_INVALID), 38 bootstrap_message_pipe_(MOJO_HANDLE_INVALID),
39 did_create_channel_event_(true, false), 39 did_create_channel_event_(true, false),
40 channel_info_(nullptr) { 40 channel_info_(nullptr) {
41 bootstrap_message_pipe_ = 41 bootstrap_message_pipe_ =
42 CreateChannel(platform_handle.Pass(), io_thread_task_runner_, 42 CreateChannel(platform_handle.Pass(),
43 io_thread_task_runner_,
43 base::Bind(&ScopedTestChannel::DidCreateChannel, 44 base::Bind(&ScopedTestChannel::DidCreateChannel,
44 base::Unretained(this)), 45 base::Unretained(this)),
45 nullptr) 46 nullptr)
46 .release() 47 .release()
47 .value(); 48 .value();
48 CHECK_NE(bootstrap_message_pipe_, MOJO_HANDLE_INVALID); 49 CHECK_NE(bootstrap_message_pipe_, MOJO_HANDLE_INVALID);
49 } 50 }
50 51
51 // Destructor: Shuts down the channel. (As noted above, for this to happen, 52 // Destructor: Shuts down the channel. (As noted above, for this to happen,
52 // the I/O thread must be alive and pumping messages.) 53 // the I/O thread must be alive and pumping messages.)
53 ~ScopedTestChannel() { 54 ~ScopedTestChannel() {
54 system::test::PostTaskAndWait( 55 system::test::PostTaskAndWait(
55 io_thread_task_runner_, FROM_HERE, 56 io_thread_task_runner_,
57 FROM_HERE,
56 base::Bind(&ScopedTestChannel::DestroyChannel, base::Unretained(this))); 58 base::Bind(&ScopedTestChannel::DestroyChannel, base::Unretained(this)));
57 } 59 }
58 60
59 // Waits for channel creation to be completed. 61 // Waits for channel creation to be completed.
60 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); } 62 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); }
61 63
62 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; } 64 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; }
63 65
64 // Call only after |WaitForChannelCreationCompletion()|. Use only to check 66 // Call only after |WaitForChannelCreationCompletion()|. Use only to check
65 // that it's not null. 67 // that it's not null.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); 123 MojoHandle server_mp = server_channel.bootstrap_message_pipe();
122 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); 124 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
123 ScopedTestChannel client_channel(test_io_thread()->task_runner(), 125 ScopedTestChannel client_channel(test_io_thread()->task_runner(),
124 channel_pair.PassClientHandle()); 126 channel_pair.PassClientHandle());
125 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); 127 MojoHandle client_mp = client_channel.bootstrap_message_pipe();
126 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 128 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
127 129
128 // We can write to a message pipe handle immediately. 130 // We can write to a message pipe handle immediately.
129 const char kHello[] = "hello"; 131 const char kHello[] = "hello";
130 EXPECT_EQ(MOJO_RESULT_OK, 132 EXPECT_EQ(MOJO_RESULT_OK,
131 MojoWriteMessage(server_mp, kHello, 133 MojoWriteMessage(server_mp,
132 static_cast<uint32_t>(sizeof(kHello)), nullptr, 134 kHello,
133 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 135 static_cast<uint32_t>(sizeof(kHello)),
136 nullptr,
137 0,
138 MOJO_WRITE_MESSAGE_FLAG_NONE));
134 139
135 // Now wait for the other side to become readable. 140 // Now wait for the other side to become readable.
136 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE, 141 EXPECT_EQ(
137 MOJO_DEADLINE_INDEFINITE)); 142 MOJO_RESULT_OK,
143 MojoWait(
144 client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
138 145
139 char buffer[1000] = {}; 146 char buffer[1000] = {};
140 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 147 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
141 EXPECT_EQ(MOJO_RESULT_OK, 148 EXPECT_EQ(MOJO_RESULT_OK,
142 MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr, 149 MojoReadMessage(client_mp,
150 buffer,
151 &num_bytes,
152 nullptr,
153 nullptr,
143 MOJO_READ_MESSAGE_FLAG_NONE)); 154 MOJO_READ_MESSAGE_FLAG_NONE));
144 EXPECT_EQ(sizeof(kHello), num_bytes); 155 EXPECT_EQ(sizeof(kHello), num_bytes);
145 EXPECT_STREQ(kHello, buffer); 156 EXPECT_STREQ(kHello, buffer);
146 157
147 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); 158 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
148 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); 159 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
149 160
150 // By this point, these waits should basically be no-ops (since we've waited 161 // By this point, these waits should basically be no-ops (since we've waited
151 // for the client message pipe to become readable, which implies that both 162 // for the client message pipe to become readable, which implies that both
152 // the server and client channels were completely created). 163 // the server and client channels were completely created).
(...skipping 18 matching lines...) Expand all
171 ScopedTestChannel client_channel(test_io_thread()->task_runner(), 182 ScopedTestChannel client_channel(test_io_thread()->task_runner(),
172 channel_pair.PassClientHandle()); 183 channel_pair.PassClientHandle());
173 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); 184 MojoHandle client_mp = client_channel.bootstrap_message_pipe();
174 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 185 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
175 186
176 MojoHandle h0, h1; 187 MojoHandle h0, h1;
177 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &h0, &h1)); 188 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &h0, &h1));
178 189
179 // Write a message to |h0| (attaching nothing). 190 // Write a message to |h0| (attaching nothing).
180 const char kHello[] = "hello"; 191 const char kHello[] = "hello";
181 EXPECT_EQ( 192 EXPECT_EQ(MOJO_RESULT_OK,
182 MOJO_RESULT_OK, 193 MojoWriteMessage(h0,
183 MojoWriteMessage(h0, kHello, static_cast<uint32_t>(sizeof(kHello)), 194 kHello,
184 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 195 static_cast<uint32_t>(sizeof(kHello)),
196 nullptr,
197 0,
198 MOJO_WRITE_MESSAGE_FLAG_NONE));
185 199
186 // Write one message to |server_mp|, attaching |h1|. 200 // Write one message to |server_mp|, attaching |h1|.
187 const char kWorld[] = "world!!!"; 201 const char kWorld[] = "world!!!";
188 EXPECT_EQ(MOJO_RESULT_OK, 202 EXPECT_EQ(MOJO_RESULT_OK,
189 MojoWriteMessage(server_mp, kWorld, 203 MojoWriteMessage(server_mp,
190 static_cast<uint32_t>(sizeof(kWorld)), &h1, 1, 204 kWorld,
205 static_cast<uint32_t>(sizeof(kWorld)),
206 &h1,
207 1,
191 MOJO_WRITE_MESSAGE_FLAG_NONE)); 208 MOJO_WRITE_MESSAGE_FLAG_NONE));
192 h1 = MOJO_HANDLE_INVALID; 209 h1 = MOJO_HANDLE_INVALID;
193 210
194 // Write another message to |h0|. 211 // Write another message to |h0|.
195 const char kFoo[] = "foo"; 212 const char kFoo[] = "foo";
196 EXPECT_EQ(MOJO_RESULT_OK, 213 EXPECT_EQ(MOJO_RESULT_OK,
197 MojoWriteMessage(h0, kFoo, static_cast<uint32_t>(sizeof(kFoo)), 214 MojoWriteMessage(h0,
198 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 215 kFoo,
216 static_cast<uint32_t>(sizeof(kFoo)),
217 nullptr,
218 0,
219 MOJO_WRITE_MESSAGE_FLAG_NONE));
199 220
200 // Wait for |client_mp| to become readable. 221 // Wait for |client_mp| to become readable.
201 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE, 222 EXPECT_EQ(
202 MOJO_DEADLINE_INDEFINITE)); 223 MOJO_RESULT_OK,
224 MojoWait(
225 client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
203 226
204 // Read a message from |client_mp|. 227 // Read a message from |client_mp|.
205 char buffer[1000] = {}; 228 char buffer[1000] = {};
206 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 229 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
207 MojoHandle handles[10] = {}; 230 MojoHandle handles[10] = {};
208 uint32_t num_handles = arraysize(handles); 231 uint32_t num_handles = arraysize(handles);
209 EXPECT_EQ(MOJO_RESULT_OK, 232 EXPECT_EQ(MOJO_RESULT_OK,
210 MojoReadMessage(client_mp, buffer, &num_bytes, handles, 233 MojoReadMessage(client_mp,
211 &num_handles, MOJO_READ_MESSAGE_FLAG_NONE)); 234 buffer,
235 &num_bytes,
236 handles,
237 &num_handles,
238 MOJO_READ_MESSAGE_FLAG_NONE));
212 EXPECT_EQ(sizeof(kWorld), num_bytes); 239 EXPECT_EQ(sizeof(kWorld), num_bytes);
213 EXPECT_STREQ(kWorld, buffer); 240 EXPECT_STREQ(kWorld, buffer);
214 EXPECT_EQ(1u, num_handles); 241 EXPECT_EQ(1u, num_handles);
215 EXPECT_NE(handles[0], MOJO_HANDLE_INVALID); 242 EXPECT_NE(handles[0], MOJO_HANDLE_INVALID);
216 h1 = handles[0]; 243 h1 = handles[0];
217 244
218 // Wait for |h1| to become readable. 245 // Wait for |h1| to become readable.
219 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, 246 EXPECT_EQ(
220 MOJO_DEADLINE_INDEFINITE)); 247 MOJO_RESULT_OK,
248 MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
221 249
222 // Read a message from |h1|. 250 // Read a message from |h1|.
223 memset(buffer, 0, sizeof(buffer)); 251 memset(buffer, 0, sizeof(buffer));
224 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 252 num_bytes = static_cast<uint32_t>(sizeof(buffer));
225 memset(handles, 0, sizeof(handles)); 253 memset(handles, 0, sizeof(handles));
226 num_handles = arraysize(handles); 254 num_handles = arraysize(handles);
227 EXPECT_EQ(MOJO_RESULT_OK, 255 EXPECT_EQ(MOJO_RESULT_OK,
228 MojoReadMessage(h1, buffer, &num_bytes, handles, &num_handles, 256 MojoReadMessage(h1,
257 buffer,
258 &num_bytes,
259 handles,
260 &num_handles,
229 MOJO_READ_MESSAGE_FLAG_NONE)); 261 MOJO_READ_MESSAGE_FLAG_NONE));
230 EXPECT_EQ(sizeof(kHello), num_bytes); 262 EXPECT_EQ(sizeof(kHello), num_bytes);
231 EXPECT_STREQ(kHello, buffer); 263 EXPECT_STREQ(kHello, buffer);
232 EXPECT_EQ(0u, num_handles); 264 EXPECT_EQ(0u, num_handles);
233 265
234 // Wait for |h1| to become readable (again). 266 // Wait for |h1| to become readable (again).
235 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, 267 EXPECT_EQ(
236 MOJO_DEADLINE_INDEFINITE)); 268 MOJO_RESULT_OK,
269 MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
237 270
238 // Read the second message from |h1|. 271 // Read the second message from |h1|.
239 memset(buffer, 0, sizeof(buffer)); 272 memset(buffer, 0, sizeof(buffer));
240 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 273 num_bytes = static_cast<uint32_t>(sizeof(buffer));
241 EXPECT_EQ(MOJO_RESULT_OK, 274 EXPECT_EQ(MOJO_RESULT_OK,
242 MojoReadMessage(h1, buffer, &num_bytes, nullptr, nullptr, 275 MojoReadMessage(h1,
276 buffer,
277 &num_bytes,
278 nullptr,
279 nullptr,
243 MOJO_READ_MESSAGE_FLAG_NONE)); 280 MOJO_READ_MESSAGE_FLAG_NONE));
244 EXPECT_EQ(sizeof(kFoo), num_bytes); 281 EXPECT_EQ(sizeof(kFoo), num_bytes);
245 EXPECT_STREQ(kFoo, buffer); 282 EXPECT_STREQ(kFoo, buffer);
246 283
247 // Write a message to |h1|. 284 // Write a message to |h1|.
248 const char kBarBaz[] = "barbaz"; 285 const char kBarBaz[] = "barbaz";
286 EXPECT_EQ(MOJO_RESULT_OK,
287 MojoWriteMessage(h1,
288 kBarBaz,
289 static_cast<uint32_t>(sizeof(kBarBaz)),
290 nullptr,
291 0,
292 MOJO_WRITE_MESSAGE_FLAG_NONE));
293
294 // Wait for |h0| to become readable.
249 EXPECT_EQ( 295 EXPECT_EQ(
250 MOJO_RESULT_OK, 296 MOJO_RESULT_OK,
251 MojoWriteMessage(h1, kBarBaz, static_cast<uint32_t>(sizeof(kBarBaz)), 297 MojoWait(h0, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
252 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
253
254 // Wait for |h0| to become readable.
255 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h0, MOJO_HANDLE_SIGNAL_READABLE,
256 MOJO_DEADLINE_INDEFINITE));
257 298
258 // Read a message from |h0|. 299 // Read a message from |h0|.
259 memset(buffer, 0, sizeof(buffer)); 300 memset(buffer, 0, sizeof(buffer));
260 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 301 num_bytes = static_cast<uint32_t>(sizeof(buffer));
261 EXPECT_EQ(MOJO_RESULT_OK, 302 EXPECT_EQ(MOJO_RESULT_OK,
262 MojoReadMessage(h0, buffer, &num_bytes, nullptr, nullptr, 303 MojoReadMessage(h0,
304 buffer,
305 &num_bytes,
306 nullptr,
307 nullptr,
263 MOJO_READ_MESSAGE_FLAG_NONE)); 308 MOJO_READ_MESSAGE_FLAG_NONE));
264 EXPECT_EQ(sizeof(kBarBaz), num_bytes); 309 EXPECT_EQ(sizeof(kBarBaz), num_bytes);
265 EXPECT_STREQ(kBarBaz, buffer); 310 EXPECT_STREQ(kBarBaz, buffer);
266 311
267 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); 312 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
268 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); 313 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
269 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0)); 314 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0));
270 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1)); 315 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1));
271 316
272 server_channel.WaitForChannelCreationCompletion(); 317 server_channel.WaitForChannelCreationCompletion();
(...skipping 29 matching lines...) Expand all
302 test_io_thread()->task_runner(), 347 test_io_thread()->task_runner(),
303 multiprocess_test_helper.server_platform_handle.Pass()); 348 multiprocess_test_helper.server_platform_handle.Pass());
304 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); 349 MojoHandle server_mp = server_channel.bootstrap_message_pipe();
305 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); 350 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
306 server_channel.WaitForChannelCreationCompletion(); 351 server_channel.WaitForChannelCreationCompletion();
307 EXPECT_TRUE(server_channel.channel_info()); 352 EXPECT_TRUE(server_channel.channel_info());
308 353
309 // 1. Write a message to |server_mp| (attaching nothing). 354 // 1. Write a message to |server_mp| (attaching nothing).
310 const char kHello[] = "hello"; 355 const char kHello[] = "hello";
311 EXPECT_EQ(MOJO_RESULT_OK, 356 EXPECT_EQ(MOJO_RESULT_OK,
312 MojoWriteMessage(server_mp, kHello, 357 MojoWriteMessage(server_mp,
313 static_cast<uint32_t>(sizeof(kHello)), nullptr, 358 kHello,
314 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 359 static_cast<uint32_t>(sizeof(kHello)),
360 nullptr,
361 0,
362 MOJO_WRITE_MESSAGE_FLAG_NONE));
315 363
316 // TODO(vtl): If the scope were ended immediately here (maybe after closing 364 // TODO(vtl): If the scope were ended immediately here (maybe after closing
317 // |server_mp|), we die with a fatal error in |Channel::HandleLocalError()|. 365 // |server_mp|), we die with a fatal error in |Channel::HandleLocalError()|.
318 366
319 // 2. Read a message from |server_mp|. 367 // 2. Read a message from |server_mp|.
320 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(server_mp, MOJO_HANDLE_SIGNAL_READABLE, 368 EXPECT_EQ(
321 MOJO_DEADLINE_INDEFINITE)); 369 MOJO_RESULT_OK,
370 MojoWait(
371 server_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
322 char buffer[1000] = {}; 372 char buffer[1000] = {};
323 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 373 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
324 EXPECT_EQ(MOJO_RESULT_OK, 374 EXPECT_EQ(MOJO_RESULT_OK,
325 MojoReadMessage(server_mp, buffer, &num_bytes, nullptr, nullptr, 375 MojoReadMessage(server_mp,
376 buffer,
377 &num_bytes,
378 nullptr,
379 nullptr,
326 MOJO_READ_MESSAGE_FLAG_NONE)); 380 MOJO_READ_MESSAGE_FLAG_NONE));
327 const char kWorld[] = "world!"; 381 const char kWorld[] = "world!";
328 EXPECT_EQ(sizeof(kWorld), num_bytes); 382 EXPECT_EQ(sizeof(kWorld), num_bytes);
329 EXPECT_STREQ(kWorld, buffer); 383 EXPECT_STREQ(kWorld, buffer);
330 384
331 // Create a new message pipe (endpoints |mp0| and |mp1|). 385 // Create a new message pipe (endpoints |mp0| and |mp1|).
332 MojoHandle mp0, mp1; 386 MojoHandle mp0, mp1;
333 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp0, &mp1)); 387 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp0, &mp1));
334 388
335 // 3. Write something to |mp0|. 389 // 3. Write something to |mp0|.
336 const char kFoo[] = "FOO"; 390 const char kFoo[] = "FOO";
337 EXPECT_EQ(MOJO_RESULT_OK, 391 EXPECT_EQ(MOJO_RESULT_OK,
338 MojoWriteMessage(mp0, kFoo, static_cast<uint32_t>(sizeof(kFoo)), 392 MojoWriteMessage(mp0,
339 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 393 kFoo,
394 static_cast<uint32_t>(sizeof(kFoo)),
395 nullptr,
396 0,
397 MOJO_WRITE_MESSAGE_FLAG_NONE));
340 398
341 // 4. Write a message to |server_mp|, attaching |mp1|. 399 // 4. Write a message to |server_mp|, attaching |mp1|.
342 const char kBar[] = "Bar"; 400 const char kBar[] = "Bar";
343 EXPECT_EQ( 401 EXPECT_EQ(MOJO_RESULT_OK,
344 MOJO_RESULT_OK, 402 MojoWriteMessage(server_mp,
345 MojoWriteMessage(server_mp, kBar, static_cast<uint32_t>(sizeof(kBar)), 403 kBar,
346 &mp1, 1, MOJO_WRITE_MESSAGE_FLAG_NONE)); 404 static_cast<uint32_t>(sizeof(kBar)),
405 &mp1,
406 1,
407 MOJO_WRITE_MESSAGE_FLAG_NONE));
347 mp1 = MOJO_HANDLE_INVALID; 408 mp1 = MOJO_HANDLE_INVALID;
348 409
349 // 5. Close |server_mp|. 410 // 5. Close |server_mp|.
350 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); 411 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
351 412
352 // 9. Read a message from |mp0|, which should have |mp2| attached. 413 // 9. Read a message from |mp0|, which should have |mp2| attached.
353 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp0, MOJO_HANDLE_SIGNAL_READABLE, 414 EXPECT_EQ(
354 MOJO_DEADLINE_INDEFINITE)); 415 MOJO_RESULT_OK,
416 MojoWait(mp0, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
355 memset(buffer, 0, sizeof(buffer)); 417 memset(buffer, 0, sizeof(buffer));
356 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 418 num_bytes = static_cast<uint32_t>(sizeof(buffer));
357 MojoHandle mp2 = MOJO_HANDLE_INVALID; 419 MojoHandle mp2 = MOJO_HANDLE_INVALID;
358 uint32_t num_handles = 1; 420 uint32_t num_handles = 1;
359 EXPECT_EQ(MOJO_RESULT_OK, 421 EXPECT_EQ(MOJO_RESULT_OK,
360 MojoReadMessage(mp0, buffer, &num_bytes, &mp2, &num_handles, 422 MojoReadMessage(mp0,
423 buffer,
424 &num_bytes,
425 &mp2,
426 &num_handles,
361 MOJO_READ_MESSAGE_FLAG_NONE)); 427 MOJO_READ_MESSAGE_FLAG_NONE));
362 const char kQuux[] = "quux"; 428 const char kQuux[] = "quux";
363 EXPECT_EQ(sizeof(kQuux), num_bytes); 429 EXPECT_EQ(sizeof(kQuux), num_bytes);
364 EXPECT_STREQ(kQuux, buffer); 430 EXPECT_STREQ(kQuux, buffer);
365 EXPECT_EQ(1u, num_handles); 431 EXPECT_EQ(1u, num_handles);
366 EXPECT_NE(mp2, MOJO_HANDLE_INVALID); 432 EXPECT_NE(mp2, MOJO_HANDLE_INVALID);
367 433
368 // 7. Read a message from |mp2|. 434 // 7. Read a message from |mp2|.
369 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE, 435 EXPECT_EQ(
370 MOJO_DEADLINE_INDEFINITE)); 436 MOJO_RESULT_OK,
437 MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
371 memset(buffer, 0, sizeof(buffer)); 438 memset(buffer, 0, sizeof(buffer));
372 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 439 num_bytes = static_cast<uint32_t>(sizeof(buffer));
373 EXPECT_EQ(MOJO_RESULT_OK, 440 EXPECT_EQ(MOJO_RESULT_OK,
374 MojoReadMessage(mp2, buffer, &num_bytes, nullptr, nullptr, 441 MojoReadMessage(mp2,
442 buffer,
443 &num_bytes,
444 nullptr,
445 nullptr,
375 MOJO_READ_MESSAGE_FLAG_NONE)); 446 MOJO_READ_MESSAGE_FLAG_NONE));
376 const char kBaz[] = "baz"; 447 const char kBaz[] = "baz";
377 EXPECT_EQ(sizeof(kBaz), num_bytes); 448 EXPECT_EQ(sizeof(kBaz), num_bytes);
378 EXPECT_STREQ(kBaz, buffer); 449 EXPECT_STREQ(kBaz, buffer);
379 450
380 // 10. Close |mp0|. 451 // 10. Close |mp0|.
381 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp0)); 452 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp0));
382 453
383 // 12. Wait on |mp2| (which should eventually fail) and then close it. 454 // 12. Wait on |mp2| (which should eventually fail) and then close it.
384 // TODO(vtl): crbug.com/351768 455 // TODO(vtl): crbug.com/351768
(...skipping 19 matching lines...) Expand all
404 475
405 { 476 {
406 ScopedTestChannel client_channel(test_io_thread.task_runner(), 477 ScopedTestChannel client_channel(test_io_thread.task_runner(),
407 client_platform_handle.Pass()); 478 client_platform_handle.Pass());
408 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); 479 MojoHandle client_mp = client_channel.bootstrap_message_pipe();
409 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 480 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
410 client_channel.WaitForChannelCreationCompletion(); 481 client_channel.WaitForChannelCreationCompletion();
411 CHECK(client_channel.channel_info() != nullptr); 482 CHECK(client_channel.channel_info() != nullptr);
412 483
413 // 1. Read the first message from |client_mp|. 484 // 1. Read the first message from |client_mp|.
414 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE, 485 EXPECT_EQ(
415 MOJO_DEADLINE_INDEFINITE)); 486 MOJO_RESULT_OK,
487 MojoWait(
488 client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
416 char buffer[1000] = {}; 489 char buffer[1000] = {};
417 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 490 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
418 EXPECT_EQ(MOJO_RESULT_OK, 491 EXPECT_EQ(MOJO_RESULT_OK,
419 MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr, 492 MojoReadMessage(client_mp,
493 buffer,
494 &num_bytes,
495 nullptr,
496 nullptr,
420 MOJO_READ_MESSAGE_FLAG_NONE)); 497 MOJO_READ_MESSAGE_FLAG_NONE));
421 const char kHello[] = "hello"; 498 const char kHello[] = "hello";
422 EXPECT_EQ(sizeof(kHello), num_bytes); 499 EXPECT_EQ(sizeof(kHello), num_bytes);
423 EXPECT_STREQ(kHello, buffer); 500 EXPECT_STREQ(kHello, buffer);
424 501
425 // 2. Write a message to |client_mp| (attaching nothing). 502 // 2. Write a message to |client_mp| (attaching nothing).
426 const char kWorld[] = "world!"; 503 const char kWorld[] = "world!";
427 EXPECT_EQ(MOJO_RESULT_OK, 504 EXPECT_EQ(MOJO_RESULT_OK,
428 MojoWriteMessage(client_mp, kWorld, 505 MojoWriteMessage(client_mp,
429 static_cast<uint32_t>(sizeof(kWorld)), nullptr, 506 kWorld,
430 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 507 static_cast<uint32_t>(sizeof(kWorld)),
508 nullptr,
509 0,
510 MOJO_WRITE_MESSAGE_FLAG_NONE));
431 511
432 // 4. Read a message from |client_mp|, which should have |mp1| attached. 512 // 4. Read a message from |client_mp|, which should have |mp1| attached.
433 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE, 513 EXPECT_EQ(
434 MOJO_DEADLINE_INDEFINITE)); 514 MOJO_RESULT_OK,
515 MojoWait(
516 client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
435 // TODO(vtl): If the scope were to end here (and |client_mp| closed), we'd 517 // TODO(vtl): If the scope were to end here (and |client_mp| closed), we'd
436 // die (again due to |Channel::HandleLocalError()|). 518 // die (again due to |Channel::HandleLocalError()|).
437 memset(buffer, 0, sizeof(buffer)); 519 memset(buffer, 0, sizeof(buffer));
438 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 520 num_bytes = static_cast<uint32_t>(sizeof(buffer));
439 MojoHandle mp1 = MOJO_HANDLE_INVALID; 521 MojoHandle mp1 = MOJO_HANDLE_INVALID;
440 uint32_t num_handles = 1; 522 uint32_t num_handles = 1;
441 EXPECT_EQ(MOJO_RESULT_OK, 523 EXPECT_EQ(MOJO_RESULT_OK,
442 MojoReadMessage(client_mp, buffer, &num_bytes, &mp1, &num_handles, 524 MojoReadMessage(client_mp,
525 buffer,
526 &num_bytes,
527 &mp1,
528 &num_handles,
443 MOJO_READ_MESSAGE_FLAG_NONE)); 529 MOJO_READ_MESSAGE_FLAG_NONE));
444 const char kBar[] = "Bar"; 530 const char kBar[] = "Bar";
445 EXPECT_EQ(sizeof(kBar), num_bytes); 531 EXPECT_EQ(sizeof(kBar), num_bytes);
446 EXPECT_STREQ(kBar, buffer); 532 EXPECT_STREQ(kBar, buffer);
447 EXPECT_EQ(1u, num_handles); 533 EXPECT_EQ(1u, num_handles);
448 EXPECT_NE(mp1, MOJO_HANDLE_INVALID); 534 EXPECT_NE(mp1, MOJO_HANDLE_INVALID);
449 // TODO(vtl): If the scope were to end here (and the two handles closed), 535 // TODO(vtl): If the scope were to end here (and the two handles closed),
450 // we'd die due to |Channel::RunRemoteMessagePipeEndpoint()| not handling 536 // we'd die due to |Channel::RunRemoteMessagePipeEndpoint()| not handling
451 // write errors (assuming the parent had closed the pipe). 537 // write errors (assuming the parent had closed the pipe).
452 538
453 // 6. Close |client_mp|. 539 // 6. Close |client_mp|.
454 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); 540 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
455 541
456 // Create a new message pipe (endpoints |mp2| and |mp3|). 542 // Create a new message pipe (endpoints |mp2| and |mp3|).
457 MojoHandle mp2, mp3; 543 MojoHandle mp2, mp3;
458 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp2, &mp3)); 544 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp2, &mp3));
459 545
460 // 7. Write a message to |mp3|. 546 // 7. Write a message to |mp3|.
461 const char kBaz[] = "baz"; 547 const char kBaz[] = "baz";
462 EXPECT_EQ(MOJO_RESULT_OK, 548 EXPECT_EQ(MOJO_RESULT_OK,
463 MojoWriteMessage(mp3, kBaz, static_cast<uint32_t>(sizeof(kBaz)), 549 MojoWriteMessage(mp3,
464 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 550 kBaz,
551 static_cast<uint32_t>(sizeof(kBaz)),
552 nullptr,
553 0,
554 MOJO_WRITE_MESSAGE_FLAG_NONE));
465 555
466 // 8. Close |mp3|. 556 // 8. Close |mp3|.
467 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3)); 557 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3));
468 558
469 // 9. Write a message to |mp1|, attaching |mp2|. 559 // 9. Write a message to |mp1|, attaching |mp2|.
470 const char kQuux[] = "quux"; 560 const char kQuux[] = "quux";
471 EXPECT_EQ(MOJO_RESULT_OK, 561 EXPECT_EQ(MOJO_RESULT_OK,
472 MojoWriteMessage(mp1, kQuux, static_cast<uint32_t>(sizeof(kQuux)), 562 MojoWriteMessage(mp1,
473 &mp2, 1, MOJO_WRITE_MESSAGE_FLAG_NONE)); 563 kQuux,
564 static_cast<uint32_t>(sizeof(kQuux)),
565 &mp2,
566 1,
567 MOJO_WRITE_MESSAGE_FLAG_NONE));
474 mp2 = MOJO_HANDLE_INVALID; 568 mp2 = MOJO_HANDLE_INVALID;
475 569
476 // 3. Read a message from |mp1|. 570 // 3. Read a message from |mp1|.
477 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, 571 EXPECT_EQ(
478 MOJO_DEADLINE_INDEFINITE)); 572 MOJO_RESULT_OK,
573 MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
479 memset(buffer, 0, sizeof(buffer)); 574 memset(buffer, 0, sizeof(buffer));
480 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 575 num_bytes = static_cast<uint32_t>(sizeof(buffer));
481 EXPECT_EQ(MOJO_RESULT_OK, 576 EXPECT_EQ(MOJO_RESULT_OK,
482 MojoReadMessage(mp1, buffer, &num_bytes, nullptr, nullptr, 577 MojoReadMessage(mp1,
578 buffer,
579 &num_bytes,
580 nullptr,
581 nullptr,
483 MOJO_READ_MESSAGE_FLAG_NONE)); 582 MOJO_READ_MESSAGE_FLAG_NONE));
484 const char kFoo[] = "FOO"; 583 const char kFoo[] = "FOO";
485 EXPECT_EQ(sizeof(kFoo), num_bytes); 584 EXPECT_EQ(sizeof(kFoo), num_bytes);
486 EXPECT_STREQ(kFoo, buffer); 585 EXPECT_STREQ(kFoo, buffer);
487 586
488 // 11. Wait on |mp1| (which should eventually fail) and then close it. 587 // 11. Wait on |mp1| (which should eventually fail) and then close it.
489 EXPECT_EQ( 588 EXPECT_EQ(
490 MOJO_RESULT_FAILED_PRECONDITION, 589 MOJO_RESULT_FAILED_PRECONDITION,
491 MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE)); 590 MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
492 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp1)); 591 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp1));
493 } 592 }
494 593
495 EXPECT_TRUE(test::Shutdown()); 594 EXPECT_TRUE(test::Shutdown());
496 } 595 }
497 596
498 // TODO(vtl): Test immediate write & close. 597 // TODO(vtl): Test immediate write & close.
499 // TODO(vtl): Test broken-connection cases. 598 // TODO(vtl): Test broken-connection cases.
500 599
501 } // namespace 600 } // namespace
502 } // namespace embedder 601 } // namespace embedder
503 } // namespace mojo 602 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/embedder_internal.h ('k') | mojo/edk/embedder/entrypoints.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698