Index: mojo/public/cpp/bindings/tests/request_response_unittest.cc |
diff --git a/mojo/public/cpp/bindings/tests/request_response_unittest.cc b/mojo/public/cpp/bindings/tests/request_response_unittest.cc |
index fa4ffa186960edfac85d6e396426170deb319a30..85d2fd42aca9d8d1e3b0bfc602b500531fa75d61 100644 |
--- a/mojo/public/cpp/bindings/tests/request_response_unittest.cc |
+++ b/mojo/public/cpp/bindings/tests/request_response_unittest.cc |
@@ -6,6 +6,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/binding.h" |
#include "mojo/public/cpp/test_support/test_utils.h" |
@@ -56,34 +57,48 @@ class ProviderImpl : public sample::Provider { |
class StringRecorder { |
public: |
- explicit StringRecorder(std::string* buf) : buf_(buf) {} |
- void Run(const String& a) const { *buf_ = a; } |
+ StringRecorder(std::string* buf, const base::Closure& closure) |
+ : buf_(buf), closure_(closure) {} |
+ void Run(const String& a) const { |
+ *buf_ = a; |
+ closure_.Run(); |
+ } |
void Run(const String& a, const String& b) const { |
*buf_ = a.get() + b.get(); |
+ closure_.Run(); |
} |
private: |
std::string* buf_; |
+ base::Closure closure_; |
}; |
class EnumRecorder { |
public: |
- explicit EnumRecorder(sample::Enum* value) : value_(value) {} |
- void Run(sample::Enum a) const { *value_ = a; } |
+ explicit EnumRecorder(sample::Enum* value, const base::Closure& closure) |
+ : value_(value), closure_(closure) {} |
+ void Run(sample::Enum a) const { |
+ *value_ = a; |
+ closure_.Run(); |
+ } |
private: |
sample::Enum* value_; |
+ base::Closure closure_; |
}; |
class MessagePipeWriter { |
public: |
- explicit MessagePipeWriter(const char* text) : text_(text) {} |
+ MessagePipeWriter(const char* text, const base::Closure& closure) |
+ : text_(text), closure_(closure) {} |
void Run(ScopedMessagePipeHandle handle) const { |
WriteTextMessage(handle.get(), text_); |
+ closure_.Run(); |
} |
private: |
std::string text_; |
+ base::Closure closure_; |
}; |
class RequestResponseTest : public testing::Test { |
@@ -102,9 +117,11 @@ TEST_F(RequestResponseTest, EchoString) { |
ProviderImpl provider_impl(GetProxy(&provider)); |
std::string buf; |
- provider->EchoString(String::From("hello"), StringRecorder(&buf)); |
+ base::RunLoop run_loop; |
+ provider->EchoString(String::From("hello"), |
+ StringRecorder(&buf, run_loop.QuitClosure())); |
- PumpMessages(); |
+ run_loop.Run(); |
EXPECT_EQ(std::string("hello"), buf); |
} |
@@ -114,10 +131,12 @@ TEST_F(RequestResponseTest, EchoStrings) { |
ProviderImpl provider_impl(GetProxy(&provider)); |
std::string buf; |
+ base::RunLoop run_loop; |
provider->EchoStrings( |
- String::From("hello"), String::From(" world"), StringRecorder(&buf)); |
+ String::From("hello"), String::From(" world"), |
+ StringRecorder(&buf, run_loop.QuitClosure())); |
- PumpMessages(); |
+ run_loop.Run(); |
EXPECT_EQ(std::string("hello world"), buf); |
} |
@@ -127,10 +146,12 @@ TEST_F(RequestResponseTest, EchoMessagePipeHandle) { |
ProviderImpl provider_impl(GetProxy(&provider)); |
MessagePipe pipe2; |
- provider->EchoMessagePipeHandle(std::move(pipe2.handle1), |
- MessagePipeWriter("hello")); |
+ base::RunLoop run_loop; |
+ provider->EchoMessagePipeHandle( |
+ std::move(pipe2.handle1), |
+ MessagePipeWriter("hello", run_loop.QuitClosure())); |
- PumpMessages(); |
+ run_loop.Run(); |
std::string value; |
ReadTextMessage(pipe2.handle0.get(), &value); |
@@ -143,9 +164,11 @@ TEST_F(RequestResponseTest, EchoEnum) { |
ProviderImpl provider_impl(GetProxy(&provider)); |
sample::Enum value; |
- provider->EchoEnum(sample::ENUM_VALUE, EnumRecorder(&value)); |
+ base::RunLoop run_loop; |
+ provider->EchoEnum(sample::ENUM_VALUE, |
+ EnumRecorder(&value, run_loop.QuitClosure())); |
- PumpMessages(); |
+ run_loop.Run(); |
EXPECT_EQ(sample::ENUM_VALUE, value); |
} |