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

Side by Side Diff: base/idletimer_unittest.cc

Issue 9258: Weee. More TODO(darin)s. :) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 1 month 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 | « 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/idle_timer.h" 5 #include "base/idle_timer.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 using base::Time; 9 using base::Time;
10 using base::TimeDelta; 10 using base::TimeDelta;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 base::OneShotTimer<ResetIdleTask> t2; 108 base::OneShotTimer<ResetIdleTask> t2;
109 t2.Start(TimeDelta::FromMilliseconds(500), &reset_task, 109 t2.Start(TimeDelta::FromMilliseconds(500), &reset_task,
110 &ResetIdleTask::Run); 110 &ResetIdleTask::Run);
111 111
112 test_task.Start(); 112 test_task.Start();
113 MessageLoop::current()->Run(); 113 MessageLoop::current()->Run();
114 114
115 EXPECT_EQ(test_task.get_idle_counter(), 2); 115 EXPECT_EQ(test_task.get_idle_counter(), 2);
116 } 116 }
117 117
118 TEST_F(IdleTimerTest, NoRepeatNotIdle) { 118 // TODO(darin): http://crbug.com/3704
119 TEST_F(IdleTimerTest, DISABLED_NoRepeatNotIdle) {
119 // Create an IdleTimer, which should fire once after 100ms. 120 // Create an IdleTimer, which should fire once after 100ms.
120 // Create a Quit timer which will fire after 1s. 121 // Create a Quit timer which will fire after 1s.
121 // Create a timer to reset idle every 50ms. 122 // Create a timer to reset idle every 50ms.
122 // Verify that we never fired. 123 // Verify that we never fired.
123 124
124 mock_timer_started = Time::Now(); 125 mock_timer_started = Time::Now();
125 TestIdleTask test_task(false); 126 TestIdleTask test_task(false);
126 127
127 TestFinishedTask finish_task; 128 TestFinishedTask finish_task;
128 ResetIdleTask reset_task; 129 ResetIdleTask reset_task;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 test_task.Start(); 167 test_task.Start();
167 MessageLoop::current()->Run(); 168 MessageLoop::current()->Run();
168 169
169 // In a perfect world, the idle_counter should be 10. However, 170 // In a perfect world, the idle_counter should be 10. However,
170 // since timers aren't guaranteed to fire perfectly, this can 171 // since timers aren't guaranteed to fire perfectly, this can
171 // be less. Just expect more than 5 and no more than 10. 172 // be less. Just expect more than 5 and no more than 10.
172 EXPECT_GT(test_task.get_idle_counter(), 5); 173 EXPECT_GT(test_task.get_idle_counter(), 5);
173 EXPECT_LE(test_task.get_idle_counter(), 10); 174 EXPECT_LE(test_task.get_idle_counter(), 10);
174 } 175 }
175 176
176 // TODO(darin): http://code.google.com/p/chromium/issues/detail?id=3780 177 // TODO(darin): http://crbug.com/3780
177 TEST_F(IdleTimerTest, DISABLED_RepeatIdleReset) { 178 TEST_F(IdleTimerTest, DISABLED_RepeatIdleReset) {
178 // Create an IdleTimer, which should fire repeatedly after 100ms. 179 // Create an IdleTimer, which should fire repeatedly after 100ms.
179 // Create a Quit timer which will fire after 1s. 180 // Create a Quit timer which will fire after 1s.
180 // Create a reset timer, which fires after 550ms 181 // Create a reset timer, which fires after 550ms
181 // Verify that we fired 9 times. 182 // Verify that we fired 9 times.
182 mock_timer_started = Time::Now(); 183 mock_timer_started = Time::Now();
183 TestIdleTask test_task(true); 184 TestIdleTask test_task(true);
184 185
185 ResetIdleTask reset_task; 186 ResetIdleTask reset_task;
186 TestFinishedTask finish_task; 187 TestFinishedTask finish_task;
187 188
188 base::OneShotTimer<TestFinishedTask> t1; 189 base::OneShotTimer<TestFinishedTask> t1;
189 t1.Start(TimeDelta::FromMilliseconds(1000), &finish_task, 190 t1.Start(TimeDelta::FromMilliseconds(1000), &finish_task,
190 &TestFinishedTask::Run); 191 &TestFinishedTask::Run);
191 192
192 base::OneShotTimer<ResetIdleTask> t2; 193 base::OneShotTimer<ResetIdleTask> t2;
193 t2.Start(TimeDelta::FromMilliseconds(550), &reset_task, 194 t2.Start(TimeDelta::FromMilliseconds(550), &reset_task,
194 &ResetIdleTask::Run); 195 &ResetIdleTask::Run);
195 196
196 test_task.Start(); 197 test_task.Start();
197 MessageLoop::current()->Run(); 198 MessageLoop::current()->Run();
198 199
199 // In a perfect world, the idle_counter should be 9. However, 200 // In a perfect world, the idle_counter should be 9. However,
200 // since timers aren't guaranteed to fire perfectly, this can 201 // since timers aren't guaranteed to fire perfectly, this can
201 // be less. Just expect more than 5 and no more than 9. 202 // be less. Just expect more than 5 and no more than 9.
202 EXPECT_GT(test_task.get_idle_counter(), 5); 203 EXPECT_GT(test_task.get_idle_counter(), 5);
203 EXPECT_LE(test_task.get_idle_counter(), 9); 204 EXPECT_LE(test_task.get_idle_counter(), 9);
204 } 205 }
205 206
206 TEST_F(IdleTimerTest, RepeatNotIdle) { 207 // TODO(darin): http://crbug.com/3704
208 TEST_F(IdleTimerTest, DISABLED_RepeatNotIdle) {
207 // Create an IdleTimer, which should fire repeatedly after 100ms. 209 // Create an IdleTimer, which should fire repeatedly after 100ms.
208 // Create a Quit timer which will fire after 1s. 210 // Create a Quit timer which will fire after 1s.
209 // Create a timer to reset idle every 50ms. 211 // Create a timer to reset idle every 50ms.
210 // Verify that we never fired. 212 // Verify that we never fired.
211 213
212 mock_timer_started = Time::Now(); 214 mock_timer_started = Time::Now();
213 TestIdleTask test_task(true); 215 TestIdleTask test_task(true);
214 216
215 TestFinishedTask finish_task; 217 TestFinishedTask finish_task;
216 ResetIdleTask reset_task; 218 ResetIdleTask reset_task;
217 219
218 base::OneShotTimer<TestFinishedTask> t; 220 base::OneShotTimer<TestFinishedTask> t;
219 t.Start(TimeDelta::FromMilliseconds(1000), &finish_task, 221 t.Start(TimeDelta::FromMilliseconds(1000), &finish_task,
220 &TestFinishedTask::Run); 222 &TestFinishedTask::Run);
221 223
222 base::RepeatingTimer<ResetIdleTask> reset_timer; 224 base::RepeatingTimer<ResetIdleTask> reset_timer;
223 reset_timer.Start(TimeDelta::FromMilliseconds(50), &reset_task, 225 reset_timer.Start(TimeDelta::FromMilliseconds(50), &reset_task,
224 &ResetIdleTask::Run); 226 &ResetIdleTask::Run);
225 227
226 test_task.Start(); 228 test_task.Start();
227 MessageLoop::current()->Run(); 229 MessageLoop::current()->Run();
228 230
229 reset_timer.Stop(); 231 reset_timer.Stop();
230 232
231 EXPECT_EQ(test_task.get_idle_counter(), 0); 233 EXPECT_EQ(test_task.get_idle_counter(), 0);
232 } 234 }
233 235
234 } // namespace 236 } // namespace
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