Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: net/reporting/reporting_test_util.cc

Issue 2740833004: Reporting: Implement garbage collector. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
20 #include "net/reporting/reporting_policy.h" 21 #include "net/reporting/reporting_policy.h"
21 #include "net/reporting/reporting_uploader.h" 22 #include "net/reporting/reporting_uploader.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 #include "url/origin.h" 25 #include "url/origin.h"
25 26
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const Callback& callback) { 113 const Callback& callback) {
113 pending_uploads_.push_back(base::MakeUnique<PendingUploadImpl>( 114 pending_uploads_.push_back(base::MakeUnique<PendingUploadImpl>(
114 url, json, callback, base::Bind(&ErasePendingUpload, &pending_uploads_))); 115 url, json, callback, base::Bind(&ErasePendingUpload, &pending_uploads_)));
115 } 116 }
116 117
117 TestReportingContext::TestReportingContext(const ReportingPolicy& policy) 118 TestReportingContext::TestReportingContext(const ReportingPolicy& policy)
118 : ReportingContext(policy), 119 : ReportingContext(policy),
119 test_delegate_(new TestReportingDelegate()), 120 test_delegate_(new TestReportingDelegate()),
120 test_clock_(new base::SimpleTestClock()), 121 test_clock_(new base::SimpleTestClock()),
121 test_tick_clock_(new base::SimpleTestTickClock()), 122 test_tick_clock_(new base::SimpleTestTickClock()),
123 test_garbage_collection_timer_(
124 new base::MockTimer(/* retain_user_task= */ false,
125 /* is_repeating= */ false)),
122 test_uploader_(new TestReportingUploader()) { 126 test_uploader_(new TestReportingUploader()) {
123 Init(base::WrapUnique(test_delegate_), base::WrapUnique(test_clock_), 127 Init(base::WrapUnique(test_delegate_), base::WrapUnique(test_clock_),
124 base::WrapUnique(test_tick_clock_), base::WrapUnique(test_uploader_)); 128 base::WrapUnique(test_tick_clock_),
129 base::WrapUnique(test_garbage_collection_timer_),
130 base::WrapUnique(test_uploader_));
125 } 131 }
126 132
127 TestReportingContext::~TestReportingContext() {} 133 TestReportingContext::~TestReportingContext() {}
128 134
129 ReportingTestBase::ReportingTestBase() { 135 ReportingTestBase::ReportingTestBase() {
130 // For tests, disable jitter. 136 // For tests, disable jitter.
131 ReportingPolicy policy; 137 ReportingPolicy policy;
132 policy.endpoint_backoff_policy.jitter_factor = 0.0; 138 policy.endpoint_backoff_policy.jitter_factor = 0.0;
133 UsePolicy(policy); 139 UsePolicy(policy);
134 } 140 }
135 141
136 ReportingTestBase::~ReportingTestBase() {} 142 ReportingTestBase::~ReportingTestBase() {}
137 143
138 void ReportingTestBase::UsePolicy(const ReportingPolicy& policy) { 144 void ReportingTestBase::UsePolicy(const ReportingPolicy& policy) {
139 context_ = base::MakeUnique<TestReportingContext>(policy); 145 context_ = base::MakeUnique<TestReportingContext>(policy);
140 } 146 }
141 147
142 base::TimeTicks ReportingTestBase::yesterday() { 148 base::TimeTicks ReportingTestBase::yesterday() {
143 return tick_clock()->NowTicks() - base::TimeDelta::FromDays(1); 149 return tick_clock()->NowTicks() - base::TimeDelta::FromDays(1);
144 } 150 }
145 151
146 base::TimeTicks ReportingTestBase::tomorrow() { 152 base::TimeTicks ReportingTestBase::tomorrow() {
147 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1); 153 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1);
148 } 154 }
149 155
150 } // namespace net 156 } // namespace net
OLDNEW
« net/reporting/reporting_context.h ('K') | « net/reporting/reporting_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698