| Index: webrtc/rtc_base/messagequeue_unittest.cc | 
| diff --git a/webrtc/rtc_base/messagequeue_unittest.cc b/webrtc/rtc_base/messagequeue_unittest.cc | 
| index 78bcfcbea9abbf6070285dde1dc73d9f81cb2ccd..e31adf954992740017837696725ff61f12cf090f 100644 | 
| --- a/webrtc/rtc_base/messagequeue_unittest.cc | 
| +++ b/webrtc/rtc_base/messagequeue_unittest.cc | 
| @@ -18,6 +18,8 @@ | 
| #include "webrtc/rtc_base/gunit.h" | 
| #include "webrtc/rtc_base/logging.h" | 
| #include "webrtc/rtc_base/nullsocketserver.h" | 
| +#include "webrtc/rtc_base/refcount.h" | 
| +#include "webrtc/rtc_base/refcountedobject.h" | 
| #include "webrtc/rtc_base/thread.h" | 
| #include "webrtc/rtc_base/timeutils.h" | 
|  | 
| @@ -215,3 +217,32 @@ TEST(MessageQueueManager, ProcessAllMessageQueuesWithClearedQueue) { | 
| rtc::Thread::Current()->Post(RTC_FROM_HERE, &event_signaler); | 
| MessageQueueManager::ProcessAllMessageQueues(); | 
| } | 
| + | 
| +class RefCountedHandler | 
| +  : public MessageHandler, | 
| +    public rtc::RefCountInterface { | 
| + public: | 
| +  void OnMessage(Message* msg) override {} | 
| +}; | 
| + | 
| +class EmptyHandler : public MessageHandler { | 
| + public: | 
| +  void OnMessage(Message* msg) override {} | 
| +}; | 
| + | 
| +TEST(MessageQueueManager, ClearReentrant) { | 
| +  Thread t; | 
| +  EmptyHandler handler; | 
| +  RefCountedHandler* inner_handler( | 
| +      new rtc::RefCountedObject<RefCountedHandler>()); | 
| +  // When the empty handler is destroyed, it will clear messages queued for | 
| +  // itself. The message to be cleared itself wraps a MessageHandler object | 
| +  // (RefCountedHandler) so this will cause the message queue to be cleared | 
| +  // again in a re-entrant fashion, which previously triggered a DCHECK. | 
| +  // The inner handler will be removed in a re-entrant fashion from the | 
| +  // message queue of the thread while the outer handler is removed, verifying | 
| +  // that the iterator is not invalidated in "MessageQueue::Clear". | 
| +  t.Post(RTC_FROM_HERE, inner_handler, 0); | 
| +  t.Post(RTC_FROM_HERE, &handler, 0, | 
| +      new ScopedRefMessageData<RefCountedHandler>(inner_handler)); | 
| +} | 
|  |