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

Side by Side Diff: mojo/public/tests/bindings_connector_unittest.cc

Issue 76393002: Enable and fix BindingsConnectorTest.MessageWithHandles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix up spacing Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "mojo/public/bindings/lib/bindings_support.h" 8 #include "mojo/public/bindings/lib/bindings_support.h"
9 #include "mojo/public/bindings/lib/connector.h" 9 #include "mojo/public/bindings/lib/connector.h"
10 #include "mojo/public/bindings/lib/message_queue.h" 10 #include "mojo/public/bindings/lib/message_queue.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 AllocMessage(kText, &message); 165 AllocMessage(kText, &message);
166 166
167 Close(handle0_); // Close the handle before writing to it. 167 Close(handle0_); // Close the handle before writing to it.
168 168
169 bool ok = connector0.Accept(&message); 169 bool ok = connector0.Accept(&message);
170 EXPECT_FALSE(ok); 170 EXPECT_FALSE(ok);
171 171
172 EXPECT_TRUE(connector0.EncounteredError()); 172 EXPECT_TRUE(connector0.EncounteredError());
173 } 173 }
174 174
175 #if 0
176 // Enable this test once MojoWriteMessage supports passing handles. 175 // Enable this test once MojoWriteMessage supports passing handles.
177 TEST_F(BindingsConnectorTest, MessageWithHandles) { 176 TEST_F(BindingsConnectorTest, MessageWithHandles) {
178 Connector connector0(handle0_); 177 Connector connector0(handle0_);
179 Connector connector1(handle1_); 178 Connector connector1(handle1_);
180 179
181 const char kText[] = "hello world"; 180 const char kText[] = "hello world";
182 181
183 Message message; 182 Message message;
184 AllocMessage(kText, &message); 183 AllocMessage(kText, &message);
185 184
186 Handle handles[2]; 185 Handle handles[2];
187 CreateMessagePipe(&handles[0], &handles[1]); 186 CreateMessagePipe(&handles[0], &handles[1]);
188 message.handles.push_back(handles[0]); 187 message.handles.push_back(handles[0]);
189 message.handles.push_back(handles[1]);
190 188
191 connector0.Accept(&message); 189 connector0.Accept(&message);
192 190
193 // The message should have been transferred. 191 // The message should have been transferred, releasing the handles.
194 EXPECT_TRUE(message.data == NULL);
195 EXPECT_TRUE(message.handles.empty()); 192 EXPECT_TRUE(message.handles.empty());
196 193
197 MessageAccumulator accumulator; 194 MessageAccumulator accumulator;
198 connector1.SetIncomingReceiver(&accumulator); 195 connector1.SetIncomingReceiver(&accumulator);
199 196
200 PumpMessages(); 197 PumpMessages();
201 198
202 ASSERT_FALSE(accumulator.IsEmpty()); 199 ASSERT_FALSE(accumulator.IsEmpty());
203 200
204 Message message_received; 201 Message message_received;
205 accumulator.Pop(&message_received); 202 accumulator.Pop(&message_received);
206 203
207 EXPECT_EQ(std::string(kText), 204 EXPECT_EQ(std::string(kText),
208 std::string( 205 std::string(
209 reinterpret_cast<char*>(message_received.data->payload))); 206 reinterpret_cast<char*>(message_received.data->payload)));
210 ASSERT_EQ(2U, message_received.handles.size()); 207 ASSERT_EQ(1U, message_received.handles.size());
211 EXPECT_EQ(handles[0].value, message_received.handles[0].value); 208
212 EXPECT_EQ(handles[1].value, message_received.handles[1].value); 209 // Now send a message to the transferred handle and confirm it's sent through
210 // to the orginal pipe.
211 Connector connector_received(message_received.handles[0]);
212 Connector connector_original(handles[1]);
213
214 AllocMessage(kText, &message);
215
216 connector_received.Accept(&message);
217 connector_original.SetIncomingReceiver(&accumulator);
218 PumpMessages();
219
220 ASSERT_FALSE(accumulator.IsEmpty());
221
222 accumulator.Pop(&message_received);
223
224 EXPECT_EQ(std::string(kText),
225 std::string(
226 reinterpret_cast<char*>(message_received.data->payload)));
213 } 227 }
214 #endif
215 228
216 } // namespace test 229 } // namespace test
217 } // namespace mojo 230 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698