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

Side by Side Diff: net/proxy/proxy_config_service_common_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "net/proxy/proxy_config_service_common_unittest.h" 5 #include "net/proxy/proxy_config_service_common_unittest.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "net/proxy/proxy_config.h" 10 #include "net/proxy/proxy_config.h"
(...skipping 11 matching lines...) Expand all
22 void MatchesProxyServerHelper(const char* failure_message, 22 void MatchesProxyServerHelper(const char* failure_message,
23 const char* expected_proxy, 23 const char* expected_proxy,
24 const ProxyList& actual_proxies, 24 const ProxyList& actual_proxies,
25 ::testing::AssertionResult* failure_details, 25 ::testing::AssertionResult* failure_details,
26 bool* did_fail) { 26 bool* did_fail) {
27 // If |expected_proxy| is empty, then we expect |actual_proxies| to be so as 27 // If |expected_proxy| is empty, then we expect |actual_proxies| to be so as
28 // well. 28 // well.
29 if (strlen(expected_proxy) == 0) { 29 if (strlen(expected_proxy) == 0) {
30 if (!actual_proxies.IsEmpty()) { 30 if (!actual_proxies.IsEmpty()) {
31 *did_fail = true; 31 *did_fail = true;
32 *failure_details 32 *failure_details << failure_message
33 << failure_message << ". Was expecting no proxies but got " 33 << ". Was expecting no proxies but got "
34 << actual_proxies.size() << "."; 34 << actual_proxies.size() << ".";
35 } 35 }
36 return; 36 return;
37 } 37 }
38 38
39 // Otherwise we check that |actual_proxies| holds a single matching proxy. 39 // Otherwise we check that |actual_proxies| holds a single matching proxy.
40 if (actual_proxies.size() != 1) { 40 if (actual_proxies.size() != 1) {
41 *did_fail = true; 41 *did_fail = true;
42 *failure_details 42 *failure_details << failure_message
43 << failure_message << ". Was expecting exactly one proxy but got " 43 << ". Was expecting exactly one proxy but got "
44 << actual_proxies.size() << "."; 44 << actual_proxies.size() << ".";
45 return; 45 return;
46 } 46 }
47 47
48 ProxyServer actual_proxy = actual_proxies.Get(); 48 ProxyServer actual_proxy = actual_proxies.Get();
49 std::string actual_proxy_string; 49 std::string actual_proxy_string;
50 if (actual_proxy.is_valid()) 50 if (actual_proxy.is_valid())
51 actual_proxy_string = actual_proxy.ToURI(); 51 actual_proxy_string = actual_proxy.ToURI();
52 52
53 if (std::string(expected_proxy) != actual_proxy_string) { 53 if (std::string(expected_proxy) != actual_proxy_string) {
54 *failure_details 54 *failure_details << failure_message << ". Was expecting: \""
55 << failure_message << ". Was expecting: \"" << expected_proxy 55 << expected_proxy << "\" but got: \""
56 << "\" but got: \"" << actual_proxy_string << "\""; 56 << actual_proxy_string << "\"";
57 *did_fail = true; 57 *did_fail = true;
58 } 58 }
59 } 59 }
60 60
61 std::string FlattenProxyBypass(const ProxyBypassRules& bypass_rules) { 61 std::string FlattenProxyBypass(const ProxyBypassRules& bypass_rules) {
62 std::string flattened_proxy_bypass; 62 std::string flattened_proxy_bypass;
63 for (ProxyBypassRules::RuleList::const_iterator it = 63 for (ProxyBypassRules::RuleList::const_iterator it =
64 bypass_rules.rules().begin(); 64 bypass_rules.rules().begin();
65 it != bypass_rules.rules().end(); ++it) { 65 it != bypass_rules.rules().end();
66 ++it) {
66 if (!flattened_proxy_bypass.empty()) 67 if (!flattened_proxy_bypass.empty())
67 flattened_proxy_bypass += ","; 68 flattened_proxy_bypass += ",";
68 flattened_proxy_bypass += (*it)->ToString(); 69 flattened_proxy_bypass += (*it)->ToString();
69 } 70 }
70 return flattened_proxy_bypass; 71 return flattened_proxy_bypass;
71 } 72 }
72 73
73 } // namespace 74 } // namespace
74 75
75 ProxyRulesExpectation::ProxyRulesExpectation( 76 ProxyRulesExpectation::ProxyRulesExpectation(ProxyConfig::ProxyRules::Type type,
76 ProxyConfig::ProxyRules::Type type, 77 const char* single_proxy,
77 const char* single_proxy, 78 const char* proxy_for_http,
78 const char* proxy_for_http, 79 const char* proxy_for_https,
79 const char* proxy_for_https, 80 const char* proxy_for_ftp,
80 const char* proxy_for_ftp, 81 const char* fallback_proxy,
81 const char* fallback_proxy, 82 const char* flattened_bypass_rules,
82 const char* flattened_bypass_rules, 83 bool reverse_bypass)
83 bool reverse_bypass)
84 : type(type), 84 : type(type),
85 single_proxy(single_proxy), 85 single_proxy(single_proxy),
86 proxy_for_http(proxy_for_http), 86 proxy_for_http(proxy_for_http),
87 proxy_for_https(proxy_for_https), 87 proxy_for_https(proxy_for_https),
88 proxy_for_ftp(proxy_for_ftp), 88 proxy_for_ftp(proxy_for_ftp),
89 fallback_proxy(fallback_proxy), 89 fallback_proxy(fallback_proxy),
90 flattened_bypass_rules(flattened_bypass_rules), 90 flattened_bypass_rules(flattened_bypass_rules),
91 reverse_bypass(reverse_bypass) { 91 reverse_bypass(reverse_bypass) {
92 } 92 }
93 93
94
95 ::testing::AssertionResult ProxyRulesExpectation::Matches( 94 ::testing::AssertionResult ProxyRulesExpectation::Matches(
96 const ProxyConfig::ProxyRules& rules) const { 95 const ProxyConfig::ProxyRules& rules) const {
97 ::testing::AssertionResult failure_details = ::testing::AssertionFailure(); 96 ::testing::AssertionResult failure_details = ::testing::AssertionFailure();
98 bool failed = false; 97 bool failed = false;
99 98
100 if (rules.type != type) { 99 if (rules.type != type) {
101 failure_details << "Type mismatch. Expected: " 100 failure_details << "Type mismatch. Expected: " << type
102 << type << " but was: " << rules.type; 101 << " but was: " << rules.type;
103 failed = true; 102 failed = true;
104 } 103 }
105 104
106 MatchesProxyServerHelper("Bad single_proxy", single_proxy, 105 MatchesProxyServerHelper("Bad single_proxy",
107 rules.single_proxies, &failure_details, &failed); 106 single_proxy,
108 MatchesProxyServerHelper("Bad proxy_for_http", proxy_for_http, 107 rules.single_proxies,
109 rules.proxies_for_http, &failure_details, 108 &failure_details,
110 &failed); 109 &failed);
111 MatchesProxyServerHelper("Bad proxy_for_https", proxy_for_https, 110 MatchesProxyServerHelper("Bad proxy_for_http",
112 rules.proxies_for_https, &failure_details, 111 proxy_for_http,
112 rules.proxies_for_http,
113 &failure_details,
113 &failed); 114 &failed);
114 MatchesProxyServerHelper("Bad fallback_proxy", fallback_proxy, 115 MatchesProxyServerHelper("Bad proxy_for_https",
115 rules.fallback_proxies, &failure_details, &failed); 116 proxy_for_https,
117 rules.proxies_for_https,
118 &failure_details,
119 &failed);
120 MatchesProxyServerHelper("Bad fallback_proxy",
121 fallback_proxy,
122 rules.fallback_proxies,
123 &failure_details,
124 &failed);
116 125
117 std::string actual_flattened_bypass = FlattenProxyBypass(rules.bypass_rules); 126 std::string actual_flattened_bypass = FlattenProxyBypass(rules.bypass_rules);
118 if (std::string(flattened_bypass_rules) != actual_flattened_bypass) { 127 if (std::string(flattened_bypass_rules) != actual_flattened_bypass) {
119 failure_details 128 failure_details << "Bad bypass rules. Expected: \""
120 << "Bad bypass rules. Expected: \"" << flattened_bypass_rules 129 << flattened_bypass_rules << "\" but got: \""
121 << "\" but got: \"" << actual_flattened_bypass << "\""; 130 << actual_flattened_bypass << "\"";
122 failed = true; 131 failed = true;
123 } 132 }
124 133
125 if (rules.reverse_bypass != reverse_bypass) { 134 if (rules.reverse_bypass != reverse_bypass) {
126 failure_details << "Bad reverse_bypass. Expected: " << reverse_bypass 135 failure_details << "Bad reverse_bypass. Expected: " << reverse_bypass
127 << " but got: " << rules.reverse_bypass; 136 << " but got: " << rules.reverse_bypass;
128 failed = true; 137 failed = true;
129 } 138 }
130 139
131 return failed ? failure_details : ::testing::AssertionSuccess(); 140 return failed ? failure_details : ::testing::AssertionSuccess();
132 } 141 }
133 142
134 // static 143 // static
135 ProxyRulesExpectation ProxyRulesExpectation::Empty() { 144 ProxyRulesExpectation ProxyRulesExpectation::Empty() {
136 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_NO_RULES, 145 return ProxyRulesExpectation(
137 "", "", "", "", "", "", false); 146 ProxyConfig::ProxyRules::TYPE_NO_RULES, "", "", "", "", "", "", false);
138 } 147 }
139 148
140 // static 149 // static
141 ProxyRulesExpectation ProxyRulesExpectation::EmptyWithBypass( 150 ProxyRulesExpectation ProxyRulesExpectation::EmptyWithBypass(
142 const char* flattened_bypass_rules) { 151 const char* flattened_bypass_rules) {
143 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_NO_RULES, 152 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_NO_RULES,
144 "", "", "", "", "", flattened_bypass_rules, 153 "",
154 "",
155 "",
156 "",
157 "",
158 flattened_bypass_rules,
145 false); 159 false);
146 } 160 }
147 161
148 // static 162 // static
149 ProxyRulesExpectation ProxyRulesExpectation::Single( 163 ProxyRulesExpectation ProxyRulesExpectation::Single(
150 const char* single_proxy, 164 const char* single_proxy,
151 const char* flattened_bypass_rules) { 165 const char* flattened_bypass_rules) {
152 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 166 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
153 single_proxy, "", "", "", "", 167 single_proxy,
154 flattened_bypass_rules, false); 168 "",
169 "",
170 "",
171 "",
172 flattened_bypass_rules,
173 false);
155 } 174 }
156 175
157 // static 176 // static
158 ProxyRulesExpectation ProxyRulesExpectation::PerScheme( 177 ProxyRulesExpectation ProxyRulesExpectation::PerScheme(
159 const char* proxy_http, 178 const char* proxy_http,
160 const char* proxy_https, 179 const char* proxy_https,
161 const char* proxy_ftp, 180 const char* proxy_ftp,
162 const char* flattened_bypass_rules) { 181 const char* flattened_bypass_rules) {
163 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 182 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
164 "", proxy_http, proxy_https, proxy_ftp, "", 183 "",
165 flattened_bypass_rules, false); 184 proxy_http,
185 proxy_https,
186 proxy_ftp,
187 "",
188 flattened_bypass_rules,
189 false);
166 } 190 }
167 191
168 // static 192 // static
169 ProxyRulesExpectation ProxyRulesExpectation::PerSchemeWithSocks( 193 ProxyRulesExpectation ProxyRulesExpectation::PerSchemeWithSocks(
170 const char* proxy_http, 194 const char* proxy_http,
171 const char* proxy_https, 195 const char* proxy_https,
172 const char* proxy_ftp, 196 const char* proxy_ftp,
173 const char* socks_proxy, 197 const char* socks_proxy,
174 const char* flattened_bypass_rules) { 198 const char* flattened_bypass_rules) {
175 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 199 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
176 "", proxy_http, proxy_https, proxy_ftp, 200 "",
177 socks_proxy, flattened_bypass_rules, false); 201 proxy_http,
202 proxy_https,
203 proxy_ftp,
204 socks_proxy,
205 flattened_bypass_rules,
206 false);
178 } 207 }
179 208
180 // static 209 // static
181 ProxyRulesExpectation ProxyRulesExpectation::PerSchemeWithBypassReversed( 210 ProxyRulesExpectation ProxyRulesExpectation::PerSchemeWithBypassReversed(
182 const char* proxy_http, 211 const char* proxy_http,
183 const char* proxy_https, 212 const char* proxy_https,
184 const char* proxy_ftp, 213 const char* proxy_ftp,
185 const char* flattened_bypass_rules) { 214 const char* flattened_bypass_rules) {
186 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 215 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
187 "", proxy_http, proxy_https, proxy_ftp, "", 216 "",
188 flattened_bypass_rules, true); 217 proxy_http,
218 proxy_https,
219 proxy_ftp,
220 "",
221 flattened_bypass_rules,
222 true);
189 } 223 }
190 224
191 } // namespace net 225 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698