OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/proxy_config_service_impl.h" | 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "chrome/browser/chromeos/net/proxy_config_handler.h" | 18 #include "chrome/browser/chromeos/net/proxy_config_handler.h" |
18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
19 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 20 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
20 #include "chrome/browser/chromeos/ui_proxy_config.h" | 21 #include "chrome/browser/chromeos/ui_proxy_config.h" |
21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
22 #include "chromeos/dbus/dbus_thread_manager.h" | 23 #include "chromeos/dbus/dbus_thread_manager.h" |
23 #include "chromeos/dbus/shill_profile_client.h" | 24 #include "chromeos/dbus/shill_profile_client.h" |
24 #include "chromeos/dbus/shill_service_client.h" | 25 #include "chromeos/dbus/shill_service_client.h" |
25 #include "chromeos/network/network_handler.h" | 26 #include "chromeos/network/network_handler.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 void SetUpProxyConfigService(PrefService* profile_prefs) { | 248 void SetUpProxyConfigService(PrefService* profile_prefs) { |
248 config_service_impl_.reset( | 249 config_service_impl_.reset( |
249 new ProxyConfigServiceImpl(profile_prefs, &pref_service_)); | 250 new ProxyConfigServiceImpl(profile_prefs, &pref_service_)); |
250 proxy_config_service_ = | 251 proxy_config_service_ = |
251 config_service_impl_->CreateTrackingProxyConfigService( | 252 config_service_impl_->CreateTrackingProxyConfigService( |
252 std::unique_ptr<net::ProxyConfigService>()); | 253 std::unique_ptr<net::ProxyConfigService>()); |
253 | 254 |
254 // CreateTrackingProxyConfigService triggers update of initial prefs proxy | 255 // CreateTrackingProxyConfigService triggers update of initial prefs proxy |
255 // config by tracker to chrome proxy config service, so flush all pending | 256 // config by tracker to chrome proxy config service, so flush all pending |
256 // tasks so that tests start fresh. | 257 // tasks so that tests start fresh. |
257 loop_.RunUntilIdle(); | 258 base::RunLoop().RunUntilIdle(); |
258 } | 259 } |
259 | 260 |
260 void SetUpPrivateWiFi() { | 261 void SetUpPrivateWiFi() { |
261 ShillProfileClient::TestInterface* profile_test = | 262 ShillProfileClient::TestInterface* profile_test = |
262 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 263 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
263 ShillServiceClient::TestInterface* service_test = | 264 ShillServiceClient::TestInterface* service_test = |
264 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 265 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
265 | 266 |
266 // Process any pending notifications before clearing services. | 267 // Process any pending notifications before clearing services. |
267 loop_.RunUntilIdle(); | 268 base::RunLoop().RunUntilIdle(); |
268 service_test->ClearServices(); | 269 service_test->ClearServices(); |
269 | 270 |
270 // Sends a notification about the added profile. | 271 // Sends a notification about the added profile. |
271 profile_test->AddProfile(kUserProfilePath, "user_hash"); | 272 profile_test->AddProfile(kUserProfilePath, "user_hash"); |
272 | 273 |
273 service_test->AddService("/service/stub_wifi2", | 274 service_test->AddService("/service/stub_wifi2", |
274 "stub_wifi2" /* guid */, | 275 "stub_wifi2" /* guid */, |
275 "wifi2_PSK", | 276 "wifi2_PSK", |
276 shill::kTypeWifi, shill::kStateOnline, | 277 shill::kTypeWifi, shill::kStateOnline, |
277 true /* visible */); | 278 true /* visible */); |
278 profile_test->AddService(kUserProfilePath, "/service/stub_wifi2"); | 279 profile_test->AddService(kUserProfilePath, "/service/stub_wifi2"); |
279 | 280 |
280 loop_.RunUntilIdle(); | 281 base::RunLoop().RunUntilIdle(); |
281 } | 282 } |
282 | 283 |
283 void SetUpSharedEthernet() { | 284 void SetUpSharedEthernet() { |
284 ShillProfileClient::TestInterface* profile_test = | 285 ShillProfileClient::TestInterface* profile_test = |
285 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 286 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
286 ShillServiceClient::TestInterface* service_test = | 287 ShillServiceClient::TestInterface* service_test = |
287 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 288 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
288 | 289 |
289 // Process any pending notifications before clearing services. | 290 // Process any pending notifications before clearing services. |
290 loop_.RunUntilIdle(); | 291 base::RunLoop().RunUntilIdle(); |
291 service_test->ClearServices(); | 292 service_test->ClearServices(); |
292 | 293 |
293 // Sends a notification about the added profile. | 294 // Sends a notification about the added profile. |
294 profile_test->AddProfile(kUserProfilePath, "user_hash"); | 295 profile_test->AddProfile(kUserProfilePath, "user_hash"); |
295 | 296 |
296 service_test->AddService("/service/ethernet", "stub_ethernet" /* guid */, | 297 service_test->AddService("/service/ethernet", "stub_ethernet" /* guid */, |
297 "eth0", shill::kTypeEthernet, shill::kStateOnline, | 298 "eth0", shill::kTypeEthernet, shill::kStateOnline, |
298 true /* visible */); | 299 true /* visible */); |
299 profile_test->AddService(NetworkProfileHandler::GetSharedProfilePath(), | 300 profile_test->AddService(NetworkProfileHandler::GetSharedProfilePath(), |
300 "/service/ethernet"); | 301 "/service/ethernet"); |
301 | 302 |
302 loop_.RunUntilIdle(); | 303 base::RunLoop().RunUntilIdle(); |
303 } | 304 } |
304 | 305 |
305 void TearDown() override { | 306 void TearDown() override { |
306 config_service_impl_->DetachFromPrefService(); | 307 config_service_impl_->DetachFromPrefService(); |
307 loop_.RunUntilIdle(); | 308 base::RunLoop().RunUntilIdle(); |
308 config_service_impl_.reset(); | 309 config_service_impl_.reset(); |
309 proxy_config_service_.reset(); | 310 proxy_config_service_.reset(); |
310 NetworkHandler::Shutdown(); | 311 NetworkHandler::Shutdown(); |
311 DBusThreadManager::Shutdown(); | 312 DBusThreadManager::Shutdown(); |
312 } | 313 } |
313 | 314 |
314 void InitConfigWithTestInput(const Input& input, | 315 void InitConfigWithTestInput(const Input& input, |
315 base::DictionaryValue* result) { | 316 base::DictionaryValue* result) { |
316 std::unique_ptr<base::DictionaryValue> new_config; | 317 std::unique_ptr<base::DictionaryValue> new_config; |
317 switch (input.mode) { | 318 switch (input.mode) { |
(...skipping 30 matching lines...) Expand all Loading... |
348 shill::kProxyConfigProperty, | 349 shill::kProxyConfigProperty, |
349 base::StringValue(proxy_config)); | 350 base::StringValue(proxy_config)); |
350 } | 351 } |
351 | 352 |
352 // Synchronously gets the latest proxy config. | 353 // Synchronously gets the latest proxy config. |
353 void SyncGetLatestProxyConfig(net::ProxyConfig* config) { | 354 void SyncGetLatestProxyConfig(net::ProxyConfig* config) { |
354 *config = net::ProxyConfig(); | 355 *config = net::ProxyConfig(); |
355 // Let message loop process all messages. This will run | 356 // Let message loop process all messages. This will run |
356 // ChromeProxyConfigService::UpdateProxyConfig, which is posted on IO from | 357 // ChromeProxyConfigService::UpdateProxyConfig, which is posted on IO from |
357 // PrefProxyConfigTrackerImpl::OnProxyConfigChanged. | 358 // PrefProxyConfigTrackerImpl::OnProxyConfigChanged. |
358 loop_.RunUntilIdle(); | 359 base::RunLoop().RunUntilIdle(); |
359 net::ProxyConfigService::ConfigAvailability availability = | 360 net::ProxyConfigService::ConfigAvailability availability = |
360 proxy_config_service_->GetLatestProxyConfig(config); | 361 proxy_config_service_->GetLatestProxyConfig(config); |
361 | 362 |
362 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, availability); | 363 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, availability); |
363 } | 364 } |
364 | 365 |
365 base::MessageLoop loop_; | 366 base::MessageLoop loop_; |
366 std::unique_ptr<net::ProxyConfigService> proxy_config_service_; | 367 std::unique_ptr<net::ProxyConfigService> proxy_config_service_; |
367 std::unique_ptr<ProxyConfigServiceImpl> config_service_impl_; | 368 std::unique_ptr<ProxyConfigServiceImpl> config_service_impl_; |
368 TestingPrefServiceSimple pref_service_; | 369 TestingPrefServiceSimple pref_service_; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 network_configs.release()); | 521 network_configs.release()); |
521 | 522 |
522 net::ProxyConfig actual_config; | 523 net::ProxyConfig actual_config; |
523 SyncGetLatestProxyConfig(&actual_config); | 524 SyncGetLatestProxyConfig(&actual_config); |
524 net::ProxyConfig expected_config = | 525 net::ProxyConfig expected_config = |
525 net::ProxyConfig::CreateFromCustomPacURL(GURL("http://domain.com/x")); | 526 net::ProxyConfig::CreateFromCustomPacURL(GURL("http://domain.com/x")); |
526 EXPECT_TRUE(expected_config.Equals(actual_config)); | 527 EXPECT_TRUE(expected_config.Equals(actual_config)); |
527 } | 528 } |
528 | 529 |
529 } // namespace chromeos | 530 } // namespace chromeos |
OLD | NEW |