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

Unified Diff: mojo/common/message_pump_mojo_unittest.cc

Issue 663873002: Add the ability to observe MessagePumpMojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 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/common/message_pump_mojo.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/message_pump_mojo_unittest.cc
diff --git a/mojo/common/message_pump_mojo_unittest.cc b/mojo/common/message_pump_mojo_unittest.cc
index d552942c8c42b7407d3201ed35cd21b83716b4d4..f34013250853b5eb77adc8af0759a799d39ce44f 100644
--- a/mojo/common/message_pump_mojo_unittest.cc
+++ b/mojo/common/message_pump_mojo_unittest.cc
@@ -47,6 +47,19 @@ class CountingMojoHandler : public MessagePumpMojoHandler {
DISALLOW_COPY_AND_ASSIGN(CountingMojoHandler);
};
+class CountingObserver : public MessagePumpMojo::Observer {
+ public:
+ virtual void WillSignalHandler() override {
+ will_signal_handler_count++;
+ }
+ virtual void DidSignalHandler() override {
+ did_signal_handler_count++;
+ }
+
+ int will_signal_handler_count = 0;
+ int did_signal_handler_count = 0;
+};
+
TEST(MessagePumpMojo, RunUntilIdle) {
base::MessageLoop message_loop(MessagePumpMojo::Create());
CountingMojoHandler handler;
@@ -64,6 +77,36 @@ TEST(MessagePumpMojo, RunUntilIdle) {
EXPECT_EQ(2, handler.success_count());
}
+TEST(MessagePumpMojo, Observer) {
+ base::MessageLoop message_loop(MessagePumpMojo::Create());
+
+ CountingObserver observer;
+ MessagePumpMojo::current()->AddObserver(&observer);
+
+ CountingMojoHandler handler;
+ MessagePipe handles;
+ MessagePumpMojo::current()->AddHandler(&handler,
+ handles.handle0.get(),
+ MOJO_HANDLE_SIGNAL_READABLE,
+ base::TimeTicks());
+ WriteMessageRaw(
+ handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
+ base::RunLoop run_loop;
+ run_loop.RunUntilIdle();
+ EXPECT_EQ(1, handler.success_count());
+ EXPECT_EQ(1, observer.will_signal_handler_count);
+ EXPECT_EQ(1, observer.did_signal_handler_count);
+ MessagePumpMojo::current()->RemoveObserver(&observer);
+
+ WriteMessageRaw(
+ handles.handle1.get(), NULL, 0, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
+ base::RunLoop run_loop2;
+ run_loop2.RunUntilIdle();
+ EXPECT_EQ(2, handler.success_count());
+ EXPECT_EQ(1, observer.will_signal_handler_count);
+ EXPECT_EQ(1, observer.did_signal_handler_count);
+}
+
TEST(MessagePumpMojo, UnregisterAfterDeadline) {
base::MessageLoop message_loop(MessagePumpMojo::Create());
CountingMojoHandler handler;
« no previous file with comments | « mojo/common/message_pump_mojo.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698