OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Note: This file tests both binding.h (mojo::Binding) and strong_binding.h | 5 // Note: This file tests both binding.h (mojo::Binding) and strong_binding.h |
6 // (mojo::StrongBinding). | 6 // (mojo::StrongBinding). |
7 | 7 |
8 #include "mojo/public/cpp/bindings/binding.h" | 8 #include "mojo/public/cpp/bindings/binding.h" |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 loop().RunUntilIdle(); | 304 loop().RunUntilIdle(); |
305 // The connection error handle should not be called as the binding is paused. | 305 // The connection error handle should not be called as the binding is paused. |
306 EXPECT_FALSE(called); | 306 EXPECT_FALSE(called); |
307 | 307 |
308 // Resume the binding, which should trigger the error handler. | 308 // Resume the binding, which should trigger the error handler. |
309 binding.ResumeIncomingMethodCallProcessing(); | 309 binding.ResumeIncomingMethodCallProcessing(); |
310 run_loop.Run(); | 310 run_loop.Run(); |
311 EXPECT_TRUE(called); | 311 EXPECT_TRUE(called); |
312 } | 312 } |
313 | 313 |
| 314 class SingleMethodImpl : public sample::SingleMethod { |
| 315 public: |
| 316 explicit SingleMethodImpl(const Closure& on_call) : on_call_(on_call) {} |
| 317 ~SingleMethodImpl() override {} |
| 318 |
| 319 private: |
| 320 // sample::SingleMethod: |
| 321 void Call() override { on_call_.Run(); } |
| 322 |
| 323 const Closure on_call_; |
| 324 }; |
| 325 |
| 326 // Tests that sync dispatch works when enabled on a Binding. |
| 327 TEST_F(BindingTest, SyncDispatch) { |
| 328 bool called = false; |
| 329 sample::SingleMethodPtr ptr; |
| 330 SingleMethodImpl impl([&called] { called = true; }); |
| 331 Binding<sample::SingleMethod> binding(&impl, GetProxy(&ptr)); |
| 332 binding.EnableImmediateDispatchOfEventsFromSameThread(true); |
| 333 ptr->Call(); |
| 334 EXPECT_TRUE(called); |
| 335 } |
| 336 |
314 // StrongBindingTest ----------------------------------------------------------- | 337 // StrongBindingTest ----------------------------------------------------------- |
315 | 338 |
316 using StrongBindingTest = BindingTestBase; | 339 using StrongBindingTest = BindingTestBase; |
317 | 340 |
318 // Tests that destroying a mojo::StrongBinding closes the bound message pipe | 341 // Tests that destroying a mojo::StrongBinding closes the bound message pipe |
319 // handle but does *not* destroy the implementation object. | 342 // handle but does *not* destroy the implementation object. |
320 TEST_F(StrongBindingTest, DestroyClosesMessagePipe) { | 343 TEST_F(StrongBindingTest, DestroyClosesMessagePipe) { |
321 base::RunLoop run_loop; | 344 base::RunLoop run_loop; |
322 bool encountered_error = false; | 345 bool encountered_error = false; |
323 bool was_deleted = false; | 346 bool was_deleted = false; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 was_deleted = false; // It shouldn't be double-deleted! | 440 was_deleted = false; // It shouldn't be double-deleted! |
418 run_loop.Run(); | 441 run_loop.Run(); |
419 EXPECT_TRUE(ptr_error_handler_called); | 442 EXPECT_TRUE(ptr_error_handler_called); |
420 EXPECT_FALSE(was_deleted); | 443 EXPECT_FALSE(was_deleted); |
421 | 444 |
422 EXPECT_FALSE(binding_error_handler_called); | 445 EXPECT_FALSE(binding_error_handler_called); |
423 } | 446 } |
424 | 447 |
425 } // namespace | 448 } // namespace |
426 } // mojo | 449 } // mojo |
OLD | NEW |