Add an exponential backoff to rechecking the app list doodle.
[chromium-blink-merge.git] / components / domain_reliability / util_unittest.cc
blob3f21fccaa50cc4bf01e1daa2424493845651f092
1 // Copyright 2014 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 "components/domain_reliability/util.h"
7 #include "base/bind.h"
8 #include "components/domain_reliability/test_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace domain_reliability {
12 namespace {
14 using base::TimeDelta;
15 using base::TimeTicks;
17 class DomainReliabilityMockTimeTest : public testing::Test {
18 protected:
19 MockTime time_;
22 TEST_F(DomainReliabilityMockTimeTest, Create) {
25 TEST_F(DomainReliabilityMockTimeTest, NowAndAdvance) {
26 const TimeDelta delta = TimeDelta::FromSeconds(1);
28 TimeTicks initial = time_.NowTicks();
29 time_.Advance(delta);
30 TimeTicks final = time_.NowTicks();
31 EXPECT_EQ(delta, final - initial);
34 TEST_F(DomainReliabilityMockTimeTest, AddTask) {
35 const TimeDelta delta = TimeDelta::FromSeconds(1);
36 TestCallback callback;
38 time_.AddTask(2 * delta, callback.callback());
39 time_.Advance(delta);
40 EXPECT_FALSE(callback.called());
41 time_.Advance(delta);
42 EXPECT_TRUE(callback.called());
45 TEST_F(DomainReliabilityMockTimeTest, TimerCreate) {
46 scoped_ptr<MockTime::Timer> timer(time_.CreateTimer());
49 TEST_F(DomainReliabilityMockTimeTest, TimerIsRunning) {
50 const TimeDelta delta = TimeDelta::FromSeconds(1);
51 TestCallback callback;
53 scoped_ptr<MockTime::Timer> timer(time_.CreateTimer());
54 EXPECT_FALSE(timer->IsRunning());
55 timer->Start(FROM_HERE, delta, callback.callback());
56 EXPECT_TRUE(timer->IsRunning());
57 timer->Stop();
58 EXPECT_FALSE(timer->IsRunning());
61 TEST_F(DomainReliabilityMockTimeTest, TimerGoesOff) {
62 const TimeDelta delta = TimeDelta::FromSeconds(1);
63 TestCallback callback;
65 scoped_ptr<MockTime::Timer> timer(time_.CreateTimer());
67 timer->Start(FROM_HERE, 2 * delta, callback.callback());
68 time_.Advance(delta);
69 EXPECT_FALSE(callback.called());
70 time_.Advance(delta);
71 EXPECT_TRUE(callback.called());
74 TEST_F(DomainReliabilityMockTimeTest, TimerStopped) {
75 const TimeDelta delta = TimeDelta::FromSeconds(1);
76 TestCallback callback;
78 scoped_ptr<MockTime::Timer> timer(time_.CreateTimer());
80 timer->Start(FROM_HERE, 2 * delta, callback.callback());
81 time_.Advance(delta);
82 timer->Stop();
83 time_.Advance(delta);
84 EXPECT_FALSE(callback.called());
87 TEST_F(DomainReliabilityMockTimeTest, TimerRestarted) {
88 const TimeDelta delta = TimeDelta::FromSeconds(1);
89 TestCallback callback;
91 scoped_ptr<MockTime::Timer> timer(time_.CreateTimer());
93 timer->Start(FROM_HERE, 2 * delta, callback.callback());
94 time_.Advance(delta);
95 timer->Start(FROM_HERE, 2 * delta, callback.callback());
96 time_.Advance(delta);
97 EXPECT_FALSE(callback.called());
98 time_.Advance(delta);
99 EXPECT_TRUE(callback.called());
102 TEST_F(DomainReliabilityMockTimeTest, TimerReentrantStart) {
103 const TimeDelta delta = TimeDelta::FromSeconds(1);
104 scoped_ptr<MockTime::Timer> timer(time_.CreateTimer());
105 TestCallback callback;
107 timer->Start(
108 FROM_HERE,
109 delta,
110 base::Bind(
111 &MockTime::Timer::Start,
112 base::Unretained(timer.get()),
113 FROM_HERE,
114 delta,
115 callback.callback()));
116 time_.Advance(delta);
117 EXPECT_FALSE(callback.called());
118 EXPECT_TRUE(timer->IsRunning());
119 time_.Advance(delta);
120 EXPECT_TRUE(callback.called());
121 EXPECT_FALSE(timer->IsRunning());
124 } // namespace
125 } // namespace domain_reliability