OLD | NEW |
---|---|
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 18 matching lines...) Expand all Loading... | |
29 beacon->status = "tcp.connection_reset"; | 29 beacon->status = "tcp.connection_reset"; |
30 beacon->chrome_error = net::ERR_CONNECTION_RESET; | 30 beacon->chrome_error = net::ERR_CONNECTION_RESET; |
31 beacon->server_ip = "127.0.0.1"; | 31 beacon->server_ip = "127.0.0.1"; |
32 beacon->was_proxied = false; | 32 beacon->was_proxied = false; |
33 beacon->protocol = "HTTP"; | 33 beacon->protocol = "HTTP"; |
34 beacon->details.quic_broken = true; | 34 beacon->details.quic_broken = true; |
35 beacon->http_response_code = -1; | 35 beacon->http_response_code = -1; |
36 beacon->elapsed = base::TimeDelta::FromMilliseconds(250); | 36 beacon->elapsed = base::TimeDelta::FromMilliseconds(250); |
37 beacon->start_time = time->NowTicks() - beacon->elapsed; | 37 beacon->start_time = time->NowTicks() - beacon->elapsed; |
38 beacon->upload_depth = 0; | 38 beacon->upload_depth = 0; |
39 beacon->sample_rate = 1.0; | |
39 return beacon.Pass(); | 40 return beacon.Pass(); |
40 } | 41 } |
41 | 42 |
42 class DomainReliabilityContextTest : public testing::Test { | 43 class DomainReliabilityContextTest : public testing::Test { |
43 protected: | 44 protected: |
44 DomainReliabilityContextTest() | 45 DomainReliabilityContextTest() |
45 : last_network_change_time_(time_.NowTicks()), | 46 : last_network_change_time_(time_.NowTicks()), |
46 dispatcher_(&time_), | 47 dispatcher_(&time_), |
47 params_(MakeTestSchedulerParams()), | 48 params_(MakeTestSchedulerParams()), |
48 uploader_(base::Bind(&DomainReliabilityContextTest::OnUploadRequest, | 49 uploader_(base::Bind(&DomainReliabilityContextTest::OnUploadRequest, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 BeaconVector beacons; | 208 BeaconVector beacons; |
208 context_.GetQueuedBeaconsForTesting(&beacons); | 209 context_.GetQueuedBeaconsForTesting(&beacons); |
209 EXPECT_EQ(1u, beacons.size()); | 210 EXPECT_EQ(1u, beacons.size()); |
210 | 211 |
211 // N.B.: Assumes max_delay is 5 minutes. | 212 // N.B.: Assumes max_delay is 5 minutes. |
212 const char* kExpectedReport = "{" | 213 const char* kExpectedReport = "{" |
213 "\"entries\":[" | 214 "\"entries\":[" |
214 "{\"failure_data\":{\"custom_error\":\"net::ERR_CONNECTION_RESET\"}," | 215 "{\"failure_data\":{\"custom_error\":\"net::ERR_CONNECTION_RESET\"}," |
215 "\"network_changed\":false,\"protocol\":\"HTTP\"," | 216 "\"network_changed\":false,\"protocol\":\"HTTP\"," |
216 "\"quic_broken\":true,\"request_age_ms\":300250," | 217 "\"quic_broken\":true,\"request_age_ms\":300250," |
217 "\"request_elapsed_ms\":250," | 218 "\"request_elapsed_ms\":250,\"sample_rate\":1.0," |
218 "\"server_ip\":\"127.0.0.1\",\"status\":\"tcp.connection_reset\"," | 219 "\"server_ip\":\"127.0.0.1\",\"status\":\"tcp.connection_reset\"," |
219 "\"url\":\"https://localhost/\"," | 220 "\"url\":\"https://localhost/\",\"was_proxied\":false}]," |
220 "\"was_proxied\":false}],\"reporter\":\"test-reporter\"}"; | 221 "\"reporter\":\"test-reporter\"}"; |
221 | 222 |
222 time_.Advance(max_delay()); | 223 time_.Advance(max_delay()); |
223 EXPECT_TRUE(upload_pending()); | 224 EXPECT_TRUE(upload_pending()); |
224 EXPECT_EQ(kExpectedReport, upload_report()); | 225 EXPECT_EQ(kExpectedReport, upload_report()); |
225 EXPECT_EQ(0, upload_max_depth()); | 226 EXPECT_EQ(0, upload_max_depth()); |
226 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); | 227 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); |
227 | 228 |
228 DomainReliabilityUploader::UploadResult result; | 229 DomainReliabilityUploader::UploadResult result; |
229 result.status = DomainReliabilityUploader::UploadResult::SUCCESS; | 230 result.status = DomainReliabilityUploader::UploadResult::SUCCESS; |
230 CallUploadCallback(result); | 231 CallUploadCallback(result); |
231 | 232 |
232 EXPECT_TRUE(CheckNoBeacons()); | 233 EXPECT_TRUE(CheckNoBeacons()); |
233 } | 234 } |
234 | 235 |
235 TEST_F(DomainReliabilityContextTest, Upload_NetworkChanged) { | 236 TEST_F(DomainReliabilityContextTest, Upload_NetworkChanged) { |
236 context_.OnBeacon(MakeBeacon(&time_)); | 237 context_.OnBeacon(MakeBeacon(&time_)); |
237 | 238 |
238 BeaconVector beacons; | 239 BeaconVector beacons; |
239 context_.GetQueuedBeaconsForTesting(&beacons); | 240 context_.GetQueuedBeaconsForTesting(&beacons); |
240 EXPECT_EQ(1u, beacons.size()); | 241 EXPECT_EQ(1u, beacons.size()); |
241 | 242 |
242 // N.B.: Assumes max_delay is 5 minutes. | 243 // N.B.: Assumes max_delay is 5 minutes. |
243 const char* kExpectedReport = "{" | 244 const char* kExpectedReport = "{" |
244 "\"entries\":[" | 245 "\"entries\":[" |
245 "{\"failure_data\":{\"custom_error\":\"net::ERR_CONNECTION_RESET\"}," | 246 "{\"failure_data\":{\"custom_error\":\"net::ERR_CONNECTION_RESET\"}," |
246 "\"network_changed\":true,\"protocol\":\"HTTP\"," | 247 "\"network_changed\":true,\"protocol\":\"HTTP\"," |
247 "\"quic_broken\":true,\"request_age_ms\":300250," | 248 "\"quic_broken\":true,\"request_age_ms\":300250," |
248 "\"request_elapsed_ms\":250," | 249 "\"request_elapsed_ms\":250,\"sample_rate\":1.0," |
jkarlin
2015/12/09 11:46:22
Needs more tests. Include rates such as 0.0, 1.0,
Deprecated (see juliatuttle)
2015/12/10 17:04:23
I've added tests for 0.0 and 0.5 (1.0 is tested im
| |
249 "\"server_ip\":\"127.0.0.1\",\"status\":\"tcp.connection_reset\"," | 250 "\"server_ip\":\"127.0.0.1\",\"status\":\"tcp.connection_reset\"," |
250 "\"url\":\"https://localhost/\"," | 251 "\"url\":\"https://localhost/\",\"was_proxied\":false}]," |
251 "\"was_proxied\":false}],\"reporter\":\"test-reporter\"}"; | 252 "\"reporter\":\"test-reporter\"}"; |
252 | 253 |
253 // Simulate a network change after the request but before the upload. | 254 // Simulate a network change after the request but before the upload. |
254 last_network_change_time_ = time_.NowTicks(); | 255 last_network_change_time_ = time_.NowTicks(); |
255 time_.Advance(max_delay()); | 256 time_.Advance(max_delay()); |
256 EXPECT_TRUE(upload_pending()); | 257 EXPECT_TRUE(upload_pending()); |
257 EXPECT_EQ(kExpectedReport, upload_report()); | 258 EXPECT_EQ(kExpectedReport, upload_report()); |
258 EXPECT_EQ(0, upload_max_depth()); | 259 EXPECT_EQ(0, upload_max_depth()); |
259 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); | 260 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); |
260 | 261 |
261 DomainReliabilityUploader::UploadResult result; | 262 DomainReliabilityUploader::UploadResult result; |
262 result.status = DomainReliabilityUploader::UploadResult::SUCCESS; | 263 result.status = DomainReliabilityUploader::UploadResult::SUCCESS; |
263 CallUploadCallback(result); | 264 CallUploadCallback(result); |
264 | 265 |
265 EXPECT_TRUE(CheckNoBeacons()); | 266 EXPECT_TRUE(CheckNoBeacons()); |
266 } | 267 } |
267 | 268 |
268 // TODO(ttuttle): Add beacon_unittest.cc to test serialization. | 269 // TODO(ttuttle): Add beacon_unittest.cc to test serialization. |
269 | 270 |
270 } // namespace | 271 } // namespace |
271 } // namespace domain_reliability | 272 } // namespace domain_reliability |
OLD | NEW |