| OLD | NEW |
| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 } | 578 } |
| 579 | 579 |
| 580 private: | 580 private: |
| 581 RawChannel* const raw_channel_; | 581 RawChannel* const raw_channel_; |
| 582 base::WaitableEvent done_event_; | 582 base::WaitableEvent done_event_; |
| 583 bool did_shutdown_; | 583 bool did_shutdown_; |
| 584 | 584 |
| 585 DISALLOW_COPY_AND_ASSIGN(ShutdownOnReadMessageRawChannelDelegate); | 585 DISALLOW_COPY_AND_ASSIGN(ShutdownOnReadMessageRawChannelDelegate); |
| 586 }; | 586 }; |
| 587 | 587 |
| 588 // TODO(vtl): crbug.com/366768 | 588 TEST_F(RawChannelTest, ShutdownOnReadMessage) { |
| 589 #if defined(OS_WIN) | |
| 590 #define MAYBE_ShutdownOnReadMessage DISABLED_ShutdownOnReadMessage | |
| 591 #else | |
| 592 #define MAYBE_ShutdownOnReadMessage ShutdownOnReadMessage | |
| 593 #endif | |
| 594 TEST_F(RawChannelTest, MAYBE_ShutdownOnReadMessage) { | |
| 595 // Write a few messages into the other end. | 589 // Write a few messages into the other end. |
| 596 for (size_t count = 0; count < 5; count++) | 590 for (size_t count = 0; count < 5; count++) |
| 597 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), 10)); | 591 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), 10)); |
| 598 | 592 |
| 599 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); | 593 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
| 600 ShutdownOnReadMessageRawChannelDelegate delegate(rc.get()); | 594 ShutdownOnReadMessageRawChannelDelegate delegate(rc.get()); |
| 601 io_thread()->PostTaskAndWait(FROM_HERE, | 595 io_thread()->PostTaskAndWait(FROM_HERE, |
| 602 base::Bind(&InitOnIOThread, rc.get(), | 596 base::Bind(&InitOnIOThread, rc.get(), |
| 603 base::Unretained(&delegate))); | 597 base::Unretained(&delegate))); |
| 604 | 598 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 634 |
| 641 private: | 635 private: |
| 642 RawChannel* const raw_channel_; | 636 RawChannel* const raw_channel_; |
| 643 const FatalError shutdown_on_error_type_; | 637 const FatalError shutdown_on_error_type_; |
| 644 base::WaitableEvent done_event_; | 638 base::WaitableEvent done_event_; |
| 645 bool did_shutdown_; | 639 bool did_shutdown_; |
| 646 | 640 |
| 647 DISALLOW_COPY_AND_ASSIGN(ShutdownOnFatalErrorRawChannelDelegate); | 641 DISALLOW_COPY_AND_ASSIGN(ShutdownOnFatalErrorRawChannelDelegate); |
| 648 }; | 642 }; |
| 649 | 643 |
| 650 // TODO(vtl): crbug.com/366768 | 644 TEST_F(RawChannelTest, ShutdownOnFatalErrorRead) { |
| 651 #if defined(OS_WIN) | |
| 652 #define MAYBE_ShutdownOnFatalErrorRead DISABLED_ShutdownOnFatalErrorRead | |
| 653 #else | |
| 654 #define MAYBE_ShutdownOnFatalErrorRead ShutdownOnFatalErrorRead | |
| 655 #endif | |
| 656 TEST_F(RawChannelTest, MAYBE_ShutdownOnFatalErrorRead) { | |
| 657 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); | 645 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
| 658 ShutdownOnFatalErrorRawChannelDelegate delegate( | 646 ShutdownOnFatalErrorRawChannelDelegate delegate( |
| 659 rc.get(), RawChannel::Delegate::FATAL_ERROR_FAILED_READ); | 647 rc.get(), RawChannel::Delegate::FATAL_ERROR_FAILED_READ); |
| 660 io_thread()->PostTaskAndWait(FROM_HERE, | 648 io_thread()->PostTaskAndWait(FROM_HERE, |
| 661 base::Bind(&InitOnIOThread, rc.get(), | 649 base::Bind(&InitOnIOThread, rc.get(), |
| 662 base::Unretained(&delegate))); | 650 base::Unretained(&delegate))); |
| 663 | 651 |
| 664 // Close the handle of the other end, which should stuff fail. | 652 // Close the handle of the other end, which should stuff fail. |
| 665 handles[1].reset(); | 653 handles[1].reset(); |
| 666 | 654 |
| 667 // Wait for the delegate, which will shut the |RawChannel| down. | 655 // Wait for the delegate, which will shut the |RawChannel| down. |
| 668 delegate.Wait(); | 656 delegate.Wait(); |
| 669 } | 657 } |
| 670 | 658 |
| 671 // TODO(vtl): crbug.com/366768 | 659 TEST_F(RawChannelTest, ShutdownOnFatalErrorWrite) { |
| 672 #if defined(OS_WIN) | |
| 673 #define MAYBE_ShutdownOnFatalErrorWrite DISABLED_ShutdownOnFatalErrorWrite | |
| 674 #else | |
| 675 #define MAYBE_ShutdownOnFatalErrorWrite ShutdownOnFatalErrorWrite | |
| 676 #endif | |
| 677 TEST_F(RawChannelTest, MAYBE_ShutdownOnFatalErrorWrite) { | |
| 678 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); | 660 scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
| 679 ShutdownOnFatalErrorRawChannelDelegate delegate( | 661 ShutdownOnFatalErrorRawChannelDelegate delegate( |
| 680 rc.get(), RawChannel::Delegate::FATAL_ERROR_FAILED_WRITE); | 662 rc.get(), RawChannel::Delegate::FATAL_ERROR_FAILED_WRITE); |
| 681 io_thread()->PostTaskAndWait(FROM_HERE, | 663 io_thread()->PostTaskAndWait(FROM_HERE, |
| 682 base::Bind(&InitOnIOThread, rc.get(), | 664 base::Bind(&InitOnIOThread, rc.get(), |
| 683 base::Unretained(&delegate))); | 665 base::Unretained(&delegate))); |
| 684 | 666 |
| 685 // Close the handle of the other end, which should stuff fail. | 667 // Close the handle of the other end, which should stuff fail. |
| 686 handles[1].reset(); | 668 handles[1].reset(); |
| 687 | 669 |
| 688 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); | 670 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); |
| 689 | 671 |
| 690 // Wait for the delegate, which will shut the |RawChannel| down. | 672 // Wait for the delegate, which will shut the |RawChannel| down. |
| 691 delegate.Wait(); | 673 delegate.Wait(); |
| 692 } | 674 } |
| 693 | 675 |
| 694 } // namespace | 676 } // namespace |
| 695 } // namespace system | 677 } // namespace system |
| 696 } // namespace mojo | 678 } // namespace mojo |
| OLD | NEW |