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

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

Issue 2729133004: Mojo C++ bindings: keep connection error handler on the stack while running it. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/interface_endpoint_client.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
index fb602f596f45c0538f072d6365236a0906a80cee..431a84425076dbd97dfb612a3501ee41b937e11e 100644
--- a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
@@ -795,7 +795,7 @@ TEST_F(InterfacePtrTest, InterfaceRequestResetWithReason) {
run_loop.Run();
}
-TEST_F(InterfacePtrTest, CallbackOwnsInterfacePtr) {
+TEST_F(InterfacePtrTest, CallbackIsPassedInterfacePtr) {
sample::PingTestPtr ptr;
sample::PingTestRequest request(&ptr);
@@ -814,6 +814,28 @@ TEST_F(InterfacePtrTest, CallbackOwnsInterfacePtr) {
run_loop.Run();
}
+TEST_F(InterfacePtrTest, ConnectionErrorHandlerOwnsInterfacePtr) {
+ sample::PingTestPtr* ptr = new sample::PingTestPtr;
+ sample::PingTestRequest request(ptr);
+
+ base::RunLoop run_loop;
+
+ // Make a call with |ptr|'s lifetime bound to the connection error handler
+ // callback.
+ ptr->set_connection_error_handler(base::Bind(
+ [](const base::Closure& quit, sample::PingTestPtr* ptr) {
+ ptr->reset();
+ quit.Run();
+ },
+ run_loop.QuitClosure(), base::Owned(ptr)));
+
+ // Trigger an error on |ptr|. In the error handler |ptr| is reset. This
+ // shouldn't immediately destroy the callback (and |ptr| that it owns), before
+ // the callback is completed.
+ request.PassMessagePipe();
+ run_loop.Run();
+}
+
TEST_F(InterfacePtrTest, ThreadSafeInterfacePointer) {
math::CalculatorPtr ptr;
MathCalculatorImpl calc_impl(MakeRequest(&ptr));
« no previous file with comments | « mojo/public/cpp/bindings/lib/interface_endpoint_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698