| 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/monitor.h" | 5 #include "components/domain_reliability/monitor.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 context_(nullptr) { | 59 context_(nullptr) { |
| 60 monitor_.MoveToNetworkThread(); | 60 monitor_.MoveToNetworkThread(); |
| 61 monitor_.InitURLRequestContext(url_request_context_getter_); | 61 monitor_.InitURLRequestContext(url_request_context_getter_); |
| 62 monitor_.SetDiscardUploads(false); | 62 monitor_.SetDiscardUploads(false); |
| 63 context_ = monitor_.AddContextForTesting(MakeTestConfig()); | 63 context_ = monitor_.AddContextForTesting(MakeTestConfig()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 static RequestInfo MakeRequestInfo() { | 66 static RequestInfo MakeRequestInfo() { |
| 67 RequestInfo request; | 67 RequestInfo request; |
| 68 request.status = net::URLRequestStatus(); | 68 request.status = net::URLRequestStatus(); |
| 69 request.status.set_status(net::URLRequestStatus::SUCCESS); | |
| 70 request.status.set_error(net::OK); | |
| 71 request.response_info.socket_address = | 69 request.response_info.socket_address = |
| 72 net::HostPortPair::FromString("12.34.56.78:80"); | 70 net::HostPortPair::FromString("12.34.56.78:80"); |
| 73 request.response_info.headers = MakeHttpResponseHeaders( | 71 request.response_info.headers = MakeHttpResponseHeaders( |
| 74 "HTTP/1.1 200 OK\n\n"); | 72 "HTTP/1.1 200 OK\n\n"); |
| 75 request.response_info.was_cached = false; | 73 request.response_info.was_cached = false; |
| 76 request.response_info.network_accessed = true; | 74 request.response_info.network_accessed = true; |
| 77 request.response_info.was_fetched_via_proxy = false; | 75 request.response_info.was_fetched_via_proxy = false; |
| 78 request.load_flags = 0; | 76 request.load_flags = 0; |
| 79 request.is_upload = false; | 77 request.is_upload = false; |
| 80 return request; | 78 return request; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 request.url = GURL("http://example/never_report"); | 144 request.url = GURL("http://example/never_report"); |
| 147 OnRequestLegComplete(request); | 145 OnRequestLegComplete(request); |
| 148 | 146 |
| 149 EXPECT_EQ(0u, CountPendingBeacons()); | 147 EXPECT_EQ(0u, CountPendingBeacons()); |
| 150 EXPECT_TRUE(CheckRequestCounts(kNeverReportIndex, 1u, 0u)); | 148 EXPECT_TRUE(CheckRequestCounts(kNeverReportIndex, 1u, 0u)); |
| 151 } | 149 } |
| 152 | 150 |
| 153 TEST_F(DomainReliabilityMonitorTest, NetworkFailure) { | 151 TEST_F(DomainReliabilityMonitorTest, NetworkFailure) { |
| 154 RequestInfo request = MakeRequestInfo(); | 152 RequestInfo request = MakeRequestInfo(); |
| 155 request.url = GURL("http://example/always_report"); | 153 request.url = GURL("http://example/always_report"); |
| 156 request.status.set_status(net::URLRequestStatus::FAILED); | 154 request.status = net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET); |
| 157 request.status.set_error(net::ERR_CONNECTION_RESET); | |
| 158 request.response_info.headers = nullptr; | 155 request.response_info.headers = nullptr; |
| 159 OnRequestLegComplete(request); | 156 OnRequestLegComplete(request); |
| 160 | 157 |
| 161 EXPECT_EQ(1u, CountPendingBeacons()); | 158 EXPECT_EQ(1u, CountPendingBeacons()); |
| 162 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 0u, 1u)); | 159 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 0u, 1u)); |
| 163 } | 160 } |
| 164 | 161 |
| 165 TEST_F(DomainReliabilityMonitorTest, ServerFailure) { | 162 TEST_F(DomainReliabilityMonitorTest, ServerFailure) { |
| 166 RequestInfo request = MakeRequestInfo(); | 163 RequestInfo request = MakeRequestInfo(); |
| 167 request.url = GURL("http://example/always_report"); | 164 request.url = GURL("http://example/always_report"); |
| 168 request.response_info.headers = | 165 request.response_info.headers = |
| 169 MakeHttpResponseHeaders("HTTP/1.1 500 :(\n\n"); | 166 MakeHttpResponseHeaders("HTTP/1.1 500 :(\n\n"); |
| 170 OnRequestLegComplete(request); | 167 OnRequestLegComplete(request); |
| 171 | 168 |
| 172 EXPECT_EQ(1u, CountPendingBeacons()); | 169 EXPECT_EQ(1u, CountPendingBeacons()); |
| 173 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 0u, 1u)); | 170 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 0u, 1u)); |
| 174 } | 171 } |
| 175 | 172 |
| 176 TEST_F(DomainReliabilityMonitorTest, NotReportedFailure) { | 173 TEST_F(DomainReliabilityMonitorTest, NotReportedFailure) { |
| 177 RequestInfo request = MakeRequestInfo(); | 174 RequestInfo request = MakeRequestInfo(); |
| 178 request.url = GURL("http://example/never_report"); | 175 request.url = GURL("http://example/never_report"); |
| 179 request.status.set_status(net::URLRequestStatus::FAILED); | 176 request.status = net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET); |
| 180 request.status.set_error(net::ERR_CONNECTION_RESET); | |
| 181 OnRequestLegComplete(request); | 177 OnRequestLegComplete(request); |
| 182 | 178 |
| 183 EXPECT_EQ(0u, CountPendingBeacons()); | 179 EXPECT_EQ(0u, CountPendingBeacons()); |
| 184 EXPECT_TRUE(CheckRequestCounts(kNeverReportIndex, 0u, 1u)); | 180 EXPECT_TRUE(CheckRequestCounts(kNeverReportIndex, 0u, 1u)); |
| 185 } | 181 } |
| 186 | 182 |
| 187 TEST_F(DomainReliabilityMonitorTest, Request) { | 183 TEST_F(DomainReliabilityMonitorTest, Request) { |
| 188 RequestInfo request = MakeRequestInfo(); | 184 RequestInfo request = MakeRequestInfo(); |
| 189 request.url = GURL("http://example/always_report"); | 185 request.url = GURL("http://example/always_report"); |
| 190 OnRequestLegComplete(request); | 186 OnRequestLegComplete(request); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 OnRequestLegComplete(request); | 219 OnRequestLegComplete(request); |
| 224 | 220 |
| 225 EXPECT_EQ(0u, CountPendingBeacons()); | 221 EXPECT_EQ(0u, CountPendingBeacons()); |
| 226 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 0u, 0u)); | 222 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 0u, 0u)); |
| 227 } | 223 } |
| 228 | 224 |
| 229 // Make sure the monitor does not log a network-local error. | 225 // Make sure the monitor does not log a network-local error. |
| 230 TEST_F(DomainReliabilityMonitorTest, LocalError) { | 226 TEST_F(DomainReliabilityMonitorTest, LocalError) { |
| 231 RequestInfo request = MakeRequestInfo(); | 227 RequestInfo request = MakeRequestInfo(); |
| 232 request.url = GURL("http://example/always_report"); | 228 request.url = GURL("http://example/always_report"); |
| 233 request.status.set_status(net::URLRequestStatus::FAILED); | 229 request.status = |
| 234 request.status.set_error(net::ERR_PROXY_CONNECTION_FAILED); | 230 net::URLRequestStatus::FromError(net::ERR_PROXY_CONNECTION_FAILED); |
| 235 OnRequestLegComplete(request); | 231 OnRequestLegComplete(request); |
| 236 | 232 |
| 237 EXPECT_EQ(0u, CountPendingBeacons()); | 233 EXPECT_EQ(0u, CountPendingBeacons()); |
| 238 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 0u, 0u)); | 234 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 0u, 0u)); |
| 239 } | 235 } |
| 240 | 236 |
| 241 // Make sure the monitor does not log the proxy's IP if one was used. | 237 // Make sure the monitor does not log the proxy's IP if one was used. |
| 242 TEST_F(DomainReliabilityMonitorTest, WasFetchedViaProxy) { | 238 TEST_F(DomainReliabilityMonitorTest, WasFetchedViaProxy) { |
| 243 RequestInfo request = MakeRequestInfo(); | 239 RequestInfo request = MakeRequestInfo(); |
| 244 request.url = GURL("http://example/always_report"); | 240 request.url = GURL("http://example/always_report"); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 269 EXPECT_EQ(1u, beacons.size()); | 265 EXPECT_EQ(1u, beacons.size()); |
| 270 EXPECT_TRUE(beacons[0].server_ip.empty()); | 266 EXPECT_TRUE(beacons[0].server_ip.empty()); |
| 271 } | 267 } |
| 272 | 268 |
| 273 // Make sure the monitor does not log the cached IP returned with a failed | 269 // Make sure the monitor does not log the cached IP returned with a failed |
| 274 // cache revalidation request. | 270 // cache revalidation request. |
| 275 TEST_F(DomainReliabilityMonitorTest, NoCachedIPFromFailedRevalidationRequest) { | 271 TEST_F(DomainReliabilityMonitorTest, NoCachedIPFromFailedRevalidationRequest) { |
| 276 RequestInfo request = MakeRequestInfo(); | 272 RequestInfo request = MakeRequestInfo(); |
| 277 request.url = GURL("http://example/always_report"); | 273 request.url = GURL("http://example/always_report"); |
| 278 request.response_info.was_cached = true; | 274 request.response_info.was_cached = true; |
| 279 request.status.set_status(net::URLRequestStatus::FAILED); | 275 request.status = |
| 280 request.status.set_error(net::ERR_NAME_RESOLUTION_FAILED); | 276 net::URLRequestStatus::FromError(net::ERR_NAME_RESOLUTION_FAILED); |
| 281 OnRequestLegComplete(request); | 277 OnRequestLegComplete(request); |
| 282 | 278 |
| 283 BeaconVector beacons; | 279 BeaconVector beacons; |
| 284 context_->GetQueuedBeaconsForTesting(&beacons); | 280 context_->GetQueuedBeaconsForTesting(&beacons); |
| 285 EXPECT_EQ(1u, beacons.size()); | 281 EXPECT_EQ(1u, beacons.size()); |
| 286 EXPECT_TRUE(beacons[0].server_ip.empty()); | 282 EXPECT_TRUE(beacons[0].server_ip.empty()); |
| 287 } | 283 } |
| 288 | 284 |
| 289 TEST_F(DomainReliabilityMonitorTest, AtLeastOneBakedInConfig) { | 285 TEST_F(DomainReliabilityMonitorTest, AtLeastOneBakedInConfig) { |
| 290 DCHECK(kBakedInJsonConfigs[0] != nullptr); | 286 DCHECK(kBakedInJsonConfigs[0] != nullptr); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 TEST_F(DomainReliabilityMonitorTest, ClearContexts) { | 332 TEST_F(DomainReliabilityMonitorTest, ClearContexts) { |
| 337 // Initially the monitor should have just the test context. | 333 // Initially the monitor should have just the test context. |
| 338 EXPECT_EQ(1u, monitor_.contexts_size_for_testing()); | 334 EXPECT_EQ(1u, monitor_.contexts_size_for_testing()); |
| 339 | 335 |
| 340 monitor_.ClearBrowsingData(CLEAR_CONTEXTS); | 336 monitor_.ClearBrowsingData(CLEAR_CONTEXTS); |
| 341 | 337 |
| 342 // Clearing contexts should leave the monitor with none. | 338 // Clearing contexts should leave the monitor with none. |
| 343 EXPECT_EQ(0u, monitor_.contexts_size_for_testing()); | 339 EXPECT_EQ(0u, monitor_.contexts_size_for_testing()); |
| 344 } | 340 } |
| 345 | 341 |
| 342 // TODO(davidben): When https://crbug.com/490311 is resolved, this test can be |
| 343 // removed. |
| 346 TEST_F(DomainReliabilityMonitorTest, IgnoreSuccessError) { | 344 TEST_F(DomainReliabilityMonitorTest, IgnoreSuccessError) { |
| 347 RequestInfo request = MakeRequestInfo(); | 345 RequestInfo request = MakeRequestInfo(); |
| 348 request.url = GURL("http://example/always_report"); | 346 request.url = GURL("http://example/always_report"); |
| 349 request.status.set_error(net::ERR_QUIC_PROTOCOL_ERROR); | 347 request.status = net::URLRequestStatus(net::URLRequestStatus::SUCCESS, |
| 348 net::ERR_QUIC_PROTOCOL_ERROR); |
| 350 OnRequestLegComplete(request); | 349 OnRequestLegComplete(request); |
| 351 | 350 |
| 352 BeaconVector beacons; | 351 BeaconVector beacons; |
| 353 context_->GetQueuedBeaconsForTesting(&beacons); | 352 context_->GetQueuedBeaconsForTesting(&beacons); |
| 354 EXPECT_EQ(1u, beacons.size()); | 353 EXPECT_EQ(1u, beacons.size()); |
| 355 EXPECT_EQ(net::OK, beacons[0].chrome_error); | 354 EXPECT_EQ(net::OK, beacons[0].chrome_error); |
| 356 | 355 |
| 357 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 1u, 0u)); | 356 EXPECT_TRUE(CheckRequestCounts(kAlwaysReportIndex, 1u, 0u)); |
| 358 } | 357 } |
| 359 | 358 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 request.url = GURL("http://test.wildcard/always_report"); | 416 request.url = GURL("http://test.wildcard/always_report"); |
| 418 OnRequestLegComplete(request); | 417 OnRequestLegComplete(request); |
| 419 | 418 |
| 420 EXPECT_TRUE(CheckRequestCounts(context1, kAlwaysReportIndex, 1u, 0u)); | 419 EXPECT_TRUE(CheckRequestCounts(context1, kAlwaysReportIndex, 1u, 0u)); |
| 421 EXPECT_TRUE(CheckRequestCounts(context2, kAlwaysReportIndex, 0u, 0u)); | 420 EXPECT_TRUE(CheckRequestCounts(context2, kAlwaysReportIndex, 0u, 0u)); |
| 422 } | 421 } |
| 423 | 422 |
| 424 } // namespace | 423 } // namespace |
| 425 | 424 |
| 426 } // namespace domain_reliability | 425 } // namespace domain_reliability |
| OLD | NEW |