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"
8 #include "components/domain_reliability/test_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace domain_reliability
{
14 using base::TimeDelta
;
15 using base::TimeTicks
;
17 class DomainReliabilityDispatcherTest
: public testing::Test
{
19 DomainReliabilityDispatcherTest() : dispatcher_(&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
);
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());
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());
59 EXPECT_TRUE(callback
.called());
63 } // namespace domain_reliability