OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/prefs/command_line_pref_store.h" | 5 #include "chrome/browser/prefs/chrome_command_line_pref_store.h" |
6 | 6 |
7 #include <gtest/gtest.h> | 7 #include <gtest/gtest.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "chrome/browser/prefs/command_line_pref_store.h" | |
14 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
15 #include "components/prefs/pref_registry_simple.h" | 14 #include "components/prefs/pref_registry_simple.h" |
16 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
17 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | 16 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" |
18 #include "components/syncable_prefs/pref_service_mock_factory.h" | 17 #include "components/syncable_prefs/pref_service_mock_factory.h" |
19 #include "net/proxy/proxy_config_service_common_unittest.h" | 18 #include "net/proxy/proxy_config_service_common_unittest.h" |
20 #include "url/gurl.h" | 19 #include "url/gurl.h" |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // Expected result | 145 // Expected result |
147 false, // is_null | 146 false, // is_null |
148 true, // auto_detect | 147 true, // auto_detect |
149 GURL(), // pac_url | 148 GURL(), // pac_url |
150 net::ProxyRulesExpectation::Empty(), | 149 net::ProxyRulesExpectation::Empty(), |
151 }, | 150 }, |
152 }; | 151 }; |
153 | 152 |
154 } // namespace | 153 } // namespace |
155 | 154 |
156 class CommandLinePrefStoreProxyTest | 155 class ChromeCommandLinePrefStoreProxyTest |
157 : public testing::TestWithParam<CommandLineTestParams> { | 156 : public testing::TestWithParam<CommandLineTestParams> { |
158 protected: | 157 protected: |
159 CommandLinePrefStoreProxyTest() | 158 ChromeCommandLinePrefStoreProxyTest() |
160 : command_line_(base::CommandLine::NO_PROGRAM) {} | 159 : command_line_(base::CommandLine::NO_PROGRAM) {} |
161 | 160 |
162 net::ProxyConfig* proxy_config() { return &proxy_config_; } | 161 net::ProxyConfig* proxy_config() { return &proxy_config_; } |
163 | 162 |
164 void SetUp() override { | 163 void SetUp() override { |
165 for (size_t i = 0; i < arraysize(GetParam().switches); i++) { | 164 for (size_t i = 0; i < arraysize(GetParam().switches); i++) { |
166 const char* name = GetParam().switches[i].name; | 165 const char* name = GetParam().switches[i].name; |
167 const char* value = GetParam().switches[i].value; | 166 const char* value = GetParam().switches[i].value; |
168 if (name && value) | 167 if (name && value) |
169 command_line_.AppendSwitchASCII(name, value); | 168 command_line_.AppendSwitchASCII(name, value); |
170 else if (name) | 169 else if (name) |
171 command_line_.AppendSwitch(name); | 170 command_line_.AppendSwitch(name); |
172 } | 171 } |
173 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple; | 172 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple; |
174 PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get()); | 173 PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get()); |
175 syncable_prefs::PrefServiceMockFactory factory; | 174 syncable_prefs::PrefServiceMockFactory factory; |
176 factory.set_command_line_prefs(new CommandLinePrefStore(&command_line_)); | 175 factory.set_command_line_prefs( |
| 176 new ChromeCommandLinePrefStore(&command_line_)); |
177 pref_service_ = factory.Create(registry.get()); | 177 pref_service_ = factory.Create(registry.get()); |
178 PrefProxyConfigTrackerImpl::ReadPrefConfig(pref_service_.get(), | 178 PrefProxyConfigTrackerImpl::ReadPrefConfig(pref_service_.get(), |
179 &proxy_config_); | 179 &proxy_config_); |
180 } | 180 } |
181 | 181 |
182 private: | 182 private: |
183 base::CommandLine command_line_; | 183 base::CommandLine command_line_; |
184 std::unique_ptr<PrefService> pref_service_; | 184 std::unique_ptr<PrefService> pref_service_; |
185 net::ProxyConfig proxy_config_; | 185 net::ProxyConfig proxy_config_; |
186 }; | 186 }; |
187 | 187 |
188 TEST_P(CommandLinePrefStoreProxyTest, CommandLine) { | 188 TEST_P(ChromeCommandLinePrefStoreProxyTest, CommandLine) { |
189 EXPECT_EQ(GetParam().auto_detect, proxy_config()->auto_detect()); | 189 EXPECT_EQ(GetParam().auto_detect, proxy_config()->auto_detect()); |
190 EXPECT_EQ(GetParam().pac_url, proxy_config()->pac_url()); | 190 EXPECT_EQ(GetParam().pac_url, proxy_config()->pac_url()); |
191 EXPECT_TRUE(GetParam().proxy_rules.Matches(proxy_config()->proxy_rules())); | 191 EXPECT_TRUE(GetParam().proxy_rules.Matches(proxy_config()->proxy_rules())); |
192 } | 192 } |
193 | 193 |
194 INSTANTIATE_TEST_CASE_P(CommandLinePrefStoreProxyTestInstance, | 194 INSTANTIATE_TEST_CASE_P(ChromeCommandLinePrefStoreProxyTestInstance, |
195 CommandLinePrefStoreProxyTest, | 195 ChromeCommandLinePrefStoreProxyTest, |
196 testing::ValuesIn(kCommandLineTestParams)); | 196 testing::ValuesIn(kCommandLineTestParams)); |
OLD | NEW |