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

Side by Side Diff: mojo/system/raw_channel_unittest.cc

Issue 187383007: Mojo: Replace TestWithIOThreadBase with just a helper TestIOThread class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 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/system/raw_channel.h" 5 #include "mojo/system/raw_channel.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/rand_util.h" 17 #include "base/rand_util.h"
18 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
19 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
20 #include "base/threading/platform_thread.h" // For |Sleep()|. 20 #include "base/threading/platform_thread.h" // For |Sleep()|.
21 #include "base/threading/simple_thread.h" 21 #include "base/threading/simple_thread.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "mojo/common/test/test_utils.h" 24 #include "mojo/common/test/test_utils.h"
25 #include "mojo/system/embedder/platform_channel_pair.h" 25 #include "mojo/system/embedder/platform_channel_pair.h"
26 #include "mojo/system/embedder/platform_handle.h" 26 #include "mojo/system/embedder/platform_handle.h"
27 #include "mojo/system/embedder/scoped_platform_handle.h" 27 #include "mojo/system/embedder/scoped_platform_handle.h"
28 #include "mojo/system/message_in_transit.h" 28 #include "mojo/system/message_in_transit.h"
29 #include "mojo/system/test_utils.h" 29 #include "mojo/system/test_utils.h"
30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 #if defined(OS_POSIX) 32 #if defined(OS_POSIX)
32 #include <sys/socket.h> 33 #include <sys/socket.h>
33 #endif 34 #endif
34 35
35 namespace mojo { 36 namespace mojo {
36 namespace system { 37 namespace system {
37 namespace { 38 namespace {
38 39
39 scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) { 40 scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) {
(...skipping 24 matching lines...) Expand all
64 scoped_ptr<MessageInTransit> message(MakeTestMessage(num_bytes)); 65 scoped_ptr<MessageInTransit> message(MakeTestMessage(num_bytes));
65 66
66 size_t write_size = 0; 67 size_t write_size = 0;
67 mojo::test::BlockingWrite( 68 mojo::test::BlockingWrite(
68 handle, message->main_buffer(), message->main_buffer_size(), &write_size); 69 handle, message->main_buffer(), message->main_buffer_size(), &write_size);
69 return write_size == message->main_buffer_size(); 70 return write_size == message->main_buffer_size();
70 } 71 }
71 72
72 // ----------------------------------------------------------------------------- 73 // -----------------------------------------------------------------------------
73 74
74 class RawChannelTest : public test::TestWithIOThreadBase { 75 class RawChannelTest : public testing::Test {
75 public: 76 public:
76 RawChannelTest() {} 77 RawChannelTest() {}
77 virtual ~RawChannelTest() {} 78 virtual ~RawChannelTest() {}
78 79
79 virtual void SetUp() OVERRIDE { 80 virtual void SetUp() OVERRIDE {
80 test::TestWithIOThreadBase::SetUp();
81
82 embedder::PlatformChannelPair channel_pair; 81 embedder::PlatformChannelPair channel_pair;
83 handles[0] = channel_pair.PassServerHandle(); 82 handles[0] = channel_pair.PassServerHandle();
84 handles[1] = channel_pair.PassClientHandle(); 83 handles[1] = channel_pair.PassClientHandle();
85 } 84 }
86 85
87 virtual void TearDown() OVERRIDE { 86 virtual void TearDown() OVERRIDE {
88 handles[0].reset(); 87 handles[0].reset();
89 handles[1].reset(); 88 handles[1].reset();
90
91 test::TestWithIOThreadBase::TearDown();
92 } 89 }
93 90
94 protected: 91 protected:
92 test::TestIOThread* io_thread() { return &io_thread_; }
93
95 embedder::ScopedPlatformHandle handles[2]; 94 embedder::ScopedPlatformHandle handles[2];
96 95
97 private: 96 private:
97 test::TestIOThread io_thread_;
98
98 DISALLOW_COPY_AND_ASSIGN(RawChannelTest); 99 DISALLOW_COPY_AND_ASSIGN(RawChannelTest);
99 }; 100 };
100 101
101 // RawChannelTest.WriteMessage ------------------------------------------------- 102 // RawChannelTest.WriteMessage -------------------------------------------------
102 103
103 class WriteOnlyRawChannelDelegate : public RawChannel::Delegate { 104 class WriteOnlyRawChannelDelegate : public RawChannel::Delegate {
104 public: 105 public:
105 WriteOnlyRawChannelDelegate() {} 106 WriteOnlyRawChannelDelegate() {}
106 virtual ~WriteOnlyRawChannelDelegate() {} 107 virtual ~WriteOnlyRawChannelDelegate() {}
107 108
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 std::vector<unsigned char> bytes_; 185 std::vector<unsigned char> bytes_;
185 186
186 DISALLOW_COPY_AND_ASSIGN(TestMessageReaderAndChecker); 187 DISALLOW_COPY_AND_ASSIGN(TestMessageReaderAndChecker);
187 }; 188 };
188 189
189 // Tests writing (and verifies reading using our own custom reader). 190 // Tests writing (and verifies reading using our own custom reader).
190 TEST_F(RawChannelTest, WriteMessage) { 191 TEST_F(RawChannelTest, WriteMessage) {
191 WriteOnlyRawChannelDelegate delegate; 192 WriteOnlyRawChannelDelegate delegate;
192 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), 193 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
193 &delegate, 194 &delegate,
194 io_thread_message_loop())); 195 io_thread()->message_loop()));
195 196
196 TestMessageReaderAndChecker checker(handles[1].get()); 197 TestMessageReaderAndChecker checker(handles[1].get());
197 198
198 test::PostTaskAndWait(io_thread_task_runner(), 199 test::PostTaskAndWait(io_thread()->task_runner(),
199 FROM_HERE, 200 FROM_HERE,
200 base::Bind(&InitOnIOThread, rc.get())); 201 base::Bind(&InitOnIOThread, rc.get()));
201 202
202 // Write and read, for a variety of sizes. 203 // Write and read, for a variety of sizes.
203 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) { 204 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) {
204 EXPECT_TRUE(rc->WriteMessage(MakeTestMessage(size))); 205 EXPECT_TRUE(rc->WriteMessage(MakeTestMessage(size)));
205 EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size; 206 EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size;
206 } 207 }
207 208
208 // Write/queue and read afterwards, for a variety of sizes. 209 // Write/queue and read afterwards, for a variety of sizes.
209 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) 210 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1)
210 EXPECT_TRUE(rc->WriteMessage(MakeTestMessage(size))); 211 EXPECT_TRUE(rc->WriteMessage(MakeTestMessage(size)));
211 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) 212 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1)
212 EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size; 213 EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size;
213 214
214 test::PostTaskAndWait(io_thread_task_runner(), 215 test::PostTaskAndWait(io_thread()->task_runner(),
215 FROM_HERE, 216 FROM_HERE,
216 base::Bind(&RawChannel::Shutdown, 217 base::Bind(&RawChannel::Shutdown,
217 base::Unretained(rc.get()))); 218 base::Unretained(rc.get())));
218 } 219 }
219 220
220 // RawChannelTest.OnReadMessage ------------------------------------------------ 221 // RawChannelTest.OnReadMessage ------------------------------------------------
221 222
222 class ReadCheckerRawChannelDelegate : public RawChannel::Delegate { 223 class ReadCheckerRawChannelDelegate : public RawChannel::Delegate {
223 public: 224 public:
224 ReadCheckerRawChannelDelegate() 225 ReadCheckerRawChannelDelegate()
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 size_t position_; 276 size_t position_;
276 277
277 DISALLOW_COPY_AND_ASSIGN(ReadCheckerRawChannelDelegate); 278 DISALLOW_COPY_AND_ASSIGN(ReadCheckerRawChannelDelegate);
278 }; 279 };
279 280
280 // Tests reading (writing using our own custom writer). 281 // Tests reading (writing using our own custom writer).
281 TEST_F(RawChannelTest, OnReadMessage) { 282 TEST_F(RawChannelTest, OnReadMessage) {
282 ReadCheckerRawChannelDelegate delegate; 283 ReadCheckerRawChannelDelegate delegate;
283 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), 284 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
284 &delegate, 285 &delegate,
285 io_thread_message_loop())); 286 io_thread()->message_loop()));
286 287
287 test::PostTaskAndWait(io_thread_task_runner(), 288 test::PostTaskAndWait(io_thread()->task_runner(),
288 FROM_HERE, 289 FROM_HERE,
289 base::Bind(&InitOnIOThread, rc.get())); 290 base::Bind(&InitOnIOThread, rc.get()));
290 291
291 // Write and read, for a variety of sizes. 292 // Write and read, for a variety of sizes.
292 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) { 293 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) {
293 delegate.SetExpectedSizes(std::vector<uint32_t>(1, size)); 294 delegate.SetExpectedSizes(std::vector<uint32_t>(1, size));
294 295
295 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size)); 296 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size));
296 297
297 delegate.Wait(); 298 delegate.Wait();
298 } 299 }
299 300
300 // Set up reader and write as fast as we can. 301 // Set up reader and write as fast as we can.
301 // Write/queue and read afterwards, for a variety of sizes. 302 // Write/queue and read afterwards, for a variety of sizes.
302 std::vector<uint32_t> expected_sizes; 303 std::vector<uint32_t> expected_sizes;
303 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) 304 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1)
304 expected_sizes.push_back(size); 305 expected_sizes.push_back(size);
305 delegate.SetExpectedSizes(expected_sizes); 306 delegate.SetExpectedSizes(expected_sizes);
306 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) 307 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1)
307 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size)); 308 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size));
308 delegate.Wait(); 309 delegate.Wait();
309 310
310 test::PostTaskAndWait(io_thread_task_runner(), 311 test::PostTaskAndWait(io_thread()->task_runner(),
311 FROM_HERE, 312 FROM_HERE,
312 base::Bind(&RawChannel::Shutdown, 313 base::Bind(&RawChannel::Shutdown,
313 base::Unretained(rc.get()))); 314 base::Unretained(rc.get())));
314 } 315 }
315 316
316 // RawChannelTest.WriteMessageAndOnReadMessage --------------------------------- 317 // RawChannelTest.WriteMessageAndOnReadMessage ---------------------------------
317 318
318 class RawChannelWriterThread : public base::SimpleThread { 319 class RawChannelWriterThread : public base::SimpleThread {
319 public: 320 public:
320 RawChannelWriterThread(RawChannel* raw_channel, size_t write_count) 321 RawChannelWriterThread(RawChannel* raw_channel, size_t write_count)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 }; 382 };
382 383
383 TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) { 384 TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
384 static const size_t kNumWriterThreads = 10; 385 static const size_t kNumWriterThreads = 10;
385 static const size_t kNumWriteMessagesPerThread = 4000; 386 static const size_t kNumWriteMessagesPerThread = 4000;
386 387
387 WriteOnlyRawChannelDelegate writer_delegate; 388 WriteOnlyRawChannelDelegate writer_delegate;
388 scoped_ptr<RawChannel> writer_rc( 389 scoped_ptr<RawChannel> writer_rc(
389 RawChannel::Create(handles[0].Pass(), 390 RawChannel::Create(handles[0].Pass(),
390 &writer_delegate, 391 &writer_delegate,
391 io_thread_message_loop())); 392 io_thread()->message_loop()));
392 393
393 test::PostTaskAndWait(io_thread_task_runner(), 394 test::PostTaskAndWait(io_thread()->task_runner(),
394 FROM_HERE, 395 FROM_HERE,
395 base::Bind(&InitOnIOThread, writer_rc.get())); 396 base::Bind(&InitOnIOThread, writer_rc.get()));
396 397
397 ReadCountdownRawChannelDelegate reader_delegate( 398 ReadCountdownRawChannelDelegate reader_delegate(
398 kNumWriterThreads * kNumWriteMessagesPerThread); 399 kNumWriterThreads * kNumWriteMessagesPerThread);
399 scoped_ptr<RawChannel> reader_rc( 400 scoped_ptr<RawChannel> reader_rc(
400 RawChannel::Create(handles[1].Pass(), 401 RawChannel::Create(handles[1].Pass(),
401 &reader_delegate, 402 &reader_delegate,
402 io_thread_message_loop())); 403 io_thread()->message_loop()));
403 404
404 test::PostTaskAndWait(io_thread_task_runner(), 405 test::PostTaskAndWait(io_thread()->task_runner(),
405 FROM_HERE, 406 FROM_HERE,
406 base::Bind(&InitOnIOThread, reader_rc.get())); 407 base::Bind(&InitOnIOThread, reader_rc.get()));
407 408
408 { 409 {
409 ScopedVector<RawChannelWriterThread> writer_threads; 410 ScopedVector<RawChannelWriterThread> writer_threads;
410 for (size_t i = 0; i < kNumWriterThreads; i++) { 411 for (size_t i = 0; i < kNumWriterThreads; i++) {
411 writer_threads.push_back(new RawChannelWriterThread( 412 writer_threads.push_back(new RawChannelWriterThread(
412 writer_rc.get(), kNumWriteMessagesPerThread)); 413 writer_rc.get(), kNumWriteMessagesPerThread));
413 } 414 }
414 for (size_t i = 0; i < writer_threads.size(); i++) 415 for (size_t i = 0; i < writer_threads.size(); i++)
415 writer_threads[i]->Start(); 416 writer_threads[i]->Start();
416 } // Joins all the writer threads. 417 } // Joins all the writer threads.
417 418
418 // Sleep a bit, to let any extraneous reads be processed. (There shouldn't be 419 // Sleep a bit, to let any extraneous reads be processed. (There shouldn't be
419 // any, but we want to know about them.) 420 // any, but we want to know about them.)
420 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 421 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
421 422
422 // Wait for reading to finish. 423 // Wait for reading to finish.
423 reader_delegate.Wait(); 424 reader_delegate.Wait();
424 425
425 test::PostTaskAndWait(io_thread_task_runner(), 426 test::PostTaskAndWait(io_thread()->task_runner(),
426 FROM_HERE, 427 FROM_HERE,
427 base::Bind(&RawChannel::Shutdown, 428 base::Bind(&RawChannel::Shutdown,
428 base::Unretained(reader_rc.get()))); 429 base::Unretained(reader_rc.get())));
429 430
430 test::PostTaskAndWait(io_thread_task_runner(), 431 test::PostTaskAndWait(io_thread()->task_runner(),
431 FROM_HERE, 432 FROM_HERE,
432 base::Bind(&RawChannel::Shutdown, 433 base::Bind(&RawChannel::Shutdown,
433 base::Unretained(writer_rc.get()))); 434 base::Unretained(writer_rc.get())));
434 } 435 }
435 436
436 // RawChannelTest.OnFatalError ------------------------------------------------- 437 // RawChannelTest.OnFatalError -------------------------------------------------
437 438
438 class FatalErrorRecordingRawChannelDelegate 439 class FatalErrorRecordingRawChannelDelegate
439 : public ReadCountdownRawChannelDelegate { 440 : public ReadCountdownRawChannelDelegate {
440 public: 441 public:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 }; 479 };
479 480
480 // Tests fatal errors. 481 // Tests fatal errors.
481 // TODO(vtl): Figure out how to make reading fail reliably. (I'm not convinced 482 // TODO(vtl): Figure out how to make reading fail reliably. (I'm not convinced
482 // that it does.) 483 // that it does.)
483 TEST_F(RawChannelTest, OnFatalError) { 484 TEST_F(RawChannelTest, OnFatalError) {
484 FatalErrorRecordingRawChannelDelegate delegate(0, false, true); 485 FatalErrorRecordingRawChannelDelegate delegate(0, false, true);
485 486
486 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), 487 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
487 &delegate, 488 &delegate,
488 io_thread_message_loop())); 489 io_thread()->message_loop()));
489 490
490 test::PostTaskAndWait(io_thread_task_runner(), 491 test::PostTaskAndWait(io_thread()->task_runner(),
491 FROM_HERE, 492 FROM_HERE,
492 base::Bind(&InitOnIOThread, rc.get())); 493 base::Bind(&InitOnIOThread, rc.get()));
493 494
494 // Close the handle of the other end, which should make writing fail. 495 // Close the handle of the other end, which should make writing fail.
495 handles[1].reset(); 496 handles[1].reset();
496 497
497 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); 498 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
498 499
499 // TODO(vtl): In theory, it's conceivable that closing the other end might 500 // TODO(vtl): In theory, it's conceivable that closing the other end might
500 // lead to read failing. In practice, it doesn't seem to. 501 // lead to read failing. In practice, it doesn't seem to.
501 delegate.WaitForFatalError(); 502 delegate.WaitForFatalError();
502 503
503 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(2))); 504 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(2)));
504 505
505 // Sleep a bit, to make sure we don't get another |OnFatalError()| 506 // Sleep a bit, to make sure we don't get another |OnFatalError()|
506 // notification. (If we actually get another one, |OnFatalError()| crashes.) 507 // notification. (If we actually get another one, |OnFatalError()| crashes.)
507 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 508 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
508 509
509 test::PostTaskAndWait(io_thread_task_runner(), 510 test::PostTaskAndWait(io_thread()->task_runner(),
510 FROM_HERE, 511 FROM_HERE,
511 base::Bind(&RawChannel::Shutdown, 512 base::Bind(&RawChannel::Shutdown,
512 base::Unretained(rc.get()))); 513 base::Unretained(rc.get())));
513 } 514 }
514 515
515 #if defined(OS_POSIX) 516 #if defined(OS_POSIX)
516 // RawChannelTest.ReadUnaffectedByWriteFatalError ------------------------------ 517 // RawChannelTest.ReadUnaffectedByWriteFatalError ------------------------------
517 518
518 // TODO(yzshen): On Windows, I haven't figured out a way to shut down one 519 // TODO(yzshen): On Windows, I haven't figured out a way to shut down one
519 // direction of the named pipe. 520 // direction of the named pipe.
520 TEST_F(RawChannelTest, ReadUnaffectedByWriteFatalError) { 521 TEST_F(RawChannelTest, ReadUnaffectedByWriteFatalError) {
521 const size_t kMessageCount = 5; 522 const size_t kMessageCount = 5;
522 523
523 FatalErrorRecordingRawChannelDelegate delegate(2 * kMessageCount, false, 524 FatalErrorRecordingRawChannelDelegate delegate(2 * kMessageCount, false,
524 true); 525 true);
525 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), 526 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
526 &delegate, 527 &delegate,
527 io_thread_message_loop())); 528 io_thread()->message_loop()));
528 529
529 test::PostTaskAndWait(io_thread_task_runner(), 530 test::PostTaskAndWait(io_thread()->task_runner(),
530 FROM_HERE, 531 FROM_HERE,
531 base::Bind(&InitOnIOThread, rc.get())); 532 base::Bind(&InitOnIOThread, rc.get()));
532 533
533 // Write into the other end a few messages. 534 // Write into the other end a few messages.
534 uint32_t message_size = 1; 535 uint32_t message_size = 1;
535 for (size_t count = 0; count < kMessageCount; 536 for (size_t count = 0; count < kMessageCount;
536 ++count, message_size += message_size / 2 + 1) { 537 ++count, message_size += message_size / 2 + 1) {
537 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), message_size)); 538 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), message_size));
538 } 539 }
539 540
(...skipping 11 matching lines...) Expand all
551 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 552 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
552 553
553 // Write into the other end a few more messages. 554 // Write into the other end a few more messages.
554 for (size_t count = 0; count < kMessageCount; 555 for (size_t count = 0; count < kMessageCount;
555 ++count, message_size += message_size / 2 + 1) { 556 ++count, message_size += message_size / 2 + 1) {
556 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), message_size)); 557 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), message_size));
557 } 558 }
558 // Wait for reading to finish. A writing failure shouldn't affect reading. 559 // Wait for reading to finish. A writing failure shouldn't affect reading.
559 delegate.Wait(); 560 delegate.Wait();
560 561
561 test::PostTaskAndWait(io_thread_task_runner(), 562 test::PostTaskAndWait(io_thread()->task_runner(),
562 FROM_HERE, 563 FROM_HERE,
563 base::Bind(&RawChannel::Shutdown, 564 base::Bind(&RawChannel::Shutdown,
564 base::Unretained(rc.get()))); 565 base::Unretained(rc.get())));
565 } 566 }
566 #endif // defined(OS_POSIX) 567 #endif // defined(OS_POSIX)
567 568
568 // RawChannelTest.WriteMessageAfterShutdown ------------------------------------ 569 // RawChannelTest.WriteMessageAfterShutdown ------------------------------------
569 570
570 // Makes sure that calling |WriteMessage()| after |Shutdown()| behaves 571 // Makes sure that calling |WriteMessage()| after |Shutdown()| behaves
571 // correctly. 572 // correctly.
572 TEST_F(RawChannelTest, WriteMessageAfterShutdown) { 573 TEST_F(RawChannelTest, WriteMessageAfterShutdown) {
573 WriteOnlyRawChannelDelegate delegate; 574 WriteOnlyRawChannelDelegate delegate;
574 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), 575 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
575 &delegate, 576 &delegate,
576 io_thread_message_loop())); 577 io_thread()->message_loop()));
577 578
578 test::PostTaskAndWait(io_thread_task_runner(), 579 test::PostTaskAndWait(io_thread()->task_runner(),
579 FROM_HERE, 580 FROM_HERE,
580 base::Bind(&InitOnIOThread, rc.get())); 581 base::Bind(&InitOnIOThread, rc.get()));
581 test::PostTaskAndWait(io_thread_task_runner(), 582 test::PostTaskAndWait(io_thread()->task_runner(),
582 FROM_HERE, 583 FROM_HERE,
583 base::Bind(&RawChannel::Shutdown, 584 base::Bind(&RawChannel::Shutdown,
584 base::Unretained(rc.get()))); 585 base::Unretained(rc.get())));
585 586
586 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); 587 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
587 } 588 }
588 589
589 } // namespace 590 } // namespace
590 } // namespace system 591 } // namespace system
591 } // namespace mojo 592 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/embedder/embedder_unittest.cc ('k') | mojo/system/remote_message_pipe_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698