OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_service.h" | 5 #include "chrome/browser/net/pref_proxy_config_service.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 "chrome/browser/prefs/command_line_pref_store.h" | |
10 #include "chrome/browser/prefs/testing_pref_store.h" | |
9 #include "chrome/browser/net/chrome_url_request_context.h" | 11 #include "chrome/browser/net/chrome_url_request_context.h" |
10 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
12 #include "chrome/test/testing_pref_service.h" | 14 #include "chrome/test/testing_pref_service.h" |
13 #include "net/proxy/proxy_config_service_common_unittest.h" | 15 #include "net/proxy/proxy_config_service_common_unittest.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 | 18 |
17 using testing::_; | 19 using testing::_; |
18 using testing::Mock; | 20 using testing::Mock; |
(...skipping 39 matching lines...) Loading... | |
58 MOCK_METHOD1(OnProxyConfigChanged, void(const net::ProxyConfig&)); | 60 MOCK_METHOD1(OnProxyConfigChanged, void(const net::ProxyConfig&)); |
59 }; | 61 }; |
60 | 62 |
61 template<typename TESTBASE> | 63 template<typename TESTBASE> |
62 class PrefProxyConfigServiceTestBase : public TESTBASE { | 64 class PrefProxyConfigServiceTestBase : public TESTBASE { |
63 protected: | 65 protected: |
64 PrefProxyConfigServiceTestBase() | 66 PrefProxyConfigServiceTestBase() |
65 : ui_thread_(BrowserThread::UI, &loop_), | 67 : ui_thread_(BrowserThread::UI, &loop_), |
66 io_thread_(BrowserThread::IO, &loop_) {} | 68 io_thread_(BrowserThread::IO, &loop_) {} |
67 | 69 |
68 virtual void SetUp() { | 70 virtual void Init(PrefService* pref_service) { |
69 ASSERT_TRUE(pref_service_.get()); | 71 ASSERT_TRUE(pref_service); |
70 ChromeURLRequestContextGetter::RegisterUserPrefs(pref_service_.get()); | 72 ChromeURLRequestContextGetter::RegisterUserPrefs(pref_service); |
71 fixed_config_.set_pac_url(GURL(kFixedPacUrl)); | 73 fixed_config_.set_pac_url(GURL(kFixedPacUrl)); |
72 delegate_service_ = new TestProxyConfigService(fixed_config_); | 74 delegate_service_ = new TestProxyConfigService(fixed_config_); |
73 proxy_config_tracker_ = new PrefProxyConfigTracker(pref_service_.get()); | 75 proxy_config_tracker_ = new PrefProxyConfigTracker(pref_service); |
74 proxy_config_service_.reset( | 76 proxy_config_service_.reset( |
75 new PrefProxyConfigService(proxy_config_tracker_.get(), | 77 new PrefProxyConfigService(proxy_config_tracker_.get(), |
76 delegate_service_)); | 78 delegate_service_)); |
77 } | 79 } |
78 | 80 |
79 virtual void TearDown() { | 81 virtual void TearDown() { |
80 proxy_config_tracker_->DetachFromPrefService(); | 82 proxy_config_tracker_->DetachFromPrefService(); |
81 loop_.RunAllPending(); | 83 loop_.RunAllPending(); |
82 proxy_config_service_.reset(); | 84 proxy_config_service_.reset(); |
83 pref_service_.reset(); | |
84 } | 85 } |
85 | 86 |
86 MessageLoop loop_; | 87 MessageLoop loop_; |
87 TestProxyConfigService* delegate_service_; // weak | 88 TestProxyConfigService* delegate_service_; // weak |
88 scoped_ptr<TestingPrefService> pref_service_; | |
89 scoped_ptr<PrefProxyConfigService> proxy_config_service_; | 89 scoped_ptr<PrefProxyConfigService> proxy_config_service_; |
90 net::ProxyConfig fixed_config_; | 90 net::ProxyConfig fixed_config_; |
91 | 91 |
92 private: | 92 private: |
93 scoped_refptr<PrefProxyConfigTracker> proxy_config_tracker_; | 93 scoped_refptr<PrefProxyConfigTracker> proxy_config_tracker_; |
94 BrowserThread ui_thread_; | 94 BrowserThread ui_thread_; |
95 BrowserThread io_thread_; | 95 BrowserThread io_thread_; |
96 }; | 96 }; |
97 | 97 |
98 class PrefProxyConfigServiceTest | 98 class PrefProxyConfigServiceTest |
99 : public PrefProxyConfigServiceTestBase<testing::Test> { | 99 : public PrefProxyConfigServiceTestBase<testing::Test> { |
100 protected: | 100 protected: |
101 virtual void SetUp() { | 101 virtual void SetUp() { |
102 pref_service_.reset(new TestingPrefService); | 102 pref_service_.reset(new TestingPrefService()); |
103 PrefProxyConfigServiceTestBase<testing::Test>::SetUp(); | 103 Init(pref_service_.get()); |
104 } | 104 } |
105 | |
106 scoped_ptr<TestingPrefService> pref_service_; | |
105 }; | 107 }; |
106 | 108 |
107 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { | 109 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { |
108 net::ProxyConfig actual_config; | 110 net::ProxyConfig actual_config; |
109 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 111 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
110 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); | 112 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); |
111 } | 113 } |
112 | 114 |
113 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { | 115 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { |
114 pref_service_->SetManagedPref( | 116 pref_service_->SetManagedPref( |
(...skipping 118 matching lines...) Loading... | |
233 | 235 |
234 virtual void SetUp() { | 236 virtual void SetUp() { |
235 for (size_t i = 0; i < arraysize(GetParam().switches); i++) { | 237 for (size_t i = 0; i < arraysize(GetParam().switches); i++) { |
236 const char* name = GetParam().switches[i].name; | 238 const char* name = GetParam().switches[i].name; |
237 const char* value = GetParam().switches[i].value; | 239 const char* value = GetParam().switches[i].value; |
238 if (name && value) | 240 if (name && value) |
239 command_line_.AppendSwitchASCII(name, value); | 241 command_line_.AppendSwitchASCII(name, value); |
240 else if (name) | 242 else if (name) |
241 command_line_.AppendSwitch(name); | 243 command_line_.AppendSwitch(name); |
242 } | 244 } |
243 pref_service_.reset(new TestingPrefService(NULL, NULL, &command_line_)); | 245 pref_service_.reset(new PrefServiceMock(&command_line_)); |
244 PrefProxyConfigServiceTestBase< | 246 Init(pref_service_.get()); |
245 testing::TestWithParam<CommandLineTestParams> >::SetUp(); | |
246 } | 247 } |
247 | 248 |
248 private: | 249 private: |
250 class PrefServiceMock : public PrefService { | |
danno
2010/12/08 13:08:45
Here it's called a PrefServiceMock, in test_extens
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Solution: Throw design patterns at it :) I introdu
| |
251 public: | |
252 explicit PrefServiceMock(const CommandLine* command_line) | |
253 : PrefService(NULL, | |
254 NULL, | |
255 NULL, | |
256 new CommandLinePrefStore(command_line), | |
257 new TestingPrefStore(), | |
258 NULL, | |
259 NULL) {} | |
260 }; | |
261 | |
249 CommandLine command_line_; | 262 CommandLine command_line_; |
263 scoped_ptr<PrefServiceMock> pref_service_; | |
250 }; | 264 }; |
251 | 265 |
252 TEST_P(PrefProxyConfigServiceCommandLineTest, CommandLine) { | 266 TEST_P(PrefProxyConfigServiceCommandLineTest, CommandLine) { |
253 net::ProxyConfig config; | 267 net::ProxyConfig config; |
254 proxy_config_service_->GetLatestProxyConfig(&config); | 268 proxy_config_service_->GetLatestProxyConfig(&config); |
255 | 269 |
256 if (GetParam().is_null) { | 270 if (GetParam().is_null) { |
257 EXPECT_EQ(GURL(kFixedPacUrl), config.pac_url()); | 271 EXPECT_EQ(GURL(kFixedPacUrl), config.pac_url()); |
258 } else { | 272 } else { |
259 EXPECT_NE(GURL(kFixedPacUrl), config.pac_url()); | 273 EXPECT_NE(GURL(kFixedPacUrl), config.pac_url()); |
(...skipping 115 matching lines...) Loading... | |
375 net::ProxyRulesExpectation::Empty(), | 389 net::ProxyRulesExpectation::Empty(), |
376 }, | 390 }, |
377 }; | 391 }; |
378 | 392 |
379 INSTANTIATE_TEST_CASE_P( | 393 INSTANTIATE_TEST_CASE_P( |
380 PrefProxyConfigServiceCommandLineTestInstance, | 394 PrefProxyConfigServiceCommandLineTestInstance, |
381 PrefProxyConfigServiceCommandLineTest, | 395 PrefProxyConfigServiceCommandLineTest, |
382 testing::ValuesIn(kCommandLineTestParams)); | 396 testing::ValuesIn(kCommandLineTestParams)); |
383 | 397 |
384 } // namespace | 398 } // namespace |
OLD | NEW |