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

Side by Side Diff: chrome/browser/net/pref_proxy_config_service_unittest.cc

Issue 6004003: Introduce a separate preference for 'proxy server mode' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more thing... Created 9 years, 12 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) 2010 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/net/pref_proxy_config_service.h" 5 #include "chrome/browser/net/pref_proxy_config_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "chrome/browser/net/chrome_url_request_context.h" 9 #include "chrome/browser/net/chrome_url_request_context.h"
10 #include "chrome/browser/prefs/pref_service_mock_builder.h" 10 #include "chrome/browser/prefs/pref_service_mock_builder.h"
11 #include "chrome/browser/prefs/proxy_prefs.h"
11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
13 #include "chrome/test/testing_pref_service.h" 14 #include "chrome/test/testing_pref_service.h"
14 #include "net/proxy/proxy_config_service_common_unittest.h" 15 #include "net/proxy/proxy_config_service_common_unittest.h"
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 using testing::_; 19 using testing::_;
19 using testing::Mock; 20 using testing::Mock;
20 21
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 108
108 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { 109 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) {
109 net::ProxyConfig actual_config; 110 net::ProxyConfig actual_config;
110 proxy_config_service_->GetLatestProxyConfig(&actual_config); 111 proxy_config_service_->GetLatestProxyConfig(&actual_config);
111 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); 112 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url());
112 } 113 }
113 114
114 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { 115 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) {
115 pref_service_->SetManagedPref( 116 pref_service_->SetManagedPref(
116 prefs::kProxyServer, Value::CreateStringValue("http://example.com:3128")); 117 prefs::kProxyServer, Value::CreateStringValue("http://example.com:3128"));
118 pref_service_->SetManagedPref(
119 prefs::kProxyMode,
120 Value::CreateIntegerValue(ProxyPrefs::kModeFixedServers));
117 loop_.RunAllPending(); 121 loop_.RunAllPending();
118 122
119 net::ProxyConfig actual_config; 123 net::ProxyConfig actual_config;
120 proxy_config_service_->GetLatestProxyConfig(&actual_config); 124 proxy_config_service_->GetLatestProxyConfig(&actual_config);
121 EXPECT_FALSE(actual_config.auto_detect()); 125 EXPECT_FALSE(actual_config.auto_detect());
122 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 126 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
123 actual_config.proxy_rules().type); 127 actual_config.proxy_rules().type);
124 EXPECT_EQ(actual_config.proxy_rules().single_proxy, 128 EXPECT_EQ(actual_config.proxy_rules().single_proxy,
125 net::ProxyServer::FromURI("http://example.com:3128", 129 net::ProxyServer::FromURI("http://example.com:3128",
126 net::ProxyServer::SCHEME_HTTP)); 130 net::ProxyServer::SCHEME_HTTP));
127 131
128 pref_service_->SetManagedPref( 132 pref_service_->SetManagedPref(
129 prefs::kProxyAutoDetect, Value::CreateBooleanValue(true)); 133 prefs::kProxyMode,
134 Value::CreateIntegerValue(ProxyPrefs::kModeAutoDetect));
130 loop_.RunAllPending(); 135 loop_.RunAllPending();
131 136
132 proxy_config_service_->GetLatestProxyConfig(&actual_config); 137 proxy_config_service_->GetLatestProxyConfig(&actual_config);
133 EXPECT_TRUE(actual_config.auto_detect()); 138 EXPECT_TRUE(actual_config.auto_detect());
134 } 139 }
135 140
136 // Compares proxy configurations, but allows different identifiers. 141 // Compares proxy configurations, but allows different identifiers.
137 MATCHER_P(ProxyConfigMatches, config, "") { 142 MATCHER_P(ProxyConfigMatches, config, "") {
138 net::ProxyConfig reference(config); 143 net::ProxyConfig reference(config);
139 reference.set_id(arg.id()); 144 reference.set_id(arg.id());
140 return reference.Equals(arg); 145 return reference.Equals(arg);
141 } 146 }
142 147
143 TEST_F(PrefProxyConfigServiceTest, Observers) { 148 TEST_F(PrefProxyConfigServiceTest, Observers) {
144 MockObserver observer; 149 MockObserver observer;
145 proxy_config_service_->AddObserver(&observer); 150 proxy_config_service_->AddObserver(&observer);
146 151
147 // Firing the observers in the delegate should trigger a notification. 152 // Firing the observers in the delegate should trigger a notification.
148 net::ProxyConfig config2; 153 net::ProxyConfig config2;
149 config2.set_auto_detect(true); 154 config2.set_auto_detect(true);
150 EXPECT_CALL(observer, 155 EXPECT_CALL(observer,
151 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1); 156 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1);
152 delegate_service_->SetProxyConfig(config2); 157 delegate_service_->SetProxyConfig(config2);
153 loop_.RunAllPending(); 158 loop_.RunAllPending();
154 Mock::VerifyAndClearExpectations(&observer); 159 Mock::VerifyAndClearExpectations(&observer);
155 160
156 // Override configuration, this should trigger a notification. 161 // Override configuration, this should trigger a notification.
157 net::ProxyConfig pref_config; 162 net::ProxyConfig pref_config;
158 pref_config.set_pac_url(GURL(kFixedPacUrl)); 163 pref_config.set_pac_url(GURL(kFixedPacUrl));
164
159 EXPECT_CALL(observer, 165 EXPECT_CALL(observer,
160 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); 166 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1);
167
161 pref_service_->SetManagedPref(prefs::kProxyPacUrl, 168 pref_service_->SetManagedPref(prefs::kProxyPacUrl,
162 Value::CreateStringValue(kFixedPacUrl)); 169 Value::CreateStringValue(kFixedPacUrl));
170 // The above does not trigger a notification, because PrefProxyConfig still
171 // sees the mode as the default (ProxyPrefs::SYSTEM), so that it doesn't claim
172 // to have proxy config.
173 // TODO(battre): Remove this comment when http://crbug.com/65732 is
174 // resolved.
175 pref_service_->SetManagedPref(
176 prefs::kProxyMode,
177 Value::CreateIntegerValue(ProxyPrefs::kModePacScript));
163 loop_.RunAllPending(); 178 loop_.RunAllPending();
164 Mock::VerifyAndClearExpectations(&observer); 179 Mock::VerifyAndClearExpectations(&observer);
165 180
166 // Since there are pref overrides, delegate changes should be ignored. 181 // Since there are pref overrides, delegate changes should be ignored.
167 net::ProxyConfig config3; 182 net::ProxyConfig config3;
168 config3.proxy_rules().ParseFromString("http=config3:80"); 183 config3.proxy_rules().ParseFromString("http=config3:80");
169 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); 184 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0);
170 fixed_config_.set_auto_detect(true); 185 fixed_config_.set_auto_detect(true);
171 delegate_service_->SetProxyConfig(config3); 186 delegate_service_->SetProxyConfig(config3);
172 loop_.RunAllPending(); 187 loop_.RunAllPending();
173 Mock::VerifyAndClearExpectations(&observer); 188 Mock::VerifyAndClearExpectations(&observer);
174 189
175 // Clear the override should switch back to the fixed configuration. 190 // Clear the override should switch back to the fixed configuration.
176 EXPECT_CALL(observer, 191 EXPECT_CALL(observer,
177 OnProxyConfigChanged(ProxyConfigMatches(config3))).Times(1); 192 OnProxyConfigChanged(ProxyConfigMatches(config3))).Times(1);
193 pref_service_->RemoveManagedPref(prefs::kProxyMode);
194 // The above switches the mode the default (ProxyPrefs::SYSTEM), so the next
eroman 2010/12/23 01:06:15 nit: I think this sentence is missing "to". "swi
battre 2010/12/23 09:41:42 Done.
195 // removal won't bother PrefProxyConfigService.
196 // TODO(battre): Remove this comment when http://crbug.com/65732 is
197 // completed.
178 pref_service_->RemoveManagedPref(prefs::kProxyPacUrl); 198 pref_service_->RemoveManagedPref(prefs::kProxyPacUrl);
179 loop_.RunAllPending(); 199 loop_.RunAllPending();
180 Mock::VerifyAndClearExpectations(&observer); 200 Mock::VerifyAndClearExpectations(&observer);
181 201
182 // Delegate service notifications should show up again. 202 // Delegate service notifications should show up again.
183 net::ProxyConfig config4; 203 net::ProxyConfig config4;
184 config4.proxy_rules().ParseFromString("socks:config4"); 204 config4.proxy_rules().ParseFromString("socks:config4");
185 EXPECT_CALL(observer, 205 EXPECT_CALL(observer,
186 OnProxyConfigChanged(ProxyConfigMatches(config4))).Times(1); 206 OnProxyConfigChanged(ProxyConfigMatches(config4))).Times(1);
187 delegate_service_->SetProxyConfig(config4); 207 delegate_service_->SetProxyConfig(config4);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 false, // is_null 363 false, // is_null
344 false, // auto_detect 364 false, // auto_detect
345 GURL(), // pac_url 365 GURL(), // pac_url
346 net::ProxyRulesExpectation::PerScheme( 366 net::ProxyRulesExpectation::PerScheme(
347 "httpproxy:8888", // http 367 "httpproxy:8888", // http
348 "", // https 368 "", // https
349 "ftpproxy:8889", // ftp 369 "ftpproxy:8889", // ftp
350 "*.google.com,foo.com:99,1.2.3.4:22,127.0.0.1/8"), 370 "*.google.com,foo.com:99,1.2.3.4:22,127.0.0.1/8"),
351 }, 371 },
352 { 372 {
353 "Pac URL with proxy bypass URLs", 373 "Pac URL",
354 // Input 374 // Input
355 { 375 {
356 { switches::kProxyPacUrl, "http://wpad/wpad.dat" }, 376 { switches::kProxyPacUrl, "http://wpad/wpad.dat" },
357 { switches::kProxyBypassList,
358 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8" },
359 }, 377 },
360 // Expected result 378 // Expected result
361 false, // is_null 379 false, // is_null
362 false, // auto_detect 380 false, // auto_detect
363 GURL("http://wpad/wpad.dat"), // pac_url 381 GURL("http://wpad/wpad.dat"), // pac_url
364 net::ProxyRulesExpectation::EmptyWithBypass( 382 net::ProxyRulesExpectation::Empty(),
365 "*.google.com,foo.com:99,1.2.3.4:22,127.0.0.1/8"),
366 }, 383 },
367 { 384 {
368 "Autodetect", 385 "Autodetect",
369 // Input 386 // Input
370 { 387 {
371 { switches::kProxyAutoDetect, NULL }, 388 { switches::kProxyAutoDetect, NULL },
372 }, 389 },
373 // Expected result 390 // Expected result
374 false, // is_null 391 false, // is_null
375 true, // auto_detect 392 true, // auto_detect
376 GURL(), // pac_url 393 GURL(), // pac_url
377 net::ProxyRulesExpectation::Empty(), 394 net::ProxyRulesExpectation::Empty(),
378 }, 395 },
379 }; 396 };
380 397
381 INSTANTIATE_TEST_CASE_P( 398 INSTANTIATE_TEST_CASE_P(
382 PrefProxyConfigServiceCommandLineTestInstance, 399 PrefProxyConfigServiceCommandLineTestInstance,
383 PrefProxyConfigServiceCommandLineTest, 400 PrefProxyConfigServiceCommandLineTest,
384 testing::ValuesIn(kCommandLineTestParams)); 401 testing::ValuesIn(kCommandLineTestParams));
385 402
386 } // namespace 403 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698