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

Side by Side Diff: remoting/jingle_glue/jingle_thread_unittest.cc

Issue 3333014: Delayed event support in JingleThread. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: - Created 10 years, 3 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 unified diff | Download patch
« no previous file with comments | « remoting/jingle_glue/jingle_thread.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/time.h"
7 #include "base/waitable_event.h"
6 #include "remoting/jingle_glue/jingle_thread.h" 8 #include "remoting/jingle_glue/jingle_thread.h"
7 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 11
10 namespace remoting { 12 namespace remoting {
11 13
12 class MockTask : public Task { 14 class MockTask : public Task {
13 public: 15 public:
14 MOCK_METHOD0(Run, void()); 16 MOCK_METHOD0(Run, void());
15 }; 17 };
16 18
19 namespace {
20 // Delay used to test delayed tasks. Shouldn't be too big, so that we don't
21 // slow down the test, yet, should be big enough to be measurable.
22 int kDelayMs = 50; // 0.05 s.
23 int kDelayTimeoutMs = 10000; // 10 s.
24 } // namespace
25
17 TEST(JingleThreadTest, PostTask) { 26 TEST(JingleThreadTest, PostTask) {
18 JingleThread thread; 27 JingleThread thread;
19 MockTask* task = new MockTask(); 28 MockTask* task = new MockTask();
20 EXPECT_CALL(*task, Run()); 29 EXPECT_CALL(*task, Run());
21 30
22 thread.Start(); 31 thread.Start();
23 thread.message_loop()->PostTask(FROM_HERE, task); 32 thread.message_loop()->PostTask(FROM_HERE, task);
24 thread.Stop(); 33 thread.Stop();
25 } 34 }
26 35
36 ACTION_P(SignalEvent, event) {
37 event->Signal();
38 }
39
40 TEST(JingleThreadTest, PostDelayedTask) {
41 JingleThread thread;
42 MockTask* task = new MockTask();
43 base::WaitableEvent event(true, false);
44 EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event));
45
46 thread.Start();
47 base::Time start = base::Time::Now();
48 thread.message_loop()->PostDelayedTask(FROM_HERE, task, kDelayMs);
49 event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs));
50 base::Time end = base::Time::Now();
51 thread.Stop();
52
53 EXPECT_GT((end - start).InMillisecondsRoundedUp(), kDelayMs);
54 }
55
27 } // namespace remoting 56 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/jingle_glue/jingle_thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698