| 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/command_line_pref_store.h" |
| 6 | 6 |
| 7 #include <gtest/gtest.h> | 7 #include <gtest/gtest.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 13 #include "chrome/browser/prefs/pref_service_mock_factory.h" | 14 #include "chrome/browser/prefs/pref_service_mock_factory.h" |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | 16 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" |
| 16 #include "net/proxy/proxy_config_service_common_unittest.h" | 17 #include "net/proxy/proxy_config_service_common_unittest.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Test parameter object for testing command line proxy configuration. | 22 // Test parameter object for testing command line proxy configuration. |
| 22 struct CommandLineTestParams { | 23 struct CommandLineTestParams { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 const char* name = GetParam().switches[i].name; | 164 const char* name = GetParam().switches[i].name; |
| 164 const char* value = GetParam().switches[i].value; | 165 const char* value = GetParam().switches[i].value; |
| 165 if (name && value) | 166 if (name && value) |
| 166 command_line_.AppendSwitchASCII(name, value); | 167 command_line_.AppendSwitchASCII(name, value); |
| 167 else if (name) | 168 else if (name) |
| 168 command_line_.AppendSwitch(name); | 169 command_line_.AppendSwitch(name); |
| 169 } | 170 } |
| 170 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple; | 171 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple; |
| 171 PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get()); | 172 PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get()); |
| 172 PrefServiceMockFactory factory; | 173 PrefServiceMockFactory factory; |
| 173 factory.SetCommandLine(&command_line_); | 174 factory.set_command_line_prefs(new CommandLinePrefStore(&command_line_)); |
| 174 pref_service_ = factory.Create(registry.get()).Pass(); | 175 pref_service_ = factory.Create(registry.get()).Pass(); |
| 175 PrefProxyConfigTrackerImpl::ReadPrefConfig(pref_service_.get(), | 176 PrefProxyConfigTrackerImpl::ReadPrefConfig(pref_service_.get(), |
| 176 &proxy_config_); | 177 &proxy_config_); |
| 177 } | 178 } |
| 178 | 179 |
| 179 private: | 180 private: |
| 180 base::CommandLine command_line_; | 181 base::CommandLine command_line_; |
| 181 scoped_ptr<PrefService> pref_service_; | 182 scoped_ptr<PrefService> pref_service_; |
| 182 net::ProxyConfig proxy_config_; | 183 net::ProxyConfig proxy_config_; |
| 183 }; | 184 }; |
| 184 | 185 |
| 185 TEST_P(CommandLinePrefStoreProxyTest, CommandLine) { | 186 TEST_P(CommandLinePrefStoreProxyTest, CommandLine) { |
| 186 EXPECT_EQ(GetParam().auto_detect, proxy_config()->auto_detect()); | 187 EXPECT_EQ(GetParam().auto_detect, proxy_config()->auto_detect()); |
| 187 EXPECT_EQ(GetParam().pac_url, proxy_config()->pac_url()); | 188 EXPECT_EQ(GetParam().pac_url, proxy_config()->pac_url()); |
| 188 EXPECT_TRUE(GetParam().proxy_rules.Matches(proxy_config()->proxy_rules())); | 189 EXPECT_TRUE(GetParam().proxy_rules.Matches(proxy_config()->proxy_rules())); |
| 189 } | 190 } |
| 190 | 191 |
| 191 INSTANTIATE_TEST_CASE_P(CommandLinePrefStoreProxyTestInstance, | 192 INSTANTIATE_TEST_CASE_P(CommandLinePrefStoreProxyTestInstance, |
| 192 CommandLinePrefStoreProxyTest, | 193 CommandLinePrefStoreProxyTest, |
| 193 testing::ValuesIn(kCommandLineTestParams)); | 194 testing::ValuesIn(kCommandLineTestParams)); |
| OLD | NEW |