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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
13 #include "components/domain_reliability/beacon.h" | 13 #include "components/domain_reliability/beacon.h" |
14 #include "components/domain_reliability/dispatcher.h" | 14 #include "components/domain_reliability/dispatcher.h" |
15 #include "components/domain_reliability/scheduler.h" | 15 #include "components/domain_reliability/scheduler.h" |
16 #include "components/domain_reliability/test_util.h" | 16 #include "components/domain_reliability/test_util.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace domain_reliability { | 21 namespace domain_reliability { |
22 namespace { | 22 namespace { |
23 | 23 |
24 typedef std::vector<DomainReliabilityBeacon> BeaconVector; | 24 typedef std::vector<DomainReliabilityBeacon> BeaconVector; |
25 | 25 |
26 DomainReliabilityBeacon MakeBeacon(MockableTime* time) { | 26 DomainReliabilityBeacon MakeBeacon(MockableTime* time) { |
27 DomainReliabilityBeacon beacon; | 27 DomainReliabilityBeacon beacon; |
| 28 beacon.domain = "localhost"; |
28 beacon.status = "ok"; | 29 beacon.status = "ok"; |
29 beacon.chrome_error = net::OK; | 30 beacon.chrome_error = net::OK; |
30 beacon.server_ip = "127.0.0.1"; | 31 beacon.server_ip = "127.0.0.1"; |
31 beacon.protocol = "HTTP"; | 32 beacon.protocol = "HTTP"; |
32 beacon.http_response_code = 200; | 33 beacon.http_response_code = 200; |
33 beacon.elapsed = base::TimeDelta::FromMilliseconds(250); | 34 beacon.elapsed = base::TimeDelta::FromMilliseconds(250); |
34 beacon.start_time = time->NowTicks() - beacon.elapsed; | 35 beacon.start_time = time->NowTicks() - beacon.elapsed; |
35 return beacon; | 36 return beacon; |
36 } | 37 } |
37 | 38 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 159 |
159 BeaconVector beacons; | 160 BeaconVector beacons; |
160 context_.GetQueuedBeaconsForTesting(&beacons); | 161 context_.GetQueuedBeaconsForTesting(&beacons); |
161 EXPECT_EQ(1u, beacons.size()); | 162 EXPECT_EQ(1u, beacons.size()); |
162 EXPECT_TRUE(CheckCounts(0, 1, 0)); | 163 EXPECT_TRUE(CheckCounts(0, 1, 0)); |
163 EXPECT_TRUE(CheckCounts(1, 0, 0)); | 164 EXPECT_TRUE(CheckCounts(1, 0, 0)); |
164 | 165 |
165 // N.B.: Assumes max_delay is 5 minutes. | 166 // N.B.: Assumes max_delay is 5 minutes. |
166 const char* kExpectedReport = "{" | 167 const char* kExpectedReport = "{" |
167 "\"config_version\":\"1\"," | 168 "\"config_version\":\"1\"," |
168 "\"entries\":[{\"http_response_code\":200,\"protocol\":\"HTTP\"," | 169 "\"entries\":[{\"domain\":\"localhost\"," |
| 170 "\"http_response_code\":200,\"protocol\":\"HTTP\"," |
169 "\"request_age_ms\":300250,\"request_elapsed_ms\":250," | 171 "\"request_age_ms\":300250,\"request_elapsed_ms\":250," |
170 "\"resource\":\"always_report\",\"server_ip\":\"127.0.0.1\"," | 172 "\"resource\":\"always_report\",\"server_ip\":\"127.0.0.1\"," |
171 "\"status\":\"ok\"}]," | 173 "\"status\":\"ok\"}]," |
172 "\"reporter\":\"test-reporter\"," | 174 "\"reporter\":\"test-reporter\"," |
173 "\"resources\":[{\"failed_requests\":0,\"name\":\"always_report\"," | 175 "\"resources\":[{\"failed_requests\":0,\"name\":\"always_report\"," |
174 "\"successful_requests\":1}]}"; | 176 "\"successful_requests\":1}]}"; |
175 | 177 |
176 time_.Advance(max_delay()); | 178 time_.Advance(max_delay()); |
177 EXPECT_TRUE(upload_pending()); | 179 EXPECT_TRUE(upload_pending()); |
178 EXPECT_EQ(kExpectedReport, upload_report()); | 180 EXPECT_EQ(kExpectedReport, upload_report()); |
179 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); | 181 EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url()); |
180 CallUploadCallback(true); | 182 CallUploadCallback(true); |
181 | 183 |
182 EXPECT_TRUE(CheckNoBeacons()); | 184 EXPECT_TRUE(CheckNoBeacons()); |
183 EXPECT_TRUE(CheckCounts(0, 0, 0)); | 185 EXPECT_TRUE(CheckCounts(0, 0, 0)); |
184 EXPECT_TRUE(CheckCounts(1, 0, 0)); | 186 EXPECT_TRUE(CheckCounts(1, 0, 0)); |
185 } | 187 } |
186 | 188 |
187 } // namespace | 189 } // namespace |
188 } // namespace domain_reliability | 190 } // namespace domain_reliability |
OLD | NEW |