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

Side by Side Diff: chrome/common/worker_thread_ticker_unittest.cc

Issue 506073: Fix a race in WorkerThreadTicker test. (Closed)
Patch Set: Created 11 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
« no previous file with comments | « no previous file | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/common/worker_thread_ticker.h" 5 #include "chrome/common/worker_thread_ticker.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/platform_thread.h" 8 #include "base/platform_thread.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 29 matching lines...) Expand all
40 MessageLoop::current()->PostDelayedTask(FROM_HERE, 40 MessageLoop::current()->PostDelayedTask(FROM_HERE,
41 new MessageLoop::QuitTask(), 500); 41 new MessageLoop::QuitTask(), 500);
42 MessageLoop::current()->Run(); 42 MessageLoop::current()->Run();
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 TEST(WorkerThreadTickerTest, Basic) { 47 TEST(WorkerThreadTickerTest, Basic) {
48 MessageLoop loop; 48 MessageLoop loop;
49 49
50 TestCallback callback;
50 WorkerThreadTicker ticker(50); 51 WorkerThreadTicker ticker(50);
51 TestCallback callback;
52 EXPECT_FALSE(ticker.IsRunning()); 52 EXPECT_FALSE(ticker.IsRunning());
53 EXPECT_TRUE(ticker.RegisterTickHandler(&callback)); 53 EXPECT_TRUE(ticker.RegisterTickHandler(&callback));
54 EXPECT_TRUE(ticker.UnregisterTickHandler(&callback)); 54 EXPECT_TRUE(ticker.UnregisterTickHandler(&callback));
55 EXPECT_TRUE(ticker.Start()); 55 EXPECT_TRUE(ticker.Start());
56 EXPECT_FALSE(ticker.RegisterTickHandler(&callback)); 56 EXPECT_FALSE(ticker.RegisterTickHandler(&callback));
57 EXPECT_FALSE(ticker.UnregisterTickHandler(&callback)); 57 EXPECT_FALSE(ticker.UnregisterTickHandler(&callback));
58 EXPECT_TRUE(ticker.IsRunning()); 58 EXPECT_TRUE(ticker.IsRunning());
59 EXPECT_FALSE(ticker.Start()); // Can't start when it is running. 59 EXPECT_FALSE(ticker.Start()); // Can't start when it is running.
60 EXPECT_TRUE(ticker.Stop()); 60 EXPECT_TRUE(ticker.Stop());
61 EXPECT_FALSE(ticker.IsRunning()); 61 EXPECT_FALSE(ticker.IsRunning());
62 EXPECT_FALSE(ticker.Stop()); // Can't stop when it isn't running. 62 EXPECT_FALSE(ticker.Stop()); // Can't stop when it isn't running.
63 } 63 }
64 64
65 TEST(WorkerThreadTickerTest, Callback) { 65 TEST(WorkerThreadTickerTest, Callback) {
66 MessageLoop loop; 66 MessageLoop loop;
67 67
68 TestCallback callback;
68 WorkerThreadTicker ticker(50); 69 WorkerThreadTicker ticker(50);
69 TestCallback callback;
70 ASSERT_TRUE(ticker.RegisterTickHandler(&callback)); 70 ASSERT_TRUE(ticker.RegisterTickHandler(&callback));
71 71
72 ASSERT_TRUE(ticker.Start()); 72 ASSERT_TRUE(ticker.Start());
73 RunMessageLoopForAWhile(); 73 RunMessageLoopForAWhile();
74 EXPECT_TRUE(callback.counter() > 0); 74 EXPECT_TRUE(callback.counter() > 0);
75 75
76 ASSERT_TRUE(ticker.Stop()); 76 ASSERT_TRUE(ticker.Stop());
77 const int counter_value = callback.counter(); 77 const int counter_value = callback.counter();
78 RunMessageLoopForAWhile(); 78 RunMessageLoopForAWhile();
79 EXPECT_EQ(counter_value, callback.counter()); 79 EXPECT_EQ(counter_value, callback.counter());
(...skipping 12 matching lines...) Expand all
92 EXPECT_TRUE(callback.counter() > 0); 92 EXPECT_TRUE(callback.counter() > 0);
93 } 93 }
94 const int counter_value = callback.counter(); 94 const int counter_value = callback.counter();
95 RunMessageLoopForAWhile(); 95 RunMessageLoopForAWhile();
96 EXPECT_EQ(counter_value, callback.counter()); 96 EXPECT_EQ(counter_value, callback.counter());
97 } 97 }
98 98
99 TEST(WorkerThreadTickerTest, LongCallback) { 99 TEST(WorkerThreadTickerTest, LongCallback) {
100 MessageLoop loop; 100 MessageLoop loop;
101 101
102 LongCallback callback;
102 WorkerThreadTicker ticker(50); 103 WorkerThreadTicker ticker(50);
103 LongCallback callback;
104 ASSERT_TRUE(ticker.RegisterTickHandler(&callback)); 104 ASSERT_TRUE(ticker.RegisterTickHandler(&callback));
105 105
106 ASSERT_TRUE(ticker.Start()); 106 ASSERT_TRUE(ticker.Start());
107 RunMessageLoopForAWhile(); 107 RunMessageLoopForAWhile();
108 } 108 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698