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