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

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

Issue 5701003: Intorduce a separate preference for 'proxy server mode' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " 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"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { 108 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) {
109 net::ProxyConfig actual_config; 109 net::ProxyConfig actual_config;
110 proxy_config_service_->GetLatestProxyConfig(&actual_config); 110 proxy_config_service_->GetLatestProxyConfig(&actual_config);
111 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); 111 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url());
112 } 112 }
113 113
114 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { 114 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) {
115 pref_service_->SetManagedPref( 115 pref_service_->SetManagedPref(
116 prefs::kProxyServer, Value::CreateStringValue("http://example.com:3128")); 116 prefs::kProxyServer, Value::CreateStringValue("http://example.com:3128"));
117 pref_service_->SetManagedPref(
118 prefs::kProxyServerMode,
119 Value::CreateIntegerValue(PrefProxyConfigService::MANUAL));
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::kProxyServerMode,
133 Value::CreateIntegerValue(PrefProxyConfigService::AUTO_DETECT));
130 loop_.RunAllPending(); 134 loop_.RunAllPending();
131 135
132 proxy_config_service_->GetLatestProxyConfig(&actual_config); 136 proxy_config_service_->GetLatestProxyConfig(&actual_config);
133 EXPECT_TRUE(actual_config.auto_detect()); 137 EXPECT_TRUE(actual_config.auto_detect());
134 } 138 }
135 139
136 // Compares proxy configurations, but allows different identifiers. 140 // Compares proxy configurations, but allows different identifiers.
137 MATCHER_P(ProxyConfigMatches, config, "") { 141 MATCHER_P(ProxyConfigMatches, config, "") {
138 net::ProxyConfig reference(config); 142 net::ProxyConfig reference(config);
139 reference.set_id(arg.id()); 143 reference.set_id(arg.id());
140 return reference.Equals(arg); 144 return reference.Equals(arg);
141 } 145 }
142 146
143 TEST_F(PrefProxyConfigServiceTest, Observers) { 147 // TODO(battre): Enable this test when http://crbug.com/65732 is fixed. (Move
148 // proxy preferences into a dictionary.) The problem is that currently the
149 // observer gets fired twice, because two preferences are set.
150 TEST_F(PrefProxyConfigServiceTest, DISABLED_Observers) {
144 MockObserver observer; 151 MockObserver observer;
145 proxy_config_service_->AddObserver(&observer); 152 proxy_config_service_->AddObserver(&observer);
146 153
147 // Firing the observers in the delegate should trigger a notification. 154 // Firing the observers in the delegate should trigger a notification.
148 net::ProxyConfig config2; 155 net::ProxyConfig config2;
149 config2.set_auto_detect(true); 156 config2.set_auto_detect(true);
150 EXPECT_CALL(observer, 157 EXPECT_CALL(observer,
151 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1); 158 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1);
152 delegate_service_->SetProxyConfig(config2); 159 delegate_service_->SetProxyConfig(config2);
153 loop_.RunAllPending(); 160 loop_.RunAllPending();
154 Mock::VerifyAndClearExpectations(&observer); 161 Mock::VerifyAndClearExpectations(&observer);
155 162
156 // Override configuration, this should trigger a notification. 163 // Override configuration, this should trigger a notification.
157 net::ProxyConfig pref_config; 164 net::ProxyConfig pref_config;
158 pref_config.set_pac_url(GURL(kFixedPacUrl)); 165 pref_config.set_pac_url(GURL(kFixedPacUrl));
159 EXPECT_CALL(observer, 166 EXPECT_CALL(observer,
160 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); 167 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1);
161 pref_service_->SetManagedPref(prefs::kProxyPacUrl, 168 pref_service_->SetManagedPref(prefs::kProxyPacUrl,
162 Value::CreateStringValue(kFixedPacUrl)); 169 Value::CreateStringValue(kFixedPacUrl));
170 pref_service_->SetManagedPref(
171 prefs::kProxyServerMode,
172 Value::CreateIntegerValue(PrefProxyConfigService::MANUAL));
163 loop_.RunAllPending(); 173 loop_.RunAllPending();
164 Mock::VerifyAndClearExpectations(&observer); 174 Mock::VerifyAndClearExpectations(&observer);
165 175
166 // Since there are pref overrides, delegate changes should be ignored. 176 // Since there are pref overrides, delegate changes should be ignored.
167 net::ProxyConfig config3; 177 net::ProxyConfig config3;
168 config3.proxy_rules().ParseFromString("http=config3:80"); 178 config3.proxy_rules().ParseFromString("http=config3:80");
169 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); 179 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0);
170 fixed_config_.set_auto_detect(true); 180 fixed_config_.set_auto_detect(true);
171 delegate_service_->SetProxyConfig(config3); 181 delegate_service_->SetProxyConfig(config3);
172 loop_.RunAllPending(); 182 loop_.RunAllPending();
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 net::ProxyRulesExpectation::Empty(), 387 net::ProxyRulesExpectation::Empty(),
378 }, 388 },
379 }; 389 };
380 390
381 INSTANTIATE_TEST_CASE_P( 391 INSTANTIATE_TEST_CASE_P(
382 PrefProxyConfigServiceCommandLineTestInstance, 392 PrefProxyConfigServiceCommandLineTestInstance,
383 PrefProxyConfigServiceCommandLineTest, 393 PrefProxyConfigServiceCommandLineTest,
384 testing::ValuesIn(kCommandLineTestParams)); 394 testing::ValuesIn(kCommandLineTestParams));
385 395
386 } // namespace 396 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698