| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/host/backoff_timer.h" | 5 #include "remoting/host/backoff_timer.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 7 #include "base/timer/mock_timer.h" | 8 #include "base/timer/mock_timer.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 namespace remoting { | 11 namespace remoting { |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 void IncrementCounter(int* counter) { | 15 void IncrementCounter(int* counter) { |
| 15 ++(*counter); | 16 ++(*counter); |
| 16 } | 17 } |
| 17 | 18 |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| 20 TEST(BackoffTimer, Basic) { | 21 TEST(BackoffTimer, Basic) { |
| 21 base::MockTimer* mock_timer = new base::MockTimer(false, false); | 22 base::MockTimer* mock_timer = new base::MockTimer(false, false); |
| 22 BackoffTimer backoff_timer; | 23 BackoffTimer backoff_timer; |
| 23 backoff_timer.SetTimerForTest(make_scoped_ptr(mock_timer)); | 24 backoff_timer.SetTimerForTest(base::WrapUnique(mock_timer)); |
| 24 ASSERT_FALSE(backoff_timer.IsRunning()); | 25 ASSERT_FALSE(backoff_timer.IsRunning()); |
| 25 | 26 |
| 26 int counter = 0; | 27 int counter = 0; |
| 27 backoff_timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(10), | 28 backoff_timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(10), |
| 28 base::TimeDelta::FromMilliseconds(50), | 29 base::TimeDelta::FromMilliseconds(50), |
| 29 base::Bind(&IncrementCounter, &counter)); | 30 base::Bind(&IncrementCounter, &counter)); |
| 30 ASSERT_TRUE(backoff_timer.IsRunning()); | 31 ASSERT_TRUE(backoff_timer.IsRunning()); |
| 31 ASSERT_EQ(0, counter); | 32 ASSERT_EQ(0, counter); |
| 32 ASSERT_NEAR(0, mock_timer->GetCurrentDelay().InMillisecondsF(), 1); | 33 ASSERT_NEAR(0, mock_timer->GetCurrentDelay().InMillisecondsF(), 1); |
| 33 | 34 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 54 mock_timer->Fire(); | 55 mock_timer->Fire(); |
| 55 ASSERT_TRUE(backoff_timer.IsRunning()); | 56 ASSERT_TRUE(backoff_timer.IsRunning()); |
| 56 ASSERT_EQ(5, counter); | 57 ASSERT_EQ(5, counter); |
| 57 EXPECT_NEAR(50, mock_timer->GetCurrentDelay().InMillisecondsF(), 1); | 58 EXPECT_NEAR(50, mock_timer->GetCurrentDelay().InMillisecondsF(), 1); |
| 58 | 59 |
| 59 backoff_timer.Stop(); | 60 backoff_timer.Stop(); |
| 60 ASSERT_FALSE(backoff_timer.IsRunning()); | 61 ASSERT_FALSE(backoff_timer.IsRunning()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 } // namespace remoting | 64 } // namespace remoting |
| OLD | NEW |