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

Side by Side Diff: ipc/ipc_channel_mojo_unittest.cc

Issue 2163633003: Support early associated interface binding on ChannelMojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@explicit-channel-ipc-task-runner
Patch Set: . Created 4 years, 5 months 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
« no previous file with comments | « ipc/ipc_channel_mojo.cc ('k') | ipc/ipc_channel_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ipc/ipc_channel_mojo.h" 5 #include "ipc/ipc_channel_mojo.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 }; 751 };
752 752
753 class IPCChannelProxyMojoTest : public IPCChannelMojoTestBase { 753 class IPCChannelProxyMojoTest : public IPCChannelMojoTestBase {
754 public: 754 public:
755 void InitWithMojo(const std::string& client_name) { 755 void InitWithMojo(const std::string& client_name) {
756 IPCChannelMojoTestBase::InitWithMojo(client_name); 756 IPCChannelMojoTestBase::InitWithMojo(client_name);
757 runner_.reset(new ChannelProxyRunner(TakeHandle(), true)); 757 runner_.reset(new ChannelProxyRunner(TakeHandle(), true));
758 } 758 }
759 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); } 759 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); }
760 void RunProxy() { runner_->RunProxy(); } 760 void RunProxy() { runner_->RunProxy(); }
761 void DestroyProxy() {
762 runner_.reset();
763 base::RunLoop().RunUntilIdle();
764 }
761 765
762 IPC::ChannelProxy* proxy() { return runner_->proxy(); } 766 IPC::ChannelProxy* proxy() { return runner_->proxy(); }
763 767
764 private: 768 private:
765 base::MessageLoop message_loop_; 769 base::MessageLoop message_loop_;
766 std::unique_ptr<ChannelProxyRunner> runner_; 770 std::unique_ptr<ChannelProxyRunner> runner_;
767 }; 771 };
768 772
769 class ListenerWithSimpleProxyAssociatedInterface 773 class ListenerWithSimpleProxyAssociatedInterface
770 : public IPC::Listener, 774 : public IPC::Listener,
(...skipping 30 matching lines...) Expand all
801 805
802 private: 806 private:
803 // IPC::mojom::SimpleTestDriver: 807 // IPC::mojom::SimpleTestDriver:
804 void ExpectString(const mojo::String& str) override { 808 void ExpectString(const mojo::String& str) override {
805 next_expected_string_ = str; 809 next_expected_string_ = str;
806 } 810 }
807 811
808 void RequestQuit(const RequestQuitCallback& callback) override { 812 void RequestQuit(const RequestQuitCallback& callback) override {
809 received_quit_ = true; 813 received_quit_ = true;
810 callback.Run(); 814 callback.Run();
815 binding_.Close();
811 base::MessageLoop::current()->QuitWhenIdle(); 816 base::MessageLoop::current()->QuitWhenIdle();
812 } 817 }
813 818
814 void BindRequest(IPC::mojom::SimpleTestDriverAssociatedRequest request) { 819 void BindRequest(IPC::mojom::SimpleTestDriverAssociatedRequest request) {
815 DCHECK(!binding_.is_bound()); 820 DCHECK(!binding_.is_bound());
816 binding_.Bind(std::move(request)); 821 binding_.Bind(std::move(request));
817 } 822 }
818 823
819 std::string next_expected_string_; 824 std::string next_expected_string_;
820 int num_messages_received_ = 0; 825 int num_messages_received_ = 0;
(...skipping 10 matching lines...) Expand all
831 ListenerWithSimpleProxyAssociatedInterface listener; 836 ListenerWithSimpleProxyAssociatedInterface listener;
832 CreateProxy(&listener); 837 CreateProxy(&listener);
833 listener.RegisterInterfaceFactory(proxy()); 838 listener.RegisterInterfaceFactory(proxy());
834 RunProxy(); 839 RunProxy();
835 840
836 base::RunLoop().Run(); 841 base::RunLoop().Run();
837 842
838 EXPECT_TRUE(WaitForClientShutdown()); 843 EXPECT_TRUE(WaitForClientShutdown());
839 EXPECT_TRUE(listener.received_all_messages()); 844 EXPECT_TRUE(listener.received_all_messages());
840 845
841 base::RunLoop().RunUntilIdle(); 846 DestroyProxy();
842 } 847 }
843 848
844 class ChannelProxyClient { 849 class ChannelProxyClient {
845 public: 850 public:
846 void Init(mojo::ScopedMessagePipeHandle handle) { 851 void Init(mojo::ScopedMessagePipeHandle handle) {
847 runner_.reset(new ChannelProxyRunner(std::move(handle), false)); 852 runner_.reset(new ChannelProxyRunner(std::move(handle), false));
848 } 853 }
849 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); } 854 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); }
850 void RunProxy() { runner_->RunProxy(); } 855 void RunProxy() { runner_->RunProxy(); }
856 void DestroyProxy() {
857 runner_.reset();
858 base::RunLoop().RunUntilIdle();
859 }
851 860
852 IPC::ChannelProxy* proxy() { return runner_->proxy(); } 861 IPC::ChannelProxy* proxy() { return runner_->proxy(); }
853 862
854 private: 863 private:
855 base::MessageLoop message_loop_; 864 base::MessageLoop message_loop_;
856 std::unique_ptr<ChannelProxyRunner> runner_; 865 std::unique_ptr<ChannelProxyRunner> runner_;
857 }; 866 };
858 867
859 class ListenerThatWaitsForConnect : public IPC::Listener { 868 class DummyListener : public IPC::Listener {
860 public: 869 public:
861 explicit ListenerThatWaitsForConnect(const base::Closure& connect_handler)
862 : connect_handler_(connect_handler) {}
863
864 // IPC::Listener 870 // IPC::Listener
865 bool OnMessageReceived(const IPC::Message& message) override { return true; } 871 bool OnMessageReceived(const IPC::Message& message) override { return true; }
866 void OnChannelConnected(int32_t) override { connect_handler_.Run(); }
867
868 private:
869 base::Closure connect_handler_;
870 }; 872 };
871 873
872 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ProxyThreadAssociatedInterfaceClient, 874 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ProxyThreadAssociatedInterfaceClient,
873 ChannelProxyClient) { 875 ChannelProxyClient) {
874 base::RunLoop connect_loop; 876 DummyListener listener;
875 ListenerThatWaitsForConnect listener(connect_loop.QuitClosure());
876 CreateProxy(&listener); 877 CreateProxy(&listener);
877 RunProxy(); 878 RunProxy();
878 connect_loop.Run();
879 879
880 // Send a bunch of interleaved messages, alternating between the associated 880 // Send a bunch of interleaved messages, alternating between the associated
881 // interface and a legacy IPC::Message. 881 // interface and a legacy IPC::Message.
882 IPC::mojom::SimpleTestDriverAssociatedPtr driver; 882 IPC::mojom::SimpleTestDriverAssociatedPtr driver;
883 proxy()->GetRemoteAssociatedInterface(&driver); 883 proxy()->GetRemoteAssociatedInterface(&driver);
884 for (int i = 0; i < ListenerWithSimpleProxyAssociatedInterface::kNumMessages; 884 for (int i = 0; i < ListenerWithSimpleProxyAssociatedInterface::kNumMessages;
885 ++i) { 885 ++i) {
886 std::string str = base::StringPrintf("Hello! %d", i); 886 std::string str = base::StringPrintf("Hello! %d", i);
887 driver->ExpectString(str); 887 driver->ExpectString(str);
888 SendString(proxy(), str); 888 SendString(proxy(), str);
889 } 889 }
890 driver->RequestQuit(base::MessageLoop::QuitWhenIdleClosure()); 890 driver->RequestQuit(base::MessageLoop::QuitWhenIdleClosure());
891 base::RunLoop().Run(); 891 base::RunLoop().Run();
892
893 DestroyProxy();
892 } 894 }
893 895
894 #if defined(OS_POSIX) 896 #if defined(OS_POSIX)
895 897
896 class ListenerThatExpectsFile : public IPC::Listener { 898 class ListenerThatExpectsFile : public IPC::Listener {
897 public: 899 public:
898 ListenerThatExpectsFile() : sender_(NULL) {} 900 ListenerThatExpectsFile() : sender_(NULL) {}
899 901
900 ~ListenerThatExpectsFile() override {} 902 ~ListenerThatExpectsFile() override {}
901 903
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 Connect(&listener); 1048 Connect(&listener);
1047 1049
1048 base::MessageLoop::current()->Run(); 1050 base::MessageLoop::current()->Run();
1049 1051
1050 Close(); 1052 Close();
1051 } 1053 }
1052 1054
1053 #endif // OS_LINUX 1055 #endif // OS_LINUX
1054 1056
1055 } // namespace 1057 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_channel_mojo.cc ('k') | ipc/ipc_channel_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698