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

Unified Diff: mojo/public/cpp/bindings/tests/request_response_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/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);
}
« no previous file with comments | « mojo/public/cpp/bindings/tests/multiplex_router_unittest.cc ('k') | mojo/public/cpp/bindings/tests/router_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698