OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <sys/timerfd.h> | 5 #include <sys/timerfd.h> |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
12 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
14 #include "components/timers/alarm_timer_chromeos.h" | 16 #include "components/timers/alarm_timer_chromeos.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 | 18 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 private: | 52 private: |
51 void Run() { | 53 void Run() { |
52 *did_run_ = true; | 54 *did_run_ = true; |
53 | 55 |
54 base::MessageLoop::current()->PostTask( | 56 base::MessageLoop::current()->PostTask( |
55 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 57 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
56 } | 58 } |
57 | 59 |
58 bool* did_run_; | 60 bool* did_run_; |
59 const base::TimeDelta delay_; | 61 const base::TimeDelta delay_; |
60 scoped_ptr<timers::OneShotAlarmTimer> timer_; | 62 std::unique_ptr<timers::OneShotAlarmTimer> timer_; |
61 | 63 |
62 DISALLOW_COPY_AND_ASSIGN(OneShotAlarmTimerTester); | 64 DISALLOW_COPY_AND_ASSIGN(OneShotAlarmTimerTester); |
63 }; | 65 }; |
64 | 66 |
65 class OneShotSelfDeletingAlarmTimerTester { | 67 class OneShotSelfDeletingAlarmTimerTester { |
66 public: | 68 public: |
67 OneShotSelfDeletingAlarmTimerTester(bool* did_run, base::TimeDelta delay) | 69 OneShotSelfDeletingAlarmTimerTester(bool* did_run, base::TimeDelta delay) |
68 : did_run_(did_run), | 70 : did_run_(did_run), |
69 delay_(delay), | 71 delay_(delay), |
70 timer_(new timers::OneShotAlarmTimer()) {} | 72 timer_(new timers::OneShotAlarmTimer()) {} |
71 void Start() { | 73 void Start() { |
72 timer_->Start(FROM_HERE, delay_, | 74 timer_->Start(FROM_HERE, delay_, |
73 base::Bind(&OneShotSelfDeletingAlarmTimerTester::Run, | 75 base::Bind(&OneShotSelfDeletingAlarmTimerTester::Run, |
74 base::Unretained(this))); | 76 base::Unretained(this))); |
75 } | 77 } |
76 | 78 |
77 private: | 79 private: |
78 void Run() { | 80 void Run() { |
79 *did_run_ = true; | 81 *did_run_ = true; |
80 timer_.reset(); | 82 timer_.reset(); |
81 | 83 |
82 base::MessageLoop::current()->PostTask( | 84 base::MessageLoop::current()->PostTask( |
83 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 85 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
84 } | 86 } |
85 | 87 |
86 bool* did_run_; | 88 bool* did_run_; |
87 const base::TimeDelta delay_; | 89 const base::TimeDelta delay_; |
88 scoped_ptr<timers::OneShotAlarmTimer> timer_; | 90 std::unique_ptr<timers::OneShotAlarmTimer> timer_; |
89 | 91 |
90 DISALLOW_COPY_AND_ASSIGN(OneShotSelfDeletingAlarmTimerTester); | 92 DISALLOW_COPY_AND_ASSIGN(OneShotSelfDeletingAlarmTimerTester); |
91 }; | 93 }; |
92 | 94 |
93 class RepeatingAlarmTimerTester { | 95 class RepeatingAlarmTimerTester { |
94 public: | 96 public: |
95 RepeatingAlarmTimerTester(bool* did_run, base::TimeDelta delay) | 97 RepeatingAlarmTimerTester(bool* did_run, base::TimeDelta delay) |
96 : did_run_(did_run), | 98 : did_run_(did_run), |
97 delay_(delay), | 99 delay_(delay), |
98 counter_(10), | 100 counter_(10), |
(...skipping 10 matching lines...) Expand all Loading... |
109 timer_->Stop(); | 111 timer_->Stop(); |
110 | 112 |
111 base::MessageLoop::current()->PostTask( | 113 base::MessageLoop::current()->PostTask( |
112 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 114 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
113 } | 115 } |
114 } | 116 } |
115 | 117 |
116 bool* did_run_; | 118 bool* did_run_; |
117 const base::TimeDelta delay_; | 119 const base::TimeDelta delay_; |
118 int counter_; | 120 int counter_; |
119 scoped_ptr<timers::RepeatingAlarmTimer> timer_; | 121 std::unique_ptr<timers::RepeatingAlarmTimer> timer_; |
120 | 122 |
121 DISALLOW_COPY_AND_ASSIGN(RepeatingAlarmTimerTester); | 123 DISALLOW_COPY_AND_ASSIGN(RepeatingAlarmTimerTester); |
122 }; | 124 }; |
123 | 125 |
124 } // namespace | 126 } // namespace |
125 | 127 |
126 //----------------------------------------------------------------------------- | 128 //----------------------------------------------------------------------------- |
127 // Each test is run against each type of MessageLoop. That way we are sure | 129 // Each test is run against each type of MessageLoop. That way we are sure |
128 // that timers work properly in all configurations. | 130 // that timers work properly in all configurations. |
129 | 131 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 if (!did_run) { | 505 if (!did_run) { |
504 base::RunLoop().Run(); | 506 base::RunLoop().Run(); |
505 EXPECT_TRUE(did_run); | 507 EXPECT_TRUE(did_run); |
506 } | 508 } |
507 } | 509 } |
508 } | 510 } |
509 | 511 |
510 } // namespace | 512 } // namespace |
511 | 513 |
512 } // namespace timers | 514 } // namespace timers |
OLD | NEW |