| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "net/reporting/reporting_test_util.h" | 5 #include "net/reporting/reporting_test_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/test/simple_test_clock.h" | 14 #include "base/test/simple_test_clock.h" |
| 15 #include "base/test/simple_test_tick_clock.h" | 15 #include "base/test/simple_test_tick_clock.h" |
| 16 #include "base/timer/mock_timer.h" | 16 #include "base/timer/mock_timer.h" |
| 17 #include "base/timer/timer.h" | |
| 18 #include "net/reporting/reporting_cache.h" | 17 #include "net/reporting/reporting_cache.h" |
| 19 #include "net/reporting/reporting_client.h" | 18 #include "net/reporting/reporting_client.h" |
| 20 #include "net/reporting/reporting_context.h" | 19 #include "net/reporting/reporting_context.h" |
| 21 #include "net/reporting/reporting_delegate.h" | 20 #include "net/reporting/reporting_delegate.h" |
| 21 #include "net/reporting/reporting_delivery_agent.h" |
| 22 #include "net/reporting/reporting_garbage_collector.h" | 22 #include "net/reporting/reporting_garbage_collector.h" |
| 23 #include "net/reporting/reporting_persister.h" | 23 #include "net/reporting/reporting_persister.h" |
| 24 #include "net/reporting/reporting_policy.h" | 24 #include "net/reporting/reporting_policy.h" |
| 25 #include "net/reporting/reporting_uploader.h" | 25 #include "net/reporting/reporting_uploader.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 28 #include "url/origin.h" | 28 #include "url/origin.h" |
| 29 | 29 |
| 30 namespace net { | 30 namespace net { |
| 31 | 31 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 pending_uploads_.push_back(base::MakeUnique<PendingUploadImpl>( | 117 pending_uploads_.push_back(base::MakeUnique<PendingUploadImpl>( |
| 118 url, json, callback, base::Bind(&ErasePendingUpload, &pending_uploads_))); | 118 url, json, callback, base::Bind(&ErasePendingUpload, &pending_uploads_))); |
| 119 } | 119 } |
| 120 | 120 |
| 121 TestReportingContext::TestReportingContext(const ReportingPolicy& policy) | 121 TestReportingContext::TestReportingContext(const ReportingPolicy& policy) |
| 122 : ReportingContext(policy, | 122 : ReportingContext(policy, |
| 123 base::MakeUnique<TestReportingDelegate>(), | 123 base::MakeUnique<TestReportingDelegate>(), |
| 124 base::MakeUnique<base::SimpleTestClock>(), | 124 base::MakeUnique<base::SimpleTestClock>(), |
| 125 base::MakeUnique<base::SimpleTestTickClock>(), | 125 base::MakeUnique<base::SimpleTestTickClock>(), |
| 126 base::MakeUnique<TestReportingUploader>()), | 126 base::MakeUnique<TestReportingUploader>()), |
| 127 delivery_timer_(new base::MockTimer(/* retain_user_task= */ false, |
| 128 /* is_repeating= */ false)), |
| 127 persistence_timer_(new base::MockTimer(/* retain_user_task= */ false, | 129 persistence_timer_(new base::MockTimer(/* retain_user_task= */ false, |
| 128 /* is_repeating= */ false)), | 130 /* is_repeating= */ false)), |
| 129 garbage_collection_timer_( | 131 garbage_collection_timer_( |
| 130 new base::MockTimer(/* retain_user_task= */ false, | 132 new base::MockTimer(/* retain_user_task= */ false, |
| 131 /* is_repeating= */ false)) { | 133 /* is_repeating= */ false)) { |
| 132 persister()->SetTimerForTesting(base::WrapUnique(persistence_timer_)); | 134 persister()->SetTimerForTesting(base::WrapUnique(persistence_timer_)); |
| 133 garbage_collector()->SetTimerForTesting( | 135 garbage_collector()->SetTimerForTesting( |
| 134 base::WrapUnique(garbage_collection_timer_)); | 136 base::WrapUnique(garbage_collection_timer_)); |
| 137 delivery_agent()->SetTimerForTesting(base::WrapUnique(delivery_timer_)); |
| 135 } | 138 } |
| 136 | 139 |
| 137 TestReportingContext::~TestReportingContext() { | 140 TestReportingContext::~TestReportingContext() { |
| 141 delivery_timer_ = nullptr; |
| 138 persistence_timer_ = nullptr; | 142 persistence_timer_ = nullptr; |
| 139 garbage_collection_timer_ = nullptr; | 143 garbage_collection_timer_ = nullptr; |
| 140 } | 144 } |
| 141 | 145 |
| 142 ReportingTestBase::ReportingTestBase() { | 146 ReportingTestBase::ReportingTestBase() { |
| 143 // For tests, disable jitter. | 147 // For tests, disable jitter. |
| 144 ReportingPolicy policy; | 148 ReportingPolicy policy; |
| 145 policy.endpoint_backoff_policy.jitter_factor = 0.0; | 149 policy.endpoint_backoff_policy.jitter_factor = 0.0; |
| 146 | 150 |
| 147 CreateAndInitializeContext(policy, std::unique_ptr<const base::Value>(), | 151 CreateAndInitializeContext(policy, std::unique_ptr<const base::Value>(), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 171 delegate()->PersistData(std::move(persisted_data)); | 175 delegate()->PersistData(std::move(persisted_data)); |
| 172 clock()->SetNow(now); | 176 clock()->SetNow(now); |
| 173 tick_clock()->SetNowTicks(now_ticks); | 177 tick_clock()->SetNowTicks(now_ticks); |
| 174 context_->Initialize(); | 178 context_->Initialize(); |
| 175 } | 179 } |
| 176 | 180 |
| 177 base::TimeTicks ReportingTestBase::yesterday() { | 181 base::TimeTicks ReportingTestBase::yesterday() { |
| 178 return tick_clock()->NowTicks() - base::TimeDelta::FromDays(1); | 182 return tick_clock()->NowTicks() - base::TimeDelta::FromDays(1); |
| 179 } | 183 } |
| 180 | 184 |
| 185 base::TimeTicks ReportingTestBase::now() { |
| 186 return tick_clock()->NowTicks(); |
| 187 } |
| 188 |
| 181 base::TimeTicks ReportingTestBase::tomorrow() { | 189 base::TimeTicks ReportingTestBase::tomorrow() { |
| 182 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1); | 190 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1); |
| 183 } | 191 } |
| 184 | 192 |
| 185 } // namespace net | 193 } // namespace net |
| OLD | NEW |