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/public/cpp/bindings/lib/router.h" | 5 #include "mojo/public/cpp/bindings/lib/router.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
| 9 #include "base/bind.h" |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
12 #include "mojo/public/cpp/bindings/tests/message_queue.h" | 13 #include "mojo/public/cpp/bindings/tests/message_queue.h" |
13 #include "mojo/public/cpp/bindings/tests/router_test_util.h" | 14 #include "mojo/public/cpp/bindings/tests/router_test_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace mojo { | 17 namespace mojo { |
17 namespace test { | 18 namespace test { |
18 namespace { | 19 namespace { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 generator2.CompleteWithResponse(); | 213 generator2.CompleteWithResponse(); |
213 run_loop4.Run(); | 214 run_loop4.Run(); |
214 | 215 |
215 // Check the second response. | 216 // Check the second response. |
216 EXPECT_FALSE(message_queue.IsEmpty()); | 217 EXPECT_FALSE(message_queue.IsEmpty()); |
217 message_queue.Pop(&response); | 218 message_queue.Pop(&response); |
218 EXPECT_EQ(std::string("hello again world!"), | 219 EXPECT_EQ(std::string("hello again world!"), |
219 std::string(reinterpret_cast<const char*>(response.payload()))); | 220 std::string(reinterpret_cast<const char*>(response.payload()))); |
220 } | 221 } |
221 | 222 |
| 223 void ForwardErrorHandler(bool* called, const base::Closure& callback) { |
| 224 *called = true; |
| 225 callback.Run(); |
| 226 } |
| 227 |
222 // Tests that if the receiving application destroys the responder_ without | 228 // Tests that if the receiving application destroys the responder_ without |
223 // sending a response, then we trigger connection error at both sides. Moreover, | 229 // sending a response, then we trigger connection error at both sides. Moreover, |
224 // both sides still appear to have a valid message pipe handle bound. | 230 // both sides still appear to have a valid message pipe handle bound. |
225 TEST_F(RouterTest, MissingResponses) { | 231 TEST_F(RouterTest, MissingResponses) { |
226 base::RunLoop run_loop0, run_loop1; | 232 base::RunLoop run_loop0, run_loop1; |
227 internal::Router router0(std::move(handle0_), internal::FilterChain(), false, | 233 internal::Router router0(std::move(handle0_), internal::FilterChain(), false, |
228 base::ThreadTaskRunnerHandle::Get()); | 234 base::ThreadTaskRunnerHandle::Get()); |
229 bool error_handler_called0 = false; | 235 bool error_handler_called0 = false; |
230 router0.set_connection_error_handler( | 236 router0.set_connection_error_handler( |
231 [&error_handler_called0, &run_loop0]() { | 237 base::Bind(&ForwardErrorHandler, &error_handler_called0, |
232 error_handler_called0 = true; | 238 run_loop0.QuitClosure())); |
233 run_loop0.Quit(); | |
234 }); | |
235 | 239 |
236 internal::Router router1(std::move(handle1_), internal::FilterChain(), false, | 240 internal::Router router1(std::move(handle1_), internal::FilterChain(), false, |
237 base::ThreadTaskRunnerHandle::Get()); | 241 base::ThreadTaskRunnerHandle::Get()); |
238 bool error_handler_called1 = false; | 242 bool error_handler_called1 = false; |
239 router1.set_connection_error_handler( | 243 router1.set_connection_error_handler( |
240 [&error_handler_called1, &run_loop1]() { | 244 base::Bind(&ForwardErrorHandler, &error_handler_called1, |
241 error_handler_called1 = true; | 245 run_loop1.QuitClosure())); |
242 run_loop1.Quit(); | |
243 }); | |
244 | 246 |
245 base::RunLoop run_loop3; | 247 base::RunLoop run_loop3; |
246 LazyResponseGenerator generator(run_loop3.QuitClosure()); | 248 LazyResponseGenerator generator(run_loop3.QuitClosure()); |
247 router1.set_incoming_receiver(&generator); | 249 router1.set_incoming_receiver(&generator); |
248 router1.set_incoming_receiver(&generator); | 250 router1.set_incoming_receiver(&generator); |
249 | 251 |
250 Message request; | 252 Message request; |
251 AllocRequestMessage(1, "hello", &request); | 253 AllocRequestMessage(1, "hello", &request); |
252 | 254 |
253 MessageQueue message_queue; | 255 MessageQueue message_queue; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 EXPECT_TRUE(generator.has_responder()); | 307 EXPECT_TRUE(generator.has_responder()); |
306 } | 308 } |
307 | 309 |
308 EXPECT_FALSE(generator.responder_is_valid()); | 310 EXPECT_FALSE(generator.responder_is_valid()); |
309 generator.CompleteWithResponse(); // This should end up doing nothing. | 311 generator.CompleteWithResponse(); // This should end up doing nothing. |
310 } | 312 } |
311 | 313 |
312 } // namespace | 314 } // namespace |
313 } // namespace test | 315 } // namespace test |
314 } // namespace mojo | 316 } // namespace mojo |
OLD | NEW |