OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "net/proxy/proxy_list.h" | 5 #include "net/proxy/proxy_list.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 // Test parsing from a PAC string. | 8 // Test parsing from a PAC string. |
9 TEST(ProxyListTest, SetFromPacString) { | 9 TEST(ProxyListTest, SetFromPacString) { |
10 const struct { | 10 const struct { |
11 const char* pac_input; | 11 const char* pac_input; |
12 const char* pac_output; | 12 const char* pac_output; |
13 } tests[] = { | 13 } tests[] = { |
14 // Valid inputs: | 14 // Valid inputs: |
15 { "PROXY foopy:10", | 15 { "PROXY foopy:10", |
16 "PROXY foopy:10", | 16 "PROXY foopy:10", |
17 }, | 17 }, |
18 { " DIRECT", // leading space. | 18 { " DIRECT", // leading space. |
19 "DIRECT", | 19 "DIRECT", |
20 }, | 20 }, |
21 { "PROXY foopy1 ; proxy foopy2;\t DIRECT", | 21 { "PROXY foopy1 ; proxy foopy2;\t DIRECT", |
22 "PROXY foopy1:80;PROXY foopy2:80;DIRECT", | 22 "PROXY foopy1:80;PROXY foopy2:80;DIRECT", |
23 }, | 23 }, |
24 { "proxy foopy1 ; SOCKS foopy2", | 24 { "proxy foopy1 ; SOCKS foopy2", |
25 "PROXY foopy1:80;SOCKS foopy2:1080", | 25 "PROXY foopy1:80;SOCKS foopy2:1080", |
26 }, | 26 }, |
| 27 // Try putting DIRECT first. |
| 28 { "DIRECT ; proxy foopy1 ; DIRECT ; SOCKS5 foopy2;DIRECT ", |
| 29 "DIRECT;PROXY foopy1:80;DIRECT;SOCKS5 foopy2:1080;DIRECT", |
| 30 }, |
| 31 // Try putting DIRECT consecutively. |
| 32 { "DIRECT ; proxy foopy1:80; DIRECT ; DIRECT", |
| 33 "DIRECT;PROXY foopy1:80;DIRECT;DIRECT", |
| 34 }, |
27 | 35 |
28 // Invalid inputs (parts which aren't understood get | 36 // Invalid inputs (parts which aren't understood get |
29 // silently discarded): | 37 // silently discarded): |
| 38 // |
| 39 // If the proxy list string parsed to empty, automatically fall-back to |
| 40 // DIRECT. |
30 { "PROXY-foopy:10", | 41 { "PROXY-foopy:10", |
31 "DIRECT", | 42 "DIRECT", |
32 }, | 43 }, |
33 { "PROXY", | 44 { "PROXY", |
34 "DIRECT", | 45 "DIRECT", |
35 }, | 46 }, |
36 { "PROXY foopy1 ; JUNK ; JUNK ; SOCKS5 foopy2 ; ;", | 47 { "PROXY foopy1 ; JUNK ; JUNK ; SOCKS5 foopy2 ; ;", |
37 "PROXY foopy1:80;SOCKS5 foopy2:1080", | 48 "PROXY foopy1:80;SOCKS5 foopy2:1080", |
38 }, | 49 }, |
39 }; | 50 }; |
40 | 51 |
41 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 52 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
42 net::ProxyList list; | 53 net::ProxyList list; |
43 list.SetFromPacString(tests[i].pac_input); | 54 list.SetFromPacString(tests[i].pac_input); |
44 EXPECT_EQ(tests[i].pac_output, list.ToPacString()); | 55 EXPECT_EQ(tests[i].pac_output, list.ToPacString()); |
| 56 EXPECT_FALSE(list.IsEmpty()); |
45 } | 57 } |
46 } | 58 } |
47 | 59 |
48 TEST(ProxyListTest, RemoveProxiesWithoutScheme) { | 60 TEST(ProxyListTest, RemoveProxiesWithoutScheme) { |
49 const struct { | 61 const struct { |
50 const char* pac_input; | 62 const char* pac_input; |
51 int filter; | 63 int filter; |
52 const char* filtered_pac_output; | 64 const char* filtered_pac_output; |
53 } tests[] = { | 65 } tests[] = { |
54 { "PROXY foopy:10 ; SOCKS5 foopy2 ; SOCKS foopy11 ; PROXY foopy3 ; DIRECT", | 66 { "PROXY foopy:10 ; SOCKS5 foopy2 ; SOCKS foopy11 ; PROXY foopy3 ; DIRECT", |
55 // Remove anything that isn't HTTP or DIRECT. | 67 // Remove anything that isn't HTTP or DIRECT. |
56 net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_HTTP, | 68 net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_HTTP, |
57 "PROXY foopy:10;PROXY foopy3:80;DIRECT", | 69 "PROXY foopy:10;PROXY foopy3:80;DIRECT", |
58 }, | 70 }, |
59 { "PROXY foopy:10 | SOCKS5 foopy2", | 71 { "PROXY foopy:10 ; SOCKS5 foopy2", |
60 // Remove anything that isn't HTTP or SOCKS5. | 72 // Remove anything that isn't HTTP or SOCKS5. |
61 net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_SOCKS4, | 73 net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_SOCKS4, |
62 "DIRECT", | 74 "", |
63 }, | 75 }, |
64 }; | 76 }; |
65 | 77 |
66 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 78 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
67 net::ProxyList list; | 79 net::ProxyList list; |
68 list.SetFromPacString(tests[i].pac_input); | 80 list.SetFromPacString(tests[i].pac_input); |
69 list.RemoveProxiesWithoutScheme(tests[i].filter); | 81 list.RemoveProxiesWithoutScheme(tests[i].filter); |
70 EXPECT_EQ(tests[i].filtered_pac_output, list.ToPacString()); | 82 EXPECT_EQ(tests[i].filtered_pac_output, list.ToPacString()); |
71 } | 83 } |
72 } | 84 } |
OLD | NEW |