Index: mojo/public/cpp/bindings/tests/associated_interface_unittest.cc |
diff --git a/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc b/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc |
index d3686ec0f62f85e5e6128fdaa101c3206987ec6a..3ba9941e895d6ed6b986010c6dd6e05773573226 100644 |
--- a/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc |
+++ b/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc |
@@ -56,6 +56,33 @@ class IntegerSenderImpl : public IntegerSender { |
base::Callback<void(int32_t)> notify_send_method_called_; |
}; |
+class IntegerSenderConnectionImpl : public IntegerSenderConnection { |
+ public: |
+ explicit IntegerSenderConnectionImpl( |
+ InterfaceRequest<IntegerSenderConnection> request) |
+ : binding_(this, request.Pass()) {} |
+ |
+ ~IntegerSenderConnectionImpl() override {} |
+ |
+ void GetSender(AssociatedInterfaceRequest<IntegerSender> sender) override { |
+ IntegerSenderImpl* sender_impl = new IntegerSenderImpl(sender.Pass()); |
+ sender_impl->set_connection_error_handler( |
+ [sender_impl]() { delete sender_impl; }); |
+ } |
+ |
+ void AsyncGetSender(const AsyncGetSenderCallback& callback) override { |
+ AssociatedInterfaceRequest<IntegerSender> request; |
+ AssociatedInterfacePtrInfo<IntegerSender> ptr_info; |
+ binding_.associated_group()->CreateAssociatedInterface( |
+ AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); |
+ GetSender(request.Pass()); |
+ callback.Run(ptr_info.Pass()); |
+ } |
+ |
+ private: |
+ Binding<IntegerSenderConnection> binding_; |
+}; |
+ |
class AssociatedInterfaceTest : public testing::Test { |
public: |
AssociatedInterfaceTest() : loop_(common::MessagePumpMojo::Create()) {} |
@@ -446,6 +473,32 @@ TEST_F(AssociatedInterfaceTest, FIFO) { |
} |
} |
+TEST_F(AssociatedInterfaceTest, PassAssociatedInterfaces) { |
+ IntegerSenderConnectionPtr connection_ptr; |
+ IntegerSenderConnectionImpl connection(GetProxy(&connection_ptr)); |
+ |
+ AssociatedInterfacePtr<IntegerSender> sender0; |
+ connection_ptr->GetSender( |
+ GetProxy(&sender0, connection_ptr.associated_group())); |
+ |
+ int32_t echoed_value = 0; |
+ sender0->Echo(123, [&echoed_value](int32_t value) { echoed_value = value; }); |
+ PumpMessages(); |
+ EXPECT_EQ(123, echoed_value); |
+ |
+ AssociatedInterfacePtr<IntegerSender> sender1; |
+ connection_ptr->AsyncGetSender( |
+ [&sender1](AssociatedInterfacePtrInfo<IntegerSender> ptr_info) { |
+ sender1.Bind(ptr_info.Pass()); |
+ }); |
+ PumpMessages(); |
+ EXPECT_TRUE(sender1); |
+ |
+ sender1->Echo(456, [&echoed_value](int32_t value) { echoed_value = value; }); |
+ PumpMessages(); |
+ EXPECT_EQ(456, echoed_value); |
+} |
+ |
} // namespace |
} // namespace test |
} // namespace mojo |