OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" | 5 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 void SetUp() override { | 44 void SetUp() override { |
45 client_.SetDMToken("token"); | 45 client_.SetDMToken("token"); |
46 | 46 |
47 // Set up the protobuf timestamp to be one minute in the past. Since the | 47 // Set up the protobuf timestamp to be one minute in the past. Since the |
48 // protobuf field only has millisecond precision, we convert the actual | 48 // protobuf field only has millisecond precision, we convert the actual |
49 // value back to get a millisecond-clamped time stamp for the checks below. | 49 // value back to get a millisecond-clamped time stamp for the checks below. |
50 store_.policy_.reset(new em::PolicyData()); | 50 store_.policy_.reset(new em::PolicyData()); |
51 base::Time now = base::Time::NowFromSystemTime(); | 51 base::Time now = base::Time::NowFromSystemTime(); |
52 base::TimeDelta initial_age = | 52 base::TimeDelta initial_age = |
53 base::TimeDelta::FromMinutes(kInitialCacheAgeMinutes); | 53 base::TimeDelta::FromMinutes(kInitialCacheAgeMinutes); |
54 store_.policy_->set_timestamp( | 54 store_.policy_->set_timestamp((now - initial_age).ToJavaTime()); |
55 ((now - initial_age) - base::Time::UnixEpoch()).InMilliseconds()); | 55 last_update_ = base::Time::FromJavaTime(store_.policy_->timestamp()); |
56 last_update_ = | |
57 base::Time::UnixEpoch() + | |
58 base::TimeDelta::FromMilliseconds(store_.policy_->timestamp()); | |
59 last_update_ticks_ = base::TimeTicks::Now() + | 56 last_update_ticks_ = base::TimeTicks::Now() + |
60 (last_update_ - base::Time::NowFromSystemTime()); | 57 (last_update_ - base::Time::NowFromSystemTime()); |
61 } | 58 } |
62 | 59 |
63 CloudPolicyRefreshScheduler* CreateRefreshScheduler() { | 60 CloudPolicyRefreshScheduler* CreateRefreshScheduler() { |
64 EXPECT_EQ(0u, task_runner_->NumPendingTasks()); | 61 EXPECT_EQ(0u, task_runner_->NumPendingTasks()); |
65 CloudPolicyRefreshScheduler* scheduler = | 62 CloudPolicyRefreshScheduler* scheduler = |
66 new CloudPolicyRefreshScheduler(&client_, &store_, task_runner_); | 63 new CloudPolicyRefreshScheduler(&client_, &store_, task_runner_); |
67 scheduler->SetDesiredRefreshDelay(kPolicyRefreshRate); | 64 scheduler->SetDesiredRefreshDelay(kPolicyRefreshRate); |
68 return scheduler; | 65 return scheduler; |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 EXPECT_EQ(base::TimeDelta(), GetLastDelay()); | 484 EXPECT_EQ(base::TimeDelta(), GetLastDelay()); |
488 EXPECT_FALSE(task_runner_->HasPendingTask()); | 485 EXPECT_FALSE(task_runner_->HasPendingTask()); |
489 } | 486 } |
490 } | 487 } |
491 | 488 |
492 INSTANTIATE_TEST_CASE_P(CloudPolicyRefreshSchedulerClientErrorTest, | 489 INSTANTIATE_TEST_CASE_P(CloudPolicyRefreshSchedulerClientErrorTest, |
493 CloudPolicyRefreshSchedulerClientErrorTest, | 490 CloudPolicyRefreshSchedulerClientErrorTest, |
494 testing::ValuesIn(kClientErrorTestCases)); | 491 testing::ValuesIn(kClientErrorTestCases)); |
495 | 492 |
496 } // namespace policy | 493 } // namespace policy |
OLD | NEW |