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

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: Addressed comments Created 10 years 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, Value::CreateIntegerValue(ProxyPrefs::FIXED_SERVERS));
117 loop_.RunAllPending(); 120 loop_.RunAllPending();
118 121
119 net::ProxyConfig actual_config; 122 net::ProxyConfig actual_config;
120 proxy_config_service_->GetLatestProxyConfig(&actual_config); 123 proxy_config_service_->GetLatestProxyConfig(&actual_config);
121 EXPECT_FALSE(actual_config.auto_detect()); 124 EXPECT_FALSE(actual_config.auto_detect());
122 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 125 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
123 actual_config.proxy_rules().type); 126 actual_config.proxy_rules().type);
124 EXPECT_EQ(actual_config.proxy_rules().single_proxy, 127 EXPECT_EQ(actual_config.proxy_rules().single_proxy,
125 net::ProxyServer::FromURI("http://example.com:3128", 128 net::ProxyServer::FromURI("http://example.com:3128",
126 net::ProxyServer::SCHEME_HTTP)); 129 net::ProxyServer::SCHEME_HTTP));
127 130
128 pref_service_->SetManagedPref( 131 pref_service_->SetManagedPref(
129 prefs::kProxyAutoDetect, Value::CreateBooleanValue(true)); 132 prefs::kProxyMode, Value::CreateIntegerValue(ProxyPrefs::AUTO_DETECT));
130 loop_.RunAllPending(); 133 loop_.RunAllPending();
131 134
132 proxy_config_service_->GetLatestProxyConfig(&actual_config); 135 proxy_config_service_->GetLatestProxyConfig(&actual_config);
133 EXPECT_TRUE(actual_config.auto_detect()); 136 EXPECT_TRUE(actual_config.auto_detect());
134 } 137 }
135 138
136 // Compares proxy configurations, but allows different identifiers. 139 // Compares proxy configurations, but allows different identifiers.
137 MATCHER_P(ProxyConfigMatches, config, "") { 140 MATCHER_P(ProxyConfigMatches, config, "") {
138 net::ProxyConfig reference(config); 141 net::ProxyConfig reference(config);
139 reference.set_id(arg.id()); 142 reference.set_id(arg.id());
140 return reference.Equals(arg); 143 return reference.Equals(arg);
141 } 144 }
142 145
143 TEST_F(PrefProxyConfigServiceTest, Observers) { 146 TEST_F(PrefProxyConfigServiceTest, Observers) {
144 MockObserver observer; 147 MockObserver observer;
145 proxy_config_service_->AddObserver(&observer); 148 proxy_config_service_->AddObserver(&observer);
146 149
147 // Firing the observers in the delegate should trigger a notification. 150 // Firing the observers in the delegate should trigger a notification.
148 net::ProxyConfig config2; 151 net::ProxyConfig config2;
149 config2.set_auto_detect(true); 152 config2.set_auto_detect(true);
150 EXPECT_CALL(observer, 153 EXPECT_CALL(observer,
151 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1); 154 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1);
152 delegate_service_->SetProxyConfig(config2); 155 delegate_service_->SetProxyConfig(config2);
153 loop_.RunAllPending(); 156 loop_.RunAllPending();
154 Mock::VerifyAndClearExpectations(&observer); 157 Mock::VerifyAndClearExpectations(&observer);
155 158
156 // Override configuration, this should trigger a notification. 159 // Override configuration, this should trigger a notification.
157 net::ProxyConfig pref_config; 160 net::ProxyConfig pref_config;
158 pref_config.set_pac_url(GURL(kFixedPacUrl)); 161 pref_config.set_pac_url(GURL(kFixedPacUrl));
162
159 EXPECT_CALL(observer, 163 EXPECT_CALL(observer,
160 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); 164 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1);
165
161 pref_service_->SetManagedPref(prefs::kProxyPacUrl, 166 pref_service_->SetManagedPref(prefs::kProxyPacUrl,
162 Value::CreateStringValue(kFixedPacUrl)); 167 Value::CreateStringValue(kFixedPacUrl));
168 // The above does not trigger a notification, because PrefProxyConfig still
169 // sees the mode as the default (ProxyPrefs::SYSTEM), so that it doesn't claim
170 // to have proxy config.
171 // TODO(battre): Remove this comment when http://crbug.com/65732 is
172 // resolved.
173 pref_service_->SetManagedPref(
174 prefs::kProxyMode, Value::CreateIntegerValue(ProxyPrefs::PAC_SCRIPT));
163 loop_.RunAllPending(); 175 loop_.RunAllPending();
164 Mock::VerifyAndClearExpectations(&observer); 176 Mock::VerifyAndClearExpectations(&observer);
165 177
166 // Since there are pref overrides, delegate changes should be ignored. 178 // Since there are pref overrides, delegate changes should be ignored.
167 net::ProxyConfig config3; 179 net::ProxyConfig config3;
168 config3.proxy_rules().ParseFromString("http=config3:80"); 180 config3.proxy_rules().ParseFromString("http=config3:80");
169 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); 181 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0);
170 fixed_config_.set_auto_detect(true); 182 fixed_config_.set_auto_detect(true);
171 delegate_service_->SetProxyConfig(config3); 183 delegate_service_->SetProxyConfig(config3);
172 loop_.RunAllPending(); 184 loop_.RunAllPending();
173 Mock::VerifyAndClearExpectations(&observer); 185 Mock::VerifyAndClearExpectations(&observer);
174 186
175 // Clear the override should switch back to the fixed configuration. 187 // Clear the override should switch back to the fixed configuration.
176 EXPECT_CALL(observer, 188 EXPECT_CALL(observer,
177 OnProxyConfigChanged(ProxyConfigMatches(config3))).Times(1); 189 OnProxyConfigChanged(ProxyConfigMatches(config3))).Times(1);
190 pref_service_->RemoveManagedPref(prefs::kProxyMode);
191 // The above switches the mode the default (ProxyPrefs::SYSTEM), so the next
192 // removal won't bother PrefProxyConfigService.
193 // TODO(battre): Remove this comment when http://crbug.com/65732 is
194 // completed.
178 pref_service_->RemoveManagedPref(prefs::kProxyPacUrl); 195 pref_service_->RemoveManagedPref(prefs::kProxyPacUrl);
179 loop_.RunAllPending(); 196 loop_.RunAllPending();
180 Mock::VerifyAndClearExpectations(&observer); 197 Mock::VerifyAndClearExpectations(&observer);
181 198
182 // Delegate service notifications should show up again. 199 // Delegate service notifications should show up again.
183 net::ProxyConfig config4; 200 net::ProxyConfig config4;
184 config4.proxy_rules().ParseFromString("socks:config4"); 201 config4.proxy_rules().ParseFromString("socks:config4");
185 EXPECT_CALL(observer, 202 EXPECT_CALL(observer,
186 OnProxyConfigChanged(ProxyConfigMatches(config4))).Times(1); 203 OnProxyConfigChanged(ProxyConfigMatches(config4))).Times(1);
187 delegate_service_->SetProxyConfig(config4); 204 delegate_service_->SetProxyConfig(config4);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 false, // is_null 360 false, // is_null
344 false, // auto_detect 361 false, // auto_detect
345 GURL(), // pac_url 362 GURL(), // pac_url
346 net::ProxyRulesExpectation::PerScheme( 363 net::ProxyRulesExpectation::PerScheme(
347 "httpproxy:8888", // http 364 "httpproxy:8888", // http
348 "", // https 365 "", // https
349 "ftpproxy:8889", // ftp 366 "ftpproxy:8889", // ftp
350 "*.google.com,foo.com:99,1.2.3.4:22,127.0.0.1/8"), 367 "*.google.com,foo.com:99,1.2.3.4:22,127.0.0.1/8"),
351 }, 368 },
352 { 369 {
353 "Pac URL with proxy bypass URLs", 370 "Pac URL",
Mattias Nissler (ping if slow) 2010/12/22 10:22:12 I think when reading the code, we came to the conc
battre 2010/12/22 14:41:16 Yes, verified. See TEST(ProxyServiceTest, BypassDo
354 // Input 371 // Input
355 { 372 {
356 { switches::kProxyPacUrl, "http://wpad/wpad.dat" }, 373 { 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 }, 374 },
360 // Expected result 375 // Expected result
361 false, // is_null 376 false, // is_null
362 false, // auto_detect 377 false, // auto_detect
363 GURL("http://wpad/wpad.dat"), // pac_url 378 GURL("http://wpad/wpad.dat"), // pac_url
364 net::ProxyRulesExpectation::EmptyWithBypass( 379 net::ProxyRulesExpectation::Empty(),
365 "*.google.com,foo.com:99,1.2.3.4:22,127.0.0.1/8"),
366 }, 380 },
367 { 381 {
368 "Autodetect", 382 "Autodetect",
369 // Input 383 // Input
370 { 384 {
371 { switches::kProxyAutoDetect, NULL }, 385 { switches::kProxyAutoDetect, NULL },
372 }, 386 },
373 // Expected result 387 // Expected result
374 false, // is_null 388 false, // is_null
375 true, // auto_detect 389 true, // auto_detect
376 GURL(), // pac_url 390 GURL(), // pac_url
377 net::ProxyRulesExpectation::Empty(), 391 net::ProxyRulesExpectation::Empty(),
378 }, 392 },
379 }; 393 };
380 394
381 INSTANTIATE_TEST_CASE_P( 395 INSTANTIATE_TEST_CASE_P(
382 PrefProxyConfigServiceCommandLineTestInstance, 396 PrefProxyConfigServiceCommandLineTestInstance,
383 PrefProxyConfigServiceCommandLineTest, 397 PrefProxyConfigServiceCommandLineTest,
384 testing::ValuesIn(kCommandLineTestParams)); 398 testing::ValuesIn(kCommandLineTestParams));
385 399
386 } // namespace 400 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698