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

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

Issue 1497803004: Domain Reliability: Add sample_rate field to Beacon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 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/context.h" 5 #include "components/domain_reliability/context.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 context_.GetQueuedBeaconsForTesting(&beacons); 207 context_.GetQueuedBeaconsForTesting(&beacons);
208 EXPECT_EQ(1u, beacons.size()); 208 EXPECT_EQ(1u, beacons.size());
209 209
210 // N.B.: Assumes max_delay is 5 minutes. 210 // N.B.: Assumes max_delay is 5 minutes.
211 const char* kExpectedReport = "{" 211 const char* kExpectedReport = "{"
212 "\"entries\":[" 212 "\"entries\":["
213 "{\"failure_data\":{\"custom_error\":\"net::ERR_CONNECTION_RESET\"}," 213 "{\"failure_data\":{\"custom_error\":\"net::ERR_CONNECTION_RESET\"},"
214 "\"network_changed\":false,\"protocol\":\"HTTP\"," 214 "\"network_changed\":false,\"protocol\":\"HTTP\","
215 "\"request_age_ms\":300250,\"request_elapsed_ms\":250," 215 "\"request_age_ms\":300250,\"request_elapsed_ms\":250,"
216 "\"server_ip\":\"127.0.0.1\",\"status\":\"tcp.connection_reset\"," 216 "\"server_ip\":\"127.0.0.1\",\"status\":\"tcp.connection_reset\","
217 "\"url\":\"https://localhost/\",\"was_proxied\":false}]," 217 "\"url\":\"https://localhost/\",\"was_proxied\":false,\"weight\":1}],"
jkarlin 2015/12/07 14:57:27 A weight of 1 isn't testing that division is happe
Deprecated (see juliatuttle) 2015/12/07 20:17:57 Acknowledged.
218 "\"reporter\":\"test-reporter\"}"; 218 "\"reporter\":\"test-reporter\"}";
219 219
220 time_.Advance(max_delay()); 220 time_.Advance(max_delay());
221 EXPECT_TRUE(upload_pending()); 221 EXPECT_TRUE(upload_pending());
222 EXPECT_EQ(kExpectedReport, upload_report()); 222 EXPECT_EQ(kExpectedReport, upload_report());
223 EXPECT_EQ(0, upload_max_depth()); 223 EXPECT_EQ(0, upload_max_depth());
224 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); 224 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url());
225 225
226 DomainReliabilityUploader::UploadResult result; 226 DomainReliabilityUploader::UploadResult result;
227 result.status = DomainReliabilityUploader::UploadResult::SUCCESS; 227 result.status = DomainReliabilityUploader::UploadResult::SUCCESS;
228 CallUploadCallback(result); 228 CallUploadCallback(result);
229 229
230 EXPECT_TRUE(CheckNoBeacons()); 230 EXPECT_TRUE(CheckNoBeacons());
231 } 231 }
232 232
233 TEST_F(DomainReliabilityContextTest, Upload_NetworkChanged) { 233 TEST_F(DomainReliabilityContextTest, Upload_NetworkChanged) {
234 context_.OnBeacon(MakeBeacon(&time_)); 234 context_.OnBeacon(MakeBeacon(&time_));
235 235
236 BeaconVector beacons; 236 BeaconVector beacons;
237 context_.GetQueuedBeaconsForTesting(&beacons); 237 context_.GetQueuedBeaconsForTesting(&beacons);
238 EXPECT_EQ(1u, beacons.size()); 238 EXPECT_EQ(1u, beacons.size());
239 239
240 // N.B.: Assumes max_delay is 5 minutes. 240 // N.B.: Assumes max_delay is 5 minutes.
241 const char* kExpectedReport = "{" 241 const char* kExpectedReport = "{"
242 "\"entries\":[" 242 "\"entries\":["
243 "{\"failure_data\":{\"custom_error\":\"net::ERR_CONNECTION_RESET\"}," 243 "{\"failure_data\":{\"custom_error\":\"net::ERR_CONNECTION_RESET\"},"
244 "\"network_changed\":true,\"protocol\":\"HTTP\"," 244 "\"network_changed\":true,\"protocol\":\"HTTP\","
245 "\"request_age_ms\":300250,\"request_elapsed_ms\":250," 245 "\"request_age_ms\":300250,\"request_elapsed_ms\":250,"
246 "\"server_ip\":\"127.0.0.1\",\"status\":\"tcp.connection_reset\"," 246 "\"server_ip\":\"127.0.0.1\",\"status\":\"tcp.connection_reset\","
247 "\"url\":\"https://localhost/\",\"was_proxied\":false}]," 247 "\"url\":\"https://localhost/\",\"was_proxied\":false,\"weight\":1}],"
248 "\"reporter\":\"test-reporter\"}"; 248 "\"reporter\":\"test-reporter\"}";
249 249
250 // Simulate a network change after the request but before the upload. 250 // Simulate a network change after the request but before the upload.
251 last_network_change_time_ = time_.NowTicks(); 251 last_network_change_time_ = time_.NowTicks();
252 time_.Advance(max_delay()); 252 time_.Advance(max_delay());
253 EXPECT_TRUE(upload_pending()); 253 EXPECT_TRUE(upload_pending());
254 EXPECT_EQ(kExpectedReport, upload_report()); 254 EXPECT_EQ(kExpectedReport, upload_report());
255 EXPECT_EQ(0, upload_max_depth()); 255 EXPECT_EQ(0, upload_max_depth());
256 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); 256 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url());
257 257
258 DomainReliabilityUploader::UploadResult result; 258 DomainReliabilityUploader::UploadResult result;
259 result.status = DomainReliabilityUploader::UploadResult::SUCCESS; 259 result.status = DomainReliabilityUploader::UploadResult::SUCCESS;
260 CallUploadCallback(result); 260 CallUploadCallback(result);
261 261
262 EXPECT_TRUE(CheckNoBeacons()); 262 EXPECT_TRUE(CheckNoBeacons());
263 } 263 }
264 264
265 // TODO(ttuttle): Add beacon_unittest.cc to test serialization. 265 // TODO(ttuttle): Add beacon_unittest.cc to test serialization.
266 266
267 } // namespace 267 } // namespace
268 } // namespace domain_reliability 268 } // namespace domain_reliability
OLDNEW
« components/domain_reliability/context.cc ('K') | « components/domain_reliability/context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698