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

Side by Side Diff: base/timer_unittest.cc

Issue 11794032: base: Update the calls from MessageLoop::Quit() to QuitWhenIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
« no previous file with comments | « base/threading/thread.cc ('k') | base/win/object_watcher_unittest.cc » ('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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/timer.h" 7 #include "base/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 17 matching lines...) Expand all
28 : did_run_(did_run), 28 : did_run_(did_run),
29 delay_ms_(milliseconds) { 29 delay_ms_(milliseconds) {
30 } 30 }
31 void Start() { 31 void Start() {
32 timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(delay_ms_), this, 32 timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(delay_ms_), this,
33 &OneShotTimerTester::Run); 33 &OneShotTimerTester::Run);
34 } 34 }
35 private: 35 private:
36 void Run() { 36 void Run() {
37 *did_run_ = true; 37 *did_run_ = true;
38 MessageLoop::current()->Quit(); 38 MessageLoop::current()->QuitWhenIdle();
39 } 39 }
40 bool* did_run_; 40 bool* did_run_;
41 base::OneShotTimer<OneShotTimerTester> timer_; 41 base::OneShotTimer<OneShotTimerTester> timer_;
42 const unsigned delay_ms_; 42 const unsigned delay_ms_;
43 }; 43 };
44 44
45 class OneShotSelfDeletingTimerTester { 45 class OneShotSelfDeletingTimerTester {
46 public: 46 public:
47 explicit OneShotSelfDeletingTimerTester(bool* did_run) : 47 explicit OneShotSelfDeletingTimerTester(bool* did_run) :
48 did_run_(did_run), 48 did_run_(did_run),
49 timer_(new base::OneShotTimer<OneShotSelfDeletingTimerTester>()) { 49 timer_(new base::OneShotTimer<OneShotSelfDeletingTimerTester>()) {
50 } 50 }
51 void Start() { 51 void Start() {
52 timer_->Start(FROM_HERE, TimeDelta::FromMilliseconds(10), this, 52 timer_->Start(FROM_HERE, TimeDelta::FromMilliseconds(10), this,
53 &OneShotSelfDeletingTimerTester::Run); 53 &OneShotSelfDeletingTimerTester::Run);
54 } 54 }
55 private: 55 private:
56 void Run() { 56 void Run() {
57 *did_run_ = true; 57 *did_run_ = true;
58 timer_.reset(); 58 timer_.reset();
59 MessageLoop::current()->Quit(); 59 MessageLoop::current()->QuitWhenIdle();
60 } 60 }
61 bool* did_run_; 61 bool* did_run_;
62 scoped_ptr<base::OneShotTimer<OneShotSelfDeletingTimerTester> > timer_; 62 scoped_ptr<base::OneShotTimer<OneShotSelfDeletingTimerTester> > timer_;
63 }; 63 };
64 64
65 class RepeatingTimerTester { 65 class RepeatingTimerTester {
66 public: 66 public:
67 explicit RepeatingTimerTester(bool* did_run) 67 explicit RepeatingTimerTester(bool* did_run)
68 : did_run_(did_run), counter_(10) { 68 : did_run_(did_run), counter_(10) {
69 } 69 }
70 70
71 void Start() { 71 void Start() {
72 timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), this, 72 timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), this,
73 &RepeatingTimerTester::Run); 73 &RepeatingTimerTester::Run);
74 } 74 }
75 private: 75 private:
76 void Run() { 76 void Run() {
77 if (--counter_ == 0) { 77 if (--counter_ == 0) {
78 *did_run_ = true; 78 *did_run_ = true;
79 MessageLoop::current()->Quit(); 79 MessageLoop::current()->QuitWhenIdle();
80 } 80 }
81 } 81 }
82 bool* did_run_; 82 bool* did_run_;
83 int counter_; 83 int counter_;
84 base::RepeatingTimer<RepeatingTimerTester> timer_; 84 base::RepeatingTimer<RepeatingTimerTester> timer_;
85 }; 85 };
86 86
87 void RunTest_OneShotTimer(MessageLoop::Type message_loop_type) { 87 void RunTest_OneShotTimer(MessageLoop::Type message_loop_type) {
88 MessageLoop loop(message_loop_type); 88 MessageLoop loop(message_loop_type);
89 89
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 bool g_callback_happened1 = false; 439 bool g_callback_happened1 = false;
440 bool g_callback_happened2 = false; 440 bool g_callback_happened2 = false;
441 441
442 void ClearAllCallbackHappened() { 442 void ClearAllCallbackHappened() {
443 g_callback_happened1 = false; 443 g_callback_happened1 = false;
444 g_callback_happened2 = false; 444 g_callback_happened2 = false;
445 } 445 }
446 446
447 void SetCallbackHappened1() { 447 void SetCallbackHappened1() {
448 g_callback_happened1 = true; 448 g_callback_happened1 = true;
449 MessageLoop::current()->Quit(); 449 MessageLoop::current()->QuitWhenIdle();
450 } 450 }
451 451
452 void SetCallbackHappened2() { 452 void SetCallbackHappened2() {
453 g_callback_happened2 = true; 453 g_callback_happened2 = true;
454 MessageLoop::current()->Quit(); 454 MessageLoop::current()->QuitWhenIdle();
455 } 455 }
456 456
457 TEST(TimerTest, ContinuationStopStart) { 457 TEST(TimerTest, ContinuationStopStart) {
458 { 458 {
459 ClearAllCallbackHappened(); 459 ClearAllCallbackHappened();
460 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 460 MessageLoop loop(MessageLoop::TYPE_DEFAULT);
461 base::Timer timer(false, false); 461 base::Timer timer(false, false);
462 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), 462 timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10),
463 base::Bind(&SetCallbackHappened1)); 463 base::Bind(&SetCallbackHappened1));
464 timer.Stop(); 464 timer.Stop();
(...skipping 14 matching lines...) Expand all
479 base::Bind(&SetCallbackHappened1)); 479 base::Bind(&SetCallbackHappened1));
480 timer.Reset(); 480 timer.Reset();
481 // Since Reset happened before task ran, the user_task must not be cleared: 481 // Since Reset happened before task ran, the user_task must not be cleared:
482 ASSERT_FALSE(timer.user_task().is_null()); 482 ASSERT_FALSE(timer.user_task().is_null());
483 MessageLoop::current()->Run(); 483 MessageLoop::current()->Run();
484 EXPECT_TRUE(g_callback_happened1); 484 EXPECT_TRUE(g_callback_happened1);
485 } 485 }
486 } 486 }
487 487
488 } // namespace 488 } // namespace
OLDNEW
« no previous file with comments | « base/threading/thread.cc ('k') | base/win/object_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698