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
3 // found in the LICENSE file.
5 #include "remoting/host/backoff_timer.h"
7 #include "base/timer/mock_timer.h"
8 #include "testing/gtest/include/gtest/gtest.h"
14 void IncrementCounter(int* counter
) {
20 TEST(BackoffTimer
, Basic
) {
21 base::MockTimer
* mock_timer
= new base::MockTimer(false, false);
22 BackoffTimer backoff_timer
;
23 backoff_timer
.SetTimerForTest(make_scoped_ptr(mock_timer
));
24 ASSERT_FALSE(backoff_timer
.IsRunning());
27 backoff_timer
.Start(FROM_HERE
, base::TimeDelta::FromMilliseconds(10),
28 base::TimeDelta::FromMilliseconds(50),
29 base::Bind(&IncrementCounter
, &counter
));
30 ASSERT_TRUE(backoff_timer
.IsRunning());
31 ASSERT_EQ(0, counter
);
32 ASSERT_NEAR(0, mock_timer
->GetCurrentDelay().InMillisecondsF(), 1);
35 ASSERT_TRUE(backoff_timer
.IsRunning());
36 ASSERT_EQ(1, counter
);
37 EXPECT_NEAR(10, mock_timer
->GetCurrentDelay().InMillisecondsF(), 1);
40 ASSERT_TRUE(backoff_timer
.IsRunning());
41 ASSERT_EQ(2, counter
);
42 EXPECT_NEAR(20, mock_timer
->GetCurrentDelay().InMillisecondsF(), 1);
45 ASSERT_TRUE(backoff_timer
.IsRunning());
46 ASSERT_EQ(3, counter
);
47 EXPECT_NEAR(40, mock_timer
->GetCurrentDelay().InMillisecondsF(), 1);
50 ASSERT_TRUE(backoff_timer
.IsRunning());
51 ASSERT_EQ(4, counter
);
52 EXPECT_NEAR(50, mock_timer
->GetCurrentDelay().InMillisecondsF(), 1);
55 ASSERT_TRUE(backoff_timer
.IsRunning());
56 ASSERT_EQ(5, counter
);
57 EXPECT_NEAR(50, mock_timer
->GetCurrentDelay().InMillisecondsF(), 1);
60 ASSERT_FALSE(backoff_timer
.IsRunning());
63 } // namespace remoting