| OLD | NEW |
| 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 16 matching lines...) Expand all Loading... |
| 27 *did_run_ = true; | 27 *did_run_ = true; |
| 28 MessageLoop::current()->Quit(); | 28 MessageLoop::current()->Quit(); |
| 29 } | 29 } |
| 30 bool* did_run_; | 30 bool* did_run_; |
| 31 base::OneShotTimer<OneShotTimerTester> timer_; | 31 base::OneShotTimer<OneShotTimerTester> timer_; |
| 32 const unsigned delay_ms_; | 32 const unsigned delay_ms_; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class OneShotSelfDeletingTimerTester { | 35 class OneShotSelfDeletingTimerTester { |
| 36 public: | 36 public: |
| 37 explicit OneShotSelfDeletingTimerTester(bool* did_run) : | 37 OneShotSelfDeletingTimerTester(bool* did_run) : |
| 38 did_run_(did_run), | 38 did_run_(did_run), |
| 39 timer_(new base::OneShotTimer<OneShotSelfDeletingTimerTester>()) { | 39 timer_(new base::OneShotTimer<OneShotSelfDeletingTimerTester>()) { |
| 40 } | 40 } |
| 41 void Start() { | 41 void Start() { |
| 42 timer_->Start(TimeDelta::FromMilliseconds(10), this, | 42 timer_->Start(TimeDelta::FromMilliseconds(10), this, |
| 43 &OneShotSelfDeletingTimerTester::Run); | 43 &OneShotSelfDeletingTimerTester::Run); |
| 44 } | 44 } |
| 45 private: | 45 private: |
| 46 void Run() { | 46 void Run() { |
| 47 *did_run_ = true; | 47 *did_run_ = true; |
| 48 timer_.reset(); | 48 timer_.reset(); |
| 49 MessageLoop::current()->Quit(); | 49 MessageLoop::current()->Quit(); |
| 50 } | 50 } |
| 51 bool* did_run_; | 51 bool* did_run_; |
| 52 scoped_ptr<base::OneShotTimer<OneShotSelfDeletingTimerTester> > timer_; | 52 scoped_ptr<base::OneShotTimer<OneShotSelfDeletingTimerTester> > timer_; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 class RepeatingTimerTester { | 55 class RepeatingTimerTester { |
| 56 public: | 56 public: |
| 57 explicit RepeatingTimerTester(bool* did_run) | 57 RepeatingTimerTester(bool* did_run) : did_run_(did_run), counter_(10) { |
| 58 : did_run_(did_run), counter_(10) { | |
| 59 } | 58 } |
| 60 | |
| 61 void Start() { | 59 void Start() { |
| 62 timer_.Start(TimeDelta::FromMilliseconds(10), this, | 60 timer_.Start(TimeDelta::FromMilliseconds(10), this, |
| 63 &RepeatingTimerTester::Run); | 61 &RepeatingTimerTester::Run); |
| 64 } | 62 } |
| 65 private: | 63 private: |
| 66 void Run() { | 64 void Run() { |
| 67 if (--counter_ == 0) { | 65 if (--counter_ == 0) { |
| 68 *did_run_ = true; | 66 *did_run_ = true; |
| 69 MessageLoop::current()->Quit(); | 67 MessageLoop::current()->Quit(); |
| 70 } | 68 } |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 OneShotTimerTester d(&did_run); | 344 OneShotTimerTester d(&did_run); |
| 347 { | 345 { |
| 348 MessageLoop loop(MessageLoop::TYPE_DEFAULT); | 346 MessageLoop loop(MessageLoop::TYPE_DEFAULT); |
| 349 a.Start(); | 347 a.Start(); |
| 350 b.Start(); | 348 b.Start(); |
| 351 } // MessageLoop destructs by falling out of scope. | 349 } // MessageLoop destructs by falling out of scope. |
| 352 } // OneShotTimers destruct. SHOULD NOT CRASH, of course. | 350 } // OneShotTimers destruct. SHOULD NOT CRASH, of course. |
| 353 | 351 |
| 354 EXPECT_EQ(false, did_run); | 352 EXPECT_EQ(false, did_run); |
| 355 } | 353 } |
| OLD | NEW |