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

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

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PrefService mock construction in PrefServiceTest to include command line store. Created 10 years 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) 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/net/chrome_url_request_context.h" 9 #include "chrome/browser/net/chrome_url_request_context.h"
10 #include "chrome/browser/prefs/pref_service_mock_builder.h"
10 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
12 #include "chrome/test/testing_pref_service.h" 13 #include "chrome/test/testing_pref_service.h"
13 #include "net/proxy/proxy_config_service_common_unittest.h" 14 #include "net/proxy/proxy_config_service_common_unittest.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 using testing::_; 18 using testing::_;
18 using testing::Mock; 19 using testing::Mock;
19 20
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 MOCK_METHOD1(OnProxyConfigChanged, void(const net::ProxyConfig&)); 59 MOCK_METHOD1(OnProxyConfigChanged, void(const net::ProxyConfig&));
59 }; 60 };
60 61
61 template<typename TESTBASE> 62 template<typename TESTBASE>
62 class PrefProxyConfigServiceTestBase : public TESTBASE { 63 class PrefProxyConfigServiceTestBase : public TESTBASE {
63 protected: 64 protected:
64 PrefProxyConfigServiceTestBase() 65 PrefProxyConfigServiceTestBase()
65 : ui_thread_(BrowserThread::UI, &loop_), 66 : ui_thread_(BrowserThread::UI, &loop_),
66 io_thread_(BrowserThread::IO, &loop_) {} 67 io_thread_(BrowserThread::IO, &loop_) {}
67 68
68 virtual void SetUp() { 69 virtual void Init(PrefService* pref_service) {
69 ASSERT_TRUE(pref_service_.get()); 70 ASSERT_TRUE(pref_service);
70 PrefProxyConfigService::RegisterUserPrefs(pref_service_.get()); 71 PrefProxyConfigService::RegisterUserPrefs(pref_service);
71 fixed_config_.set_pac_url(GURL(kFixedPacUrl)); 72 fixed_config_.set_pac_url(GURL(kFixedPacUrl));
72 delegate_service_ = new TestProxyConfigService(fixed_config_); 73 delegate_service_ = new TestProxyConfigService(fixed_config_);
73 proxy_config_tracker_ = new PrefProxyConfigTracker(pref_service_.get()); 74 proxy_config_tracker_ = new PrefProxyConfigTracker(pref_service);
74 proxy_config_service_.reset( 75 proxy_config_service_.reset(
75 new PrefProxyConfigService(proxy_config_tracker_.get(), 76 new PrefProxyConfigService(proxy_config_tracker_.get(),
76 delegate_service_)); 77 delegate_service_));
77 } 78 }
78 79
79 virtual void TearDown() { 80 virtual void TearDown() {
80 proxy_config_tracker_->DetachFromPrefService(); 81 proxy_config_tracker_->DetachFromPrefService();
81 loop_.RunAllPending(); 82 loop_.RunAllPending();
82 proxy_config_service_.reset(); 83 proxy_config_service_.reset();
83 pref_service_.reset();
84 } 84 }
85 85
86 MessageLoop loop_; 86 MessageLoop loop_;
87 TestProxyConfigService* delegate_service_; // weak 87 TestProxyConfigService* delegate_service_; // weak
88 scoped_ptr<TestingPrefService> pref_service_;
89 scoped_ptr<PrefProxyConfigService> proxy_config_service_; 88 scoped_ptr<PrefProxyConfigService> proxy_config_service_;
90 net::ProxyConfig fixed_config_; 89 net::ProxyConfig fixed_config_;
91 90
92 private: 91 private:
93 scoped_refptr<PrefProxyConfigTracker> proxy_config_tracker_; 92 scoped_refptr<PrefProxyConfigTracker> proxy_config_tracker_;
94 BrowserThread ui_thread_; 93 BrowserThread ui_thread_;
95 BrowserThread io_thread_; 94 BrowserThread io_thread_;
96 }; 95 };
97 96
98 class PrefProxyConfigServiceTest 97 class PrefProxyConfigServiceTest
99 : public PrefProxyConfigServiceTestBase<testing::Test> { 98 : public PrefProxyConfigServiceTestBase<testing::Test> {
100 protected: 99 protected:
101 virtual void SetUp() { 100 virtual void SetUp() {
102 pref_service_.reset(new TestingPrefService); 101 pref_service_.reset(new TestingPrefService());
103 PrefProxyConfigServiceTestBase<testing::Test>::SetUp(); 102 Init(pref_service_.get());
104 } 103 }
104
105 scoped_ptr<TestingPrefService> pref_service_;
105 }; 106 };
106 107
107 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { 108 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) {
108 net::ProxyConfig actual_config; 109 net::ProxyConfig actual_config;
109 proxy_config_service_->GetLatestProxyConfig(&actual_config); 110 proxy_config_service_->GetLatestProxyConfig(&actual_config);
110 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); 111 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url());
111 } 112 }
112 113
113 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { 114 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) {
114 pref_service_->SetManagedPref( 115 pref_service_->SetManagedPref(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 234
234 virtual void SetUp() { 235 virtual void SetUp() {
235 for (size_t i = 0; i < arraysize(GetParam().switches); i++) { 236 for (size_t i = 0; i < arraysize(GetParam().switches); i++) {
236 const char* name = GetParam().switches[i].name; 237 const char* name = GetParam().switches[i].name;
237 const char* value = GetParam().switches[i].value; 238 const char* value = GetParam().switches[i].value;
238 if (name && value) 239 if (name && value)
239 command_line_.AppendSwitchASCII(name, value); 240 command_line_.AppendSwitchASCII(name, value);
240 else if (name) 241 else if (name)
241 command_line_.AppendSwitch(name); 242 command_line_.AppendSwitch(name);
242 } 243 }
243 pref_service_.reset(new TestingPrefService(NULL, NULL, &command_line_)); 244 pref_service_.reset(
244 PrefProxyConfigServiceTestBase< 245 PrefServiceMockBuilder().WithCommandLine(&command_line_).Create());
245 testing::TestWithParam<CommandLineTestParams> >::SetUp(); 246 Init(pref_service_.get());
246 } 247 }
247 248
248 private: 249 private:
249 CommandLine command_line_; 250 CommandLine command_line_;
251 scoped_ptr<PrefService> pref_service_;
250 }; 252 };
251 253
252 TEST_P(PrefProxyConfigServiceCommandLineTest, CommandLine) { 254 TEST_P(PrefProxyConfigServiceCommandLineTest, CommandLine) {
253 net::ProxyConfig config; 255 net::ProxyConfig config;
254 proxy_config_service_->GetLatestProxyConfig(&config); 256 proxy_config_service_->GetLatestProxyConfig(&config);
255 257
256 if (GetParam().is_null) { 258 if (GetParam().is_null) {
257 EXPECT_EQ(GURL(kFixedPacUrl), config.pac_url()); 259 EXPECT_EQ(GURL(kFixedPacUrl), config.pac_url());
258 } else { 260 } else {
259 EXPECT_NE(GURL(kFixedPacUrl), config.pac_url()); 261 EXPECT_NE(GURL(kFixedPacUrl), config.pac_url());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 net::ProxyRulesExpectation::Empty(), 377 net::ProxyRulesExpectation::Empty(),
376 }, 378 },
377 }; 379 };
378 380
379 INSTANTIATE_TEST_CASE_P( 381 INSTANTIATE_TEST_CASE_P(
380 PrefProxyConfigServiceCommandLineTestInstance, 382 PrefProxyConfigServiceCommandLineTestInstance,
381 PrefProxyConfigServiceCommandLineTest, 383 PrefProxyConfigServiceCommandLineTest,
382 testing::ValuesIn(kCommandLineTestParams)); 384 testing::ValuesIn(kCommandLineTestParams));
383 385
384 } // namespace 386 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service_uitest.cc ('k') | chrome/browser/policy/configuration_policy_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698