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 12 matching lines...) Expand all Loading... |
23 namespace { | 23 namespace { |
24 | 24 |
25 typedef std::vector<DomainReliabilityBeacon> BeaconVector; | 25 typedef std::vector<DomainReliabilityBeacon> BeaconVector; |
26 | 26 |
27 DomainReliabilityBeacon MakeBeacon(MockableTime* time) { | 27 DomainReliabilityBeacon MakeBeacon(MockableTime* time) { |
28 DomainReliabilityBeacon beacon; | 28 DomainReliabilityBeacon beacon; |
29 beacon.domain = "localhost"; | 29 beacon.domain = "localhost"; |
30 beacon.status = "ok"; | 30 beacon.status = "ok"; |
31 beacon.chrome_error = net::OK; | 31 beacon.chrome_error = net::OK; |
32 beacon.server_ip = "127.0.0.1"; | 32 beacon.server_ip = "127.0.0.1"; |
| 33 beacon.was_proxied = false; |
33 beacon.protocol = "HTTP"; | 34 beacon.protocol = "HTTP"; |
34 beacon.http_response_code = 200; | 35 beacon.http_response_code = 200; |
35 beacon.elapsed = base::TimeDelta::FromMilliseconds(250); | 36 beacon.elapsed = base::TimeDelta::FromMilliseconds(250); |
36 beacon.start_time = time->NowTicks() - beacon.elapsed; | 37 beacon.start_time = time->NowTicks() - beacon.elapsed; |
37 return beacon; | 38 return beacon; |
38 } | 39 } |
39 | 40 |
40 class DomainReliabilityContextTest : public testing::Test { | 41 class DomainReliabilityContextTest : public testing::Test { |
41 protected: | 42 protected: |
42 DomainReliabilityContextTest() | 43 DomainReliabilityContextTest() |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 EXPECT_TRUE(CheckCounts(0, 1, 0)); | 173 EXPECT_TRUE(CheckCounts(0, 1, 0)); |
173 EXPECT_TRUE(CheckCounts(1, 0, 0)); | 174 EXPECT_TRUE(CheckCounts(1, 0, 0)); |
174 | 175 |
175 // N.B.: Assumes max_delay is 5 minutes. | 176 // N.B.: Assumes max_delay is 5 minutes. |
176 const char* kExpectedReport = "{" | 177 const char* kExpectedReport = "{" |
177 "\"config_version\":\"1\"," | 178 "\"config_version\":\"1\"," |
178 "\"entries\":[{\"domain\":\"localhost\"," | 179 "\"entries\":[{\"domain\":\"localhost\"," |
179 "\"http_response_code\":200,\"network_changed\":false," | 180 "\"http_response_code\":200,\"network_changed\":false," |
180 "\"protocol\":\"HTTP\",\"request_age_ms\":300250," | 181 "\"protocol\":\"HTTP\",\"request_age_ms\":300250," |
181 "\"request_elapsed_ms\":250,\"resource\":\"always_report\"," | 182 "\"request_elapsed_ms\":250,\"resource\":\"always_report\"," |
182 "\"server_ip\":\"127.0.0.1\",\"status\":\"ok\"}]," | 183 "\"server_ip\":\"127.0.0.1\",\"status\":\"ok\"," |
| 184 "\"was_proxied\":false}]," |
183 "\"reporter\":\"test-reporter\"," | 185 "\"reporter\":\"test-reporter\"," |
184 "\"resources\":[{\"failed_requests\":0,\"name\":\"always_report\"," | 186 "\"resources\":[{\"failed_requests\":0,\"name\":\"always_report\"," |
185 "\"successful_requests\":1}]}"; | 187 "\"successful_requests\":1}]}"; |
186 | 188 |
187 time_.Advance(max_delay()); | 189 time_.Advance(max_delay()); |
188 EXPECT_TRUE(upload_pending()); | 190 EXPECT_TRUE(upload_pending()); |
189 EXPECT_EQ(kExpectedReport, upload_report()); | 191 EXPECT_EQ(kExpectedReport, upload_report()); |
190 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); | 192 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); |
191 | 193 |
192 DomainReliabilityUploader::UploadResult result; | 194 DomainReliabilityUploader::UploadResult result; |
(...skipping 16 matching lines...) Expand all Loading... |
209 EXPECT_TRUE(CheckCounts(0, 1, 0)); | 211 EXPECT_TRUE(CheckCounts(0, 1, 0)); |
210 EXPECT_TRUE(CheckCounts(1, 0, 0)); | 212 EXPECT_TRUE(CheckCounts(1, 0, 0)); |
211 | 213 |
212 // N.B.: Assumes max_delay is 5 minutes. | 214 // N.B.: Assumes max_delay is 5 minutes. |
213 const char* kExpectedReport = "{" | 215 const char* kExpectedReport = "{" |
214 "\"config_version\":\"1\"," | 216 "\"config_version\":\"1\"," |
215 "\"entries\":[{\"domain\":\"localhost\"," | 217 "\"entries\":[{\"domain\":\"localhost\"," |
216 "\"http_response_code\":200,\"network_changed\":true," | 218 "\"http_response_code\":200,\"network_changed\":true," |
217 "\"protocol\":\"HTTP\",\"request_age_ms\":300250," | 219 "\"protocol\":\"HTTP\",\"request_age_ms\":300250," |
218 "\"request_elapsed_ms\":250,\"resource\":\"always_report\"," | 220 "\"request_elapsed_ms\":250,\"resource\":\"always_report\"," |
219 "\"server_ip\":\"127.0.0.1\",\"status\":\"ok\"}]," | 221 "\"server_ip\":\"127.0.0.1\",\"status\":\"ok\"," |
| 222 "\"was_proxied\":false}]," |
220 "\"reporter\":\"test-reporter\"," | 223 "\"reporter\":\"test-reporter\"," |
221 "\"resources\":[{\"failed_requests\":0,\"name\":\"always_report\"," | 224 "\"resources\":[{\"failed_requests\":0,\"name\":\"always_report\"," |
222 "\"successful_requests\":1}]}"; | 225 "\"successful_requests\":1}]}"; |
223 | 226 |
224 // Simulate a network change after the request but before the upload. | 227 // Simulate a network change after the request but before the upload. |
225 last_network_change_time_ = time_.NowTicks(); | 228 last_network_change_time_ = time_.NowTicks(); |
226 time_.Advance(max_delay()); | 229 time_.Advance(max_delay()); |
227 | 230 |
228 EXPECT_TRUE(upload_pending()); | 231 EXPECT_TRUE(upload_pending()); |
229 EXPECT_EQ(kExpectedReport, upload_report()); | 232 EXPECT_EQ(kExpectedReport, upload_report()); |
230 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); | 233 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); |
231 | 234 |
232 DomainReliabilityUploader::UploadResult result; | 235 DomainReliabilityUploader::UploadResult result; |
233 result.status = DomainReliabilityUploader::UploadResult::SUCCESS; | 236 result.status = DomainReliabilityUploader::UploadResult::SUCCESS; |
234 CallUploadCallback(result); | 237 CallUploadCallback(result); |
235 | 238 |
236 EXPECT_TRUE(CheckNoBeacons()); | 239 EXPECT_TRUE(CheckNoBeacons()); |
237 EXPECT_TRUE(CheckCounts(0, 0, 0)); | 240 EXPECT_TRUE(CheckCounts(0, 0, 0)); |
238 EXPECT_TRUE(CheckCounts(1, 0, 0)); | 241 EXPECT_TRUE(CheckCounts(1, 0, 0)); |
239 } | 242 } |
240 | 243 |
241 } // namespace | 244 } // namespace |
242 } // namespace domain_reliability | 245 } // namespace domain_reliability |
OLD | NEW |