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

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

Issue 2778953003: media: Add RunOnDestruction
Patch Set: Created 3 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
« no previous file with comments | « mojo/public/cpp/bindings/tests/BUILD.gn ('k') | mojo/public/interfaces/bindings/tests/sample_service.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/tests/binding_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/binding_unittest.cc b/mojo/public/cpp/bindings/tests/binding_unittest.cc
index e76993bb68ddeff3508a202975a631f171f2b4ef..bd3a7e3f61f8024840fea44690c6a112b78246b9 100644
--- a/mojo/public/cpp/bindings/tests/binding_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/binding_unittest.cc
@@ -21,6 +21,8 @@
#include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "media/base/run_on_destruction.h"
+
namespace mojo {
namespace {
@@ -55,8 +57,12 @@ class ServiceImpl : public sample::Service {
callback.Run(1);
}
void GetPort(InterfaceRequest<sample::Port> port) override {}
+ void EatCallback(const EatCallbackCallback& callback) override {
+ eat_callback_ = callback;
+ }
bool* const was_deleted_;
+ EatCallbackCallback eat_callback_;
DISALLOW_COPY_AND_ASSIGN(ServiceImpl);
};
@@ -77,6 +83,11 @@ base::Callback<void(Args...)> SetFlagAndRunClosure(
return base::Bind(&DoSetFlagAndRunClosure<Args...>, flag, callback);
}
+void OnResult(bool* result_storage, bool result) {
+ LOG(ERROR) << __func__ << ": " << result;
+ *result_storage = result;
+}
+
// BindingTest -----------------------------------------------------------------
using BindingTest = BindingTestBase;
@@ -107,15 +118,18 @@ TEST_F(BindingTest, DestroyClosesMessagePipe) {
ptr.set_connection_error_handler(
SetFlagAndRunClosure(&encountered_error, run_loop.QuitClosure()));
bool called = false;
+ bool result = false;
base::RunLoop run_loop2;
{
Binding<sample::Service> binding(&impl, std::move(request));
ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr,
SetFlagAndRunClosure<int32_t>(&called,
run_loop2.QuitClosure()));
+ ptr->EatCallback(media::RunOnDestruction(base::Bind(&OnResult, &result), true));
run_loop2.Run();
EXPECT_TRUE(called);
EXPECT_FALSE(encountered_error);
+ EXPECT_FALSE(result);
}
// Now that the Binding is out of scope we should detect an error on the other
// end of the pipe.
@@ -129,6 +143,7 @@ TEST_F(BindingTest, DestroyClosesMessagePipe) {
run_loop2.QuitClosure()));
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(called);
+ EXPECT_TRUE(result);
}
// Tests that the binding's connection error handler gets called when the other
« no previous file with comments | « mojo/public/cpp/bindings/tests/BUILD.gn ('k') | mojo/public/interfaces/bindings/tests/sample_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698