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

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

Issue 1126413006: Temporary fix to prevent the DRP from being activated improperly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 7 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/pref_proxy_config_tracker_impl.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_tracker_impl.h" 5 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h"
6 6
7 #include <string>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
9 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_registry_simple.h" 12 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/testing_pref_service.h" 13 #include "base/prefs/testing_pref_service.h"
12 #include "chrome/browser/prefs/pref_service_mock_factory.h" 14 #include "chrome/browser/prefs/pref_service_mock_factory.h"
13 #include "chrome/browser/prefs/proxy_config_dictionary.h" 15 #include "chrome/browser/prefs/proxy_config_dictionary.h"
14 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
16 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
17 #include "net/proxy/proxy_config_service_common_unittest.h" 19 #include "net/proxy/proxy_config_service_common_unittest.h"
20 #include "net/proxy/proxy_info.h"
21 #include "net/proxy/proxy_list.h"
18 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
20 24
21 using content::BrowserThread; 25 using content::BrowserThread;
22 using testing::_; 26 using testing::_;
23 using testing::Mock; 27 using testing::Mock;
24 28
25 namespace { 29 namespace {
26 30
27 const char kFixedPacUrl[] = "http://chromium.org/fixed_pac_url"; 31 const char kFixedPacUrl[] = "http://chromium.org/fixed_pac_url";
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 ProxyConfigDictionary::CreateSystem()); 284 ProxyConfigDictionary::CreateSystem());
281 loop_.RunUntilIdle(); 285 loop_.RunUntilIdle();
282 286
283 // Test if we actually use the system setting, which is |kFixedPacUrl|. 287 // Test if we actually use the system setting, which is |kFixedPacUrl|.
284 net::ProxyConfig actual_config; 288 net::ProxyConfig actual_config;
285 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, 289 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
286 proxy_config_service_->GetLatestProxyConfig(&actual_config)); 290 proxy_config_service_->GetLatestProxyConfig(&actual_config));
287 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); 291 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url());
288 } 292 }
289 293
294 void CheckResolvedProxyMatches(net::ProxyConfig* config,
295 const GURL& url,
296 const std::string& result_string) {
297 net::ProxyInfo expected_result;
298 expected_result.UseNamedProxy(result_string);
299
300 net::ProxyInfo result;
301 config->proxy_rules().Apply(url, &result);
302
303 EXPECT_TRUE(expected_result.proxy_list().Equals(result.proxy_list()))
304 << "expected: " << expected_result.proxy_list().ToPacString()
305 << "\nactual: " << result.proxy_list().ToPacString();
306 }
307
308 TEST_F(PrefProxyConfigTrackerImplTest, ExcludeGooglezipDataReductionProxies) {
309 const std::string kDataReductionProxies =
310 "https://proxy.googlezip.net:443,compress.googlezip.net,"
311 "https://proxy-dev.googlezip.net:443,proxy-dev.googlezip.net,"
312 "quic://proxy.googlezip.net";
313
314 struct {
315 std::string initial_proxy_rules;
316 const char* http_proxy_info;
317 const char* https_proxy_info;
318 const char* ftp_proxy_info;
319 } test_cases[] = {
320 {"http=foopyhttp," + kDataReductionProxies +
321 ",direct://;https=foopyhttps," + kDataReductionProxies +
322 ",direct://;ftp=foopyftp," + kDataReductionProxies + ",direct://",
323 "foopyhttp;direct://",
324 "foopyhttps;direct://",
325 "foopyftp;direct://"},
326
327 {"foopy," + kDataReductionProxies + ",direct://",
328 "foopy;direct://",
329 "foopy;direct://",
330 "foopy;direct://"},
331
332 {"http=" + kDataReductionProxies + ";https=" + kDataReductionProxies +
333 ";ftp=" + kDataReductionProxies,
334 "direct://",
335 "direct://",
336 "direct://"},
337
338 {"http=" + kDataReductionProxies + ",foopy,direct://",
339 "foopy;direct://",
340 "direct://",
341 "direct://"},
342 };
343
344 // Test setting the proxy from a user pref.
345 for (const auto& test : test_cases) {
346 pref_service_->SetUserPref(prefs::kProxy,
347 ProxyConfigDictionary::CreateFixedServers(
348 test.initial_proxy_rules, std::string()));
349 loop_.RunUntilIdle();
350
351 net::ProxyConfig config;
352 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID,
353 proxy_config_service_->GetLatestProxyConfig(&config));
354
355 CheckResolvedProxyMatches(&config, GURL("http://google.com"),
356 test.http_proxy_info);
357 CheckResolvedProxyMatches(&config, GURL("https://google.com"),
358 test.https_proxy_info);
359 CheckResolvedProxyMatches(&config, GURL("ftp://google.com"),
360 test.ftp_proxy_info);
361 }
362 }
363
290 // Test parameter object for testing command line proxy configuration. 364 // Test parameter object for testing command line proxy configuration.
291 struct CommandLineTestParams { 365 struct CommandLineTestParams {
292 // Explicit assignment operator, so testing::TestWithParam works with MSVC. 366 // Explicit assignment operator, so testing::TestWithParam works with MSVC.
293 CommandLineTestParams& operator=(const CommandLineTestParams& other) { 367 CommandLineTestParams& operator=(const CommandLineTestParams& other) {
294 description = other.description; 368 description = other.description;
295 for (unsigned int i = 0; i < arraysize(switches); i++) 369 for (unsigned int i = 0; i < arraysize(switches); i++)
296 switches[i] = other.switches[i]; 370 switches[i] = other.switches[i];
297 is_null = other.is_null; 371 is_null = other.is_null;
298 auto_detect = other.auto_detect; 372 auto_detect = other.auto_detect;
299 pac_url = other.pac_url; 373 pac_url = other.pac_url;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 net::ProxyRulesExpectation::Empty(), 547 net::ProxyRulesExpectation::Empty(),
474 }, 548 },
475 }; 549 };
476 550
477 INSTANTIATE_TEST_CASE_P( 551 INSTANTIATE_TEST_CASE_P(
478 PrefProxyConfigTrackerImplCommandLineTestInstance, 552 PrefProxyConfigTrackerImplCommandLineTestInstance,
479 PrefProxyConfigTrackerImplCommandLineTest, 553 PrefProxyConfigTrackerImplCommandLineTest,
480 testing::ValuesIn(kCommandLineTestParams)); 554 testing::ValuesIn(kCommandLineTestParams));
481 555
482 } // namespace 556 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/net/pref_proxy_config_tracker_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698