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

Side by Side Diff: base/timer/timer_unittest.cc

Issue 136683004: Removes MessageLoop::TYPE_XXX where possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: resolve merge Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/timer/timer.h" 7 #include "base/timer/timer.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 using base::TimeDelta; 10 using base::TimeDelta;
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // message loop does not cause crashes if there were pending 368 // message loop does not cause crashes if there were pending
369 // timers not yet fired. It may only trigger exceptions 369 // timers not yet fired. It may only trigger exceptions
370 // if debug heap checking is enabled. 370 // if debug heap checking is enabled.
371 bool did_run = false; 371 bool did_run = false;
372 { 372 {
373 OneShotTimerTester a(&did_run); 373 OneShotTimerTester a(&did_run);
374 OneShotTimerTester b(&did_run); 374 OneShotTimerTester b(&did_run);
375 OneShotTimerTester c(&did_run); 375 OneShotTimerTester c(&did_run);
376 OneShotTimerTester d(&did_run); 376 OneShotTimerTester d(&did_run);
377 { 377 {
378 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); 378 base::MessageLoop loop;
379 a.Start(); 379 a.Start();
380 b.Start(); 380 b.Start();
381 } // MessageLoop destructs by falling out of scope. 381 } // MessageLoop destructs by falling out of scope.
382 } // OneShotTimers destruct. SHOULD NOT CRASH, of course. 382 } // OneShotTimers destruct. SHOULD NOT CRASH, of course.
383 383
384 EXPECT_FALSE(did_run); 384 EXPECT_FALSE(did_run);
385 } 385 }
386 386
387 void TimerTestCallback() { 387 void TimerTestCallback() {
388 } 388 }
389 389
390 TEST(TimerTest, NonRepeatIsRunning) { 390 TEST(TimerTest, NonRepeatIsRunning) {
391 { 391 {
392 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); 392 base::MessageLoop loop;
393 base::Timer timer(false, false); 393 base::Timer timer(false, false);
394 EXPECT_FALSE(timer.IsRunning()); 394 EXPECT_FALSE(timer.IsRunning());
395 timer.Start(FROM_HERE, TimeDelta::FromDays(1), 395 timer.Start(FROM_HERE, TimeDelta::FromDays(1),
396 base::Bind(&TimerTestCallback)); 396 base::Bind(&TimerTestCallback));
397 EXPECT_TRUE(timer.IsRunning()); 397 EXPECT_TRUE(timer.IsRunning());
398 timer.Stop(); 398 timer.Stop();
399 EXPECT_FALSE(timer.IsRunning()); 399 EXPECT_FALSE(timer.IsRunning());
400 EXPECT_TRUE(timer.user_task().is_null()); 400 EXPECT_TRUE(timer.user_task().is_null());
401 } 401 }
402 402
403 { 403 {
404 base::Timer timer(true, false); 404 base::Timer timer(true, false);
405 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); 405 base::MessageLoop loop;
406 EXPECT_FALSE(timer.IsRunning()); 406 EXPECT_FALSE(timer.IsRunning());
407 timer.Start(FROM_HERE, TimeDelta::FromDays(1), 407 timer.Start(FROM_HERE, TimeDelta::FromDays(1),
408 base::Bind(&TimerTestCallback)); 408 base::Bind(&TimerTestCallback));
409 EXPECT_TRUE(timer.IsRunning()); 409 EXPECT_TRUE(timer.IsRunning());
410 timer.Stop(); 410 timer.Stop();
411 EXPECT_FALSE(timer.IsRunning()); 411 EXPECT_FALSE(timer.IsRunning());
412 ASSERT_FALSE(timer.user_task().is_null()); 412 ASSERT_FALSE(timer.user_task().is_null());
413 timer.Reset(); 413 timer.Reset();
414 EXPECT_TRUE(timer.IsRunning()); 414 EXPECT_TRUE(timer.IsRunning());
415 } 415 }
416 } 416 }
417 417
418 TEST(TimerTest, NonRepeatMessageLoopDeath) { 418 TEST(TimerTest, NonRepeatMessageLoopDeath) {
419 base::Timer timer(false, false); 419 base::Timer timer(false, false);
420 { 420 {
421 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); 421 base::MessageLoop loop;
422 EXPECT_FALSE(timer.IsRunning()); 422 EXPECT_FALSE(timer.IsRunning());
423 timer.Start(FROM_HERE, TimeDelta::FromDays(1), 423 timer.Start(FROM_HERE, TimeDelta::FromDays(1),
424 base::Bind(&TimerTestCallback)); 424 base::Bind(&TimerTestCallback));
425 EXPECT_TRUE(timer.IsRunning()); 425 EXPECT_TRUE(timer.IsRunning());
426 } 426 }
427 EXPECT_FALSE(timer.IsRunning()); 427 EXPECT_FALSE(timer.IsRunning());
428 EXPECT_TRUE(timer.user_task().is_null()); 428 EXPECT_TRUE(timer.user_task().is_null());
429 } 429 }
430 430
431 TEST(TimerTest, RetainRepeatIsRunning) { 431 TEST(TimerTest, RetainRepeatIsRunning) {
432 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); 432 base::MessageLoop loop;
433 base::Timer timer(FROM_HERE, TimeDelta::FromDays(1), 433 base::Timer timer(FROM_HERE, TimeDelta::FromDays(1),
434 base::Bind(&TimerTestCallback), true); 434 base::Bind(&TimerTestCallback), true);
435 EXPECT_FALSE(timer.IsRunning()); 435 EXPECT_FALSE(timer.IsRunning());
436 timer.Reset(); 436 timer.Reset();
437 EXPECT_TRUE(timer.IsRunning()); 437 EXPECT_TRUE(timer.IsRunning());
438 timer.Stop(); 438 timer.Stop();
439 EXPECT_FALSE(timer.IsRunning()); 439 EXPECT_FALSE(timer.IsRunning());
440 timer.Reset(); 440 timer.Reset();
441 EXPECT_TRUE(timer.IsRunning()); 441 EXPECT_TRUE(timer.IsRunning());
442 } 442 }
443 443
444 TEST(TimerTest, RetainNonRepeatIsRunning) { 444 TEST(TimerTest, RetainNonRepeatIsRunning) {
445 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); 445 base::MessageLoop loop;
446 base::Timer timer(FROM_HERE, TimeDelta::FromDays(1), 446 base::Timer timer(FROM_HERE, TimeDelta::FromDays(1),
447 base::Bind(&TimerTestCallback), false); 447 base::Bind(&TimerTestCallback), false);
448 EXPECT_FALSE(timer.IsRunning()); 448 EXPECT_FALSE(timer.IsRunning());
449 timer.Reset(); 449 timer.Reset();
450 EXPECT_TRUE(timer.IsRunning()); 450 EXPECT_TRUE(timer.IsRunning());
451 timer.Stop(); 451 timer.Stop();
452 EXPECT_FALSE(timer.IsRunning()); 452 EXPECT_FALSE(timer.IsRunning());
453 timer.Reset(); 453 timer.Reset();
454 EXPECT_TRUE(timer.IsRunning()); 454 EXPECT_TRUE(timer.IsRunning());
455 } 455 }
(...skipping 14 matching lines...) Expand all
470 } 470 }
471 471
472 void SetCallbackHappened2() { 472 void SetCallbackHappened2() {
473 g_callback_happened2 = true; 473 g_callback_happened2 = true;
474 base::MessageLoop::current()->QuitWhenIdle(); 474 base::MessageLoop::current()->QuitWhenIdle();
475 } 475 }
476 476
477 TEST(TimerTest, ContinuationStopStart) { 477 TEST(TimerTest, ContinuationStopStart) {
478 { 478 {
479 ClearAllCallbackHappened(); 479 ClearAllCallbackHappened();
480 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); 480 base::MessageLoop loop;
481 base::Timer timer(false, false); 481 base::Timer timer(false, false);
482 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), 482 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10),
483 base::Bind(&SetCallbackHappened1)); 483 base::Bind(&SetCallbackHappened1));
484 timer.Stop(); 484 timer.Stop();
485 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(40), 485 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(40),
486 base::Bind(&SetCallbackHappened2)); 486 base::Bind(&SetCallbackHappened2));
487 base::MessageLoop::current()->Run(); 487 base::MessageLoop::current()->Run();
488 EXPECT_FALSE(g_callback_happened1); 488 EXPECT_FALSE(g_callback_happened1);
489 EXPECT_TRUE(g_callback_happened2); 489 EXPECT_TRUE(g_callback_happened2);
490 } 490 }
491 } 491 }
492 492
493 TEST(TimerTest, ContinuationReset) { 493 TEST(TimerTest, ContinuationReset) {
494 { 494 {
495 ClearAllCallbackHappened(); 495 ClearAllCallbackHappened();
496 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); 496 base::MessageLoop loop;
497 base::Timer timer(false, false); 497 base::Timer timer(false, false);
498 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), 498 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10),
499 base::Bind(&SetCallbackHappened1)); 499 base::Bind(&SetCallbackHappened1));
500 timer.Reset(); 500 timer.Reset();
501 // Since Reset happened before task ran, the user_task must not be cleared: 501 // Since Reset happened before task ran, the user_task must not be cleared:
502 ASSERT_FALSE(timer.user_task().is_null()); 502 ASSERT_FALSE(timer.user_task().is_null());
503 base::MessageLoop::current()->Run(); 503 base::MessageLoop::current()->Run();
504 EXPECT_TRUE(g_callback_happened1); 504 EXPECT_TRUE(g_callback_happened1);
505 } 505 }
506 } 506 }
507 507
508 } // namespace 508 } // namespace
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_provider_unittest.cc ('k') | chrome/browser/chromeos/login/login_utils_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698