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

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

Issue 6003003: Fix crash in JingleThread caused by non-nestable tasks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/sync
Patch Set: - Created 10 years 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 | Annotate | Revision Log
« 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" 6 #include "base/time.h"
7 #include "base/waitable_event.h" 7 #include "base/waitable_event.h"
8 #include "remoting/jingle_glue/jingle_thread.h" 8 #include "remoting/jingle_glue/jingle_thread.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 15 matching lines...) Expand all
26 TEST(JingleThreadTest, PostTask) { 26 TEST(JingleThreadTest, PostTask) {
27 JingleThread thread; 27 JingleThread thread;
28 MockTask* task = new MockTask(); 28 MockTask* task = new MockTask();
29 EXPECT_CALL(*task, Run()); 29 EXPECT_CALL(*task, Run());
30 30
31 thread.Start(); 31 thread.Start();
32 thread.message_loop()->PostTask(FROM_HERE, task); 32 thread.message_loop()->PostTask(FROM_HERE, task);
33 thread.Stop(); 33 thread.Stop();
34 } 34 }
35 35
36 TEST(JingleThreadTest, PostNonNestableTask) {
37 JingleThread thread;
38 MockTask* task = new MockTask();
39 EXPECT_CALL(*task, Run());
40
41 thread.Start();
42 thread.message_loop()->PostNonNestableTask(FROM_HERE, task);
43 thread.Stop();
44 }
45
36 ACTION_P(SignalEvent, event) { 46 ACTION_P(SignalEvent, event) {
37 event->Signal(); 47 event->Signal();
38 } 48 }
39 49
40 TEST(JingleThreadTest, PostDelayedTask) { 50 TEST(JingleThreadTest, PostDelayedTask) {
41 JingleThread thread; 51 JingleThread thread;
42 MockTask* task = new MockTask(); 52 MockTask* task = new MockTask();
43 base::WaitableEvent event(true, false); 53 base::WaitableEvent event(true, false);
44 EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event)); 54 EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event));
45 55
46 thread.Start(); 56 thread.Start();
47 base::Time start = base::Time::Now(); 57 base::Time start = base::Time::Now();
48 thread.message_loop()->PostDelayedTask(FROM_HERE, task, kDelayMs); 58 thread.message_loop()->PostDelayedTask(FROM_HERE, task, kDelayMs);
49 event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs)); 59 event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs));
50 base::Time end = base::Time::Now(); 60 base::Time end = base::Time::Now();
51 thread.Stop(); 61 thread.Stop();
52 62
53 EXPECT_GE((end - start).InMillisecondsRoundedUp(), kDelayMs); 63 EXPECT_GE((end - start).InMillisecondsRoundedUp(), kDelayMs);
54 } 64 }
55 65
66 TEST(JingleThreadTest, PostNonNestableDelayedTask) {
67 JingleThread thread;
68 MockTask* task = new MockTask();
69 base::WaitableEvent event(true, false);
70 EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event));
71
72 thread.Start();
73 base::Time start = base::Time::Now();
74 thread.message_loop()->PostNonNestableDelayedTask(FROM_HERE, task, kDelayMs);
75 event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs));
76 base::Time end = base::Time::Now();
77 thread.Stop();
78
79 EXPECT_GE((end - start).InMillisecondsRoundedUp(), kDelayMs);
80 }
81
56 } // namespace remoting 82 } // 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