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

Side by Side Diff: ipc/ipc_channel_mojo_unittest.cc

Issue 2173753002: Revert of 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 }
765 761
766 IPC::ChannelProxy* proxy() { return runner_->proxy(); } 762 IPC::ChannelProxy* proxy() { return runner_->proxy(); }
767 763
768 private: 764 private:
769 base::MessageLoop message_loop_; 765 base::MessageLoop message_loop_;
770 std::unique_ptr<ChannelProxyRunner> runner_; 766 std::unique_ptr<ChannelProxyRunner> runner_;
771 }; 767 };
772 768
773 class ListenerWithSimpleProxyAssociatedInterface 769 class ListenerWithSimpleProxyAssociatedInterface
774 : public IPC::Listener, 770 : public IPC::Listener,
(...skipping 30 matching lines...) Expand all
805 801
806 private: 802 private:
807 // IPC::mojom::SimpleTestDriver: 803 // IPC::mojom::SimpleTestDriver:
808 void ExpectString(const mojo::String& str) override { 804 void ExpectString(const mojo::String& str) override {
809 next_expected_string_ = str; 805 next_expected_string_ = str;
810 } 806 }
811 807
812 void RequestQuit(const RequestQuitCallback& callback) override { 808 void RequestQuit(const RequestQuitCallback& callback) override {
813 received_quit_ = true; 809 received_quit_ = true;
814 callback.Run(); 810 callback.Run();
815 binding_.Close();
816 base::MessageLoop::current()->QuitWhenIdle(); 811 base::MessageLoop::current()->QuitWhenIdle();
817 } 812 }
818 813
819 void BindRequest(IPC::mojom::SimpleTestDriverAssociatedRequest request) { 814 void BindRequest(IPC::mojom::SimpleTestDriverAssociatedRequest request) {
820 DCHECK(!binding_.is_bound()); 815 DCHECK(!binding_.is_bound());
821 binding_.Bind(std::move(request)); 816 binding_.Bind(std::move(request));
822 } 817 }
823 818
824 std::string next_expected_string_; 819 std::string next_expected_string_;
825 int num_messages_received_ = 0; 820 int num_messages_received_ = 0;
(...skipping 10 matching lines...) Expand all
836 ListenerWithSimpleProxyAssociatedInterface listener; 831 ListenerWithSimpleProxyAssociatedInterface listener;
837 CreateProxy(&listener); 832 CreateProxy(&listener);
838 listener.RegisterInterfaceFactory(proxy()); 833 listener.RegisterInterfaceFactory(proxy());
839 RunProxy(); 834 RunProxy();
840 835
841 base::RunLoop().Run(); 836 base::RunLoop().Run();
842 837
843 EXPECT_TRUE(WaitForClientShutdown()); 838 EXPECT_TRUE(WaitForClientShutdown());
844 EXPECT_TRUE(listener.received_all_messages()); 839 EXPECT_TRUE(listener.received_all_messages());
845 840
846 DestroyProxy(); 841 base::RunLoop().RunUntilIdle();
847 } 842 }
848 843
849 class ChannelProxyClient { 844 class ChannelProxyClient {
850 public: 845 public:
851 void Init(mojo::ScopedMessagePipeHandle handle) { 846 void Init(mojo::ScopedMessagePipeHandle handle) {
852 runner_.reset(new ChannelProxyRunner(std::move(handle), false)); 847 runner_.reset(new ChannelProxyRunner(std::move(handle), false));
853 } 848 }
854 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); } 849 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); }
855 void RunProxy() { runner_->RunProxy(); } 850 void RunProxy() { runner_->RunProxy(); }
856 void DestroyProxy() {
857 runner_.reset();
858 base::RunLoop().RunUntilIdle();
859 }
860 851
861 IPC::ChannelProxy* proxy() { return runner_->proxy(); } 852 IPC::ChannelProxy* proxy() { return runner_->proxy(); }
862 853
863 private: 854 private:
864 base::MessageLoop message_loop_; 855 base::MessageLoop message_loop_;
865 std::unique_ptr<ChannelProxyRunner> runner_; 856 std::unique_ptr<ChannelProxyRunner> runner_;
866 }; 857 };
867 858
868 class DummyListener : public IPC::Listener { 859 class ListenerThatWaitsForConnect : public IPC::Listener {
869 public: 860 public:
861 explicit ListenerThatWaitsForConnect(const base::Closure& connect_handler)
862 : connect_handler_(connect_handler) {}
863
870 // IPC::Listener 864 // IPC::Listener
871 bool OnMessageReceived(const IPC::Message& message) override { return true; } 865 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_;
872 }; 870 };
873 871
874 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ProxyThreadAssociatedInterfaceClient, 872 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ProxyThreadAssociatedInterfaceClient,
875 ChannelProxyClient) { 873 ChannelProxyClient) {
876 DummyListener listener; 874 base::RunLoop connect_loop;
875 ListenerThatWaitsForConnect listener(connect_loop.QuitClosure());
877 CreateProxy(&listener); 876 CreateProxy(&listener);
878 RunProxy(); 877 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();
894 } 892 }
895 893
896 #if defined(OS_POSIX) 894 #if defined(OS_POSIX)
897 895
898 class ListenerThatExpectsFile : public IPC::Listener { 896 class ListenerThatExpectsFile : public IPC::Listener {
899 public: 897 public:
900 ListenerThatExpectsFile() : sender_(NULL) {} 898 ListenerThatExpectsFile() : sender_(NULL) {}
901 899
902 ~ListenerThatExpectsFile() override {} 900 ~ListenerThatExpectsFile() override {}
903 901
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 Connect(&listener); 1046 Connect(&listener);
1049 1047
1050 base::MessageLoop::current()->Run(); 1048 base::MessageLoop::current()->Run();
1051 1049
1052 Close(); 1050 Close();
1053 } 1051 }
1054 1052
1055 #endif // OS_LINUX 1053 #endif // OS_LINUX
1056 1054
1057 } // namespace 1055 } // 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