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

Side by Side Diff: base/idletimer_unittest.cc

Issue 9264: Undisable the now not-flaky unittests! (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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 base::OneShotTimer<ResetIdleTask> t2; 116 base::OneShotTimer<ResetIdleTask> t2;
117 t2.Start(TimeDelta::FromMilliseconds(4 * kSafeTestIntervalMs), &reset_task, 117 t2.Start(TimeDelta::FromMilliseconds(4 * kSafeTestIntervalMs), &reset_task,
118 &ResetIdleTask::Run); 118 &ResetIdleTask::Run);
119 119
120 test_task.Start(); 120 test_task.Start();
121 MessageLoop::current()->Run(); 121 MessageLoop::current()->Run();
122 122
123 EXPECT_EQ(test_task.get_idle_counter(), 2); 123 EXPECT_EQ(test_task.get_idle_counter(), 2);
124 } 124 }
125 125
126 // TODO(darin): http://crbug.com/3704 126 TEST_F(IdleTimerTest, NoRepeatNotIdle) {
127 TEST_F(IdleTimerTest, DISABLED_NoRepeatNotIdle) {
128 // Create an IdleTimer, which should fire once after 500ms. 127 // Create an IdleTimer, which should fire once after 500ms.
129 // Create a Quit timer which will fire after 5s. 128 // Create a Quit timer which will fire after 5s.
130 // Create a timer to reset idle every 50ms. 129 // Create a timer to reset idle every 50ms.
131 // Verify that we never fired. 130 // Verify that we never fired.
132 131
133 mock_timer_started = Time::Now(); 132 mock_timer_started = Time::Now();
134 TestIdleTask test_task(false); 133 TestIdleTask test_task(false);
135 134
136 TestFinishedTask finish_task; 135 TestFinishedTask finish_task;
137 ResetIdleTask reset_task; 136 ResetIdleTask reset_task;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 173
175 test_task.Start(); 174 test_task.Start();
176 MessageLoop::current()->Run(); 175 MessageLoop::current()->Run();
177 176
178 // In a perfect world, the idle_counter should be 2. However, 177 // In a perfect world, the idle_counter should be 2. However,
179 // due to timer 'slop', accept 2 or 3. 178 // due to timer 'slop', accept 2 or 3.
180 EXPECT_GE(test_task.get_idle_counter(), 2); 179 EXPECT_GE(test_task.get_idle_counter(), 2);
181 EXPECT_LE(test_task.get_idle_counter(), 3); 180 EXPECT_LE(test_task.get_idle_counter(), 3);
182 } 181 }
183 182
184 // TODO(darin): http://crbug.com/3780
185 TEST_F(IdleTimerTest, RepeatIdleReset) { 183 TEST_F(IdleTimerTest, RepeatIdleReset) {
186 // Create an IdleTimer, which should fire repeatedly after 500ms. 184 // Create an IdleTimer, which should fire repeatedly after 500ms.
187 // Create a Quit timer which will fire after 5s. 185 // Create a Quit timer which will fire after 5s.
188 // Create a reset timer, which fires after 2500ms 186 // Create a reset timer, which fires after 2500ms
189 // Verify that we fired 8-10 times. 187 // Verify that we fired 8-10 times.
190 mock_timer_started = Time::Now(); 188 mock_timer_started = Time::Now();
191 TestIdleTask test_task(true); 189 TestIdleTask test_task(true);
192 190
193 ResetIdleTask reset_task; 191 ResetIdleTask reset_task;
194 TestFinishedTask finish_task; 192 TestFinishedTask finish_task;
195 193
196 base::OneShotTimer<TestFinishedTask> t1; 194 base::OneShotTimer<TestFinishedTask> t1;
197 t1.Start(TimeDelta::FromMilliseconds(10 * kSafeTestIntervalMs), &finish_task, 195 t1.Start(TimeDelta::FromMilliseconds(10 * kSafeTestIntervalMs), &finish_task,
198 &TestFinishedTask::Run); 196 &TestFinishedTask::Run);
199 197
200 base::OneShotTimer<ResetIdleTask> t2; 198 base::OneShotTimer<ResetIdleTask> t2;
201 t2.Start(TimeDelta::FromMilliseconds(5 * kSafeTestIntervalMs), &reset_task, 199 t2.Start(TimeDelta::FromMilliseconds(5 * kSafeTestIntervalMs), &reset_task,
202 &ResetIdleTask::Run); 200 &ResetIdleTask::Run);
203 201
204 test_task.Start(); 202 test_task.Start();
205 MessageLoop::current()->Run(); 203 MessageLoop::current()->Run();
206 204
207 // In a perfect world, the idle_counter should be 9. However, 205 // In a perfect world, the idle_counter should be 9. However,
208 // since timers aren't guaranteed to fire perfectly, this can 206 // since timers aren't guaranteed to fire perfectly, this can
209 // be less. Accept 8-10. 207 // be less. Accept 8-10.
210 EXPECT_GE(test_task.get_idle_counter(), 8); 208 EXPECT_GE(test_task.get_idle_counter(), 8);
211 EXPECT_LE(test_task.get_idle_counter(), 10); 209 EXPECT_LE(test_task.get_idle_counter(), 10);
212 } 210 }
213 211
214 // TODO(darin): http://crbug.com/3704 212 TEST_F(IdleTimerTest, RepeatNotIdle) {
215 TEST_F(IdleTimerTest, DISABLED_RepeatNotIdle) {
216 // Create an IdleTimer, which should fire repeatedly after 500ms. 213 // Create an IdleTimer, which should fire repeatedly after 500ms.
217 // Create a Quit timer which will fire after 4s. 214 // Create a Quit timer which will fire after 4s.
218 // Create a timer to reset idle every 50ms. 215 // Create a timer to reset idle every 50ms.
219 // Verify that we never fired. 216 // Verify that we never fired.
220 217
221 mock_timer_started = Time::Now(); 218 mock_timer_started = Time::Now();
222 TestIdleTask test_task(true); 219 TestIdleTask test_task(true);
223 220
224 TestFinishedTask finish_task; 221 TestFinishedTask finish_task;
225 ResetIdleTask reset_task; 222 ResetIdleTask reset_task;
226 223
227 base::OneShotTimer<TestFinishedTask> t; 224 base::OneShotTimer<TestFinishedTask> t;
228 t.Start(TimeDelta::FromMilliseconds(8 * kSafeTestIntervalMs), &finish_task, 225 t.Start(TimeDelta::FromMilliseconds(8 * kSafeTestIntervalMs), &finish_task,
229 &TestFinishedTask::Run); 226 &TestFinishedTask::Run);
230 227
231 base::RepeatingTimer<ResetIdleTask> reset_timer; 228 base::RepeatingTimer<ResetIdleTask> reset_timer;
232 reset_timer.Start(TimeDelta::FromMilliseconds(50), &reset_task, 229 reset_timer.Start(TimeDelta::FromMilliseconds(50), &reset_task,
233 &ResetIdleTask::Run); 230 &ResetIdleTask::Run);
234 231
235 test_task.Start(); 232 test_task.Start();
236 MessageLoop::current()->Run(); 233 MessageLoop::current()->Run();
237 234
238 reset_timer.Stop(); 235 reset_timer.Stop();
239 236
240 EXPECT_EQ(test_task.get_idle_counter(), 0); 237 EXPECT_EQ(test_task.get_idle_counter(), 0);
241 } 238 }
242 239
243 } // namespace 240 } // 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