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

Unified Diff: mojo/public/cpp/bindings/tests/associated_interface_unittest.cc

Issue 1811433002: [mojo-edk] Expose notification source to MojoWatch callbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
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..80f82402881c6dc669ac880df93b0578d284b046 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,
yzshen1 2016/03/16 18:31:33 nit: explicit is not needed here, but needed on li
+ 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_.EnableImmediateDispatchOfEventsFromSameThread(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

Powered by Google App Engine
This is Rietveld 408576698