dispatcher_unittest.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.
  4. #include "components/domain_reliability/dispatcher.h"
  5. #include "base/bind.h"
  6. #include "components/domain_reliability/test_util.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace domain_reliability {
  9. namespace {
  10. using base::TimeTicks;
  11. class DomainReliabilityDispatcherTest : public testing::Test {
  12. public:
  13. DomainReliabilityDispatcherTest() : dispatcher_(&time_) {}
  14. protected:
  15. MockTime time_;
  16. DomainReliabilityDispatcher dispatcher_;
  17. };
  18. TEST_F(DomainReliabilityDispatcherTest, Create) {
  19. }
  20. TEST_F(DomainReliabilityDispatcherTest, TaskDoesntRunEarly) {
  21. base::TimeDelta delay = base::Seconds(1);
  22. TestCallback callback;
  23. dispatcher_.ScheduleTask(callback.callback(), 2 * delay, 3 * delay);
  24. time_.Advance(delay);
  25. dispatcher_.RunEligibleTasks();
  26. EXPECT_FALSE(callback.called());
  27. }
  28. TEST_F(DomainReliabilityDispatcherTest, TaskRunsWhenEligible) {
  29. base::TimeDelta delay = base::Seconds(1);
  30. TestCallback callback;
  31. dispatcher_.ScheduleTask(callback.callback(), 2 * delay, 3 * delay);
  32. time_.Advance(2 * delay);
  33. EXPECT_FALSE(callback.called());
  34. dispatcher_.RunEligibleTasks();
  35. EXPECT_TRUE(callback.called());
  36. time_.Advance(delay);
  37. }
  38. TEST_F(DomainReliabilityDispatcherTest, TaskRunsAtDeadline) {
  39. base::TimeDelta delay = base::Seconds(1);
  40. TestCallback callback;
  41. dispatcher_.ScheduleTask(callback.callback(), 2 * delay, 3 * delay);
  42. time_.Advance(2 * delay);
  43. EXPECT_FALSE(callback.called());
  44. time_.Advance(delay);
  45. EXPECT_TRUE(callback.called());
  46. }
  47. } // namespace
  48. } // namespace domain_reliability