OLD | NEW |
1 // Copyright (c) 2012 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/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace { | 11 namespace { |
(...skipping 13 matching lines...) Expand all Loading... |
25 int counter() const { return counter_; } | 25 int counter() const { return counter_; } |
26 | 26 |
27 private: | 27 private: |
28 int counter_; | 28 int counter_; |
29 MessageLoop* message_loop_; | 29 MessageLoop* message_loop_; |
30 }; | 30 }; |
31 | 31 |
32 class LongCallback : public WorkerThreadTicker::Callback { | 32 class LongCallback : public WorkerThreadTicker::Callback { |
33 public: | 33 public: |
34 virtual void OnTick() { | 34 virtual void OnTick() { |
35 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1500)); | 35 base::PlatformThread::Sleep(1500); |
36 } | 36 } |
37 }; | 37 }; |
38 | 38 |
39 void RunMessageLoopForAWhile() { | 39 void RunMessageLoopForAWhile() { |
40 MessageLoop::current()->PostDelayedTask( | 40 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
41 FROM_HERE, | 41 MessageLoop::QuitClosure(), 500); |
42 MessageLoop::QuitClosure(), | |
43 base::TimeDelta::FromMilliseconds(500)); | |
44 MessageLoop::current()->Run(); | 42 MessageLoop::current()->Run(); |
45 } | 43 } |
46 | 44 |
47 } // namespace | 45 } // namespace |
48 | 46 |
49 TEST(WorkerThreadTickerTest, Basic) { | 47 TEST(WorkerThreadTickerTest, Basic) { |
50 MessageLoop loop; | 48 MessageLoop loop; |
51 | 49 |
52 TestCallback callback; | 50 TestCallback callback; |
53 WorkerThreadTicker ticker(50); | 51 WorkerThreadTicker ticker(50); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 TEST(WorkerThreadTickerTest, LongCallback) { | 99 TEST(WorkerThreadTickerTest, LongCallback) { |
102 MessageLoop loop; | 100 MessageLoop loop; |
103 | 101 |
104 LongCallback callback; | 102 LongCallback callback; |
105 WorkerThreadTicker ticker(50); | 103 WorkerThreadTicker ticker(50); |
106 ASSERT_TRUE(ticker.RegisterTickHandler(&callback)); | 104 ASSERT_TRUE(ticker.RegisterTickHandler(&callback)); |
107 | 105 |
108 ASSERT_TRUE(ticker.Start()); | 106 ASSERT_TRUE(ticker.Start()); |
109 RunMessageLoopForAWhile(); | 107 RunMessageLoopForAWhile(); |
110 } | 108 } |
OLD | NEW |