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

Side by Side Diff: components/data_reduction_proxy/core/common/data_reduction_proxy_params_unittest.cc

Issue 2922663002: Data Reduction Proxy: Remove duplicate functions (Closed)
Patch Set: megjablon comments Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/data_reduction_proxy_param s.h" 5 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/metrics/field_trial.h" 15 #include "base/metrics/field_trial.h"
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h" 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h"
17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve r.h" 17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve r.h"
18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" 18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h"
19 #include "components/data_reduction_proxy/proto/client_config.pb.h" 19 #include "components/data_reduction_proxy/proto/client_config.pb.h"
20 #include "components/variations/variations_associated_data.h" 20 #include "components/variations/variations_associated_data.h"
21 #include "net/proxy/proxy_server.h" 21 #include "net/proxy/proxy_server.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 namespace data_reduction_proxy { 25 namespace data_reduction_proxy {
26 class DataReductionProxyParamsTest : public testing::Test { 26 class DataReductionProxyParamsTest : public testing::Test {
27 public: 27 public:
28 void CheckParams(const TestDataReductionProxyParams& params, 28 void CheckParams(const TestDataReductionProxyParams& params,
29 bool expected_init_result, 29 bool expected_init_result) {
30 bool expected_promo_allowed) {
31 EXPECT_EQ(expected_init_result, params.init_result()); 30 EXPECT_EQ(expected_init_result, params.init_result());
32 EXPECT_EQ(expected_promo_allowed, params.promo_allowed());
33 } 31 }
34 void CheckValues(const TestDataReductionProxyParams& params, 32 void CheckValues(const TestDataReductionProxyParams& params,
35 const std::string& expected_origin, 33 const std::string& expected_origin,
36 const std::string& expected_fallback_origin, 34 const std::string& expected_fallback_origin,
37 const std::string& expected_secure_proxy_check_url) { 35 const std::string& expected_secure_proxy_check_url) {
38 std::vector<net::ProxyServer> expected_proxies; 36 std::vector<net::ProxyServer> expected_proxies;
39 if (!expected_origin.empty()) { 37 if (!expected_origin.empty()) {
40 expected_proxies.push_back(net::ProxyServer::FromURI( 38 expected_proxies.push_back(net::ProxyServer::FromURI(
41 expected_origin, net::ProxyServer::SCHEME_HTTP)); 39 expected_origin, net::ProxyServer::SCHEME_HTTP));
42 } 40 }
43 41
44 if (!expected_fallback_origin.empty()) { 42 if (!expected_fallback_origin.empty()) {
45 expected_proxies.push_back(net::ProxyServer::FromURI( 43 expected_proxies.push_back(net::ProxyServer::FromURI(
46 expected_fallback_origin, net::ProxyServer::SCHEME_HTTP)); 44 expected_fallback_origin, net::ProxyServer::SCHEME_HTTP));
47 } 45 }
48 46
49 EXPECT_EQ(expected_proxies, 47 EXPECT_EQ(expected_proxies,
50 DataReductionProxyServer::ConvertToNetProxyServers( 48 DataReductionProxyServer::ConvertToNetProxyServers(
51 params.proxies_for_http())); 49 params.proxies_for_http()));
52 EXPECT_EQ(GURL(expected_secure_proxy_check_url), 50 EXPECT_EQ(GURL(expected_secure_proxy_check_url),
53 params.secure_proxy_check_url()); 51 params.secure_proxy_check_url());
54 } 52 }
55 }; 53 };
56 54
57 TEST_F(DataReductionProxyParamsTest, EverythingDefined) { 55 TEST_F(DataReductionProxyParamsTest, EverythingDefined) {
58 TestDataReductionProxyParams params( 56 TestDataReductionProxyParams params;
59 DataReductionProxyParams::kPromoAllowed, 57 CheckParams(params, true);
60 TestDataReductionProxyParams::HAS_EVERYTHING);
61 CheckParams(params, true, true);
62 std::vector<DataReductionProxyServer> expected_proxies; 58 std::vector<DataReductionProxyServer> expected_proxies;
63 59
64 // Both the origin and fallback proxy must have type CORE. 60 // Both the origin and fallback proxy must have type CORE.
65 expected_proxies.push_back(DataReductionProxyServer( 61 expected_proxies.push_back(DataReductionProxyServer(
66 net::ProxyServer::FromURI(TestDataReductionProxyParams::DefaultOrigin(), 62 net::ProxyServer::FromURI(TestDataReductionProxyParams::DefaultOrigin(),
67 net::ProxyServer::SCHEME_HTTP), 63 net::ProxyServer::SCHEME_HTTP),
68 ProxyServer::CORE)); 64 ProxyServer::CORE));
69 expected_proxies.push_back(DataReductionProxyServer( 65 expected_proxies.push_back(DataReductionProxyServer(
70 net::ProxyServer::FromURI( 66 net::ProxyServer::FromURI(
71 TestDataReductionProxyParams::DefaultFallbackOrigin(), 67 TestDataReductionProxyParams::DefaultFallbackOrigin(),
72 net::ProxyServer::SCHEME_HTTP), 68 net::ProxyServer::SCHEME_HTTP),
73 ProxyServer::CORE)); 69 ProxyServer::CORE));
74 70
75 EXPECT_EQ(expected_proxies, params.proxies_for_http()); 71 EXPECT_EQ(expected_proxies, params.proxies_for_http());
76 EXPECT_EQ(GURL(TestDataReductionProxyParams::DefaultSecureProxyCheckURL()), 72 EXPECT_EQ(GURL(TestDataReductionProxyParams::DefaultSecureProxyCheckURL()),
77 params.secure_proxy_check_url()); 73 params.secure_proxy_check_url());
78 } 74 }
79 75
80 TEST_F(DataReductionProxyParamsTest, Flags) { 76 TEST_F(DataReductionProxyParamsTest, Flags) {
81 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 77 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
82 switches::kDataReductionProxy, 78 switches::kDataReductionProxy,
83 TestDataReductionProxyParams::FlagOrigin()); 79 TestDataReductionProxyParams::FlagOrigin());
84 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 80 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
85 switches::kDataReductionProxyFallback, 81 switches::kDataReductionProxyFallback,
86 TestDataReductionProxyParams::FlagFallbackOrigin()); 82 TestDataReductionProxyParams::FlagFallbackOrigin());
87 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 83 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
88 switches::kDataReductionProxySecureProxyCheckURL, 84 switches::kDataReductionProxySecureProxyCheckURL,
89 TestDataReductionProxyParams::FlagSecureProxyCheckURL()); 85 TestDataReductionProxyParams::FlagSecureProxyCheckURL());
90 TestDataReductionProxyParams params( 86 TestDataReductionProxyParams params;
91 DataReductionProxyParams::kPromoAllowed, 87 CheckParams(params, true);
92 TestDataReductionProxyParams::HAS_EVERYTHING);
93 CheckParams(params, true, true);
94 CheckValues(params, TestDataReductionProxyParams::FlagOrigin(), 88 CheckValues(params, TestDataReductionProxyParams::FlagOrigin(),
95 TestDataReductionProxyParams::FlagFallbackOrigin(), 89 TestDataReductionProxyParams::FlagFallbackOrigin(),
96 TestDataReductionProxyParams::FlagSecureProxyCheckURL()); 90 TestDataReductionProxyParams::FlagSecureProxyCheckURL());
97 } 91 }
98 92
99 TEST_F(DataReductionProxyParamsTest, CarrierTestFlag) { 93 TEST_F(DataReductionProxyParamsTest, CarrierTestFlag) {
100 static const char kCarrierTestOrigin[] = 94 static const char kCarrierTestOrigin[] =
101 "http://o-o.preferred.nttdocomodcp-hnd1.proxy-dev.googlezip.net:80"; 95 "http://o-o.preferred.nttdocomodcp-hnd1.proxy-dev.googlezip.net:80";
102 static const char kDefaultFallbackOrigin[] = "compress.googlezip.net:80"; 96 static const char kDefaultFallbackOrigin[] = "compress.googlezip.net:80";
103 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, nullptr); 97 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, nullptr);
104 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 98 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
105 switches::kEnableDataReductionProxyCarrierTest, kCarrierTestOrigin); 99 switches::kEnableDataReductionProxyCarrierTest, kCarrierTestOrigin);
106 DataReductionProxyParams params(0); 100 DataReductionProxyParams params;
107 std::vector<DataReductionProxyServer> proxies_for_http; 101 std::vector<DataReductionProxyServer> proxies_for_http;
108 proxies_for_http.push_back(DataReductionProxyServer( 102 proxies_for_http.push_back(DataReductionProxyServer(
109 net::ProxyServer::FromURI(kCarrierTestOrigin, 103 net::ProxyServer::FromURI(kCarrierTestOrigin,
110 net::ProxyServer::SCHEME_HTTP), 104 net::ProxyServer::SCHEME_HTTP),
111 ProxyServer::CORE)); 105 ProxyServer::CORE));
112 proxies_for_http.push_back(DataReductionProxyServer( 106 proxies_for_http.push_back(DataReductionProxyServer(
113 net::ProxyServer::FromURI(kDefaultFallbackOrigin, 107 net::ProxyServer::FromURI(kDefaultFallbackOrigin,
114 net::ProxyServer::SCHEME_HTTP), 108 net::ProxyServer::SCHEME_HTTP),
115 ProxyServer::CORE)); 109 ProxyServer::CORE));
116 EXPECT_EQ(params.proxies_for_http(), proxies_for_http); 110 EXPECT_EQ(params.proxies_for_http(), proxies_for_http);
117 } 111 }
118 112
119 TEST_F(DataReductionProxyParamsTest, InvalidConfigurations) {
120 const struct {
121 bool promo_allowed;
122 unsigned int missing_definitions;
123 bool expected_result;
124 } tests[] = {
125 {true, TestDataReductionProxyParams::HAS_NOTHING, true},
126 {true, TestDataReductionProxyParams::HAS_ORIGIN, false},
127 {true, TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, false},
128 {true, TestDataReductionProxyParams::HAS_SECURE_PROXY_CHECK_URL, false},
129 };
130
131 for (size_t i = 0; i < arraysize(tests); ++i) {
132 int flags = 0;
133 if (tests[i].promo_allowed)
134 flags |= DataReductionProxyParams::kPromoAllowed;
135 TestDataReductionProxyParams params(
136 flags,
137 TestDataReductionProxyParams::HAS_EVERYTHING &
138 ~(tests[i].missing_definitions));
139 EXPECT_EQ(tests[i].expected_result, params.init_result()) << i;
140 }
141 }
142
143 TEST_F(DataReductionProxyParamsTest, AndroidOnePromoFieldTrial) { 113 TEST_F(DataReductionProxyParamsTest, AndroidOnePromoFieldTrial) {
144 EXPECT_TRUE(params::IsIncludedInAndroidOnePromoFieldTrial( 114 EXPECT_TRUE(params::IsIncludedInAndroidOnePromoFieldTrialForTesting(
145 "google/sprout/sprout:4.4.4/KPW53/1379542:user/release-keys")); 115 "google/sprout/sprout:4.4.4/KPW53/1379542:user/release-keys"));
146 EXPECT_FALSE(params::IsIncludedInAndroidOnePromoFieldTrial( 116 EXPECT_FALSE(params::IsIncludedInAndroidOnePromoFieldTrialForTesting(
147 "google/hammerhead/hammerhead:5.0/LRX210/1570415:user/release-keys")); 117 "google/hammerhead/hammerhead:5.0/LRX210/1570415:user/release-keys"));
148 } 118 }
149 119
150 TEST_F(DataReductionProxyParamsTest, IsClientConfigEnabled) { 120 TEST_F(DataReductionProxyParamsTest, IsClientConfigEnabled) {
151 const struct { 121 const struct {
152 std::string test_case; 122 std::string test_case;
153 std::string trial_group_value; 123 std::string trial_group_value;
154 bool expected; 124 bool expected;
155 } tests[] = { 125 } tests[] = {
156 { 126 {
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 switches::kDataReductionProxyConfigURL, test.flag_value); 523 switches::kDataReductionProxyConfigURL, test.flag_value);
554 } 524 }
555 EXPECT_EQ(test.expected, params::GetConfigServiceURL()) << test.test_case; 525 EXPECT_EQ(test.expected, params::GetConfigServiceURL()) << test.test_case;
556 } 526 }
557 } 527 }
558 528
559 TEST(DataReductionProxyParamsStandaloneTest, OverrideProxiesForHttp) { 529 TEST(DataReductionProxyParamsStandaloneTest, OverrideProxiesForHttp) {
560 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 530 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
561 switches::kDataReductionProxyHttpProxies, 531 switches::kDataReductionProxyHttpProxies,
562 "http://override-first.net;http://override-second.net"); 532 "http://override-first.net;http://override-second.net");
563 DataReductionProxyParams params(0); 533 DataReductionProxyParams params;
564 534
565 // Overriding proxies must have type UNSPECIFIED_TYPE. 535 // Overriding proxies must have type UNSPECIFIED_TYPE.
566 std::vector<DataReductionProxyServer> expected_override_proxies_for_http; 536 std::vector<DataReductionProxyServer> expected_override_proxies_for_http;
567 expected_override_proxies_for_http.push_back(DataReductionProxyServer( 537 expected_override_proxies_for_http.push_back(DataReductionProxyServer(
568 net::ProxyServer::FromURI("http://override-first.net", 538 net::ProxyServer::FromURI("http://override-first.net",
569 net::ProxyServer::SCHEME_HTTP), 539 net::ProxyServer::SCHEME_HTTP),
570 ProxyServer::UNSPECIFIED_TYPE)); 540 ProxyServer::UNSPECIFIED_TYPE));
571 expected_override_proxies_for_http.push_back(DataReductionProxyServer( 541 expected_override_proxies_for_http.push_back(DataReductionProxyServer(
572 net::ProxyServer::FromURI("http://override-second.net", 542 net::ProxyServer::FromURI("http://override-second.net",
573 net::ProxyServer::SCHEME_HTTP), 543 net::ProxyServer::SCHEME_HTTP),
574 ProxyServer::UNSPECIFIED_TYPE)); 544 ProxyServer::UNSPECIFIED_TYPE));
575 545
576 EXPECT_EQ(expected_override_proxies_for_http, params.proxies_for_http()); 546 EXPECT_EQ(expected_override_proxies_for_http, params.proxies_for_http());
577 } 547 }
578 548
579 } // namespace data_reduction_proxy 549 } // namespace data_reduction_proxy
OLDNEW
« no previous file with comments | « components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698