Add an exponential backoff to rechecking the app list doodle.
[chromium-blink-merge.git] / components / domain_reliability / dispatcher_unittest.cc
blob0ffdbf059f33c1a52bda55a1439cf3696e638f08
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/dispatcher.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 DomainReliabilityDispatcherTest : public testing::Test {
18 public:
19 DomainReliabilityDispatcherTest() : dispatcher_(&time_) {}
21 protected:
22 MockTime time_;
23 DomainReliabilityDispatcher dispatcher_;
26 TEST_F(DomainReliabilityDispatcherTest, Create) {
29 TEST_F(DomainReliabilityDispatcherTest, TaskDoesntRunEarly) {
30 TimeDelta delay = TimeDelta::FromSeconds(1);
31 TestCallback callback;
33 dispatcher_.ScheduleTask(callback.callback(), 2 * delay, 3 * delay);
34 time_.Advance(delay);
35 dispatcher_.RunEligibleTasks();
36 EXPECT_FALSE(callback.called());
39 TEST_F(DomainReliabilityDispatcherTest, TaskRunsWhenEligible) {
40 TimeDelta delay = TimeDelta::FromSeconds(1);
41 TestCallback callback;
43 dispatcher_.ScheduleTask(callback.callback(), 2 * delay, 3 * delay);
44 time_.Advance(2 * delay);
45 EXPECT_FALSE(callback.called());
46 dispatcher_.RunEligibleTasks();
47 EXPECT_TRUE(callback.called());
48 time_.Advance(delay);
51 TEST_F(DomainReliabilityDispatcherTest, TaskRunsAtDeadline) {
52 TimeDelta delay = TimeDelta::FromSeconds(1);
53 TestCallback callback;
55 dispatcher_.ScheduleTask(callback.callback(), 2 * delay, 3 * delay);
56 time_.Advance(2 * delay);
57 EXPECT_FALSE(callback.called());
58 time_.Advance(delay);
59 EXPECT_TRUE(callback.called());
62 } // namespace
63 } // namespace domain_reliability