OLD | NEW |
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 <stdint.h> | 5 #include <stdint.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // Ensure that simply accessing request->pipe does not close it. | 88 // Ensure that simply accessing request->pipe does not close it. |
89 EXPECT_TRUE(request->pipe.is_valid()); | 89 EXPECT_TRUE(request->pipe.is_valid()); |
90 } | 90 } |
91 | 91 |
92 ScopedMessagePipeHandle pipe0; | 92 ScopedMessagePipeHandle pipe0; |
93 if (!text2.empty()) { | 93 if (!text2.empty()) { |
94 CreateMessagePipe(nullptr, &pipe0, &pipe1_); | 94 CreateMessagePipe(nullptr, &pipe0, &pipe1_); |
95 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), text2)); | 95 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), text2)); |
96 } | 96 } |
97 | 97 |
98 sample::ResponsePtr response(sample::Response::New()); | 98 sample::ResponsePtr response(sample::Response::New(2, std::move(pipe0))); |
99 response->x = 2; | |
100 response->pipe = std::move(pipe0); | |
101 callback.Run(std::move(response), text1); | 99 callback.Run(std::move(response), text1); |
102 | 100 |
103 if (request->obj) | 101 if (request->obj) |
104 request->obj->DoSomething(); | 102 request->obj->DoSomething(); |
105 } | 103 } |
106 | 104 |
107 void DoStuff2(ScopedDataPipeConsumerHandle pipe, | 105 void DoStuff2(ScopedDataPipeConsumerHandle pipe, |
108 const DoStuff2Callback& callback) override { | 106 const DoStuff2Callback& callback) override { |
109 // Read the data from the pipe, writing the response (as a string) to | 107 // Read the data from the pipe, writing the response (as a string) to |
110 // DidStuff2(). | 108 // DidStuff2(). |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 EXPECT_TRUE(WriteTextMessage(pipe0.handle1.get(), kText1)); | 205 EXPECT_TRUE(WriteTextMessage(pipe0.handle1.get(), kText1)); |
208 | 206 |
209 MessagePipe pipe1; | 207 MessagePipe pipe1; |
210 EXPECT_TRUE(WriteTextMessage(pipe1.handle1.get(), kText2)); | 208 EXPECT_TRUE(WriteTextMessage(pipe1.handle1.get(), kText2)); |
211 | 209 |
212 imported::ImportedInterfacePtr imported; | 210 imported::ImportedInterfacePtr imported; |
213 base::RunLoop run_loop; | 211 base::RunLoop run_loop; |
214 ImportedInterfaceImpl imported_impl(MakeRequest(&imported), | 212 ImportedInterfaceImpl imported_impl(MakeRequest(&imported), |
215 run_loop.QuitClosure()); | 213 run_loop.QuitClosure()); |
216 | 214 |
217 sample::RequestPtr request(sample::Request::New()); | 215 sample::RequestPtr request(sample::Request::New( |
218 request->x = 1; | 216 1, std::move(pipe1.handle0), base::nullopt, std::move(imported))); |
219 request->pipe = std::move(pipe1.handle0); | |
220 request->obj = std::move(imported); | |
221 bool got_response = false; | 217 bool got_response = false; |
222 std::string got_text_reply; | 218 std::string got_text_reply; |
223 base::RunLoop run_loop2; | 219 base::RunLoop run_loop2; |
224 factory->DoStuff(std::move(request), std::move(pipe0.handle0), | 220 factory->DoStuff(std::move(request), std::move(pipe0.handle0), |
225 base::Bind(&DoStuff, &got_response, &got_text_reply, | 221 base::Bind(&DoStuff, &got_response, &got_text_reply, |
226 run_loop2.QuitClosure())); | 222 run_loop2.QuitClosure())); |
227 | 223 |
228 EXPECT_FALSE(got_response); | 224 EXPECT_FALSE(got_response); |
229 int count_before = ImportedInterfaceImpl::do_something_count(); | 225 int count_before = ImportedInterfaceImpl::do_something_count(); |
230 | 226 |
231 run_loop.Run(); | 227 run_loop.Run(); |
232 run_loop2.Run(); | 228 run_loop2.Run(); |
233 | 229 |
234 EXPECT_TRUE(got_response); | 230 EXPECT_TRUE(got_response); |
235 EXPECT_EQ(kText1, got_text_reply); | 231 EXPECT_EQ(kText1, got_text_reply); |
236 EXPECT_EQ(1, ImportedInterfaceImpl::do_something_count() - count_before); | 232 EXPECT_EQ(1, ImportedInterfaceImpl::do_something_count() - count_before); |
237 } | 233 } |
238 | 234 |
239 TEST_F(HandlePassingTest, PassInvalid) { | 235 TEST_F(HandlePassingTest, PassInvalid) { |
240 sample::FactoryPtr factory; | 236 sample::FactoryPtr factory; |
241 SampleFactoryImpl factory_impl(MakeRequest(&factory)); | 237 SampleFactoryImpl factory_impl(MakeRequest(&factory)); |
242 | 238 |
243 sample::RequestPtr request(sample::Request::New()); | 239 sample::RequestPtr request( |
244 request->x = 1; | 240 sample::Request::New(1, ScopedMessagePipeHandle(), base::nullopt, |
| 241 imported::ImportedInterfacePtr())); |
245 bool got_response = false; | 242 bool got_response = false; |
246 std::string got_text_reply; | 243 std::string got_text_reply; |
247 base::RunLoop run_loop; | 244 base::RunLoop run_loop; |
248 factory->DoStuff(std::move(request), ScopedMessagePipeHandle(), | 245 factory->DoStuff(std::move(request), ScopedMessagePipeHandle(), |
249 base::Bind(&DoStuff, &got_response, &got_text_reply, | 246 base::Bind(&DoStuff, &got_response, &got_text_reply, |
250 run_loop.QuitClosure())); | 247 run_loop.QuitClosure())); |
251 | 248 |
252 EXPECT_FALSE(got_response); | 249 EXPECT_FALSE(got_response); |
253 | 250 |
254 run_loop.Run(); | 251 run_loop.Run(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 run_loop.Run(); | 347 run_loop.Run(); |
351 run_loop2.Run(); | 348 run_loop2.Run(); |
352 | 349 |
353 EXPECT_EQ(std::string("object1"), name1); | 350 EXPECT_EQ(std::string("object1"), name1); |
354 EXPECT_EQ(std::string("object2"), name2); | 351 EXPECT_EQ(std::string("object2"), name2); |
355 } | 352 } |
356 | 353 |
357 } // namespace | 354 } // namespace |
358 } // namespace test | 355 } // namespace test |
359 } // namespace mojo | 356 } // namespace mojo |
OLD | NEW |