| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/domain_reliability/scheduler.h" | 5 #include "components/domain_reliability/scheduler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "components/domain_reliability/config.h" | 9 #include "components/domain_reliability/config.h" |
| 10 #include "components/domain_reliability/test_util.h" | 10 #include "components/domain_reliability/test_util.h" |
| 11 #include "components/domain_reliability/util.h" | 11 #include "components/domain_reliability/util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace domain_reliability { | 14 namespace domain_reliability { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 using base::TimeDelta; | 17 using base::TimeDelta; |
| 18 using base::TimeTicks; | 18 using base::TimeTicks; |
| 19 | 19 |
| 20 class DomainReliabilitySchedulerTest : public testing::Test { | 20 class DomainReliabilitySchedulerTest : public testing::Test { |
| 21 public: | 21 public: |
| 22 DomainReliabilitySchedulerTest() | 22 DomainReliabilitySchedulerTest() |
| 23 : num_collectors_(0), | 23 : num_collectors_(0), |
| 24 params_(CreateDefaultParams()), | 24 params_(MakeTestSchedulerParams()), |
| 25 callback_called_(false) {} | 25 callback_called_(false) {} |
| 26 | 26 |
| 27 void CreateScheduler(int num_collectors) { | 27 void CreateScheduler(int num_collectors) { |
| 28 DCHECK_LT(0, num_collectors); | 28 DCHECK_LT(0, num_collectors); |
| 29 DCHECK(!scheduler_); | 29 DCHECK(!scheduler_); |
| 30 | 30 |
| 31 num_collectors_ = num_collectors; | 31 num_collectors_ = num_collectors; |
| 32 scheduler_.reset(new DomainReliabilityScheduler( | 32 scheduler_.reset(new DomainReliabilityScheduler( |
| 33 &time_, | 33 &time_, |
| 34 num_collectors_, | 34 num_collectors_, |
| 35 params_, | 35 params_, |
| 36 base::Bind(&DomainReliabilitySchedulerTest::ScheduleUploadCallback, | 36 base::Bind(&DomainReliabilitySchedulerTest::ScheduleUploadCallback, |
| 37 base::Unretained(this)))); | 37 base::Unretained(this)))); |
| 38 } | 38 } |
| 39 | 39 |
| 40 static DomainReliabilityScheduler::Params CreateDefaultParams() { | |
| 41 DomainReliabilityScheduler::Params params; | |
| 42 params.minimum_upload_delay = base::TimeDelta::FromSeconds(60); | |
| 43 params.maximum_upload_delay = base::TimeDelta::FromSeconds(300); | |
| 44 params.upload_retry_interval = base::TimeDelta::FromSeconds(15); | |
| 45 return params; | |
| 46 } | |
| 47 | |
| 48 ::testing::AssertionResult CheckNoPendingUpload() { | 40 ::testing::AssertionResult CheckNoPendingUpload() { |
| 49 DCHECK(scheduler_); | 41 DCHECK(scheduler_); |
| 50 | 42 |
| 51 if (!callback_called_) | 43 if (!callback_called_) |
| 52 return ::testing::AssertionSuccess(); | 44 return ::testing::AssertionSuccess(); |
| 53 | 45 |
| 54 return ::testing::AssertionFailure() | 46 return ::testing::AssertionFailure() |
| 55 << "expected no upload, got upload between " | 47 << "expected no upload, got upload between " |
| 56 << callback_min_.InSeconds() << " and " | 48 << callback_min_.InSeconds() << " and " |
| 57 << callback_max_.InSeconds() << " seconds from now"; | 49 << callback_max_.InSeconds() << " seconds from now"; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ASSERT_TRUE(CheckPendingUpload(min_delay(), max_delay())); | 235 ASSERT_TRUE(CheckPendingUpload(min_delay(), max_delay())); |
| 244 | 236 |
| 245 time_.Advance(min_delay()); | 237 time_.Advance(min_delay()); |
| 246 ASSERT_TRUE(CheckStartingUpload(0)); | 238 ASSERT_TRUE(CheckStartingUpload(0)); |
| 247 scheduler_->OnUploadComplete(true); | 239 scheduler_->OnUploadComplete(true); |
| 248 ASSERT_TRUE(CheckNoPendingUpload()); | 240 ASSERT_TRUE(CheckNoPendingUpload()); |
| 249 } | 241 } |
| 250 | 242 |
| 251 } // namespace | 243 } // namespace |
| 252 } // namespace domain_reliability | 244 } // namespace domain_reliability |
| OLD | NEW |