proxy_info_unittest.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "net/proxy_resolution/proxy_info.h"
  5. #include "net/base/net_errors.h"
  6. #include "net/log/net_log_with_source.h"
  7. #include "net/proxy_resolution/proxy_config.h"
  8. #include "net/proxy_resolution/proxy_list.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. namespace net {
  11. namespace {
  12. TEST(ProxyInfoTest, ProxyInfoIsDirectOnly) {
  13. // Test the is_direct_only() predicate.
  14. ProxyInfo info;
  15. // An empty ProxyInfo is not considered direct.
  16. EXPECT_FALSE(info.is_direct_only());
  17. info.UseDirect();
  18. EXPECT_TRUE(info.is_direct_only());
  19. info.UsePacString("DIRECT");
  20. EXPECT_TRUE(info.is_direct_only());
  21. info.UsePacString("PROXY myproxy:80");
  22. EXPECT_FALSE(info.is_direct_only());
  23. info.UsePacString("DIRECT; PROXY myproxy:80");
  24. EXPECT_TRUE(info.is_direct());
  25. EXPECT_FALSE(info.is_direct_only());
  26. info.UsePacString("PROXY myproxy:80; DIRECT");
  27. EXPECT_FALSE(info.is_direct());
  28. EXPECT_FALSE(info.is_direct_only());
  29. EXPECT_EQ(2u, info.proxy_list().size());
  30. EXPECT_EQ("PROXY myproxy:80;DIRECT", info.proxy_list().ToPacString());
  31. // After falling back to direct, we shouldn't consider it DIRECT only.
  32. EXPECT_TRUE(info.Fallback(ERR_PROXY_CONNECTION_FAILED, NetLogWithSource()));
  33. EXPECT_TRUE(info.is_direct());
  34. EXPECT_FALSE(info.is_direct_only());
  35. }
  36. } // namespace
  37. TEST(ProxyInfoTest, UseVsOverrideProxyList) {
  38. ProxyInfo info;
  39. ProxyList proxy_list;
  40. proxy_list.Set("http://foo.com");
  41. info.OverrideProxyList(proxy_list);
  42. EXPECT_EQ("PROXY foo.com:80", info.proxy_list().ToPacString());
  43. proxy_list.Set("http://bar.com");
  44. info.UseProxyList(proxy_list);
  45. EXPECT_EQ("PROXY bar.com:80", info.proxy_list().ToPacString());
  46. }
  47. } // namespace net