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

Side by Side Diff: components/domain_reliability/test_util.cc

Issue 291493004: Domain Reliability: Deduplicate some code into test_util (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 7 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
« no previous file with comments | « components/domain_reliability/test_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/domain_reliability/test_util.h" 5 #include "components/domain_reliability/test_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "components/domain_reliability/scheduler.h"
8 #include "net/url_request/url_request_status.h" 9 #include "net/url_request/url_request_status.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace domain_reliability { 12 namespace domain_reliability {
12 13
13 namespace { 14 namespace {
14 15
15 class MockTimer : public MockableTime::Timer { 16 class MockTimer : public MockableTime::Timer {
16 public: 17 public:
17 MockTimer(MockTime* time) 18 MockTimer(MockTime* time)
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 void MockTime::AddTask(base::TimeDelta delay, const base::Closure& task) { 137 void MockTime::AddTask(base::TimeDelta delay, const base::Closure& task) {
137 tasks_[TaskKey(now_ticks_ + delay, task_sequence_number_++)] = task; 138 tasks_[TaskKey(now_ticks_ + delay, task_sequence_number_++)] = task;
138 } 139 }
139 140
140 void MockTime::AdvanceToInternal(base::TimeTicks target_ticks) { 141 void MockTime::AdvanceToInternal(base::TimeTicks target_ticks) {
141 base::TimeDelta delta = target_ticks - now_ticks_; 142 base::TimeDelta delta = target_ticks - now_ticks_;
142 now_ += delta; 143 now_ += delta;
143 now_ticks_ += delta; 144 now_ticks_ += delta;
144 } 145 }
145 146
147 DomainReliabilityScheduler::Params MakeTestSchedulerParams() {
148 DomainReliabilityScheduler::Params params;
149 params.minimum_upload_delay = base::TimeDelta::FromMinutes(1);
150 params.maximum_upload_delay = base::TimeDelta::FromMinutes(5);
151 params.upload_retry_interval = base::TimeDelta::FromSeconds(15);
152 return params;
153 }
154
155 scoped_ptr<const DomainReliabilityConfig> MakeTestConfig() {
156 DomainReliabilityConfig* config = new DomainReliabilityConfig();
157 DomainReliabilityConfig::Resource* resource;
158
159 resource = new DomainReliabilityConfig::Resource();
160 resource->name = "always_report";
161 resource->url_patterns.push_back(
162 new std::string("http://example/always_report"));
163 resource->success_sample_rate = 1.0;
164 resource->failure_sample_rate = 1.0;
165 config->resources.push_back(resource);
166
167 resource = new DomainReliabilityConfig::Resource();
168 resource->name = "never_report";
169 resource->url_patterns.push_back(
170 new std::string("http://example/never_report"));
171 resource->success_sample_rate = 0.0;
172 resource->failure_sample_rate = 0.0;
173 config->resources.push_back(resource);
174
175 DomainReliabilityConfig::Collector* collector;
176 collector = new DomainReliabilityConfig::Collector();
177 collector->upload_url = GURL("https://example/upload");
178 config->collectors.push_back(collector);
179
180 config->version = "1";
181 config->valid_until = 1234567890.0;
182 config->domain = "example";
183
184 DCHECK(config->IsValid());
185
186 return scoped_ptr<const DomainReliabilityConfig>(config);
187 }
188
146 } // namespace domain_reliability 189 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « components/domain_reliability/test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698