| OLD | NEW |
| (Empty) |
| 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 | |
| 5 #include "components/metrics/metrics_reporting_scheduler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "base/run_loop.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace metrics { | |
| 14 | |
| 15 class MetricsReportingSchedulerTest : public testing::Test { | |
| 16 public: | |
| 17 MetricsReportingSchedulerTest() : callback_call_count_(0) {} | |
| 18 ~MetricsReportingSchedulerTest() override {} | |
| 19 | |
| 20 base::Closure GetCallback() { | |
| 21 return base::Bind(&MetricsReportingSchedulerTest::SchedulerCallback, | |
| 22 base::Unretained(this)); | |
| 23 } | |
| 24 | |
| 25 base::Callback<base::TimeDelta(void)> GetConnectionCallback() { | |
| 26 return base::Bind(&MetricsReportingSchedulerTest::GetStandardUploadInterval, | |
| 27 base::Unretained(this)); | |
| 28 } | |
| 29 | |
| 30 int callback_call_count() const { return callback_call_count_; } | |
| 31 | |
| 32 private: | |
| 33 void SchedulerCallback() { | |
| 34 ++callback_call_count_; | |
| 35 } | |
| 36 | |
| 37 base::TimeDelta GetStandardUploadInterval() { | |
| 38 return base::TimeDelta::FromMinutes(5); | |
| 39 } | |
| 40 | |
| 41 int callback_call_count_; | |
| 42 | |
| 43 base::MessageLoopForUI message_loop_; | |
| 44 | |
| 45 DISALLOW_COPY_AND_ASSIGN(MetricsReportingSchedulerTest); | |
| 46 }; | |
| 47 | |
| 48 | |
| 49 TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteBeforeTimer) { | |
| 50 MetricsReportingScheduler scheduler(GetCallback(), GetConnectionCallback()); | |
| 51 scheduler.SetUploadIntervalForTesting(base::TimeDelta()); | |
| 52 scheduler.InitTaskComplete(); | |
| 53 scheduler.Start(); | |
| 54 EXPECT_EQ(0, callback_call_count()); | |
| 55 | |
| 56 base::RunLoop().RunUntilIdle(); | |
| 57 EXPECT_EQ(1, callback_call_count()); | |
| 58 } | |
| 59 | |
| 60 TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteAfterTimer) { | |
| 61 MetricsReportingScheduler scheduler(GetCallback(), GetConnectionCallback()); | |
| 62 scheduler.SetUploadIntervalForTesting(base::TimeDelta()); | |
| 63 scheduler.Start(); | |
| 64 base::RunLoop().RunUntilIdle(); | |
| 65 EXPECT_EQ(0, callback_call_count()); | |
| 66 | |
| 67 scheduler.InitTaskComplete(); | |
| 68 EXPECT_EQ(1, callback_call_count()); | |
| 69 } | |
| 70 | |
| 71 } // namespace metrics | |
| OLD | NEW |