| 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 f368dfcc78fd64523af2d405f12cb4444939441b..e8ffc95b3eaa7d9b3dad66f95d0ee6db51d1ff36 100644
|
| --- a/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc
|
| +++ b/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc
|
| @@ -19,6 +19,7 @@
|
| #include "mojo/public/cpp/bindings/associated_interface_request.h"
|
| #include "mojo/public/cpp/bindings/binding.h"
|
| #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
|
| +#include "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.h"
|
| #include "mojo/public/interfaces/bindings/tests/test_associated_interfaces.mojom.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -582,6 +583,77 @@ TEST_F(AssociatedInterfaceTest, BindingWaitAndPauseWhenNoAssociatedInterfaces) {
|
| EXPECT_TRUE(connection.binding()->HasAssociatedInterfaces());
|
| }
|
|
|
| +class SingleMethodImpl : public sample::SingleMethod {
|
| + public:
|
| + explicit SingleMethodImpl(const Closure& on_call,
|
| + sample::SingleMethodAssociatedRequest request)
|
| + : on_call_(on_call), binding_(this, std::move(request)) {
|
| + }
|
| + ~SingleMethodImpl() override {}
|
| +
|
| + void set_connection_error_handler(const Closure& handler) {
|
| + binding_.set_connection_error_handler(handler);
|
| + }
|
| +
|
| + private:
|
| + // sample::SingleMethod:
|
| + void Call() override { on_call_.Run(); }
|
| +
|
| + const Closure on_call_;
|
| + AssociatedBinding<SingleMethod> binding_;
|
| +};
|
| +
|
| +class SingleMethodVendorImpl : public sample::SingleMethodVendor {
|
| + public:
|
| + SingleMethodVendorImpl(sample::SingleMethodVendorRequest request)
|
| + : binding_(this, std::move(request)) {
|
| + binding_.SetAllowSyncDispatch(true);
|
| + }
|
| + ~SingleMethodVendorImpl() override {}
|
| +
|
| + void SetCallerCallback(const Closure& callback) {
|
| + caller_callback_ = callback;
|
| + }
|
| +
|
| + void GetCaller(sample::SingleMethodAssociatedRequest request) override {
|
| + SingleMethodImpl* impl =
|
| + new SingleMethodImpl(caller_callback_, std::move(request));
|
| + impl->set_connection_error_handler([impl] { delete impl; });
|
| + }
|
| +
|
| + private:
|
| + Binding<SingleMethodVendor> binding_;
|
| + Closure caller_callback_;
|
| +};
|
| +
|
| +TEST_F(AssociatedInterfaceTest, SyncDispatch) {
|
| + sample::SingleMethodVendorPtr ptr;
|
| + SingleMethodVendorImpl vendor(GetProxy(&ptr));
|
| +
|
| + bool called1 = false, called2 = false;
|
| + sample::SingleMethodAssociatedPtr caller1, caller2;
|
| +
|
| + vendor.SetCallerCallback([&called1] {
|
| + EXPECT_FALSE(called1);
|
| + called1 = true;
|
| + });
|
| + ptr->GetCaller(GetProxy(&caller1, ptr.associated_group()));
|
| + vendor.SetCallerCallback([&called2] {
|
| + EXPECT_FALSE(called2);
|
| + called2 = true;
|
| + });
|
| + ptr->GetCaller(GetProxy(&caller2, ptr.associated_group()));
|
| +
|
| + caller1->Call();
|
| + caller2->Call();
|
| +
|
| + EXPECT_TRUE(called1);
|
| + EXPECT_TRUE(called2);
|
| +
|
| + caller1.reset();
|
| + caller2.reset();
|
| +}
|
| +
|
| } // namespace
|
| } // namespace test
|
| } // namespace mojo
|
|
|