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

Side by Side Diff: components/proxy_config/pref_proxy_config_tracker_impl_unittest.cc

Issue 2785883003: Use unique_ptr<DictionaryValue> in ProxyConfigDictionary (Closed)
Patch Set: one constructor Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "components/proxy_config/pref_proxy_config_tracker_impl.h" 5 #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 12 #include "base/run_loop.h"
14 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
15 #include "components/prefs/pref_registry_simple.h" 14 #include "components/prefs/pref_registry_simple.h"
16 #include "components/prefs/testing_pref_service.h" 15 #include "components/prefs/testing_pref_service.h"
17 #include "components/proxy_config/proxy_config_dictionary.h" 16 #include "components/proxy_config/proxy_config_dictionary.h"
18 #include "components/proxy_config/proxy_config_pref_names.h" 17 #include "components/proxy_config/proxy_config_pref_names.h"
19 #include "net/proxy/proxy_info.h" 18 #include "net/proxy/proxy_info.h"
20 #include "net/proxy/proxy_list.h" 19 #include "net/proxy/proxy_list.h"
21 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 }; 110 };
112 111
113 TEST_F(PrefProxyConfigTrackerImplTest, BaseConfiguration) { 112 TEST_F(PrefProxyConfigTrackerImplTest, BaseConfiguration) {
114 net::ProxyConfig actual_config; 113 net::ProxyConfig actual_config;
115 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, 114 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
116 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 115 proxy_config_service_->GetLatestProxyConfig(&actual_config));
117 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); 116 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url());
118 } 117 }
119 118
120 TEST_F(PrefProxyConfigTrackerImplTest, DynamicPrefOverrides) { 119 TEST_F(PrefProxyConfigTrackerImplTest, DynamicPrefOverrides) {
121 pref_service_->SetManagedPref( 120 pref_service_->SetManagedPref(proxy_config::prefs::kProxy,
122 proxy_config::prefs::kProxy, 121 ProxyConfigDictionary::CreateFixedServers(
123 base::WrapUnique(ProxyConfigDictionary::CreateFixedServers( 122 "http://example.com:3128", std::string()));
124 "http://example.com:3128", std::string())));
125 base::RunLoop().RunUntilIdle(); 123 base::RunLoop().RunUntilIdle();
126 124
127 net::ProxyConfig actual_config; 125 net::ProxyConfig actual_config;
128 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, 126 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
129 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 127 proxy_config_service_->GetLatestProxyConfig(&actual_config));
130 EXPECT_FALSE(actual_config.auto_detect()); 128 EXPECT_FALSE(actual_config.auto_detect());
131 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 129 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
132 actual_config.proxy_rules().type); 130 actual_config.proxy_rules().type);
133 EXPECT_EQ(actual_config.proxy_rules().single_proxies.Get(), 131 EXPECT_EQ(actual_config.proxy_rules().single_proxies.Get(),
134 net::ProxyServer::FromURI("http://example.com:3128", 132 net::ProxyServer::FromURI("http://example.com:3128",
135 net::ProxyServer::SCHEME_HTTP)); 133 net::ProxyServer::SCHEME_HTTP));
136 134
137 pref_service_->SetManagedPref( 135 pref_service_->SetManagedPref(proxy_config::prefs::kProxy,
138 proxy_config::prefs::kProxy, 136 ProxyConfigDictionary::CreateAutoDetect());
139 base::WrapUnique(ProxyConfigDictionary::CreateAutoDetect()));
140 base::RunLoop().RunUntilIdle(); 137 base::RunLoop().RunUntilIdle();
141 138
142 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, 139 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
143 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 140 proxy_config_service_->GetLatestProxyConfig(&actual_config));
144 EXPECT_TRUE(actual_config.auto_detect()); 141 EXPECT_TRUE(actual_config.auto_detect());
145 } 142 }
146 143
147 // Compares proxy configurations, but allows different identifiers. 144 // Compares proxy configurations, but allows different identifiers.
148 MATCHER_P(ProxyConfigMatches, config, "") { 145 MATCHER_P(ProxyConfigMatches, config, "") {
149 net::ProxyConfig reference(config); 146 net::ProxyConfig reference(config);
(...skipping 17 matching lines...) Expand all
167 Mock::VerifyAndClearExpectations(&observer); 164 Mock::VerifyAndClearExpectations(&observer);
168 165
169 // Override configuration, this should trigger a notification. 166 // Override configuration, this should trigger a notification.
170 net::ProxyConfig pref_config; 167 net::ProxyConfig pref_config;
171 pref_config.set_pac_url(GURL(kFixedPacUrl)); 168 pref_config.set_pac_url(GURL(kFixedPacUrl));
172 169
173 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(pref_config), 170 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(pref_config),
174 CONFIG_VALID)).Times(1); 171 CONFIG_VALID)).Times(1);
175 pref_service_->SetManagedPref( 172 pref_service_->SetManagedPref(
176 proxy_config::prefs::kProxy, 173 proxy_config::prefs::kProxy,
177 base::WrapUnique( 174 ProxyConfigDictionary::CreatePacScript(kFixedPacUrl, false));
178 ProxyConfigDictionary::CreatePacScript(kFixedPacUrl, false)));
179 base::RunLoop().RunUntilIdle(); 175 base::RunLoop().RunUntilIdle();
180 Mock::VerifyAndClearExpectations(&observer); 176 Mock::VerifyAndClearExpectations(&observer);
181 177
182 // Since there are pref overrides, delegate changes should be ignored. 178 // Since there are pref overrides, delegate changes should be ignored.
183 net::ProxyConfig config3; 179 net::ProxyConfig config3;
184 config3.proxy_rules().ParseFromString("http=config3:80"); 180 config3.proxy_rules().ParseFromString("http=config3:80");
185 EXPECT_CALL(observer, OnProxyConfigChanged(_, _)).Times(0); 181 EXPECT_CALL(observer, OnProxyConfigChanged(_, _)).Times(0);
186 fixed_config_.set_auto_detect(true); 182 fixed_config_.set_auto_detect(true);
187 delegate_service_->SetProxyConfig(config3, CONFIG_VALID); 183 delegate_service_->SetProxyConfig(config3, CONFIG_VALID);
188 base::RunLoop().RunUntilIdle(); 184 base::RunLoop().RunUntilIdle();
(...skipping 29 matching lines...) Expand all
218 214
219 // Prepare test data. 215 // Prepare test data.
220 net::ProxyConfig recommended_config = net::ProxyConfig::CreateAutoDetect(); 216 net::ProxyConfig recommended_config = net::ProxyConfig::CreateAutoDetect();
221 net::ProxyConfig user_config = 217 net::ProxyConfig user_config =
222 net::ProxyConfig::CreateFromCustomPacURL(GURL(kFixedPacUrl)); 218 net::ProxyConfig::CreateFromCustomPacURL(GURL(kFixedPacUrl));
223 219
224 // Set a recommended pref. 220 // Set a recommended pref.
225 EXPECT_CALL(observer, 221 EXPECT_CALL(observer,
226 OnProxyConfigChanged(ProxyConfigMatches(recommended_config), 222 OnProxyConfigChanged(ProxyConfigMatches(recommended_config),
227 CONFIG_VALID)).Times(1); 223 CONFIG_VALID)).Times(1);
228 pref_service_->SetRecommendedPref( 224 pref_service_->SetRecommendedPref(proxy_config::prefs::kProxy,
229 proxy_config::prefs::kProxy, 225 ProxyConfigDictionary::CreateAutoDetect());
230 base::WrapUnique(ProxyConfigDictionary::CreateAutoDetect()));
231 base::RunLoop().RunUntilIdle(); 226 base::RunLoop().RunUntilIdle();
232 Mock::VerifyAndClearExpectations(&observer); 227 Mock::VerifyAndClearExpectations(&observer);
233 EXPECT_EQ(CONFIG_VALID, 228 EXPECT_EQ(CONFIG_VALID,
234 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 229 proxy_config_service_->GetLatestProxyConfig(&actual_config));
235 EXPECT_TRUE(actual_config.Equals(recommended_config)); 230 EXPECT_TRUE(actual_config.Equals(recommended_config));
236 231
237 // Override in user prefs. 232 // Override in user prefs.
238 EXPECT_CALL(observer, 233 EXPECT_CALL(observer,
239 OnProxyConfigChanged(ProxyConfigMatches(user_config), 234 OnProxyConfigChanged(ProxyConfigMatches(user_config),
240 CONFIG_VALID)).Times(1); 235 CONFIG_VALID)).Times(1);
241 pref_service_->SetManagedPref( 236 pref_service_->SetManagedPref(
242 proxy_config::prefs::kProxy, 237 proxy_config::prefs::kProxy,
243 base::WrapUnique( 238 ProxyConfigDictionary::CreatePacScript(kFixedPacUrl, false));
244 ProxyConfigDictionary::CreatePacScript(kFixedPacUrl, false)));
245 base::RunLoop().RunUntilIdle(); 239 base::RunLoop().RunUntilIdle();
246 Mock::VerifyAndClearExpectations(&observer); 240 Mock::VerifyAndClearExpectations(&observer);
247 EXPECT_EQ(CONFIG_VALID, 241 EXPECT_EQ(CONFIG_VALID,
248 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 242 proxy_config_service_->GetLatestProxyConfig(&actual_config));
249 EXPECT_TRUE(actual_config.Equals(user_config)); 243 EXPECT_TRUE(actual_config.Equals(user_config));
250 244
251 // Go back to recommended pref. 245 // Go back to recommended pref.
252 EXPECT_CALL(observer, 246 EXPECT_CALL(observer,
253 OnProxyConfigChanged(ProxyConfigMatches(recommended_config), 247 OnProxyConfigChanged(ProxyConfigMatches(recommended_config),
254 CONFIG_VALID)).Times(1); 248 CONFIG_VALID)).Times(1);
255 pref_service_->RemoveManagedPref(proxy_config::prefs::kProxy); 249 pref_service_->RemoveManagedPref(proxy_config::prefs::kProxy);
256 base::RunLoop().RunUntilIdle(); 250 base::RunLoop().RunUntilIdle();
257 Mock::VerifyAndClearExpectations(&observer); 251 Mock::VerifyAndClearExpectations(&observer);
258 EXPECT_EQ(CONFIG_VALID, 252 EXPECT_EQ(CONFIG_VALID,
259 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 253 proxy_config_service_->GetLatestProxyConfig(&actual_config));
260 EXPECT_TRUE(actual_config.Equals(recommended_config)); 254 EXPECT_TRUE(actual_config.Equals(recommended_config));
261 255
262 proxy_config_service_->RemoveObserver(&observer); 256 proxy_config_service_->RemoveObserver(&observer);
263 } 257 }
264 258
265 TEST_F(PrefProxyConfigTrackerImplTest, ExplicitSystemSettings) { 259 TEST_F(PrefProxyConfigTrackerImplTest, ExplicitSystemSettings) {
266 pref_service_->SetRecommendedPref( 260 pref_service_->SetRecommendedPref(proxy_config::prefs::kProxy,
267 proxy_config::prefs::kProxy, 261 ProxyConfigDictionary::CreateAutoDetect());
268 base::WrapUnique(ProxyConfigDictionary::CreateAutoDetect())); 262 pref_service_->SetUserPref(proxy_config::prefs::kProxy,
269 pref_service_->SetUserPref( 263 ProxyConfigDictionary::CreateSystem());
270 proxy_config::prefs::kProxy,
271 base::WrapUnique(ProxyConfigDictionary::CreateSystem()));
272 base::RunLoop().RunUntilIdle(); 264 base::RunLoop().RunUntilIdle();
273 265
274 // Test if we actually use the system setting, which is |kFixedPacUrl|. 266 // Test if we actually use the system setting, which is |kFixedPacUrl|.
275 net::ProxyConfig actual_config; 267 net::ProxyConfig actual_config;
276 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, 268 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
277 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 269 proxy_config_service_->GetLatestProxyConfig(&actual_config));
278 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); 270 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url());
279 } 271 }
280 272
281 } // namespace 273 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698