| 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/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_stats.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_stats.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 .WillRepeatedly(testing::Return( | 172 .WillRepeatedly(testing::Return( |
| 173 test_case.fallback_proxy_server_is_data_reduction_proxy)); | 173 test_case.fallback_proxy_server_is_data_reduction_proxy)); |
| 174 EXPECT_CALL(*config(), WasDataReductionProxyUsed(url_request(), testing::_)) | 174 EXPECT_CALL(*config(), WasDataReductionProxyUsed(url_request(), testing::_)) |
| 175 .WillRepeatedly(testing::Return(test_case.was_proxy_used)); | 175 .WillRepeatedly(testing::Return(test_case.was_proxy_used)); |
| 176 | 176 |
| 177 std::unique_ptr<DataReductionProxyBypassStats> bypass_stats = | 177 std::unique_ptr<DataReductionProxyBypassStats> bypass_stats = |
| 178 BuildBypassStats(); | 178 BuildBypassStats(); |
| 179 | 179 |
| 180 bypass_stats->OnProxyFallback(fallback_proxy_server, | 180 bypass_stats->OnProxyFallback(fallback_proxy_server, |
| 181 net::ERR_PROXY_CONNECTION_FAILED); | 181 net::ERR_PROXY_CONNECTION_FAILED); |
| 182 bypass_stats->OnUrlRequestCompleted(url_request(), false); | 182 bypass_stats->OnUrlRequestCompleted(url_request(), false, net::OK); |
| 183 RunUntilIdle(); | 183 RunUntilIdle(); |
| 184 | 184 |
| 185 EXPECT_EQ(test_case.is_unreachable, IsUnreachable()); | 185 EXPECT_EQ(test_case.is_unreachable, IsUnreachable()); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 TEST_F(DataReductionProxyBypassStatsTest, ProxyUnreachableThenReachable) { | 189 TEST_F(DataReductionProxyBypassStatsTest, ProxyUnreachableThenReachable) { |
| 190 net::ProxyServer fallback_proxy_server = | 190 net::ProxyServer fallback_proxy_server = |
| 191 net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP); | 191 net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP); |
| 192 std::unique_ptr<DataReductionProxyBypassStats> bypass_stats = | 192 std::unique_ptr<DataReductionProxyBypassStats> bypass_stats = |
| 193 BuildBypassStats(); | 193 BuildBypassStats(); |
| 194 EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, testing::_)) | 194 EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, testing::_)) |
| 195 .WillOnce(testing::Return(true)); | 195 .WillOnce(testing::Return(true)); |
| 196 EXPECT_CALL(*config(), WasDataReductionProxyUsed(url_request(), testing::_)) | 196 EXPECT_CALL(*config(), WasDataReductionProxyUsed(url_request(), testing::_)) |
| 197 .WillOnce(testing::Return(true)); | 197 .WillOnce(testing::Return(true)); |
| 198 | 198 |
| 199 // proxy falls back | 199 // proxy falls back |
| 200 bypass_stats->OnProxyFallback(fallback_proxy_server, | 200 bypass_stats->OnProxyFallback(fallback_proxy_server, |
| 201 net::ERR_PROXY_CONNECTION_FAILED); | 201 net::ERR_PROXY_CONNECTION_FAILED); |
| 202 RunUntilIdle(); | 202 RunUntilIdle(); |
| 203 EXPECT_TRUE(IsUnreachable()); | 203 EXPECT_TRUE(IsUnreachable()); |
| 204 | 204 |
| 205 // proxy succeeds | 205 // proxy succeeds |
| 206 bypass_stats->OnUrlRequestCompleted(url_request(), false); | 206 bypass_stats->OnUrlRequestCompleted(url_request(), false, net::OK); |
| 207 RunUntilIdle(); | 207 RunUntilIdle(); |
| 208 EXPECT_FALSE(IsUnreachable()); | 208 EXPECT_FALSE(IsUnreachable()); |
| 209 } | 209 } |
| 210 | 210 |
| 211 TEST_F(DataReductionProxyBypassStatsTest, ProxyReachableThenUnreachable) { | 211 TEST_F(DataReductionProxyBypassStatsTest, ProxyReachableThenUnreachable) { |
| 212 net::ProxyServer fallback_proxy_server = | 212 net::ProxyServer fallback_proxy_server = |
| 213 net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP); | 213 net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP); |
| 214 std::unique_ptr<DataReductionProxyBypassStats> bypass_stats = | 214 std::unique_ptr<DataReductionProxyBypassStats> bypass_stats = |
| 215 BuildBypassStats(); | 215 BuildBypassStats(); |
| 216 EXPECT_CALL(*config(), WasDataReductionProxyUsed(url_request(), testing::_)) | 216 EXPECT_CALL(*config(), WasDataReductionProxyUsed(url_request(), testing::_)) |
| 217 .WillOnce(testing::Return(true)); | 217 .WillOnce(testing::Return(true)); |
| 218 EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, testing::_)) | 218 EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, testing::_)) |
| 219 .WillRepeatedly(testing::Return(true)); | 219 .WillRepeatedly(testing::Return(true)); |
| 220 | 220 |
| 221 // Proxy succeeds. | 221 // Proxy succeeds. |
| 222 bypass_stats->OnUrlRequestCompleted(url_request(), false); | 222 bypass_stats->OnUrlRequestCompleted(url_request(), false, net::OK); |
| 223 RunUntilIdle(); | 223 RunUntilIdle(); |
| 224 EXPECT_FALSE(IsUnreachable()); | 224 EXPECT_FALSE(IsUnreachable()); |
| 225 | 225 |
| 226 // Then proxy falls back indefinitely. | 226 // Then proxy falls back indefinitely. |
| 227 bypass_stats->OnProxyFallback(fallback_proxy_server, | 227 bypass_stats->OnProxyFallback(fallback_proxy_server, |
| 228 net::ERR_PROXY_CONNECTION_FAILED); | 228 net::ERR_PROXY_CONNECTION_FAILED); |
| 229 bypass_stats->OnProxyFallback(fallback_proxy_server, | 229 bypass_stats->OnProxyFallback(fallback_proxy_server, |
| 230 net::ERR_PROXY_CONNECTION_FAILED); | 230 net::ERR_PROXY_CONNECTION_FAILED); |
| 231 bypass_stats->OnProxyFallback(fallback_proxy_server, | 231 bypass_stats->OnProxyFallback(fallback_proxy_server, |
| 232 net::ERR_PROXY_CONNECTION_FAILED); | 232 net::ERR_PROXY_CONNECTION_FAILED); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (test.net_error != net::OK) | 492 if (test.net_error != net::OK) |
| 493 fake_request->CancelWithError(static_cast<int>(test.net_error)); | 493 fake_request->CancelWithError(static_cast<int>(test.net_error)); |
| 494 | 494 |
| 495 DataReductionProxyTypeInfo proxy_info; | 495 DataReductionProxyTypeInfo proxy_info; |
| 496 proxy_info.proxy_index = test.proxy_index; | 496 proxy_info.proxy_index = test.proxy_index; |
| 497 EXPECT_CALL(*config(), WasDataReductionProxyUsed(fake_request.get(), | 497 EXPECT_CALL(*config(), WasDataReductionProxyUsed(fake_request.get(), |
| 498 testing::NotNull())) | 498 testing::NotNull())) |
| 499 .WillRepeatedly(testing::DoAll(testing::SetArgPointee<1>(proxy_info), | 499 .WillRepeatedly(testing::DoAll(testing::SetArgPointee<1>(proxy_info), |
| 500 Return(test.was_proxy_used))); | 500 Return(test.was_proxy_used))); |
| 501 | 501 |
| 502 bypass_stats->OnUrlRequestCompleted(fake_request.get(), false); | 502 bypass_stats->OnUrlRequestCompleted(fake_request.get(), false, |
| 503 test.net_error); |
| 503 | 504 |
| 504 if (test.was_proxy_used && !test.is_load_bypass_proxy && | 505 if (test.was_proxy_used && !test.is_load_bypass_proxy && |
| 505 test.net_error == net::OK) { | 506 test.net_error == net::OK) { |
| 506 histogram_tester.ExpectUniqueSample(kPrimaryHistogramName, | 507 histogram_tester.ExpectUniqueSample(kPrimaryHistogramName, |
| 507 test.proxy_index, 1); | 508 test.proxy_index, 1); |
| 508 } else { | 509 } else { |
| 509 histogram_tester.ExpectTotalCount(kPrimaryHistogramName, 0); | 510 histogram_tester.ExpectTotalCount(kPrimaryHistogramName, 0); |
| 510 } | 511 } |
| 511 | 512 |
| 512 if (test.was_proxy_used && !test.is_load_bypass_proxy && | 513 if (test.was_proxy_used && !test.is_load_bypass_proxy && |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 kNextBody.c_str(), nullptr, nullptr); | 964 kNextBody.c_str(), nullptr, nullptr); |
| 964 histogram_tester.ExpectUniqueSample( | 965 histogram_tester.ExpectUniqueSample( |
| 965 "DataReductionProxy.BypassedBytes.NotBypassed", kNextBody.size(), 1); | 966 "DataReductionProxy.BypassedBytes.NotBypassed", kNextBody.size(), 1); |
| 966 ExpectOtherBypassedBytesHistogramsEmpty( | 967 ExpectOtherBypassedBytesHistogramsEmpty( |
| 967 histogram_tester, "DataReductionProxy.BypassedBytes.NotBypassed"); | 968 histogram_tester, "DataReductionProxy.BypassedBytes.NotBypassed"); |
| 968 } | 969 } |
| 969 } | 970 } |
| 970 } | 971 } |
| 971 | 972 |
| 972 } // namespace data_reduction_proxy | 973 } // namespace data_reduction_proxy |
| OLD | NEW |