1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_COMMON_UNITTEST_H_ 6 #define NET_PROXY_PROXY_CONFIG_SERVICE_COMMON_UNITTEST_H_ 7 #pragma once 8 9 #include "net/proxy/proxy_config.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 // Helper functions to describe the expected value of a 13 // ProxyConfig::ProxyRules, and to check for a match. 14 15 namespace net { 16 17 // This structure contains our expectations on what values the ProxyRules 18 // should have. 19 struct ProxyRulesExpectation { 20 ProxyRulesExpectation(ProxyConfig::ProxyRules::Type type, 21 const char* single_proxy, 22 const char* proxy_for_http, 23 const char* proxy_for_https, 24 const char* proxy_for_ftp, 25 const char* fallback_proxy, 26 const char* flattened_bypass_rules, 27 bool reverse_bypass); 28 29 // Call this within an EXPECT_TRUE(), to assert that |rules| matches 30 // our expected values |*this|. 31 ::testing::AssertionResult Matches( 32 const ProxyConfig::ProxyRules& rules) const; 33 34 // Creates an expectation that the ProxyRules has no rules. 35 static ProxyRulesExpectation Empty(); 36 37 // Creates an expectation that the ProxyRules has nothing other than 38 // the specified bypass rules. 39 static ProxyRulesExpectation EmptyWithBypass( 40 const char* flattened_bypass_rules); 41 42 // Creates an expectation that the ProxyRules is for a single proxy 43 // server for all schemes. 44 static ProxyRulesExpectation Single(const char* single_proxy, 45 const char* flattened_bypass_rules); 46 47 // Creates an expectation that the ProxyRules specifies a different 48 // proxy server for each URL scheme. 49 static ProxyRulesExpectation PerScheme(const char* proxy_http, 50 const char* proxy_https, 51 const char* proxy_ftp, 52 const char* flattened_bypass_rules); 53 54 // Same as above, but additionally with a SOCKS fallback. 55 static ProxyRulesExpectation PerSchemeWithSocks( 56 const char* proxy_http, 57 const char* proxy_https, 58 const char* proxy_ftp, 59 const char* fallback_proxy, 60 const char* flattened_bypass_rules); 61 62 // Same as PerScheme, but with the bypass rules reversed 63 static ProxyRulesExpectation PerSchemeWithBypassReversed( 64 const char* proxy_http, 65 const char* proxy_https, 66 const char* proxy_ftp, 67 const char* flattened_bypass_rules); 68 69 ProxyConfig::ProxyRules::Type type; 70 const char* single_proxy; 71 const char* proxy_for_http; 72 const char* proxy_for_https; 73 const char* proxy_for_ftp; 74 const char* fallback_proxy; 75 const char* flattened_bypass_rules; 76 bool reverse_bypass; 77 }; 78 79 } // namespace net 80 81 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_COMMON_UNITTEST_H_ 82