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/spdyproxy/data_reduction_proxy_chrome_settings_unittest.cc

Issue 1148793008: Check for embedded PAC scripts when migrating proxy pref for DRP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed histograms.xml changes Created 5 years, 6 months 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
« no previous file with comments | « chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 TEST_F(DataReductionProxyChromeSettingsTest, MigrateBadlyFormedProxyPref) { 59 TEST_F(DataReductionProxyChromeSettingsTest, MigrateBadlyFormedProxyPref) {
60 const struct { 60 const struct {
61 // NULL indicates that mode is unset. 61 // NULL indicates that mode is unset.
62 const char* proxy_mode_string; 62 const char* proxy_mode_string;
63 // NULL indicates that server is unset. 63 // NULL indicates that server is unset.
64 const char* proxy_server_string; 64 const char* proxy_server_string;
65 } test_cases[] = { 65 } test_cases[] = {
66 // The pref should not be cleared if mode is unset. 66 // The pref should not be cleared if mode is unset.
67 {nullptr, "http=compress.googlezip.net"}, 67 {nullptr, "http=compress.googlezip.net"},
68 // The pref should not be cleared for modes other than "fixed_servers". 68 // The pref should not be cleared for modes other than "fixed_servers" and
69 {"pac_script", "http=compress.googlezip.net"}, 69 // "pac_script".
70 {"auto_detect", "http=compress.googlezip.net"},
70 // The pref should not be cleared when the server field is unset. 71 // The pref should not be cleared when the server field is unset.
71 {"fixed_servers", nullptr}, 72 {"fixed_servers", nullptr},
72 }; 73 };
73 74
74 for (const auto& test : test_cases) { 75 for (const auto& test : test_cases) {
75 base::HistogramTester histogram_tester; 76 base::HistogramTester histogram_tester;
76 dict_.reset(new base::DictionaryValue()); 77 dict_.reset(new base::DictionaryValue());
77 if (test.proxy_mode_string) 78 if (test.proxy_mode_string)
78 dict_->SetString("mode", test.proxy_mode_string); 79 dict_->SetString("mode", test.proxy_mode_string);
79 if (test.proxy_server_string) 80 if (test.proxy_server_string)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs( 173 drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
173 test_context_->pref_service()); 174 test_context_->pref_service());
174 175
175 EXPECT_EQ(NULL, test_context_->pref_service()->GetUserPref(prefs::kProxy)); 176 EXPECT_EQ(NULL, test_context_->pref_service()->GetUserPref(prefs::kProxy));
176 histogram_tester.ExpectUniqueSample( 177 histogram_tester.ExpectUniqueSample(
177 "DataReductionProxy.ProxyPrefMigrationResult", 178 "DataReductionProxy.ProxyPrefMigrationResult",
178 DataReductionProxyChromeSettings::PROXY_PREF_CLEARED_GOOGLEZIP, 1); 179 DataReductionProxyChromeSettings::PROXY_PREF_CLEARED_GOOGLEZIP, 1);
179 } 180 }
180 } 181 }
181 182
183 TEST_F(DataReductionProxyChromeSettingsTest,
184 MigratePacGooglezipDataReductionProxy) {
185 const struct {
186 const char* pac_url;
187 bool expect_pref_cleared;
188 } test_cases[] = {
189 // PAC with bypass rules that returns 'HTTPS proxy.googlezip.net:443;
190 // PROXY compress.googlezip.net:80; DIRECT'.
191 {"data:application/"
192 "x-ns-proxy-autoconfig;base64,"
193 "ZnVuY3Rpb24gRmluZFByb3h5Rm9yVVJMKHVybCwgaG9zdCkgeyAgaWYgKChzaEV4cE1hdGN"
194 "oKHVybCwgJ2h0dHA6Ly93d3cuZ29vZ2xlLmNvbS9wb2xpY2llcy9wcml2YWN5KicpKSkgey"
195 "AgICByZXR1cm4gJ0RJUkVDVCc7ICB9ICAgaWYgKHVybC5zdWJzdHJpbmcoMCwgNSkgPT0gJ"
196 "2h0dHA6JykgeyAgICByZXR1cm4gJ0hUVFBTIHByb3h5Lmdvb2dsZXppcC5uZXQ6NDQzOyBQ"
197 "Uk9YWSBjb21wcmVzcy5nb29nbGV6aXAubmV0OjgwOyBESVJFQ1QnOyAgfSAgcmV0dXJuICd"
198 "ESVJFQ1QnO30=",
199 true},
200 // PAC with bypass rules that returns 'PROXY compress.googlezip.net:80;
201 // DIRECT'.
202 {"data:application/"
203 "x-ns-proxy-autoconfig;base64,"
204 "ZnVuY3Rpb24gRmluZFByb3h5Rm9yVVJMKHVybCwgaG9zdCkgeyAgaWYgKChzaEV4cE1hdGN"
205 "oKHVybCwgJ2h0dHA6Ly93d3cuZ29vZ2xlLmNvbS9wb2xpY2llcy9wcml2YWN5KicpKSkgey"
206 "AgICByZXR1cm4gJ0RJUkVDVCc7ICB9ICAgaWYgKHVybC5zdWJzdHJpbmcoMCwgNSkgPT0gJ"
207 "2h0dHA6JykgeyAgICByZXR1cm4gJ1BST1hZIGNvbXByZXNzLmdvb2dsZXppcC5uZXQ6ODA7"
208 "IERJUkVDVCc7ICB9ICByZXR1cm4gJ0RJUkVDVCc7fQ==",
209 true},
210 // PAC with bypass rules that returns 'PROXY proxy-dev.googlezip.net:80;
211 // DIRECT'.
212 {"data:application/"
213 "x-ns-proxy-autoconfig;base64,"
214 "ZnVuY3Rpb24gRmluZFByb3h5Rm9yVVJMKHVybCwgaG9zdCkgeyAgaWYgKChzaEV4cE1hdGN"
215 "oKHVybCwgJ2h0dHA6Ly93d3cuZ29vZ2xlLmNvbS9wb2xpY2llcy9wcml2YWN5KicpKSkgey"
216 "AgICByZXR1cm4gJ0RJUkVDVCc7ICB9ICAgaWYgKHVybC5zdWJzdHJpbmcoMCwgNSkgPT0gJ"
217 "2h0dHA6JykgeyAgICByZXR1cm4gJ1BST1hZIHByb3h5LWRldi5nb29nbGV6aXAubmV0Ojgw"
218 "OyBESVJFQ1QnOyAgfSAgcmV0dXJuICdESVJFQ1QnO30=",
219 true},
220 // Simple PAC that returns 'PROXY compress.googlezip.net:80'.
221 {"data:application/"
222 "x-ns-proxy-autoconfig;base64,"
223 "ZnVuY3Rpb24gRmluZFByb3h5Rm9yVVJMKHVybCwgaG9zdCkge3JldHVybiAnUFJPWFkgY29"
224 "tcHJlc3MuZ29vZ2xlemlwLm5ldDo4MCc7fQo=",
225 true},
226 // Simple PAC that returns 'PROXY compress.googlezip.net'. Note that since
227 // the port is not specified, the pref will not be cleared.
228 {"data:application/"
229 "x-ns-proxy-autoconfig;base64,"
230 "ZnVuY3Rpb24gRmluZFByb3h5Rm9yVVJMKHVybCwgaG9zdCkge3JldHVybiAnUFJPWFkgY29"
231 "tcHJlc3MuZ29vZ2xlemlwLm5ldCc7fQ==",
232 false},
233 // Simple PAC that returns 'PROXY mycustomdrp.net:80'.
234 {"data:application/"
235 "x-ns-proxy-autoconfig;base64,"
236 "ZnVuY3Rpb24gRmluZFByb3h5Rm9yVVJMKHVybCwgaG9zdCkge3JldHVybiAnUFJPWFkgb3J"
237 "pZ2luLm5ldDo4MCc7fQo=",
238 false},
239 // Simple PAC that returns 'PROXY myprefixgooglezip.net:80'.
240 {"data:application/"
241 "x-ns-proxy-autoconfig;base64,"
242 "ZnVuY3Rpb24gRmluZFByb3h5Rm9yVVJMKHVybCwgaG9zdCkge3JldHVybiAnUFJPWFkgbXl"
243 "wcmVmaXhnb29nbGV6aXAubmV0OjgwJzt9Cg==",
244 false},
245 // Simple PAC that returns 'PROXY compress.googlezip.net.mydomain.com:80'.
246 {"data:application/"
247 "x-ns-proxy-autoconfig;base64,"
248 "ZnVuY3Rpb24gRmluZFByb3h5Rm9yVVJMKHVybCwgaG9zdCkge3JldHVybiAnUFJPWFkgY29"
249 "tcHJlc3MuZ29vZ2xlemlwLm5ldC5teWRvbWFpbi5jb206ODAnO30K",
250 false},
251 // PAC URL that doesn't embed a script.
252 {"http://compress.googlezip.net/pac", false},
253 };
254
255 for (const auto& test : test_cases) {
256 base::HistogramTester histogram_tester;
257 dict_.reset(new base::DictionaryValue());
258 dict_->SetString("mode", "pac_script");
259 dict_->SetString("pac_url", test.pac_url);
260 test_context_->pref_service()->Set(prefs::kProxy, *dict_.get());
261 EXPECT_CALL(*config_, ContainsDataReductionProxy(_)).Times(0);
262
263 drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
264 test_context_->pref_service());
265
266 if (test.expect_pref_cleared) {
267 EXPECT_EQ(NULL,
268 test_context_->pref_service()->GetUserPref(prefs::kProxy));
269 histogram_tester.ExpectUniqueSample(
270 "DataReductionProxy.ProxyPrefMigrationResult",
271 DataReductionProxyChromeSettings::PROXY_PREF_CLEARED_PAC_GOOGLEZIP,
272 1);
273 } else {
274 const base::DictionaryValue* value;
275 EXPECT_TRUE(test_context_->pref_service()
276 ->GetUserPref(prefs::kProxy)
277 ->GetAsDictionary(&value));
278 std::string mode;
279 EXPECT_TRUE(value->GetString("mode", &mode));
280 EXPECT_EQ("pac_script", mode);
281 std::string pac_url;
282 EXPECT_TRUE(value->GetString("pac_url", &pac_url));
283 EXPECT_EQ(test.pac_url, pac_url);
284
285 histogram_tester.ExpectUniqueSample(
286 "DataReductionProxy.ProxyPrefMigrationResult",
287 DataReductionProxyChromeSettings::PROXY_PREF_NOT_CLEARED, 1);
288 }
289 }
290 }
291
182 TEST_F(DataReductionProxyChromeSettingsTest, MigrateIgnoreOtherProxy) { 292 TEST_F(DataReductionProxyChromeSettingsTest, MigrateIgnoreOtherProxy) {
183 const std::string kTestServers[] = { 293 const std::string kTestServers[] = {
184 "http=https://youtube.com", 294 "http=https://youtube.com",
185 "http=http://googlezip.net", 295 "http=http://googlezip.net",
186 "http=http://thisismyproxynotgooglezip.net", 296 "http=http://thisismyproxynotgooglezip.net",
187 "https=http://arbitraryprefixgooglezip.net"}; 297 "https=http://arbitraryprefixgooglezip.net"};
188 298
189 for (const std::string& test_server : kTestServers) { 299 for (const std::string& test_server : kTestServers) {
190 base::HistogramTester histogram_tester; 300 base::HistogramTester histogram_tester;
191 dict_.reset(new base::DictionaryValue()); 301 dict_.reset(new base::DictionaryValue());
(...skipping 15 matching lines...) Expand all
207 EXPECT_EQ("fixed_servers", mode); 317 EXPECT_EQ("fixed_servers", mode);
208 std::string server; 318 std::string server;
209 EXPECT_TRUE(value->GetString("server", &server)); 319 EXPECT_TRUE(value->GetString("server", &server));
210 EXPECT_EQ(test_server, server); 320 EXPECT_EQ(test_server, server);
211 321
212 histogram_tester.ExpectUniqueSample( 322 histogram_tester.ExpectUniqueSample(
213 "DataReductionProxy.ProxyPrefMigrationResult", 323 "DataReductionProxy.ProxyPrefMigrationResult",
214 DataReductionProxyChromeSettings::PROXY_PREF_NOT_CLEARED, 1); 324 DataReductionProxyChromeSettings::PROXY_PREF_NOT_CLEARED, 1);
215 } 325 }
216 } 326 }
OLDNEW
« no previous file with comments | « chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698