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

Unified Diff: base/message_loop/message_pump_libevent_unittest.cc

Issue 245923005: libeven message-pump: Fix a particular case of nested message-loop runs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change-string Created 6 years, 8 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 | « base/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: base/message_loop/message_pump_libevent_unittest.cc
diff --git a/base/message_loop/message_pump_libevent_unittest.cc b/base/message_loop/message_pump_libevent_unittest.cc
index 4530e188179308c0b0d75ef897e4aefda5ac147a..9298d687609cff87a05f43f1a1c55e728ef8fb5a 100644
--- a/base/message_loop/message_pump_libevent_unittest.cc
+++ b/base/message_loop/message_pump_libevent_unittest.cc
@@ -6,8 +6,10 @@
#include <unistd.h>
+#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/posix/eintr_wrapper.h"
+#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libevent/event.h"
@@ -81,6 +83,12 @@ TEST_F(MessagePumpLibeventTest, TestWatchingFromBadThread) {
"watch_file_descriptor_caller_checker_.CalledOnValidThread\\(\\)");
}
+TEST_F(MessagePumpLibeventTest, QuitOutsideOfRun) {
+ scoped_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
+ ASSERT_DEATH(pump->Quit(), "Check failed: in_run_. "
+ "Quit was called outside of Run!");
+}
+
#endif // GTEST_HAS_DEATH_TEST && !defined(NDEBUG)
class BaseWatcher : public MessagePumpLibevent::Watcher {
@@ -157,6 +165,41 @@ TEST_F(MessagePumpLibeventTest, StopWatcher) {
OnLibeventNotification(pump.get(), &watcher);
}
+void QuitMessageLoopAndStart(const Closure& quit_closure) {
+ quit_closure.Run();
+
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
+ RunLoop runloop;
+ MessageLoop::current()->PostTask(FROM_HERE, runloop.QuitClosure());
+ runloop.Run();
+}
+
+class NestedPumpWatcher : public MessagePumpLibevent::Watcher {
+ public:
+ NestedPumpWatcher() {}
+ virtual ~NestedPumpWatcher() {}
+
+ virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {
+ RunLoop runloop;
+ MessageLoop::current()->PostTask(FROM_HERE, Bind(&QuitMessageLoopAndStart,
+ runloop.QuitClosure()));
+ runloop.Run();
+ }
+
+ virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {}
+};
+
+TEST_F(MessagePumpLibeventTest, NestedPumpWatcher) {
+ scoped_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
+ MessagePumpLibevent::FileDescriptorWatcher watcher;
+ NestedPumpWatcher delegate;
+ pump->WatchFileDescriptor(pipefds_[1],
+ false, MessagePumpLibevent::WATCH_READ, &watcher, &delegate);
+
+ // Spoof a libevent notification.
+ OnLibeventNotification(pump.get(), &watcher);
+}
+
} // namespace
} // namespace base
« no previous file with comments | « base/message_loop/message_pump_libevent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698