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

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

Issue 137063010: Mojo: Move platform handle/channel stuff in system to embedder namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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
« no previous file with comments | « mojo/system/raw_channel_posix.cc ('k') | mojo/system/raw_channel_win.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 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 // TODO(vtl): Factor out the remaining POSIX-specific bits of this test (once we 5 // TODO(vtl): Factor out the remaining POSIX-specific bits of this test (once we
6 // have a non-POSIX implementation). 6 // have a non-POSIX implementation).
7 7
8 #include "mojo/system/raw_channel.h" 8 #include "mojo/system/raw_channel.h"
9 9
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // ----------------------------------------------------------------------------- 64 // -----------------------------------------------------------------------------
65 65
66 class RawChannelPosixTest : public test::TestWithIOThreadBase { 66 class RawChannelPosixTest : public test::TestWithIOThreadBase {
67 public: 67 public:
68 RawChannelPosixTest() {} 68 RawChannelPosixTest() {}
69 virtual ~RawChannelPosixTest() {} 69 virtual ~RawChannelPosixTest() {}
70 70
71 virtual void SetUp() OVERRIDE { 71 virtual void SetUp() OVERRIDE {
72 test::TestWithIOThreadBase::SetUp(); 72 test::TestWithIOThreadBase::SetUp();
73 73
74 PlatformChannelPair channel_pair; 74 embedder::PlatformChannelPair channel_pair;
75 handles[0] = channel_pair.PassServerHandle(); 75 handles[0] = channel_pair.PassServerHandle();
76 handles[1] = channel_pair.PassClientHandle(); 76 handles[1] = channel_pair.PassClientHandle();
77 } 77 }
78 78
79 virtual void TearDown() OVERRIDE { 79 virtual void TearDown() OVERRIDE {
80 handles[0].reset(); 80 handles[0].reset();
81 handles[1].reset(); 81 handles[1].reset();
82 82
83 test::TestWithIOThreadBase::TearDown(); 83 test::TestWithIOThreadBase::TearDown();
84 } 84 }
85 85
86 protected: 86 protected:
87 ScopedPlatformHandle handles[2]; 87 embedder::ScopedPlatformHandle handles[2];
88 88
89 private: 89 private:
90 DISALLOW_COPY_AND_ASSIGN(RawChannelPosixTest); 90 DISALLOW_COPY_AND_ASSIGN(RawChannelPosixTest);
91 }; 91 };
92 92
93 // RawChannelPosixTest.WriteMessage -------------------------------------------- 93 // RawChannelPosixTest.WriteMessage --------------------------------------------
94 94
95 class WriteOnlyRawChannelDelegate : public RawChannel::Delegate { 95 class WriteOnlyRawChannelDelegate : public RawChannel::Delegate {
96 public: 96 public:
97 WriteOnlyRawChannelDelegate() {} 97 WriteOnlyRawChannelDelegate() {}
98 virtual ~WriteOnlyRawChannelDelegate() {} 98 virtual ~WriteOnlyRawChannelDelegate() {}
99 99
100 // |RawChannel::Delegate| implementation: 100 // |RawChannel::Delegate| implementation:
101 virtual void OnReadMessage(const MessageInTransit& /*message*/) OVERRIDE { 101 virtual void OnReadMessage(const MessageInTransit& /*message*/) OVERRIDE {
102 NOTREACHED(); 102 NOTREACHED();
103 } 103 }
104 virtual void OnFatalError(FatalError /*fatal_error*/) OVERRIDE { 104 virtual void OnFatalError(FatalError /*fatal_error*/) OVERRIDE {
105 NOTREACHED(); 105 NOTREACHED();
106 } 106 }
107 107
108 private: 108 private:
109 DISALLOW_COPY_AND_ASSIGN(WriteOnlyRawChannelDelegate); 109 DISALLOW_COPY_AND_ASSIGN(WriteOnlyRawChannelDelegate);
110 }; 110 };
111 111
112 static const int64_t kMessageReaderSleepMs = 1; 112 static const int64_t kMessageReaderSleepMs = 1;
113 static const size_t kMessageReaderMaxPollIterations = 3000; 113 static const size_t kMessageReaderMaxPollIterations = 3000;
114 114
115 class TestMessageReaderAndChecker { 115 class TestMessageReaderAndChecker {
116 public: 116 public:
117 explicit TestMessageReaderAndChecker(PlatformHandle handle) 117 explicit TestMessageReaderAndChecker(embedder::PlatformHandle handle)
118 : handle_(handle) {} 118 : handle_(handle) {}
119 ~TestMessageReaderAndChecker() { CHECK(bytes_.empty()); } 119 ~TestMessageReaderAndChecker() { CHECK(bytes_.empty()); }
120 120
121 bool ReadAndCheckNextMessage(uint32_t expected_size) { 121 bool ReadAndCheckNextMessage(uint32_t expected_size) {
122 unsigned char buffer[4096]; 122 unsigned char buffer[4096];
123 123
124 for (size_t i = 0; i < kMessageReaderMaxPollIterations;) { 124 for (size_t i = 0; i < kMessageReaderMaxPollIterations;) {
125 ssize_t read_size = HANDLE_EINTR( 125 ssize_t read_size = HANDLE_EINTR(
126 read(handle_.fd, buffer, sizeof(buffer))); 126 read(handle_.fd, buffer, sizeof(buffer)));
127 if (read_size < 0) { 127 if (read_size < 0) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 base::PlatformThread::Sleep( 165 base::PlatformThread::Sleep(
166 base::TimeDelta::FromMilliseconds(kMessageReaderSleepMs)); 166 base::TimeDelta::FromMilliseconds(kMessageReaderSleepMs));
167 } 167 }
168 } 168 }
169 169
170 LOG(ERROR) << "Too many iterations."; 170 LOG(ERROR) << "Too many iterations.";
171 return false; 171 return false;
172 } 172 }
173 173
174 private: 174 private:
175 const PlatformHandle handle_; 175 const embedder::PlatformHandle handle_;
176 176
177 // The start of the received data should always be on a message boundary. 177 // The start of the received data should always be on a message boundary.
178 std::vector<unsigned char> bytes_; 178 std::vector<unsigned char> bytes_;
179 179
180 DISALLOW_COPY_AND_ASSIGN(TestMessageReaderAndChecker); 180 DISALLOW_COPY_AND_ASSIGN(TestMessageReaderAndChecker);
181 }; 181 };
182 182
183 // Tests writing (and verifies reading using our own custom reader). 183 // Tests writing (and verifies reading using our own custom reader).
184 TEST_F(RawChannelPosixTest, WriteMessage) { 184 TEST_F(RawChannelPosixTest, WriteMessage) {
185 WriteOnlyRawChannelDelegate delegate; 185 WriteOnlyRawChannelDelegate delegate;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 FROM_HERE, 521 FROM_HERE,
522 base::Bind(&RawChannel::Shutdown, 522 base::Bind(&RawChannel::Shutdown,
523 base::Unretained(rc.get()))); 523 base::Unretained(rc.get())));
524 524
525 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); 525 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
526 } 526 }
527 527
528 } // namespace 528 } // namespace
529 } // namespace system 529 } // namespace system
530 } // namespace mojo 530 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/raw_channel_posix.cc ('k') | mojo/system/raw_channel_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698