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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.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/test/test_io_thread.h" |
20 #include "base/threading/platform_thread.h" // For |Sleep()|. | 21 #include "base/threading/platform_thread.h" // For |Sleep()|. |
21 #include "base/threading/simple_thread.h" | 22 #include "base/threading/simple_thread.h" |
22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
24 #include "mojo/common/test/test_utils.h" | 25 #include "mojo/common/test/test_utils.h" |
25 #include "mojo/embedder/platform_channel_pair.h" | 26 #include "mojo/embedder/platform_channel_pair.h" |
26 #include "mojo/embedder/platform_handle.h" | 27 #include "mojo/embedder/platform_handle.h" |
27 #include "mojo/embedder/scoped_platform_handle.h" | 28 #include "mojo/embedder/scoped_platform_handle.h" |
28 #include "mojo/system/message_in_transit.h" | 29 #include "mojo/system/message_in_transit.h" |
29 #include "mojo/system/test_utils.h" | 30 #include "mojo/system/test_utils.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 size_t write_size = 0; | 65 size_t write_size = 0; |
65 mojo::test::BlockingWrite( | 66 mojo::test::BlockingWrite( |
66 handle, message->main_buffer(), message->main_buffer_size(), &write_size); | 67 handle, message->main_buffer(), message->main_buffer_size(), &write_size); |
67 return write_size == message->main_buffer_size(); | 68 return write_size == message->main_buffer_size(); |
68 } | 69 } |
69 | 70 |
70 // ----------------------------------------------------------------------------- | 71 // ----------------------------------------------------------------------------- |
71 | 72 |
72 class RawChannelTest : public testing::Test { | 73 class RawChannelTest : public testing::Test { |
73 public: | 74 public: |
74 RawChannelTest() : io_thread_(test::TestIOThread::kManualStart) {} | 75 RawChannelTest() : io_thread_(base::TestIOThread::kManualStart) {} |
75 virtual ~RawChannelTest() {} | 76 virtual ~RawChannelTest() {} |
76 | 77 |
77 virtual void SetUp() OVERRIDE { | 78 virtual void SetUp() OVERRIDE { |
78 embedder::PlatformChannelPair channel_pair; | 79 embedder::PlatformChannelPair channel_pair; |
79 handles[0] = channel_pair.PassServerHandle(); | 80 handles[0] = channel_pair.PassServerHandle(); |
80 handles[1] = channel_pair.PassClientHandle(); | 81 handles[1] = channel_pair.PassClientHandle(); |
81 io_thread_.Start(); | 82 io_thread_.Start(); |
82 } | 83 } |
83 | 84 |
84 virtual void TearDown() OVERRIDE { | 85 virtual void TearDown() OVERRIDE { |
85 io_thread_.Stop(); | 86 io_thread_.Stop(); |
86 handles[0].reset(); | 87 handles[0].reset(); |
87 handles[1].reset(); | 88 handles[1].reset(); |
88 } | 89 } |
89 | 90 |
90 protected: | 91 protected: |
91 test::TestIOThread* io_thread() { return &io_thread_; } | 92 base::TestIOThread* io_thread() { return &io_thread_; } |
92 | 93 |
93 embedder::ScopedPlatformHandle handles[2]; | 94 embedder::ScopedPlatformHandle handles[2]; |
94 | 95 |
95 private: | 96 private: |
96 test::TestIOThread io_thread_; | 97 base::TestIOThread io_thread_; |
97 | 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() {} |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 679 |
679 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); | 680 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); |
680 | 681 |
681 // Wait for the delegate, which will shut the |RawChannel| down. | 682 // Wait for the delegate, which will shut the |RawChannel| down. |
682 delegate.Wait(); | 683 delegate.Wait(); |
683 } | 684 } |
684 | 685 |
685 } // namespace | 686 } // namespace |
686 } // namespace system | 687 } // namespace system |
687 } // namespace mojo | 688 } // namespace mojo |
OLD | NEW |