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

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

Issue 1552983003: Fix a bunch of mojo_public_*_unittests with the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 12 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/binding_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/binding_unittest.cc b/mojo/public/cpp/bindings/tests/binding_unittest.cc
index 91002a4503cb21edd7a4be87067596d182fad31e..e3741bb07e96ed495184f858e56109b8f2519b9c 100644
--- a/mojo/public/cpp/bindings/tests/binding_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/binding_unittest.cc
@@ -11,6 +11,7 @@
#include <utility>
#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/macros.h"
@@ -66,13 +67,17 @@ TEST_F(BindingTest, Close) {
bool called = false;
sample::ServicePtr ptr;
auto request = GetProxy(&ptr);
- ptr.set_connection_error_handler([&called]() { called = true; });
+ base::RunLoop run_loop;
+ ptr.set_connection_error_handler([&called, &run_loop]() {
+ called = true;
+ run_loop.Quit();
+ });
ServiceImpl impl;
Binding<sample::Service> binding(&impl, std::move(request));
binding.Close();
EXPECT_FALSE(called);
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(called);
}
@@ -82,21 +87,29 @@ TEST_F(BindingTest, DestroyClosesMessagePipe) {
ServiceImpl impl;
sample::ServicePtr ptr;
auto request = GetProxy(&ptr);
+ base::RunLoop run_loop;
ptr.set_connection_error_handler(
- [&encountered_error]() { encountered_error = true; });
+ [&encountered_error, &run_loop]() {
+ encountered_error = true;
+ run_loop.Quit();
+ });
bool called = false;
- auto called_cb = [&called](int32_t result) { called = true; };
+ base::RunLoop run_loop2;
+ auto called_cb = [&called, &run_loop2](int32_t result) {
+ called = true;
+ run_loop2.Quit();
+ };
{
Binding<sample::Service> binding(&impl, std::move(request));
ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr,
called_cb);
- loop().RunUntilIdle();
+ run_loop2.Run();
EXPECT_TRUE(called);
EXPECT_FALSE(encountered_error);
}
// Now that the Binding is out of scope we should detect an error on the other
// end of the pipe.
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(encountered_error);
// And calls should fail.
@@ -115,10 +128,14 @@ TEST_F(BindingTest, ConnectionError) {
ServiceImpl impl;
sample::ServicePtr ptr;
Binding<sample::Service> binding(&impl, GetProxy(&ptr));
- binding.set_connection_error_handler([&called]() { called = true; });
+ base::RunLoop run_loop;
+ binding.set_connection_error_handler([&called, &run_loop]() {
+ called = true;
+ run_loop.Quit();
+ });
ptr.reset();
EXPECT_FALSE(called);
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(called);
// We want to make sure that it isn't called again during destruction.
called = false;
@@ -148,13 +165,21 @@ TEST_F(BindingTest, CloseDoesntCallConnectionErrorHandler) {
class ServiceImplWithBinding : public ServiceImpl {
public:
ServiceImplWithBinding(bool* was_deleted,
+ const base::Closure& closure,
InterfaceRequest<sample::Service> request)
- : ServiceImpl(was_deleted), binding_(this, std::move(request)) {
+ : ServiceImpl(was_deleted),
+ binding_(this, std::move(request)),
+ closure_(closure) {
binding_.set_connection_error_handler([this]() { delete this; });
}
private:
+ ~ServiceImplWithBinding() override{
+ closure_.Run();
+ }
+
Binding<sample::Service> binding_;
+ base::Closure closure_;
MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceImplWithBinding);
};
@@ -164,10 +189,12 @@ TEST_F(BindingTest, SelfDeleteOnConnectionError) {
bool was_deleted = false;
sample::ServicePtr ptr;
// This should delete itself on connection error.
- new ServiceImplWithBinding(&was_deleted, GetProxy(&ptr));
+ base::RunLoop run_loop;
+ new ServiceImplWithBinding(&was_deleted, run_loop.QuitClosure(),
+ GetProxy(&ptr));
ptr.reset();
EXPECT_FALSE(was_deleted);
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(was_deleted);
}
@@ -178,10 +205,14 @@ TEST_F(BindingTest, Unbind) {
Binding<sample::Service> binding(&impl, GetProxy(&ptr));
bool called = false;
- auto called_cb = [&called](int32_t result) { called = true; };
+ base::RunLoop run_loop;
+ auto called_cb = [&called, &run_loop](int32_t result) {
+ called = true;
+ run_loop.Quit();
+ };
ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr,
called_cb);
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(called);
called = false;
@@ -197,9 +228,14 @@ TEST_F(BindingTest, Unbind) {
binding.Bind(std::move(request));
EXPECT_TRUE(binding.is_bound());
// ...and should succeed again when the rebound.
+ base::RunLoop run_loop2;
+ auto called_cb2 = [&called, &run_loop2](int32_t result) {
+ called = true;
+ run_loop2.Quit();
+ };
ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr,
- called_cb);
- loop().RunUntilIdle();
+ called_cb2);
+ run_loop2.Run();
EXPECT_TRUE(called);
}
@@ -227,7 +263,11 @@ TEST_F(BindingTest, SetInterfacePtrVersion) {
TEST_F(BindingTest, PauseResume) {
bool called = false;
- auto called_cb = [&called](int32_t result) { called = true; };
+ base::RunLoop run_loop;
+ auto called_cb = [&called, &run_loop](int32_t result) {
+ called = true;
+ run_loop.Quit();
+ };
sample::ServicePtr ptr;
auto request = GetProxy(&ptr);
ServiceImpl impl;
@@ -242,18 +282,22 @@ TEST_F(BindingTest, PauseResume) {
// Resume the binding, which should trigger processing.
binding.ResumeIncomingMethodCallProcessing();
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(called);
}
// Verifies the connection error handler is not run while a binding is paused.
TEST_F(BindingTest, ErrorHandleNotRunWhilePaused) {
bool called = false;
+ base::RunLoop run_loop;
sample::ServicePtr ptr;
auto request = GetProxy(&ptr);
ServiceImpl impl;
Binding<sample::Service> binding(&impl, std::move(request));
- binding.set_connection_error_handler([&called]() { called = true; });
+ binding.set_connection_error_handler([&called, &run_loop]() {
+ called = true;
+ run_loop.Quit();
+ });
binding.PauseIncomingMethodCallProcessing();
ptr.reset();
@@ -263,7 +307,7 @@ TEST_F(BindingTest, ErrorHandleNotRunWhilePaused) {
// Resume the binding, which should trigger the error handler.
binding.ResumeIncomingMethodCallProcessing();
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(called);
}
@@ -274,26 +318,34 @@ using StrongBindingTest = BindingTestBase;
// Tests that destroying a mojo::StrongBinding closes the bound message pipe
// handle but does *not* destroy the implementation object.
TEST_F(StrongBindingTest, DestroyClosesMessagePipe) {
+ base::RunLoop run_loop;
bool encountered_error = false;
bool was_deleted = false;
ServiceImpl impl(&was_deleted);
sample::ServicePtr ptr;
auto request = GetProxy(&ptr);
ptr.set_connection_error_handler(
- [&encountered_error]() { encountered_error = true; });
+ [&encountered_error, &run_loop]() {
+ encountered_error = true;
+ run_loop.Quit();
+ });
bool called = false;
- auto called_cb = [&called](int32_t result) { called = true; };
+ base::RunLoop run_loop2;
+ auto called_cb = [&called, &run_loop2](int32_t result) {
+ called = true;
+ run_loop2.Quit();
+ };
{
StrongBinding<sample::Service> binding(&impl, std::move(request));
ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr,
called_cb);
- loop().RunUntilIdle();
+ run_loop2.Run();
EXPECT_TRUE(called);
EXPECT_FALSE(encountered_error);
}
// Now that the StrongBinding is out of scope we should detect an error on the
// other end of the pipe.
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(encountered_error);
// But destroying the StrongBinding doesn't destroy the object.
ASSERT_FALSE(was_deleted);
@@ -319,14 +371,16 @@ TEST_F(StrongBindingTest, ConnectionErrorDestroysImpl) {
sample::ServicePtr ptr;
bool was_deleted = false;
// Will delete itself.
- new ServiceImplWithBinding(&was_deleted, GetProxy(&ptr));
+ base::RunLoop run_loop;
+ new ServiceImplWithBinding(&was_deleted, run_loop.QuitClosure(),
+ GetProxy(&ptr));
loop().RunUntilIdle();
EXPECT_FALSE(was_deleted);
ptr.reset();
EXPECT_FALSE(was_deleted);
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(was_deleted);
}
@@ -338,8 +392,12 @@ TEST_F(StrongBindingTest, ExplicitDeleteImpl) {
bool ptr_error_handler_called = false;
sample::ServicePtr ptr;
auto request = GetProxy(&ptr);
+ base::RunLoop run_loop;
ptr.set_connection_error_handler(
- [&ptr_error_handler_called]() { ptr_error_handler_called = true; });
+ [&ptr_error_handler_called, &run_loop]() {
+ ptr_error_handler_called = true;
+ run_loop.Quit();
+ });
bool was_deleted = false;
ServiceImplWithStrongBinding* impl =
new ServiceImplWithStrongBinding(&was_deleted, std::move(request));
@@ -357,7 +415,7 @@ TEST_F(StrongBindingTest, ExplicitDeleteImpl) {
EXPECT_FALSE(ptr_error_handler_called);
EXPECT_TRUE(was_deleted);
was_deleted = false; // It shouldn't be double-deleted!
- loop().RunUntilIdle();
+ run_loop.Run();
EXPECT_TRUE(ptr_error_handler_called);
EXPECT_FALSE(was_deleted);
« no previous file with comments | « mojo/public/cpp/bindings/tests/binding_callback_unittest.cc ('k') | mojo/public/cpp/bindings/tests/connector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698