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

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

Issue 12315019: Change ProxyRules to handle ProxyLists rather than just single ProxyServer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 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
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"
11 11
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 namespace { 16 namespace {
17 17
18 // Helper to verify that |expected_proxy| matches |actual_proxy|. If it does 18 // Helper to verify that |expected_proxy| matches the first proxy conatined in
19 // not, then |*did_fail| is set to true, and |*failure_details| is filled with 19 // |actual_proxies|, and that |actual_proxies| contains exactly one proxy. If
20 // a description of the failure. 20 // either condition is untrue, then |*did_fail| is set to true, and
21 // |*failure_details| is filled with a description of the failure.
21 void MatchesProxyServerHelper(const char* failure_message, 22 void MatchesProxyServerHelper(const char* failure_message,
22 const char* expected_proxy, 23 const char* expected_proxy,
23 const ProxyServer& actual_proxy, 24 const ProxyList& actual_proxies,
24 ::testing::AssertionResult* failure_details, 25 ::testing::AssertionResult* failure_details,
25 bool* did_fail) { 26 bool* did_fail) {
27 // If |expected_proxy| is empty, then we expect |actual_proxies| to be so as
28 // well.
29 if (strlen(expected_proxy) == 0) {
30 if (!actual_proxies.IsEmpty()) {
31 *did_fail = true;
32 *failure_details
33 << failure_message << ". Was expecting no proxies but got "
34 << actual_proxies.size() << ".";
35 }
36 return;
37 }
38
39 // Otherwise we check that |actual_proxies| holds a single matching proxy.
40 if (actual_proxies.size() != 1) {
41 *did_fail = true;
42 *failure_details
43 << failure_message << ". Was expecting exactly one proxy but got "
44 << actual_proxies.size() << ".";
45 return;
46 }
47
48 ProxyServer actual_proxy = actual_proxies.Get();
26 std::string actual_proxy_string; 49 std::string actual_proxy_string;
27 if (actual_proxy.is_valid()) 50 if (actual_proxy.is_valid())
28 actual_proxy_string = actual_proxy.ToURI(); 51 actual_proxy_string = actual_proxy.ToURI();
29 52
30 if (std::string(expected_proxy) != actual_proxy_string) { 53 if (std::string(expected_proxy) != actual_proxy_string) {
31 *failure_details 54 *failure_details
32 << failure_message << ". Was expecting: \"" << expected_proxy 55 << failure_message << ". Was expecting: \"" << expected_proxy
33 << "\" but got: \"" << actual_proxy_string << "\""; 56 << "\" but got: \"" << actual_proxy_string << "\"";
34 *did_fail = true; 57 *did_fail = true;
35 } 58 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 ::testing::AssertionResult failure_details = ::testing::AssertionFailure(); 97 ::testing::AssertionResult failure_details = ::testing::AssertionFailure();
75 bool failed = false; 98 bool failed = false;
76 99
77 if (rules.type != type) { 100 if (rules.type != type) {
78 failure_details << "Type mismatch. Expected: " 101 failure_details << "Type mismatch. Expected: "
79 << type << " but was: " << rules.type; 102 << type << " but was: " << rules.type;
80 failed = true; 103 failed = true;
81 } 104 }
82 105
83 MatchesProxyServerHelper("Bad single_proxy", single_proxy, 106 MatchesProxyServerHelper("Bad single_proxy", single_proxy,
84 rules.single_proxy, &failure_details, &failed); 107 rules.single_proxies, &failure_details, &failed);
85 MatchesProxyServerHelper("Bad proxy_for_http", proxy_for_http, 108 MatchesProxyServerHelper("Bad proxy_for_http", proxy_for_http,
86 rules.proxy_for_http, &failure_details, &failed); 109 rules.proxies_for_http, &failure_details,
110 &failed);
87 MatchesProxyServerHelper("Bad proxy_for_https", proxy_for_https, 111 MatchesProxyServerHelper("Bad proxy_for_https", proxy_for_https,
88 rules.proxy_for_https, &failure_details, &failed); 112 rules.proxies_for_https, &failure_details,
89 MatchesProxyServerHelper("Bad fallback_proxy", fallback_proxy, 113 &failed);
eroman 2013/03/06 23:26:32 Is it intentional that you removed the check on fa
marq_use_my_chromium_address 2013/03/07 00:34:29 That was a mistake; fixed.
90 rules.fallback_proxy, &failure_details, &failed);
91 114
92 std::string actual_flattened_bypass = FlattenProxyBypass(rules.bypass_rules); 115 std::string actual_flattened_bypass = FlattenProxyBypass(rules.bypass_rules);
93 if (std::string(flattened_bypass_rules) != actual_flattened_bypass) { 116 if (std::string(flattened_bypass_rules) != actual_flattened_bypass) {
94 failure_details 117 failure_details
95 << "Bad bypass rules. Expected: \"" << flattened_bypass_rules 118 << "Bad bypass rules. Expected: \"" << flattened_bypass_rules
96 << "\" but got: \"" << actual_flattened_bypass << "\""; 119 << "\" but got: \"" << actual_flattened_bypass << "\"";
97 failed = true; 120 failed = true;
98 } 121 }
99 122
100 if (rules.reverse_bypass != reverse_bypass) { 123 if (rules.reverse_bypass != reverse_bypass) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 const char* proxy_http, 180 const char* proxy_http,
158 const char* proxy_https, 181 const char* proxy_https,
159 const char* proxy_ftp, 182 const char* proxy_ftp,
160 const char* flattened_bypass_rules) { 183 const char* flattened_bypass_rules) {
161 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 184 return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
162 "", proxy_http, proxy_https, proxy_ftp, "", 185 "", proxy_http, proxy_https, proxy_ftp, "",
163 flattened_bypass_rules, true); 186 flattened_bypass_rules, true);
164 } 187 }
165 188
166 } // namespace net 189 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698