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

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

Issue 1576603002: Makes bindings work with nested message loops (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 11 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/message.h ('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/connector_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/connector_unittest.cc b/mojo/public/cpp/bindings/tests/connector_unittest.cc
index 879abfa8a6d7f3876bbe5026ed6c3fb72c968b84..d8da36a72c8ac5321e63f261fb1188ef728c600e 100644
--- a/mojo/public/cpp/bindings/tests/connector_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/connector_unittest.cc
@@ -28,9 +28,11 @@ class MessageAccumulator : public MessageReceiver {
bool Accept(Message* message) override {
queue_.Push(message);
- if (!closure_.is_null())
- closure_.Run();
- closure_.reset();
+ if (!closure_.is_null()) {
+ Closure closure = closure_;
+ closure_.reset();
+ closure.Run();
+ }
return true;
}
@@ -38,9 +40,7 @@ class MessageAccumulator : public MessageReceiver {
void Pop(Message* message) { queue_.Pop(message); }
- void set_closure(const base::Closure& closure) {
- closure_ = closure;
- }
+ void set_closure(const Closure& closure) { closure_ = closure; }
size_t size() const { return queue_.size(); }
@@ -526,6 +526,40 @@ TEST_F(ConnectorTest, PauseWithQueuedMessages) {
ASSERT_EQ(1u, accumulator.size());
}
+TEST_F(ConnectorTest, ProcessWhenNested) {
+ internal::Connector connector0(std::move(handle0_),
+ internal::Connector::SINGLE_THREADED_SEND);
+ internal::Connector connector1(std::move(handle1_),
+ internal::Connector::SINGLE_THREADED_SEND);
+
+ const char kText[] = "hello world";
+
+ Message message;
+ AllocMessage(kText, &message);
+
+ // Queue up two messages.
+ connector0.Accept(&message);
+ connector0.Accept(&message);
+
+ base::RunLoop run_loop;
+ MessageAccumulator accumulator;
+ // When the accumulator gets the first message it spins a nested message
+ // loop. The loop is quit when another message is received.
+ accumulator.set_closure([&accumulator, &connector1, &run_loop]() {
+ base::RunLoop nested_run_loop;
+ base::MessageLoop::ScopedNestableTaskAllower allow(
+ base::MessageLoop::current());
+ accumulator.set_closure([&nested_run_loop]() { nested_run_loop.Quit(); });
+ nested_run_loop.Run();
+ run_loop.Quit();
+ });
+ connector1.set_incoming_receiver(&accumulator);
+
+ run_loop.Run();
+
+ ASSERT_EQ(2u, accumulator.size());
+}
+
} // namespace
} // namespace test
} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/message.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698