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/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 Binding<sample::PingTest> binding_; | 701 Binding<sample::PingTest> binding_; |
702 }; | 702 }; |
703 | 703 |
704 // Tests that FuseProxy does what it's supposed to do. | 704 // Tests that FuseProxy does what it's supposed to do. |
705 TEST_F(InterfacePtrTest, Fusion) { | 705 TEST_F(InterfacePtrTest, Fusion) { |
706 sample::PingTestPtr proxy; | 706 sample::PingTestPtr proxy; |
707 PingTestImpl impl(MakeRequest(&proxy)); | 707 PingTestImpl impl(MakeRequest(&proxy)); |
708 | 708 |
709 // Create another PingTest pipe. | 709 // Create another PingTest pipe. |
710 sample::PingTestPtr ptr; | 710 sample::PingTestPtr ptr; |
711 sample::PingTestRequest request = MakeRequest(&ptr); | 711 sample::PingTestRequest request(&ptr); |
712 | 712 |
713 // Fuse the new pipe to the one hanging off |impl|. | 713 // Fuse the new pipe to the one hanging off |impl|. |
714 EXPECT_TRUE(FuseInterface(std::move(request), proxy.PassInterface())); | 714 EXPECT_TRUE(FuseInterface(std::move(request), proxy.PassInterface())); |
715 | 715 |
716 // Ping! | 716 // Ping! |
717 bool called = false; | 717 bool called = false; |
718 base::RunLoop loop; | 718 base::RunLoop loop; |
719 ptr->Ping(base::Bind(&SetFlagAndRunClosure, &called, loop.QuitClosure())); | 719 ptr->Ping(base::Bind(&SetFlagAndRunClosure, &called, loop.QuitClosure())); |
720 loop.Run(); | 720 loop.Run(); |
721 EXPECT_TRUE(called); | 721 EXPECT_TRUE(called); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 }, | 789 }, |
790 run_loop.QuitClosure())); | 790 run_loop.QuitClosure())); |
791 | 791 |
792 request.ResetWithReason(88u, "greetings"); | 792 request.ResetWithReason(88u, "greetings"); |
793 | 793 |
794 run_loop.Run(); | 794 run_loop.Run(); |
795 } | 795 } |
796 | 796 |
797 TEST_F(InterfacePtrTest, CallbackOwnsInterfacePtr) { | 797 TEST_F(InterfacePtrTest, CallbackOwnsInterfacePtr) { |
798 sample::PingTestPtr ptr; | 798 sample::PingTestPtr ptr; |
799 sample::PingTestRequest request = MakeRequest(&ptr); | 799 sample::PingTestRequest request(&ptr); |
800 | 800 |
801 base::RunLoop run_loop; | 801 base::RunLoop run_loop; |
802 | 802 |
803 // Make a call with the proxy's lifetime bound to the response callback. | 803 // Make a call with the proxy's lifetime bound to the response callback. |
804 sample::PingTest* raw_proxy = ptr.get(); | 804 sample::PingTest* raw_proxy = ptr.get(); |
805 ptr.set_connection_error_handler(run_loop.QuitClosure()); | 805 ptr.set_connection_error_handler(run_loop.QuitClosure()); |
806 raw_proxy->Ping( | 806 raw_proxy->Ping( |
807 base::Bind([](sample::PingTestPtr ptr) {}, base::Passed(&ptr))); | 807 base::Bind([](sample::PingTestPtr ptr) {}, base::Passed(&ptr))); |
808 | 808 |
809 // Trigger an error on |ptr|. This will ultimately lead to the proxy's | 809 // Trigger an error on |ptr|. This will ultimately lead to the proxy's |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 other_thread_task_runner->DeleteSoon(FROM_HERE, math_calc_impl); | 900 other_thread_task_runner->DeleteSoon(FROM_HERE, math_calc_impl); |
901 | 901 |
902 // Reset the pointer now so the InterfacePtr associated resources can be | 902 // Reset the pointer now so the InterfacePtr associated resources can be |
903 // deleted before the background thread's message loop is invalidated. | 903 // deleted before the background thread's message loop is invalidated. |
904 thread_safe_ptr = nullptr; | 904 thread_safe_ptr = nullptr; |
905 } | 905 } |
906 | 906 |
907 } // namespace | 907 } // namespace |
908 } // namespace test | 908 } // namespace test |
909 } // namespace mojo | 909 } // namespace mojo |
OLD | NEW |