Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Unified Diff: components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc

Issue 390533003: Bypassed Bytes UMAs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed bengr comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc
index cb8f7af56907903112629df0f6729643bd8d6a50..4785dac290156af26835523fb0e3fa67abbb649f 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc
@@ -4,10 +4,13 @@
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
+#include <map>
+
#include "base/command_line.h"
#include "base/logging.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params_test_utils.h"
#include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h"
+#include "net/proxy/proxy_retry_info.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace data_reduction_proxy {
@@ -558,4 +561,382 @@ TEST_F(DataReductionProxyParamsTest, IsDataReductionProxy) {
net::HostPortPair::FromURL(proxy_servers.second)));
}
}
+
+TEST_F(DataReductionProxyParamsTest, AreProxiesBypassed) {
+ const struct {
+ // proxy rules
+ bool allowed;
+ bool fallback_allowed;
+ bool alt_allowed;
+ bool ssl;
+ // proxies in retry map
+ bool origin;
+ bool fallback_origin;
+ bool alt_origin;
+ bool alt_fallback_origin;
+ bool ssl_origin;
+ bool expected_result;
bengr 2014/07/21 22:23:57 Add a blank line above this so we know it does not
megjablon 2014/07/22 02:11:30 Done.
+ } tests[] = {
+ {
bengr 2014/07/21 22:23:57 See http_response_headers_unittest.cc for formatti
megjablon 2014/07/22 02:11:30 Done.
+ // proxy rules
+ false,
+ false,
+ false,
+ false,
+ // proxies in retry map
+ false,
+ false,
+ false,
+ false,
+ false,
+ // expected result
+ false,
+ },
+ {
+ // proxy rules
+ true,
+ false,
+ false,
+ false,
+ // proxies in retry map
+ false,
+ false,
+ false,
+ false,
+ false,
+ // expected result
+ false,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ false,
+ false,
+ // proxies in retry map
+ false,
+ false,
+ false,
+ false,
+ false,
+ // expected result
+ false,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ false,
+ // proxies in retry map
+ false,
+ false,
+ false,
+ false,
+ false,
+ // expected result
+ false,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ true,
+ // proxies in retry map
+ false,
+ false,
+ false,
+ false,
+ false,
+ // expected result
+ false,
+ },
+ {
+ // proxy rules
+ false,
+ false,
+ false,
+ true,
+ // proxies in retry map
+ false,
+ false,
+ false,
+ false,
+ true,
+ // expected result
+ false,
+ },
+ {
+ // proxy rules
+ false,
+ false,
+ true,
+ true,
+ // proxies in retry map
+ false,
+ false,
+ false,
+ false,
+ true,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ true,
+ // proxies in retry map
+ false,
+ false,
+ false,
+ false,
+ true,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ true,
+ false,
+ false,
+ false,
+ // proxies in retry map
+ true,
+ false,
+ false,
+ false,
+ false,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ false,
+ false,
+ // proxies in retry map
+ true,
+ false,
+ false,
+ false,
+ false,
+ // expected result
+ false,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ false,
+ false,
+ // proxies in retry map
+ true,
+ true,
+ false,
+ false,
+ false,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ false,
+ // proxies in retry map
+ true,
+ true,
+ false,
+ false,
+ false,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ false,
+ // proxies in retry map
+ true,
+ false,
+ true,
+ false,
+ false,
+ // expected result
+ false,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ false,
+ // proxies in retry map
+ false,
+ false,
+ true,
+ true,
+ false,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ false,
+ true,
+ true,
+ false,
+ // proxies in retry map
+ false,
+ false,
+ true,
+ true,
+ false,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ false,
+ true,
+ false,
+ false,
+ // proxies in retry map
+ false,
+ false,
+ true,
+ false,
+ false,
+ // expected result
+ false,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ false,
+ // proxies in retry map
+ true,
+ false,
+ true,
+ true,
+ false,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ false,
+ // proxies in retry map
+ true,
+ true,
+ true,
+ true,
+ true,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ true,
+ // proxies in retry map
+ true,
+ true,
+ true,
+ true,
+ true,
+ // expected result
+ true,
+ },
+ {
+ // proxy rules
+ true,
+ true,
+ true,
+ true,
+ // proxies in retry map
+ true,
+ true,
+ true,
+ true,
+ false,
+ // expected result
+ false,
+ },
+ };
+
+ // The retry map has the scheme prefix for https but not for http.
+ std::string origin = TestDataReductionProxyParams::DefaultOrigin();
+ if (GURL(origin).SchemeIs(url::kHttpScheme)) {
+ origin = origin.substr(7);
bengr 2014/07/21 22:23:57 Add a helper function called GetRetryMapKeyFromOri
megjablon 2014/07/22 02:11:30 Done.
+ }
+ std::string fallback_origin =
+ TestDataReductionProxyParams::DefaultFallbackOrigin();
+ if (GURL(fallback_origin).SchemeIs(url::kHttpScheme)) {
+ fallback_origin = fallback_origin.substr(7);
+ }
+ std::string alt_origin =
+ TestDataReductionProxyParams::DefaultAltOrigin();
+ if (GURL(alt_origin).SchemeIs(url::kHttpScheme)) {
+ alt_origin = alt_origin.substr(7);
+ }
+ std::string alt_fallback_origin =
+ TestDataReductionProxyParams::DefaultAltFallbackOrigin();
+ if (GURL(alt_fallback_origin).SchemeIs(url::kHttpScheme)) {
+ alt_fallback_origin = alt_fallback_origin.substr(7);
+ }
+ std::string ssl_origin =
+ TestDataReductionProxyParams::DefaultSSLOrigin();
+ if (GURL(ssl_origin).SchemeIs(url::kHttpScheme)) {
+ ssl_origin = ssl_origin.substr(7);
+ }
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ int flags = 0;
+ if (tests[i].allowed)
+ flags |= DataReductionProxyParams::kAllowed;
+ if(tests[i].alt_allowed)
+ flags |= DataReductionProxyParams::kAlternativeAllowed;
+ if (tests[i].fallback_allowed)
+ flags |= DataReductionProxyParams::kFallbackAllowed;
+ TestDataReductionProxyParams params(
+ flags, TestDataReductionProxyParams::HAS_EVERYTHING &
+ ~TestDataReductionProxyParams::HAS_DEV_ORIGIN);
+
+ net::ProxyRetryInfoMap retry_map;
+ net::ProxyRetryInfo retry_info;
+
+ // The retry list has the scheme prefix for https but not for http.
+ if (tests[i].origin)
+ retry_map[origin] = retry_info;
+ if (tests[i].fallback_origin)
+ retry_map[fallback_origin] = retry_info;
+ if (tests[i].alt_origin)
+ retry_map[alt_origin] = retry_info;
+ if (tests[i].alt_fallback_origin)
+ retry_map[alt_fallback_origin] = retry_info;
+ if (tests[i].ssl_origin)
+ retry_map[ssl_origin] = retry_info;
+
+ bool was_bypassed = params.AreProxiesBypassed(retry_map,
+ tests[i].ssl,
+ NULL);
+
+ EXPECT_EQ(tests[i].expected_result, was_bypassed);
+ }
+}
} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698