| OLD | NEW |
| 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; |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // The message loops on which each timer should be tested. | 14 // The message loops on which each timer should be tested. |
| 15 const MessageLoop::Type testing_message_loops[] = { | 15 const MessageLoop::Type testing_message_loops[] = { |
| 16 MessageLoop::TYPE_DEFAULT, | 16 MessageLoop::TYPE_DEFAULT, |
| 17 MessageLoop::TYPE_IO, | 17 MessageLoop::TYPE_IO, |
| 18 #if !defined(OS_IOS) // iOS does not allow direct running of the UI loop. | 18 #if !defined(OS_IOS) // iOS does not allow direct running of the UI loop. |
| 19 MessageLoop::TYPE_UI, | 19 MessageLoop::TYPE_UI, |
| 20 #endif | 20 #endif |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 const int kNumTestingMessageLoops = arraysize(testing_message_loops); | 23 const int kNumTestingMessageLoops = arraysize(testing_message_loops); |
| 24 | 24 |
| 25 class OneShotTimerTester { | 25 class OneShotTimerTester { |
| 26 public: | 26 public: |
| 27 OneShotTimerTester(bool* did_run, unsigned milliseconds = 10) | 27 explicit OneShotTimerTester(bool* did_run, unsigned milliseconds = 10) |
| 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; |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |