diff options
Diffstat (limited to 'remoting/jingle_glue/jingle_thread_unittest.cc')
-rw-r--r-- | remoting/jingle_glue/jingle_thread_unittest.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/remoting/jingle_glue/jingle_thread_unittest.cc b/remoting/jingle_glue/jingle_thread_unittest.cc index a29b69c..bebb16d 100644 --- a/remoting/jingle_glue/jingle_thread_unittest.cc +++ b/remoting/jingle_glue/jingle_thread_unittest.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include "base/message_loop.h" +#include "base/time.h" +#include "base/waitable_event.h" #include "remoting/jingle_glue/jingle_thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -14,6 +16,13 @@ class MockTask : public Task { MOCK_METHOD0(Run, void()); }; +namespace { +// Delay used to test delayed tasks. Shouldn't be too big, so that we don't +// slow down the test, yet, should be big enough to be measurable. +int kDelayMs = 50; // 0.05 s. +int kDelayTimeoutMs = 10000; // 10 s. +} // namespace + TEST(JingleThreadTest, PostTask) { JingleThread thread; MockTask* task = new MockTask(); @@ -24,4 +33,24 @@ TEST(JingleThreadTest, PostTask) { thread.Stop(); } +ACTION_P(SignalEvent, event) { + event->Signal(); +} + +TEST(JingleThreadTest, PostDelayedTask) { + JingleThread thread; + MockTask* task = new MockTask(); + base::WaitableEvent event(true, false); + EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event)); + + thread.Start(); + base::Time start = base::Time::Now(); + thread.message_loop()->PostDelayedTask(FROM_HERE, task, kDelayMs); + event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs)); + base::Time end = base::Time::Now(); + thread.Stop(); + + EXPECT_GT((end - start).InMillisecondsRoundedUp(), kDelayMs); +} + } // namespace remoting |