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

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

Issue 2837863004: Use base::OneShotTimer instead of base::Timer(false, false)
Patch Set: rebase Created 3 years, 7 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 | « no previous file | components/component_updater/timer.h » ('j') | 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) 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/timer/timer.h" 5 #include "base/timer/timer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 600
601 // MessageLoop destructs by falling out of scope. SHOULD NOT CRASH. 601 // MessageLoop destructs by falling out of scope. SHOULD NOT CRASH.
602 } 602 }
603 603
604 void TimerTestCallback() { 604 void TimerTestCallback() {
605 } 605 }
606 606
607 TEST(TimerTest, NonRepeatIsRunning) { 607 TEST(TimerTest, NonRepeatIsRunning) {
608 { 608 {
609 MessageLoop loop; 609 MessageLoop loop;
610 Timer timer(false, false); 610 OneShotTimer timer;
611 EXPECT_FALSE(timer.IsRunning()); 611 EXPECT_FALSE(timer.IsRunning());
612 timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback)); 612 timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback));
613 EXPECT_TRUE(timer.IsRunning()); 613 EXPECT_TRUE(timer.IsRunning());
614 timer.Stop(); 614 timer.Stop();
615 EXPECT_FALSE(timer.IsRunning()); 615 EXPECT_FALSE(timer.IsRunning());
616 EXPECT_TRUE(timer.user_task().is_null()); 616 EXPECT_TRUE(timer.user_task().is_null());
617 } 617 }
618 618
619 { 619 {
620 Timer timer(true, false); 620 Timer timer(true, false);
621 MessageLoop loop; 621 MessageLoop loop;
622 EXPECT_FALSE(timer.IsRunning()); 622 EXPECT_FALSE(timer.IsRunning());
623 timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback)); 623 timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback));
624 EXPECT_TRUE(timer.IsRunning()); 624 EXPECT_TRUE(timer.IsRunning());
625 timer.Stop(); 625 timer.Stop();
626 EXPECT_FALSE(timer.IsRunning()); 626 EXPECT_FALSE(timer.IsRunning());
627 ASSERT_FALSE(timer.user_task().is_null()); 627 ASSERT_FALSE(timer.user_task().is_null());
628 timer.Reset(); 628 timer.Reset();
629 EXPECT_TRUE(timer.IsRunning()); 629 EXPECT_TRUE(timer.IsRunning());
630 } 630 }
631 } 631 }
632 632
633 TEST(TimerTest, NonRepeatMessageLoopDeath) { 633 TEST(TimerTest, NonRepeatMessageLoopDeath) {
634 Timer timer(false, false); 634 OneShotTimer timer;
635 { 635 {
636 MessageLoop loop; 636 MessageLoop loop;
637 EXPECT_FALSE(timer.IsRunning()); 637 EXPECT_FALSE(timer.IsRunning());
638 timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback)); 638 timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback));
639 EXPECT_TRUE(timer.IsRunning()); 639 EXPECT_TRUE(timer.IsRunning());
640 } 640 }
641 EXPECT_FALSE(timer.IsRunning()); 641 EXPECT_FALSE(timer.IsRunning());
642 EXPECT_TRUE(timer.user_task().is_null()); 642 EXPECT_TRUE(timer.user_task().is_null());
643 } 643 }
644 644
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 g_callback_happened2 = true; 687 g_callback_happened2 = true;
688 MessageLoop::current()->QuitWhenIdle(); 688 MessageLoop::current()->QuitWhenIdle();
689 } 689 }
690 690
691 } // namespace 691 } // namespace
692 692
693 TEST(TimerTest, ContinuationStopStart) { 693 TEST(TimerTest, ContinuationStopStart) {
694 { 694 {
695 ClearAllCallbackHappened(); 695 ClearAllCallbackHappened();
696 MessageLoop loop; 696 MessageLoop loop;
697 Timer timer(false, false); 697 OneShotTimer timer;
698 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), 698 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10),
699 Bind(&SetCallbackHappened1)); 699 Bind(&SetCallbackHappened1));
700 timer.Stop(); 700 timer.Stop();
701 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(40), 701 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(40),
702 Bind(&SetCallbackHappened2)); 702 Bind(&SetCallbackHappened2));
703 RunLoop().Run(); 703 RunLoop().Run();
704 EXPECT_FALSE(g_callback_happened1); 704 EXPECT_FALSE(g_callback_happened1);
705 EXPECT_TRUE(g_callback_happened2); 705 EXPECT_TRUE(g_callback_happened2);
706 } 706 }
707 } 707 }
708 708
709 TEST(TimerTest, ContinuationReset) { 709 TEST(TimerTest, ContinuationReset) {
710 { 710 {
711 ClearAllCallbackHappened(); 711 ClearAllCallbackHappened();
712 MessageLoop loop; 712 MessageLoop loop;
713 Timer timer(false, false); 713 OneShotTimer timer;
714 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), 714 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10),
715 Bind(&SetCallbackHappened1)); 715 Bind(&SetCallbackHappened1));
716 timer.Reset(); 716 timer.Reset();
717 // Since Reset happened before task ran, the user_task must not be cleared: 717 // Since Reset happened before task ran, the user_task must not be cleared:
718 ASSERT_FALSE(timer.user_task().is_null()); 718 ASSERT_FALSE(timer.user_task().is_null());
719 RunLoop().Run(); 719 RunLoop().Run();
720 EXPECT_TRUE(g_callback_happened1); 720 EXPECT_TRUE(g_callback_happened1);
721 } 721 }
722 } 722 }
723 723
724 } // namespace base 724 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | components/component_updater/timer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698