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

Unified Diff: chrome/browser/chromeos/proxy_config_service_impl_unittest.cc

Issue 8102019: redesign and reimplement proxy config service and tracker, revise proxy ui on cros (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/proxy_config_service_impl_unittest.cc
===================================================================
--- chrome/browser/chromeos/proxy_config_service_impl_unittest.cc (revision 103881)
+++ chrome/browser/chromeos/proxy_config_service_impl_unittest.cc (working copy)
@@ -48,7 +48,7 @@
std::string description;
bool is_valid;
- bool test_read_write_access;
+ bool test_modifiable;
Input input;
@@ -61,7 +61,7 @@
TEST_DESC("No proxying"),
true, // is_valid
- true, // test_read_write_access
+ true, // test_modifiable
{ // Input.
MK_MODE(DIRECT), // mode
@@ -77,7 +77,7 @@
TEST_DESC("Auto detect"),
true, // is_valid
- true, // test_read_write_access
+ true, // test_modifiable
{ // Input.
MK_MODE(AUTO_DETECT), // mode
@@ -93,7 +93,7 @@
TEST_DESC("Valid PAC URL"),
true, // is_valid
- true, // test_read_write_access
+ true, // test_modifiable
{ // Input.
MK_MODE(PAC_SCRIPT), // mode
@@ -110,7 +110,7 @@
TEST_DESC("Invalid PAC URL"),
false, // is_valid
- false, // test_read_write_access
+ false, // test_modifiable
{ // Input.
MK_MODE(PAC_SCRIPT), // mode
@@ -127,7 +127,7 @@
TEST_DESC("Single-host in proxy list"),
true, // is_valid
- true, // test_read_write_access
+ true, // test_modifiable
{ // Input.
MK_MODE(SINGLE_PROXY), // mode
@@ -147,7 +147,7 @@
TEST_DESC("Single-host, different port"),
true, // is_valid
- false, // test_read_write_access
+ false, // test_modifiable
{ // Input.
MK_MODE(SINGLE_PROXY), // mode
@@ -167,7 +167,7 @@
TEST_DESC("Tolerate a scheme"),
true, // is_valid
- false, // test_read_write_access
+ false, // test_modifiable
{ // Input.
MK_MODE(SINGLE_PROXY), // mode
@@ -187,7 +187,7 @@
TEST_DESC("Per-scheme proxy rules"),
true, // is_valid
- true, // test_read_write_access
+ true, // test_modifiable
{ // Input.
MK_MODE(PROXY_PER_SCHEME), // mode
@@ -214,7 +214,7 @@
TEST_DESC("Bypass rules"),
true, // is_valid
- true, // test_read_write_access
+ true, // test_modifiable
{ // Input.
MK_MODE(SINGLE_PROXY), // mode
@@ -261,7 +261,7 @@
ProxyConfigServiceImpl::ProxyConfig* config,
ProxyConfigServiceImpl::ProxyConfig::AutomaticProxy* automatic_proxy) {
config->mode = mode;
- automatic_proxy->source = source;
+ config->source = source;
if (pac_url)
automatic_proxy->pac_url = GURL(pac_url);
}
@@ -276,7 +276,7 @@
if (!server_uri)
return;
config->mode = mode;
- manual_proxy->source = source;
+ config->source = source;
manual_proxy->server = net::ProxyServer::FromURI(server_uri, scheme);
}
@@ -310,8 +310,9 @@
}
}
- void TestReadWriteAccessForMode(const Input& input,
- ProxyConfigServiceImpl::ProxyConfig::Source source) {
+ void TestModifiable(const Input& input,
+ ProxyConfigServiceImpl::ProxyConfig::Source source,
+ bool expected_modifiable) {
// Init config from |source|.
ProxyConfigServiceImpl::ProxyConfig init_config;
InitConfigWithTestInput(input, source, &init_config);
@@ -320,80 +321,9 @@
ProxyConfigServiceImpl::ProxyConfig config;
config_service()->UIGetProxyConfig(&config);
- // For owner, write access to config should be equal CanBeWrittenByOwner().
- // For non-owner, config is never writeable.
- bool expected_writeable_by_owner = CanBeWrittenByOwner(source);
- if (config.mode == MK_MODE(PROXY_PER_SCHEME)) {
- if (input.http_uri) {
- EXPECT_EQ(expected_writeable_by_owner,
- config.CanBeWrittenByUser(true, "http"));
- EXPECT_FALSE(config.CanBeWrittenByUser(false, "http"));
- }
- if (input.https_uri) {
- EXPECT_EQ(expected_writeable_by_owner,
- config.CanBeWrittenByUser(true, "http"));
- EXPECT_FALSE(config.CanBeWrittenByUser(false, "https"));
- }
- if (input.ftp_uri) {
- EXPECT_EQ(expected_writeable_by_owner,
- config.CanBeWrittenByUser(true, "http"));
- EXPECT_FALSE(config.CanBeWrittenByUser(false, "ftp"));
- }
- if (input.socks_uri) {
- EXPECT_EQ(expected_writeable_by_owner,
- config.CanBeWrittenByUser(true, "http"));
- EXPECT_FALSE(config.CanBeWrittenByUser(false, "socks"));
- }
- } else {
- EXPECT_EQ(expected_writeable_by_owner,
- config.CanBeWrittenByUser(true, std::string()));
- EXPECT_FALSE(config.CanBeWrittenByUser(false, std::string()));
- }
+ EXPECT_EQ(expected_modifiable, config.IsUserModifiable());
}
- void TestReadWriteAccessForScheme(
- ProxyConfigServiceImpl::ProxyConfig::Source source,
- const char* server_uri,
- const std::string& scheme) {
- // Init with manual |scheme| proxy.
- ProxyConfigServiceImpl::ProxyConfig init_config;
- ProxyConfigServiceImpl::ProxyConfig::ManualProxy* proxy =
- init_config.MapSchemeToProxy(scheme);
- net::ProxyServer::Scheme net_scheme = MK_SCHM(HTTP);
- if (scheme == "http" || scheme == "ftp")
- net_scheme = MK_SCHM(HTTP);
- else if (scheme == "https")
- net_scheme = MK_SCHM(HTTPS);
- else if (scheme == "socks")
- net_scheme = MK_SCHM(SOCKS4);
- SetManualProxy(MK_MODE(PROXY_PER_SCHEME), source, server_uri, net_scheme,
- &init_config, proxy);
- CreateConfigService(init_config);
-
- ProxyConfigServiceImpl::ProxyConfig config;
- config_service()->UIGetProxyConfig(&config);
-
- // For owner, write access to config should be equal CanBeWrittenByOwner().
- // For non-owner, config is never writeable.
- bool expected_writeable_by_owner = CanBeWrittenByOwner(source);
- EXPECT_EQ(expected_writeable_by_owner,
- config.CanBeWrittenByUser(true, scheme));
- EXPECT_FALSE(config.CanBeWrittenByUser(false, scheme));
-
- const char* all_schemes[] = {
- "http", "https", "ftp", "socks",
- };
-
- // Rest of protos should be writeable by owner, but not writeable by
- // non-owner.
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(all_schemes); ++i) {
- if (scheme == all_schemes[i])
- continue;
- EXPECT_TRUE(config.CanBeWrittenByUser(true, all_schemes[i]));
- EXPECT_FALSE(config.CanBeWrittenByUser(false, all_schemes[i]));
- }
- }
-
// Synchronously gets the latest proxy config.
bool SyncGetLatestProxyConfig(net::ProxyConfig* config) {
// Let message loop process all messages.
@@ -408,11 +338,6 @@
}
private:
- bool CanBeWrittenByOwner(
- ProxyConfigServiceImpl::ProxyConfig::Source source) const {
- return source == MK_SRC(POLICY) ? false : true;
- }
-
ScopedStubCrosEnabler stub_cros_enabler_;
MessageLoop message_loop_;
BrowserThread ui_thread_;
@@ -427,7 +352,7 @@
tests[i].description.c_str()));
ProxyConfigServiceImpl::ProxyConfig init_config;
- InitConfigWithTestInput(tests[i].input, MK_SRC(OWNER), &init_config);
+ InitConfigWithTestInput(tests[i].input, MK_SRC(NETWORK), &init_config);
CreateConfigService(init_config);
net::ProxyConfig config;
@@ -446,7 +371,7 @@
// Init with direct.
ProxyConfigServiceImpl::ProxyConfig init_config;
- SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(OWNER), NULL, &init_config,
+ SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(NETWORK), NULL, &init_config,
&init_config.automatic_proxy);
CreateConfigService(init_config);
@@ -566,7 +491,7 @@
// Init with direct.
ProxyConfigServiceImpl::ProxyConfig init_config;
- SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(OWNER), NULL, &init_config,
+ SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(NETWORK), NULL, &init_config,
&init_config.automatic_proxy);
CreateConfigService(init_config);
@@ -593,7 +518,7 @@
tests[i].description.c_str()));
ProxyConfigServiceImpl::ProxyConfig source_config;
- InitConfigWithTestInput(tests[i].input, MK_SRC(OWNER), &source_config);
+ InitConfigWithTestInput(tests[i].input, MK_SRC(NETWORK), &source_config);
// Serialize source_config into std::string.
std::string serialized_value;
@@ -623,43 +548,21 @@
}
}
-TEST_F(ProxyConfigServiceImplTest, ReadWriteAccessForPolicySource) {
+TEST_F(ProxyConfigServiceImplTest, Modifiable) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- if (!tests[i].test_read_write_access)
+ if (!tests[i].test_modifiable)
continue;
SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i,
tests[i].description.c_str()));
- TestReadWriteAccessForMode(tests[i].input, MK_SRC(POLICY));
+ TestModifiable(tests[i].input, MK_SRC(NONE), true);
+ TestModifiable(tests[i].input, MK_SRC(NONE_DISABLED), false);
+ TestModifiable(tests[i].input, MK_SRC(POLICY), false);
+ TestModifiable(tests[i].input, MK_SRC(EXTENSION), false);
+ TestModifiable(tests[i].input, MK_SRC(NETWORK), true);
+ TestModifiable(tests[i].input, MK_SRC(NETWORK_DISABLED), false);
+ TestModifiable(tests[i].input, MK_SRC(RECOMMENDED), true);
+ TestModifiable(tests[i].input, MK_SRC(RECOMMENDED_DISABLED), false);
}
}
-TEST_F(ProxyConfigServiceImplTest, ReadWriteAccessForOwnerSource) {
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- if (!tests[i].test_read_write_access)
- continue;
- SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i,
- tests[i].description.c_str()));
- TestReadWriteAccessForMode(tests[i].input, MK_SRC(OWNER));
- }
-}
-
-TEST_F(ProxyConfigServiceImplTest, ReadWriteAccessForMixedSchemes) {
- const char* http_uri = "www.google.com:80";
- const char* https_uri = "www.foo.com:110";
- const char* ftp_uri = "ftp.foo.com:121";
- const char* socks_uri = "socks.com:888";
-
- // Init with policy source.
- TestReadWriteAccessForScheme(MK_SRC(POLICY), http_uri, "http");
- TestReadWriteAccessForScheme(MK_SRC(POLICY), https_uri, "https");
- TestReadWriteAccessForScheme(MK_SRC(POLICY), ftp_uri, "ftp");
- TestReadWriteAccessForScheme(MK_SRC(POLICY), socks_uri, "socks");
-
- // Init with owner source.
- TestReadWriteAccessForScheme(MK_SRC(OWNER), http_uri, "http");
- TestReadWriteAccessForScheme(MK_SRC(OWNER), https_uri, "https");
- TestReadWriteAccessForScheme(MK_SRC(OWNER), ftp_uri, "ftp");
- TestReadWriteAccessForScheme(MK_SRC(OWNER), socks_uri, "socks");
-}
-
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698