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

Unified Diff: message_loop/message_pump_libevent_unittest.cc

Issue 1921183002: Add a mechanism to extend a libevent based message pump. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/domokit/base@master
Patch Set: added test case Created 4 years, 7 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 | « message_loop/message_pump_libevent.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: message_loop/message_pump_libevent_unittest.cc
diff --git a/message_loop/message_pump_libevent_unittest.cc b/message_loop/message_pump_libevent_unittest.cc
index e911905abd7b489b47254a7195f6315701b422e9..16aba35353d2e63c6652659006b25eb01aa2ca80 100644
--- a/message_loop/message_pump_libevent_unittest.cc
+++ b/message_loop/message_pump_libevent_unittest.cc
@@ -271,6 +271,41 @@ TEST_F(MessagePumpLibeventTest, QuitWatcher) {
Owned(watcher.release())));
}
+class FakeEventSource : public MessagePumpLibevent::EventSource {
+ public:
+ FakeEventSource() : work_units_(0u) {}
+ ~FakeEventSource() override {}
+
+ void set_work_units(uint32_t work_units) { work_units_ = work_units; }
+ uint32_t work_units() const { return work_units_; }
+
+ bool Poll() override {
+ if (!work_units_)
+ return false;
+ work_units_--;
+ return true;
+ }
+
+ private:
+ uint32_t work_units_;
+};
+
+TEST_F(MessagePumpLibeventTest, PollEventSource) {
+ FakeEventSource event_source;
+
+ // Verify event source gets polled repeatedly until no work remains.
+ MessageLoopForUI::current()->SetEventSource(&event_source);
+ event_source.set_work_units(5u);
+ ui_loop_->RunUntilIdle();
+ EXPECT_EQ(0u, event_source.work_units());
+
+ // After removing the event source, it should no longer be polled.
+ MessageLoopForUI::current()->ClearEventSource();
+ event_source.set_work_units(5u);
+ ui_loop_->RunUntilIdle();
+ EXPECT_EQ(5u, event_source.work_units());
+}
+
} // namespace
} // namespace base
« no previous file with comments | « message_loop/message_pump_libevent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698