diff options
Diffstat (limited to 'jingle')
-rw-r--r-- | jingle/glue/thread_wrapper.cc | 2 | ||||
-rw-r--r-- | jingle/glue/thread_wrapper_unittest.cc | 20 |
2 files changed, 16 insertions, 6 deletions
diff --git a/jingle/glue/thread_wrapper.cc b/jingle/glue/thread_wrapper.cc index fe26094..979064b 100644 --- a/jingle/glue/thread_wrapper.cc +++ b/jingle/glue/thread_wrapper.cc @@ -30,6 +30,7 @@ JingleThreadWrapper::JingleThreadWrapper(MessageLoop* message_loop) DCHECK_EQ(message_loop_, MessageLoop::current()); talk_base::ThreadManager::SetCurrent(this); + talk_base::MessageQueueManager::Instance()->Add(this); message_loop_->AddDestructionObserver(this); } @@ -38,6 +39,7 @@ JingleThreadWrapper::~JingleThreadWrapper() { void JingleThreadWrapper::WillDestroyCurrentMessageLoop() { talk_base::ThreadManager::SetCurrent(NULL); + talk_base::MessageQueueManager::Instance()->Remove(this); message_loop_->RemoveDestructionObserver(this); delete this; } diff --git a/jingle/glue/thread_wrapper_unittest.cc b/jingle/glue/thread_wrapper_unittest.cc index 18f8bb4..042970e 100644 --- a/jingle/glue/thread_wrapper_unittest.cc +++ b/jingle/glue/thread_wrapper_unittest.cc @@ -35,20 +35,15 @@ class ThreadWrapperTest : public testing::Test { } virtual void SetUp() OVERRIDE { - wrapper_ = new JingleThreadWrapper(&message_loop_); + JingleThreadWrapper::EnsureForCurrentThread(); } // ThreadWrapper destroyes itself when |message_loop_| is destroyed. - JingleThreadWrapper* wrapper_; MessageLoop message_loop_; MockMessageHandler handler1_; MockMessageHandler handler2_; }; -TEST_F(ThreadWrapperTest, Create) { - EXPECT_EQ(thread(), static_cast<talk_base::Thread*>(wrapper_)); -} - MATCHER_P3(MatchMessageAndDeleteData, handler, message_id, data, "") { delete arg->pdata; return arg->phandler == handler && @@ -156,4 +151,17 @@ TEST_F(ThreadWrapperTest, ClearDelayed) { message_loop_.Run(); } +// Verify that the queue is cleared when a handler is destroyed. +TEST_F(ThreadWrapperTest, ClearDestoroyed) { + MockMessageHandler* handler_ptr; + { + MockMessageHandler handler; + handler_ptr = &handler; + thread()->Post(&handler, kTestMessage1, NULL); + } + talk_base::MessageList removed; + thread()->Clear(handler_ptr, talk_base::MQID_ANY, &removed); + DCHECK_EQ(0U, removed.size()); +} + } // namespace jingle_glue |