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

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

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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) 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 "chrome/browser/net/pref_proxy_config_tracker_impl.h" 5 #include "chrome/browser/net/pref_proxy_config_tracker_impl.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 "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/net/chrome_url_request_context.h" 10 #include "chrome/browser/net/chrome_url_request_context.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 new TestProxyConfigService(fixed_config_, 85 new TestProxyConfigService(fixed_config_,
86 net::ProxyConfigService::CONFIG_VALID); 86 net::ProxyConfigService::CONFIG_VALID);
87 proxy_config_service_.reset( 87 proxy_config_service_.reset(
88 new ChromeProxyConfigService(delegate_service_, true)); 88 new ChromeProxyConfigService(delegate_service_, true));
89 proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl(pref_service)); 89 proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl(pref_service));
90 proxy_config_tracker_->SetChromeProxyConfigService( 90 proxy_config_tracker_->SetChromeProxyConfigService(
91 proxy_config_service_.get()); 91 proxy_config_service_.get());
92 // SetChromeProxyConfigService triggers update of initial prefs proxy 92 // SetChromeProxyConfigService triggers update of initial prefs proxy
93 // config by tracker to chrome proxy config service, so flush all pending 93 // config by tracker to chrome proxy config service, so flush all pending
94 // tasks so that tests start fresh. 94 // tasks so that tests start fresh.
95 loop_.RunAllPending(); 95 loop_.RunUntilIdle();
96 } 96 }
97 97
98 virtual void TearDown() { 98 virtual void TearDown() {
99 proxy_config_tracker_->DetachFromPrefService(); 99 proxy_config_tracker_->DetachFromPrefService();
100 loop_.RunAllPending(); 100 loop_.RunUntilIdle();
101 proxy_config_tracker_.reset(); 101 proxy_config_tracker_.reset();
102 proxy_config_service_.reset(); 102 proxy_config_service_.reset();
103 } 103 }
104 104
105 MessageLoop loop_; 105 MessageLoop loop_;
106 TestProxyConfigService* delegate_service_; // weak 106 TestProxyConfigService* delegate_service_; // weak
107 scoped_ptr<ChromeProxyConfigService> proxy_config_service_; 107 scoped_ptr<ChromeProxyConfigService> proxy_config_service_;
108 net::ProxyConfig fixed_config_; 108 net::ProxyConfig fixed_config_;
109 109
110 private: 110 private:
(...skipping 17 matching lines...) Expand all
128 net::ProxyConfig actual_config; 128 net::ProxyConfig actual_config;
129 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, 129 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
130 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 130 proxy_config_service_->GetLatestProxyConfig(&actual_config));
131 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); 131 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url());
132 } 132 }
133 133
134 TEST_F(PrefProxyConfigTrackerImplTest, DynamicPrefOverrides) { 134 TEST_F(PrefProxyConfigTrackerImplTest, DynamicPrefOverrides) {
135 pref_service_->SetManagedPref( 135 pref_service_->SetManagedPref(
136 prefs::kProxy, 136 prefs::kProxy,
137 ProxyConfigDictionary::CreateFixedServers("http://example.com:3128", "")); 137 ProxyConfigDictionary::CreateFixedServers("http://example.com:3128", ""));
138 loop_.RunAllPending(); 138 loop_.RunUntilIdle();
139 139
140 net::ProxyConfig actual_config; 140 net::ProxyConfig actual_config;
141 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, 141 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
142 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 142 proxy_config_service_->GetLatestProxyConfig(&actual_config));
143 EXPECT_FALSE(actual_config.auto_detect()); 143 EXPECT_FALSE(actual_config.auto_detect());
144 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 144 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
145 actual_config.proxy_rules().type); 145 actual_config.proxy_rules().type);
146 EXPECT_EQ(actual_config.proxy_rules().single_proxy, 146 EXPECT_EQ(actual_config.proxy_rules().single_proxy,
147 net::ProxyServer::FromURI("http://example.com:3128", 147 net::ProxyServer::FromURI("http://example.com:3128",
148 net::ProxyServer::SCHEME_HTTP)); 148 net::ProxyServer::SCHEME_HTTP));
149 149
150 pref_service_->SetManagedPref(prefs::kProxy, 150 pref_service_->SetManagedPref(prefs::kProxy,
151 ProxyConfigDictionary::CreateAutoDetect()); 151 ProxyConfigDictionary::CreateAutoDetect());
152 loop_.RunAllPending(); 152 loop_.RunUntilIdle();
153 153
154 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, 154 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
155 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 155 proxy_config_service_->GetLatestProxyConfig(&actual_config));
156 EXPECT_TRUE(actual_config.auto_detect()); 156 EXPECT_TRUE(actual_config.auto_detect());
157 } 157 }
158 158
159 // Compares proxy configurations, but allows different identifiers. 159 // Compares proxy configurations, but allows different identifiers.
160 MATCHER_P(ProxyConfigMatches, config, "") { 160 MATCHER_P(ProxyConfigMatches, config, "") {
161 net::ProxyConfig reference(config); 161 net::ProxyConfig reference(config);
162 reference.set_id(arg.id()); 162 reference.set_id(arg.id());
163 return reference.Equals(arg); 163 return reference.Equals(arg);
164 } 164 }
165 165
166 TEST_F(PrefProxyConfigTrackerImplTest, Observers) { 166 TEST_F(PrefProxyConfigTrackerImplTest, Observers) {
167 const net::ProxyConfigService::ConfigAvailability CONFIG_VALID = 167 const net::ProxyConfigService::ConfigAvailability CONFIG_VALID =
168 net::ProxyConfigService::CONFIG_VALID; 168 net::ProxyConfigService::CONFIG_VALID;
169 MockObserver observer; 169 MockObserver observer;
170 proxy_config_service_->AddObserver(&observer); 170 proxy_config_service_->AddObserver(&observer);
171 171
172 // Firing the observers in the delegate should trigger a notification. 172 // Firing the observers in the delegate should trigger a notification.
173 net::ProxyConfig config2; 173 net::ProxyConfig config2;
174 config2.set_auto_detect(true); 174 config2.set_auto_detect(true);
175 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(config2), 175 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(config2),
176 CONFIG_VALID)).Times(1); 176 CONFIG_VALID)).Times(1);
177 delegate_service_->SetProxyConfig(config2, CONFIG_VALID); 177 delegate_service_->SetProxyConfig(config2, CONFIG_VALID);
178 loop_.RunAllPending(); 178 loop_.RunUntilIdle();
179 Mock::VerifyAndClearExpectations(&observer); 179 Mock::VerifyAndClearExpectations(&observer);
180 180
181 // Override configuration, this should trigger a notification. 181 // Override configuration, this should trigger a notification.
182 net::ProxyConfig pref_config; 182 net::ProxyConfig pref_config;
183 pref_config.set_pac_url(GURL(kFixedPacUrl)); 183 pref_config.set_pac_url(GURL(kFixedPacUrl));
184 184
185 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(pref_config), 185 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(pref_config),
186 CONFIG_VALID)).Times(1); 186 CONFIG_VALID)).Times(1);
187 pref_service_->SetManagedPref( 187 pref_service_->SetManagedPref(
188 prefs::kProxy, 188 prefs::kProxy,
189 ProxyConfigDictionary::CreatePacScript(kFixedPacUrl, false)); 189 ProxyConfigDictionary::CreatePacScript(kFixedPacUrl, false));
190 loop_.RunAllPending(); 190 loop_.RunUntilIdle();
191 Mock::VerifyAndClearExpectations(&observer); 191 Mock::VerifyAndClearExpectations(&observer);
192 192
193 // Since there are pref overrides, delegate changes should be ignored. 193 // Since there are pref overrides, delegate changes should be ignored.
194 net::ProxyConfig config3; 194 net::ProxyConfig config3;
195 config3.proxy_rules().ParseFromString("http=config3:80"); 195 config3.proxy_rules().ParseFromString("http=config3:80");
196 EXPECT_CALL(observer, OnProxyConfigChanged(_, _)).Times(0); 196 EXPECT_CALL(observer, OnProxyConfigChanged(_, _)).Times(0);
197 fixed_config_.set_auto_detect(true); 197 fixed_config_.set_auto_detect(true);
198 delegate_service_->SetProxyConfig(config3, CONFIG_VALID); 198 delegate_service_->SetProxyConfig(config3, CONFIG_VALID);
199 loop_.RunAllPending(); 199 loop_.RunUntilIdle();
200 Mock::VerifyAndClearExpectations(&observer); 200 Mock::VerifyAndClearExpectations(&observer);
201 201
202 // Clear the override should switch back to the fixed configuration. 202 // Clear the override should switch back to the fixed configuration.
203 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(config3), 203 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(config3),
204 CONFIG_VALID)).Times(1); 204 CONFIG_VALID)).Times(1);
205 pref_service_->RemoveManagedPref(prefs::kProxy); 205 pref_service_->RemoveManagedPref(prefs::kProxy);
206 loop_.RunAllPending(); 206 loop_.RunUntilIdle();
207 Mock::VerifyAndClearExpectations(&observer); 207 Mock::VerifyAndClearExpectations(&observer);
208 208
209 // Delegate service notifications should show up again. 209 // Delegate service notifications should show up again.
210 net::ProxyConfig config4; 210 net::ProxyConfig config4;
211 config4.proxy_rules().ParseFromString("socks:config4"); 211 config4.proxy_rules().ParseFromString("socks:config4");
212 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(config4), 212 EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(config4),
213 CONFIG_VALID)).Times(1); 213 CONFIG_VALID)).Times(1);
214 delegate_service_->SetProxyConfig(config4, CONFIG_VALID); 214 delegate_service_->SetProxyConfig(config4, CONFIG_VALID);
215 loop_.RunAllPending(); 215 loop_.RunUntilIdle();
216 Mock::VerifyAndClearExpectations(&observer); 216 Mock::VerifyAndClearExpectations(&observer);
217 217
218 proxy_config_service_->RemoveObserver(&observer); 218 proxy_config_service_->RemoveObserver(&observer);
219 } 219 }
220 220
221 TEST_F(PrefProxyConfigTrackerImplTest, Fallback) { 221 TEST_F(PrefProxyConfigTrackerImplTest, Fallback) {
222 const net::ProxyConfigService::ConfigAvailability CONFIG_VALID = 222 const net::ProxyConfigService::ConfigAvailability CONFIG_VALID =
223 net::ProxyConfigService::CONFIG_VALID; 223 net::ProxyConfigService::CONFIG_VALID;
224 MockObserver observer; 224 MockObserver observer;
225 net::ProxyConfig actual_config; 225 net::ProxyConfig actual_config;
226 delegate_service_->SetProxyConfig(net::ProxyConfig::CreateDirect(), 226 delegate_service_->SetProxyConfig(net::ProxyConfig::CreateDirect(),
227 net::ProxyConfigService::CONFIG_UNSET); 227 net::ProxyConfigService::CONFIG_UNSET);
228 proxy_config_service_->AddObserver(&observer); 228 proxy_config_service_->AddObserver(&observer);
229 229
230 // Prepare test data. 230 // Prepare test data.
231 net::ProxyConfig recommended_config = net::ProxyConfig::CreateAutoDetect(); 231 net::ProxyConfig recommended_config = net::ProxyConfig::CreateAutoDetect();
232 net::ProxyConfig user_config = 232 net::ProxyConfig user_config =
233 net::ProxyConfig::CreateFromCustomPacURL(GURL(kFixedPacUrl)); 233 net::ProxyConfig::CreateFromCustomPacURL(GURL(kFixedPacUrl));
234 234
235 // Set a recommended pref. 235 // Set a recommended pref.
236 EXPECT_CALL(observer, 236 EXPECT_CALL(observer,
237 OnProxyConfigChanged(ProxyConfigMatches(recommended_config), 237 OnProxyConfigChanged(ProxyConfigMatches(recommended_config),
238 CONFIG_VALID)).Times(1); 238 CONFIG_VALID)).Times(1);
239 pref_service_->SetRecommendedPref( 239 pref_service_->SetRecommendedPref(
240 prefs::kProxy, 240 prefs::kProxy,
241 ProxyConfigDictionary::CreateAutoDetect()); 241 ProxyConfigDictionary::CreateAutoDetect());
242 loop_.RunAllPending(); 242 loop_.RunUntilIdle();
243 Mock::VerifyAndClearExpectations(&observer); 243 Mock::VerifyAndClearExpectations(&observer);
244 EXPECT_EQ(CONFIG_VALID, 244 EXPECT_EQ(CONFIG_VALID,
245 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 245 proxy_config_service_->GetLatestProxyConfig(&actual_config));
246 EXPECT_TRUE(actual_config.Equals(recommended_config)); 246 EXPECT_TRUE(actual_config.Equals(recommended_config));
247 247
248 // Override in user prefs. 248 // Override in user prefs.
249 EXPECT_CALL(observer, 249 EXPECT_CALL(observer,
250 OnProxyConfigChanged(ProxyConfigMatches(user_config), 250 OnProxyConfigChanged(ProxyConfigMatches(user_config),
251 CONFIG_VALID)).Times(1); 251 CONFIG_VALID)).Times(1);
252 pref_service_->SetManagedPref( 252 pref_service_->SetManagedPref(
253 prefs::kProxy, 253 prefs::kProxy,
254 ProxyConfigDictionary::CreatePacScript(kFixedPacUrl, false)); 254 ProxyConfigDictionary::CreatePacScript(kFixedPacUrl, false));
255 loop_.RunAllPending(); 255 loop_.RunUntilIdle();
256 Mock::VerifyAndClearExpectations(&observer); 256 Mock::VerifyAndClearExpectations(&observer);
257 EXPECT_EQ(CONFIG_VALID, 257 EXPECT_EQ(CONFIG_VALID,
258 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 258 proxy_config_service_->GetLatestProxyConfig(&actual_config));
259 EXPECT_TRUE(actual_config.Equals(user_config)); 259 EXPECT_TRUE(actual_config.Equals(user_config));
260 260
261 // Go back to recommended pref. 261 // Go back to recommended pref.
262 EXPECT_CALL(observer, 262 EXPECT_CALL(observer,
263 OnProxyConfigChanged(ProxyConfigMatches(recommended_config), 263 OnProxyConfigChanged(ProxyConfigMatches(recommended_config),
264 CONFIG_VALID)).Times(1); 264 CONFIG_VALID)).Times(1);
265 pref_service_->RemoveManagedPref(prefs::kProxy); 265 pref_service_->RemoveManagedPref(prefs::kProxy);
266 loop_.RunAllPending(); 266 loop_.RunUntilIdle();
267 Mock::VerifyAndClearExpectations(&observer); 267 Mock::VerifyAndClearExpectations(&observer);
268 EXPECT_EQ(CONFIG_VALID, 268 EXPECT_EQ(CONFIG_VALID,
269 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 269 proxy_config_service_->GetLatestProxyConfig(&actual_config));
270 EXPECT_TRUE(actual_config.Equals(recommended_config)); 270 EXPECT_TRUE(actual_config.Equals(recommended_config));
271 271
272 proxy_config_service_->RemoveObserver(&observer); 272 proxy_config_service_->RemoveObserver(&observer);
273 } 273 }
274 274
275 TEST_F(PrefProxyConfigTrackerImplTest, ExplicitSystemSettings) { 275 TEST_F(PrefProxyConfigTrackerImplTest, ExplicitSystemSettings) {
276 pref_service_->SetRecommendedPref( 276 pref_service_->SetRecommendedPref(
277 prefs::kProxy, 277 prefs::kProxy,
278 ProxyConfigDictionary::CreateAutoDetect()); 278 ProxyConfigDictionary::CreateAutoDetect());
279 pref_service_->SetUserPref( 279 pref_service_->SetUserPref(
280 prefs::kProxy, 280 prefs::kProxy,
281 ProxyConfigDictionary::CreateSystem()); 281 ProxyConfigDictionary::CreateSystem());
282 loop_.RunAllPending(); 282 loop_.RunUntilIdle();
283 283
284 // Test if we actually use the system setting, which is |kFixedPacUrl|. 284 // Test if we actually use the system setting, which is |kFixedPacUrl|.
285 net::ProxyConfig actual_config; 285 net::ProxyConfig actual_config;
286 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, 286 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
287 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 287 proxy_config_service_->GetLatestProxyConfig(&actual_config));
288 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); 288 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url());
289 } 289 }
290 290
291 // Test parameter object for testing command line proxy configuration. 291 // Test parameter object for testing command line proxy configuration.
292 struct CommandLineTestParams { 292 struct CommandLineTestParams {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 net::ProxyRulesExpectation::Empty(), 472 net::ProxyRulesExpectation::Empty(),
473 }, 473 },
474 }; 474 };
475 475
476 INSTANTIATE_TEST_CASE_P( 476 INSTANTIATE_TEST_CASE_P(
477 PrefProxyConfigTrackerImplCommandLineTestInstance, 477 PrefProxyConfigTrackerImplCommandLineTestInstance,
478 PrefProxyConfigTrackerImplCommandLineTest, 478 PrefProxyConfigTrackerImplCommandLineTest,
479 testing::ValuesIn(kCommandLineTestParams)); 479 testing::ValuesIn(kCommandLineTestParams));
480 480
481 } // namespace 481 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor_unittest.cc ('k') | chrome/browser/net/ssl_config_service_manager_pref_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698