| 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 "net/reporting/reporting_cache.h" | 17 #include "net/reporting/reporting_cache.h" |
| 17 #include "net/reporting/reporting_client.h" | 18 #include "net/reporting/reporting_client.h" |
| 18 #include "net/reporting/reporting_context.h" | 19 #include "net/reporting/reporting_context.h" |
| 19 #include "net/reporting/reporting_delegate.h" | 20 #include "net/reporting/reporting_delegate.h" |
| 21 #include "net/reporting/reporting_garbage_collector.h" |
| 20 #include "net/reporting/reporting_policy.h" | 22 #include "net/reporting/reporting_policy.h" |
| 21 #include "net/reporting/reporting_uploader.h" | 23 #include "net/reporting/reporting_uploader.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 24 #include "url/origin.h" | 26 #include "url/origin.h" |
| 25 | 27 |
| 26 namespace net { | 28 namespace net { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 const Callback& callback) { | 114 const Callback& callback) { |
| 113 pending_uploads_.push_back(base::MakeUnique<PendingUploadImpl>( | 115 pending_uploads_.push_back(base::MakeUnique<PendingUploadImpl>( |
| 114 url, json, callback, base::Bind(&ErasePendingUpload, &pending_uploads_))); | 116 url, json, callback, base::Bind(&ErasePendingUpload, &pending_uploads_))); |
| 115 } | 117 } |
| 116 | 118 |
| 117 TestReportingContext::TestReportingContext(const ReportingPolicy& policy) | 119 TestReportingContext::TestReportingContext(const ReportingPolicy& policy) |
| 118 : ReportingContext(policy, | 120 : ReportingContext(policy, |
| 119 base::MakeUnique<TestReportingDelegate>(), | 121 base::MakeUnique<TestReportingDelegate>(), |
| 120 base::MakeUnique<base::SimpleTestClock>(), | 122 base::MakeUnique<base::SimpleTestClock>(), |
| 121 base::MakeUnique<base::SimpleTestTickClock>(), | 123 base::MakeUnique<base::SimpleTestTickClock>(), |
| 122 base::MakeUnique<TestReportingUploader>()) {} | 124 base::MakeUnique<TestReportingUploader>()), |
| 125 garbage_collection_timer_( |
| 126 new base::MockTimer(/* retain_user_task= */ false, |
| 127 /* is_repeating= */ false)) { |
| 128 garbage_collector()->SetTimerForTesting( |
| 129 base::WrapUnique(garbage_collection_timer_)); |
| 130 } |
| 123 | 131 |
| 124 TestReportingContext::~TestReportingContext() {} | 132 TestReportingContext::~TestReportingContext() { |
| 133 garbage_collection_timer_ = nullptr; |
| 134 } |
| 125 | 135 |
| 126 ReportingTestBase::ReportingTestBase() { | 136 ReportingTestBase::ReportingTestBase() { |
| 127 // For tests, disable jitter. | 137 // For tests, disable jitter. |
| 128 ReportingPolicy policy; | 138 ReportingPolicy policy; |
| 129 policy.endpoint_backoff_policy.jitter_factor = 0.0; | 139 policy.endpoint_backoff_policy.jitter_factor = 0.0; |
| 130 UsePolicy(policy); | 140 UsePolicy(policy); |
| 131 } | 141 } |
| 132 | 142 |
| 133 ReportingTestBase::~ReportingTestBase() {} | 143 ReportingTestBase::~ReportingTestBase() {} |
| 134 | 144 |
| 135 void ReportingTestBase::UsePolicy(const ReportingPolicy& policy) { | 145 void ReportingTestBase::UsePolicy(const ReportingPolicy& policy) { |
| 136 context_ = base::MakeUnique<TestReportingContext>(policy); | 146 context_ = base::MakeUnique<TestReportingContext>(policy); |
| 137 } | 147 } |
| 138 | 148 |
| 139 base::TimeTicks ReportingTestBase::yesterday() { | 149 base::TimeTicks ReportingTestBase::yesterday() { |
| 140 return tick_clock()->NowTicks() - base::TimeDelta::FromDays(1); | 150 return tick_clock()->NowTicks() - base::TimeDelta::FromDays(1); |
| 141 } | 151 } |
| 142 | 152 |
| 143 base::TimeTicks ReportingTestBase::tomorrow() { | 153 base::TimeTicks ReportingTestBase::tomorrow() { |
| 144 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1); | 154 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1); |
| 145 } | 155 } |
| 146 | 156 |
| 147 } // namespace net | 157 } // namespace net |
| OLD | NEW |