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 "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" |
11 #include "chrome/browser/prefs/pref_registry_simple.h" | |
11 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 12 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
12 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 13 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/testing_pref_service.h" | 16 #include "chrome/test/base/testing_pref_service.h" |
16 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
17 #include "net/proxy/proxy_config_service_common_unittest.h" | 18 #include "net/proxy/proxy_config_service_common_unittest.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 net::ProxyConfigService::ConfigAvailability)); | 71 net::ProxyConfigService::ConfigAvailability)); |
71 }; | 72 }; |
72 | 73 |
73 template<typename TESTBASE> | 74 template<typename TESTBASE> |
74 class PrefProxyConfigTrackerImplTestBase : public TESTBASE { | 75 class PrefProxyConfigTrackerImplTestBase : public TESTBASE { |
75 protected: | 76 protected: |
76 PrefProxyConfigTrackerImplTestBase() | 77 PrefProxyConfigTrackerImplTestBase() |
77 : ui_thread_(BrowserThread::UI, &loop_), | 78 : ui_thread_(BrowserThread::UI, &loop_), |
78 io_thread_(BrowserThread::IO, &loop_) {} | 79 io_thread_(BrowserThread::IO, &loop_) {} |
79 | 80 |
80 virtual void Init(PrefServiceSimple* pref_service) { | 81 virtual void Init(PrefService* pref_service, PrefRegistrySimple* registry) { |
81 ASSERT_TRUE(pref_service); | 82 ASSERT_TRUE(pref_service); |
82 PrefProxyConfigTrackerImpl::RegisterPrefs(pref_service); | 83 PrefProxyConfigTrackerImpl::RegisterPrefs(registry); |
83 fixed_config_.set_pac_url(GURL(kFixedPacUrl)); | 84 fixed_config_.set_pac_url(GURL(kFixedPacUrl)); |
84 delegate_service_ = | 85 delegate_service_ = |
85 new TestProxyConfigService(fixed_config_, | 86 new TestProxyConfigService(fixed_config_, |
86 net::ProxyConfigService::CONFIG_VALID); | 87 net::ProxyConfigService::CONFIG_VALID); |
87 proxy_config_service_.reset( | 88 proxy_config_service_.reset( |
88 new ChromeProxyConfigService(delegate_service_)); | 89 new ChromeProxyConfigService(delegate_service_)); |
89 proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl(pref_service)); | 90 proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl(pref_service)); |
90 proxy_config_tracker_->SetChromeProxyConfigService( | 91 proxy_config_tracker_->SetChromeProxyConfigService( |
91 proxy_config_service_.get()); | 92 proxy_config_service_.get()); |
92 // SetChromeProxyConfigService triggers update of initial prefs proxy | 93 // SetChromeProxyConfigService triggers update of initial prefs proxy |
(...skipping 18 matching lines...) Expand all Loading... | |
111 scoped_ptr<PrefProxyConfigTrackerImpl> proxy_config_tracker_; | 112 scoped_ptr<PrefProxyConfigTrackerImpl> proxy_config_tracker_; |
112 content::TestBrowserThread ui_thread_; | 113 content::TestBrowserThread ui_thread_; |
113 content::TestBrowserThread io_thread_; | 114 content::TestBrowserThread io_thread_; |
114 }; | 115 }; |
115 | 116 |
116 class PrefProxyConfigTrackerImplTest | 117 class PrefProxyConfigTrackerImplTest |
117 : public PrefProxyConfigTrackerImplTestBase<testing::Test> { | 118 : public PrefProxyConfigTrackerImplTestBase<testing::Test> { |
118 protected: | 119 protected: |
119 virtual void SetUp() { | 120 virtual void SetUp() { |
120 pref_service_.reset(new TestingPrefServiceSimple()); | 121 pref_service_.reset(new TestingPrefServiceSimple()); |
121 Init(pref_service_.get()); | 122 Init(pref_service_.get(), pref_service_->registry()); |
122 } | 123 } |
123 | 124 |
124 scoped_ptr<TestingPrefServiceSimple> pref_service_; | 125 scoped_ptr<TestingPrefServiceSimple> pref_service_; |
125 }; | 126 }; |
126 | 127 |
127 TEST_F(PrefProxyConfigTrackerImplTest, BaseConfiguration) { | 128 TEST_F(PrefProxyConfigTrackerImplTest, BaseConfiguration) { |
128 net::ProxyConfig actual_config; | 129 net::ProxyConfig actual_config; |
129 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, | 130 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, |
130 proxy_config_service_->GetLatestProxyConfig(&actual_config)); | 131 proxy_config_service_->GetLatestProxyConfig(&actual_config)); |
131 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); | 132 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 for (size_t i = 0; i < arraysize(GetParam().switches); i++) { | 334 for (size_t i = 0; i < arraysize(GetParam().switches); i++) { |
334 const char* name = GetParam().switches[i].name; | 335 const char* name = GetParam().switches[i].name; |
335 const char* value = GetParam().switches[i].value; | 336 const char* value = GetParam().switches[i].value; |
336 if (name && value) | 337 if (name && value) |
337 command_line_.AppendSwitchASCII(name, value); | 338 command_line_.AppendSwitchASCII(name, value); |
338 else if (name) | 339 else if (name) |
339 command_line_.AppendSwitch(name); | 340 command_line_.AppendSwitch(name); |
340 } | 341 } |
341 pref_service_.reset( | 342 pref_service_.reset( |
342 PrefServiceMockBuilder().WithCommandLine( | 343 PrefServiceMockBuilder().WithCommandLine( |
343 &command_line_).CreateSimple()); | 344 &command_line_).Create(new PrefRegistrySimple)); |
Mattias Nissler (ping if slow)
2013/01/31 16:30:54
In this case, I'd rather create a PrefRegistrySimp
Jói
2013/01/31 17:29:32
Done.
| |
344 Init(pref_service_.get()); | 345 Init(pref_service_.get(), |
346 static_cast<PrefRegistrySimple*>( | |
347 pref_service_->DeprecatedGetPrefRegistry())); | |
345 } | 348 } |
346 | 349 |
347 private: | 350 private: |
348 CommandLine command_line_; | 351 CommandLine command_line_; |
349 scoped_ptr<PrefServiceSimple> pref_service_; | 352 scoped_ptr<PrefService> pref_service_; |
350 }; | 353 }; |
351 | 354 |
352 TEST_P(PrefProxyConfigTrackerImplCommandLineTest, CommandLine) { | 355 TEST_P(PrefProxyConfigTrackerImplCommandLineTest, CommandLine) { |
353 net::ProxyConfig config; | 356 net::ProxyConfig config; |
354 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, | 357 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, |
355 proxy_config_service_->GetLatestProxyConfig(&config)); | 358 proxy_config_service_->GetLatestProxyConfig(&config)); |
356 | 359 |
357 if (GetParam().is_null) { | 360 if (GetParam().is_null) { |
358 EXPECT_EQ(GURL(kFixedPacUrl), config.pac_url()); | 361 EXPECT_EQ(GURL(kFixedPacUrl), config.pac_url()); |
359 } else { | 362 } else { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 net::ProxyRulesExpectation::Empty(), | 476 net::ProxyRulesExpectation::Empty(), |
474 }, | 477 }, |
475 }; | 478 }; |
476 | 479 |
477 INSTANTIATE_TEST_CASE_P( | 480 INSTANTIATE_TEST_CASE_P( |
478 PrefProxyConfigTrackerImplCommandLineTestInstance, | 481 PrefProxyConfigTrackerImplCommandLineTestInstance, |
479 PrefProxyConfigTrackerImplCommandLineTest, | 482 PrefProxyConfigTrackerImplCommandLineTest, |
480 testing::ValuesIn(kCommandLineTestParams)); | 483 testing::ValuesIn(kCommandLineTestParams)); |
481 | 484 |
482 } // namespace | 485 } // namespace |
OLD | NEW |