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/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/browser/prefs/pref_service_mock_builder.h" |
11 #include "chrome/browser/prefs/proxy_prefs.h" | |
11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/testing_pref_service.h" | 14 #include "chrome/test/testing_pref_service.h" |
14 #include "net/proxy/proxy_config_service_common_unittest.h" | 15 #include "net/proxy/proxy_config_service_common_unittest.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using testing::_; | 19 using testing::_; |
19 using testing::Mock; | 20 using testing::Mock; |
20 | 21 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 108 |
108 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { | 109 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { |
109 net::ProxyConfig actual_config; | 110 net::ProxyConfig actual_config; |
110 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 111 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
111 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); | 112 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); |
112 } | 113 } |
113 | 114 |
114 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { | 115 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { |
115 pref_service_->SetManagedPref( | 116 pref_service_->SetManagedPref( |
116 prefs::kProxyServer, Value::CreateStringValue("http://example.com:3128")); | 117 prefs::kProxyServer, Value::CreateStringValue("http://example.com:3128")); |
118 pref_service_->SetManagedPref( | |
119 prefs::kProxyServerMode, | |
120 Value::CreateIntegerValue(ProxyPrefs::MANUAL)); | |
117 loop_.RunAllPending(); | 121 loop_.RunAllPending(); |
118 | 122 |
119 net::ProxyConfig actual_config; | 123 net::ProxyConfig actual_config; |
120 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 124 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
121 EXPECT_FALSE(actual_config.auto_detect()); | 125 EXPECT_FALSE(actual_config.auto_detect()); |
122 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, | 126 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, |
123 actual_config.proxy_rules().type); | 127 actual_config.proxy_rules().type); |
124 EXPECT_EQ(actual_config.proxy_rules().single_proxy, | 128 EXPECT_EQ(actual_config.proxy_rules().single_proxy, |
125 net::ProxyServer::FromURI("http://example.com:3128", | 129 net::ProxyServer::FromURI("http://example.com:3128", |
126 net::ProxyServer::SCHEME_HTTP)); | 130 net::ProxyServer::SCHEME_HTTP)); |
127 | 131 |
128 pref_service_->SetManagedPref( | 132 pref_service_->SetManagedPref( |
129 prefs::kProxyAutoDetect, Value::CreateBooleanValue(true)); | 133 prefs::kProxyServerMode, |
134 Value::CreateIntegerValue(ProxyPrefs::AUTO_DETECT)); | |
130 loop_.RunAllPending(); | 135 loop_.RunAllPending(); |
131 | 136 |
132 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 137 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
133 EXPECT_TRUE(actual_config.auto_detect()); | 138 EXPECT_TRUE(actual_config.auto_detect()); |
134 } | 139 } |
135 | 140 |
136 // Compares proxy configurations, but allows different identifiers. | 141 // Compares proxy configurations, but allows different identifiers. |
137 MATCHER_P(ProxyConfigMatches, config, "") { | 142 MATCHER_P(ProxyConfigMatches, config, "") { |
138 net::ProxyConfig reference(config); | 143 net::ProxyConfig reference(config); |
139 reference.set_id(arg.id()); | 144 reference.set_id(arg.id()); |
140 return reference.Equals(arg); | 145 return reference.Equals(arg); |
141 } | 146 } |
142 | 147 |
143 TEST_F(PrefProxyConfigServiceTest, Observers) { | 148 TEST_F(PrefProxyConfigServiceTest, Observers) { |
144 MockObserver observer; | 149 MockObserver observer; |
145 proxy_config_service_->AddObserver(&observer); | 150 proxy_config_service_->AddObserver(&observer); |
146 | 151 |
147 // Firing the observers in the delegate should trigger a notification. | 152 // Firing the observers in the delegate should trigger a notification. |
148 net::ProxyConfig config2; | 153 net::ProxyConfig config2; |
149 config2.set_auto_detect(true); | 154 config2.set_auto_detect(true); |
150 EXPECT_CALL(observer, | 155 EXPECT_CALL(observer, |
151 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1); | 156 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1); |
152 delegate_service_->SetProxyConfig(config2); | 157 delegate_service_->SetProxyConfig(config2); |
153 loop_.RunAllPending(); | 158 loop_.RunAllPending(); |
154 Mock::VerifyAndClearExpectations(&observer); | 159 Mock::VerifyAndClearExpectations(&observer); |
155 | 160 |
156 // Override configuration, this should trigger a notification. | 161 // Override configuration, this should trigger a notification. |
157 net::ProxyConfig pref_config; | 162 net::ProxyConfig pref_config; |
158 pref_config.set_pac_url(GURL(kFixedPacUrl)); | 163 pref_config.set_pac_url(GURL(kFixedPacUrl)); |
164 | |
159 EXPECT_CALL(observer, | 165 EXPECT_CALL(observer, |
160 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); | 166 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); |
167 | |
161 pref_service_->SetManagedPref(prefs::kProxyPacUrl, | 168 pref_service_->SetManagedPref(prefs::kProxyPacUrl, |
162 Value::CreateStringValue(kFixedPacUrl)); | 169 Value::CreateStringValue(kFixedPacUrl)); |
170 // The above does not trigger a notification, because PreProxyConfig still | |
Mattias Nissler (ping if slow)
2010/12/20 13:34:03
s/PreProxyConfig/PrefProxyConfig/
battre (please use the other)
2010/12/21 14:18:18
Done.
| |
171 // sees the mode as the dafault (ProxyPrefs::SYSTEM), so that it doesn't claim | |
172 // to have proxy config. | |
173 // TODO(battre): Remove this comment when http://crbug.com/65732 is | |
174 // completed. | |
Mattias Nissler (ping if slow)
2010/12/20 13:34:03
s/completed/resolved/? Also below. I'm not really
battre (please use the other)
2010/12/21 14:18:18
Done.
| |
175 pref_service_->SetManagedPref( | |
176 prefs::kProxyServerMode, | |
177 Value::CreateIntegerValue(ProxyPrefs::MANUAL)); | |
Mattias Nissler (ping if slow)
2010/12/20 13:34:03
Don't the parameters fit line after the opening pa
battre (please use the other)
2010/12/21 14:18:18
No, but formated nicely, now.
| |
163 loop_.RunAllPending(); | 178 loop_.RunAllPending(); |
164 Mock::VerifyAndClearExpectations(&observer); | 179 Mock::VerifyAndClearExpectations(&observer); |
165 | 180 |
166 // Since there are pref overrides, delegate changes should be ignored. | 181 // Since there are pref overrides, delegate changes should be ignored. |
167 net::ProxyConfig config3; | 182 net::ProxyConfig config3; |
168 config3.proxy_rules().ParseFromString("http=config3:80"); | 183 config3.proxy_rules().ParseFromString("http=config3:80"); |
169 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); | 184 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); |
170 fixed_config_.set_auto_detect(true); | 185 fixed_config_.set_auto_detect(true); |
171 delegate_service_->SetProxyConfig(config3); | 186 delegate_service_->SetProxyConfig(config3); |
172 loop_.RunAllPending(); | 187 loop_.RunAllPending(); |
173 Mock::VerifyAndClearExpectations(&observer); | 188 Mock::VerifyAndClearExpectations(&observer); |
174 | 189 |
175 // Clear the override should switch back to the fixed configuration. | 190 // Clear the override should switch back to the fixed configuration. |
176 EXPECT_CALL(observer, | 191 EXPECT_CALL(observer, |
177 OnProxyConfigChanged(ProxyConfigMatches(config3))).Times(1); | 192 OnProxyConfigChanged(ProxyConfigMatches(config3))).Times(1); |
193 pref_service_->RemoveManagedPref(prefs::kProxyServerMode); | |
194 // The above swithces the mode the default (ProxyPrefs::SYSTEM), so the next | |
Mattias Nissler (ping if slow)
2010/12/20 13:34:03
s/swithces/switches/
s/mode the default/mode to th
battre (please use the other)
2010/12/21 14:18:18
Done.
| |
195 // removal won't bother PrefProxyConfigService. | |
196 // TODO(battre): Remove this comment when http://crbug.com/65732 is | |
197 // completed. | |
178 pref_service_->RemoveManagedPref(prefs::kProxyPacUrl); | 198 pref_service_->RemoveManagedPref(prefs::kProxyPacUrl); |
179 loop_.RunAllPending(); | 199 loop_.RunAllPending(); |
180 Mock::VerifyAndClearExpectations(&observer); | 200 Mock::VerifyAndClearExpectations(&observer); |
181 | 201 |
182 // Delegate service notifications should show up again. | 202 // Delegate service notifications should show up again. |
183 net::ProxyConfig config4; | 203 net::ProxyConfig config4; |
184 config4.proxy_rules().ParseFromString("socks:config4"); | 204 config4.proxy_rules().ParseFromString("socks:config4"); |
185 EXPECT_CALL(observer, | 205 EXPECT_CALL(observer, |
186 OnProxyConfigChanged(ProxyConfigMatches(config4))).Times(1); | 206 OnProxyConfigChanged(ProxyConfigMatches(config4))).Times(1); |
187 delegate_service_->SetProxyConfig(config4); | 207 delegate_service_->SetProxyConfig(config4); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 net::ProxyRulesExpectation::Empty(), | 397 net::ProxyRulesExpectation::Empty(), |
378 }, | 398 }, |
379 }; | 399 }; |
380 | 400 |
381 INSTANTIATE_TEST_CASE_P( | 401 INSTANTIATE_TEST_CASE_P( |
382 PrefProxyConfigServiceCommandLineTestInstance, | 402 PrefProxyConfigServiceCommandLineTestInstance, |
383 PrefProxyConfigServiceCommandLineTest, | 403 PrefProxyConfigServiceCommandLineTest, |
384 testing::ValuesIn(kCommandLineTestParams)); | 404 testing::ValuesIn(kCommandLineTestParams)); |
385 | 405 |
386 } // namespace | 406 } // namespace |
OLD | NEW |