Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / backoff_timer_unittest.cc
blob0dfb9d7ce67c2da3c73b1b42f3c5893765c79328
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"
10 namespace remoting {
12 namespace {
14 void IncrementCounter(int* counter) {
15 ++(*counter);
18 } // namespace
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());
26 int counter = 0;
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);
34 mock_timer->Fire();
35 ASSERT_TRUE(backoff_timer.IsRunning());
36 ASSERT_EQ(1, counter);
37 EXPECT_NEAR(10, mock_timer->GetCurrentDelay().InMillisecondsF(), 1);
39 mock_timer->Fire();
40 ASSERT_TRUE(backoff_timer.IsRunning());
41 ASSERT_EQ(2, counter);
42 EXPECT_NEAR(20, mock_timer->GetCurrentDelay().InMillisecondsF(), 1);
44 mock_timer->Fire();
45 ASSERT_TRUE(backoff_timer.IsRunning());
46 ASSERT_EQ(3, counter);
47 EXPECT_NEAR(40, mock_timer->GetCurrentDelay().InMillisecondsF(), 1);
49 mock_timer->Fire();
50 ASSERT_TRUE(backoff_timer.IsRunning());
51 ASSERT_EQ(4, counter);
52 EXPECT_NEAR(50, mock_timer->GetCurrentDelay().InMillisecondsF(), 1);
54 mock_timer->Fire();
55 ASSERT_TRUE(backoff_timer.IsRunning());
56 ASSERT_EQ(5, counter);
57 EXPECT_NEAR(50, mock_timer->GetCurrentDelay().InMillisecondsF(), 1);
59 backoff_timer.Stop();
60 ASSERT_FALSE(backoff_timer.IsRunning());
63 } // namespace remoting