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