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

Side by Side Diff: base/timer_unittest.cc

Issue 27234: DelayTimer destruction test (Closed)
Patch Set: ... Created 11 years, 10 months 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 | « base/timer.h ('k') | 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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/scoped_ptr.h" 6 #include "base/scoped_ptr.h"
7 #include "base/task.h" 7 #include "base/task.h"
8 #include "base/timer.h" 8 #include "base/timer.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 236 }
237 237
238 bool did_run = false; 238 bool did_run = false;
239 OneShotTimerTester tester(&did_run, 300); 239 OneShotTimerTester tester(&did_run, 300);
240 tester.Start(); 240 tester.Start();
241 MessageLoop::current()->Run(); 241 MessageLoop::current()->Run();
242 242
243 ASSERT_TRUE(target.signaled()); 243 ASSERT_TRUE(target.signaled());
244 } 244 }
245 245
246 class DelayTimerFatalTarget {
247 public:
248 void Signal() {
249 ASSERT_TRUE(false);
250 }
251 };
252
253
254 void RunTest_DelayTimer_Deleted(MessageLoop::Type message_loop_type) {
255 MessageLoop loop(message_loop_type);
256
257 DelayTimerFatalTarget target;
258
259 {
260 base::DelayTimer<DelayTimerFatalTarget> timer(
261 TimeDelta::FromMilliseconds(50), &target,
262 &DelayTimerFatalTarget::Signal);
263 timer.Reset();
264 }
265
266 // When the timer is deleted, the DelayTimerFatalTarget should never be
267 // called.
268 PlatformThread::Sleep(100);
269 }
270
246 } // namespace 271 } // namespace
247 272
248 //----------------------------------------------------------------------------- 273 //-----------------------------------------------------------------------------
249 // Each test is run against each type of MessageLoop. That way we are sure 274 // Each test is run against each type of MessageLoop. That way we are sure
250 // that timers work properly in all configurations. 275 // that timers work properly in all configurations.
251 276
252 TEST(TimerTest, OneShotTimer) { 277 TEST(TimerTest, OneShotTimer) {
253 RunTest_OneShotTimer(MessageLoop::TYPE_DEFAULT); 278 RunTest_OneShotTimer(MessageLoop::TYPE_DEFAULT);
254 RunTest_OneShotTimer(MessageLoop::TYPE_UI); 279 RunTest_OneShotTimer(MessageLoop::TYPE_UI);
255 RunTest_OneShotTimer(MessageLoop::TYPE_IO); 280 RunTest_OneShotTimer(MessageLoop::TYPE_IO);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 RunTest_DelayTimer_OneCall(MessageLoop::TYPE_UI); 317 RunTest_DelayTimer_OneCall(MessageLoop::TYPE_UI);
293 RunTest_DelayTimer_OneCall(MessageLoop::TYPE_IO); 318 RunTest_DelayTimer_OneCall(MessageLoop::TYPE_IO);
294 } 319 }
295 320
296 TEST(TimerTest, DelayTimer_Reset) { 321 TEST(TimerTest, DelayTimer_Reset) {
297 RunTest_DelayTimer_Reset(MessageLoop::TYPE_DEFAULT); 322 RunTest_DelayTimer_Reset(MessageLoop::TYPE_DEFAULT);
298 RunTest_DelayTimer_Reset(MessageLoop::TYPE_UI); 323 RunTest_DelayTimer_Reset(MessageLoop::TYPE_UI);
299 RunTest_DelayTimer_Reset(MessageLoop::TYPE_IO); 324 RunTest_DelayTimer_Reset(MessageLoop::TYPE_IO);
300 } 325 }
301 326
327 TEST(TimerTest, DelayTimer_Deleted) {
328 RunTest_DelayTimer_Deleted(MessageLoop::TYPE_DEFAULT);
329 RunTest_DelayTimer_Deleted(MessageLoop::TYPE_UI);
330 RunTest_DelayTimer_Deleted(MessageLoop::TYPE_IO);
331 }
332
302 TEST(TimerTest, MessageLoopShutdown) { 333 TEST(TimerTest, MessageLoopShutdown) {
303 // This test is designed to verify that shutdown of the 334 // This test is designed to verify that shutdown of the
304 // message loop does not cause crashes if there were pending 335 // message loop does not cause crashes if there were pending
305 // timers not yet fired. It may only trigger exceptions 336 // timers not yet fired. It may only trigger exceptions
306 // if debug heap checking (or purify) is enabled. 337 // if debug heap checking (or purify) is enabled.
307 bool did_run = false; 338 bool did_run = false;
308 { 339 {
309 OneShotTimerTester a(&did_run); 340 OneShotTimerTester a(&did_run);
310 OneShotTimerTester b(&did_run); 341 OneShotTimerTester b(&did_run);
311 OneShotTimerTester c(&did_run); 342 OneShotTimerTester c(&did_run);
312 OneShotTimerTester d(&did_run); 343 OneShotTimerTester d(&did_run);
313 { 344 {
314 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 345 MessageLoop loop(MessageLoop::TYPE_DEFAULT);
315 a.Start(); 346 a.Start();
316 b.Start(); 347 b.Start();
317 } // MessageLoop destructs by falling out of scope. 348 } // MessageLoop destructs by falling out of scope.
318 } // OneShotTimers destruct. SHOULD NOT CRASH, of course. 349 } // OneShotTimers destruct. SHOULD NOT CRASH, of course.
319 350
320 EXPECT_EQ(false, did_run); 351 EXPECT_EQ(false, did_run);
321 } 352 }
OLDNEW
« no previous file with comments | « base/timer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698