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/timer/timer.h" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 | 8 |
| 9 #include <memory> |
| 10 |
7 #include "base/macros.h" | 11 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
10 #include "base/test/test_simple_task_runner.h" | 13 #include "base/test/test_simple_task_runner.h" |
11 #include "base/timer/timer.h" | |
12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 using base::TimeDelta; | 17 using base::TimeDelta; |
16 using base::SingleThreadTaskRunner; | 18 using base::SingleThreadTaskRunner; |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 // The message loops on which each timer should be tested. | 22 // The message loops on which each timer should be tested. |
21 const base::MessageLoop::Type testing_message_loops[] = { | 23 const base::MessageLoop::Type testing_message_loops[] = { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 73 } |
72 | 74 |
73 private: | 75 private: |
74 void Run() { | 76 void Run() { |
75 *did_run_ = true; | 77 *did_run_ = true; |
76 timer_.reset(); | 78 timer_.reset(); |
77 base::MessageLoop::current()->QuitWhenIdle(); | 79 base::MessageLoop::current()->QuitWhenIdle(); |
78 } | 80 } |
79 | 81 |
80 bool* did_run_; | 82 bool* did_run_; |
81 scoped_ptr<base::OneShotTimer> timer_; | 83 std::unique_ptr<base::OneShotTimer> timer_; |
82 }; | 84 }; |
83 | 85 |
84 class RepeatingTimerTester { | 86 class RepeatingTimerTester { |
85 public: | 87 public: |
86 explicit RepeatingTimerTester(bool* did_run, const TimeDelta& delay) | 88 explicit RepeatingTimerTester(bool* did_run, const TimeDelta& delay) |
87 : did_run_(did_run), counter_(10), delay_(delay) { | 89 : did_run_(did_run), counter_(10), delay_(delay) { |
88 } | 90 } |
89 | 91 |
90 void Start() { | 92 void Start() { |
91 timer_.Start(FROM_HERE, delay_, this, &RepeatingTimerTester::Run); | 93 timer_.Start(FROM_HERE, delay_, this, &RepeatingTimerTester::Run); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 base::Bind(&SetCallbackHappened1)); | 528 base::Bind(&SetCallbackHappened1)); |
527 timer.Reset(); | 529 timer.Reset(); |
528 // Since Reset happened before task ran, the user_task must not be cleared: | 530 // Since Reset happened before task ran, the user_task must not be cleared: |
529 ASSERT_FALSE(timer.user_task().is_null()); | 531 ASSERT_FALSE(timer.user_task().is_null()); |
530 base::MessageLoop::current()->Run(); | 532 base::MessageLoop::current()->Run(); |
531 EXPECT_TRUE(g_callback_happened1); | 533 EXPECT_TRUE(g_callback_happened1); |
532 } | 534 } |
533 } | 535 } |
534 | 536 |
535 } // namespace | 537 } // namespace |
OLD | NEW |