Commit 4c0456af authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Fix ProxyConfig::ToValue() when a proxy list is specified per URL scheme.

Bug: 1004532
Change-Id: I1a883ddc6c7a0459706afdadf099e6658801e829
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1810042Reviewed-by: default avatarMatt Mueller <mattm@chromium.org>
Commit-Queue: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697659}
parent a1ac80c6
...@@ -234,7 +234,7 @@ base::Value ProxyConfig::ToValue() const { ...@@ -234,7 +234,7 @@ base::Value ProxyConfig::ToValue() const {
AddProxyListToValue("https", proxy_rules_.proxies_for_https, &dict2); AddProxyListToValue("https", proxy_rules_.proxies_for_https, &dict2);
AddProxyListToValue("ftp", proxy_rules_.proxies_for_ftp, &dict2); AddProxyListToValue("ftp", proxy_rules_.proxies_for_ftp, &dict2);
AddProxyListToValue("fallback", proxy_rules_.fallback_proxies, &dict2); AddProxyListToValue("fallback", proxy_rules_.fallback_proxies, &dict2);
dict2.SetKey("proxy_per_scheme", std::move(dict2)); dict.SetKey("proxy_per_scheme", std::move(dict2));
break; break;
} }
default: default:
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "net/proxy_resolution/proxy_config.h" #include "net/proxy_resolution/proxy_config.h"
#include "base/json/json_writer.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/values.h"
#include "net/proxy_resolution/proxy_config_service_common_unittest.h" #include "net/proxy_resolution/proxy_config_service_common_unittest.h"
#include "net/proxy_resolution/proxy_info.h" #include "net/proxy_resolution/proxy_info.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -96,6 +98,128 @@ TEST(ProxyConfigTest, Equals) { ...@@ -96,6 +98,128 @@ TEST(ProxyConfigTest, Equals) {
EXPECT_TRUE(config2.Equals(config1)); EXPECT_TRUE(config2.Equals(config1));
} }
struct ProxyConfigToValueTestCase {
ProxyConfig config;
const char* expected_value_json;
};
class ProxyConfigToValueTest
: public ::testing::TestWithParam<ProxyConfigToValueTestCase> {};
TEST_P(ProxyConfigToValueTest, ToValueJSON) {
const ProxyConfigToValueTestCase& test_case = GetParam();
base::Value value = test_case.config.ToValue();
std::string json_string;
ASSERT_TRUE(base::JSONWriter::Write(value, &json_string));
EXPECT_EQ(std::string(test_case.expected_value_json), json_string);
}
ProxyConfigToValueTestCase GetTestCaseDirect() {
return {ProxyConfig::CreateDirect(), "{}"};
}
ProxyConfigToValueTestCase GetTestCaseAutoDetect() {
return {ProxyConfig::CreateAutoDetect(), "{\"auto_detect\":true}"};
}
ProxyConfigToValueTestCase GetTestCasePacUrl() {
ProxyConfig config;
config.set_pac_url(GURL("http://www.example.com/test.pac"));
return {std::move(config),
"{\"pac_url\":\"http://www.example.com/test.pac\"}"};
}
ProxyConfigToValueTestCase GetTestCasePacUrlMandatory() {
ProxyConfig config;
config.set_pac_url(GURL("http://www.example.com/test.pac"));
config.set_pac_mandatory(true);
return {std::move(config),
"{\"pac_mandatory\":true,\"pac_url\":\"http://www.example.com/"
"test.pac\"}"};
}
ProxyConfigToValueTestCase GetTestCasePacUrlAndAutoDetect() {
ProxyConfig config = ProxyConfig::CreateAutoDetect();
config.set_pac_url(GURL("http://www.example.com/test.pac"));
return {
std::move(config),
"{\"auto_detect\":true,\"pac_url\":\"http://www.example.com/test.pac\"}"};
}
ProxyConfigToValueTestCase GetTestCaseSingleProxy() {
ProxyConfig config;
config.proxy_rules().ParseFromString("https://proxy1:8080");
return {std::move(config), "{\"single_proxy\":[\"https://proxy1:8080\"]}"};
}
ProxyConfigToValueTestCase GetTestCaseSingleProxyWithBypass() {
ProxyConfig config;
config.proxy_rules().ParseFromString("https://proxy1:8080");
config.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
config.proxy_rules().bypass_rules.AddRuleFromString("192.168.0.1/16");
return {std::move(config),
"{\"bypass_list\":[\"*.google.com\",\"192.168.0.1/"
"16\"],\"single_proxy\":[\"https://proxy1:8080\"]}"};
}
ProxyConfigToValueTestCase GetTestCaseSingleProxyWithReversedBypass() {
ProxyConfig config;
config.proxy_rules().ParseFromString("https://proxy1:8080");
config.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
config.proxy_rules().reverse_bypass = true;
return {std::move(config),
"{\"bypass_list\":[\"*.google.com\"],\"reverse_bypass\":true,"
"\"single_proxy\":[\"https://proxy1:8080\"]}"};
}
ProxyConfigToValueTestCase GetTestCaseProxyPerScheme() {
ProxyConfig config;
config.proxy_rules().ParseFromString(
"http=https://proxy1:8080;https=socks5://proxy2");
config.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
config.set_pac_url(GURL("http://wpad/wpad.dat"));
config.set_auto_detect(true);
return {
std::move(config),
"{\"auto_detect\":true,\"bypass_list\":[\"*.google.com\"],\"pac_url\":"
"\"http://wpad/wpad.dat\",\"proxy_per_scheme\":{\"http\":[\"https://"
"proxy1:8080\"],\"https\":[\"socks5://proxy2:1080\"]}}"};
}
ProxyConfigToValueTestCase GetTestCaseSingleProxyList() {
ProxyConfig config;
config.proxy_rules().ParseFromString(
"https://proxy1:8080,http://proxy2,direct://");
return {std::move(config),
"{\"single_proxy\":[\"https://proxy1:8080\",\"proxy2:80\",\"direct://"
"\"]}"};
}
INSTANTIATE_TEST_SUITE_P(
,
ProxyConfigToValueTest,
testing::Values(GetTestCaseDirect(),
GetTestCaseAutoDetect(),
GetTestCasePacUrl(),
GetTestCasePacUrlMandatory(),
GetTestCasePacUrlAndAutoDetect(),
GetTestCaseSingleProxy(),
GetTestCaseSingleProxyWithBypass(),
GetTestCaseSingleProxyWithReversedBypass(),
GetTestCaseProxyPerScheme(),
GetTestCaseSingleProxyList()));
TEST(ProxyConfigTest, ParseProxyRules) { TEST(ProxyConfigTest, ParseProxyRules) {
const struct { const struct {
const char* proxy_rules; const char* proxy_rules;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment