OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 <deque> | 5 #include <deque> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> |
9 | 9 |
10 #include "update_engine/chrome_proxy_resolver.h" | 10 #include "update_engine/chrome_proxy_resolver.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 &out)); | 74 &out)); |
75 | 75 |
76 // Bad proxy scheme | 76 // Bad proxy scheme |
77 EXPECT_TRUE(resolver.GetProxiesForUrlWithSettings("http://foo.com", | 77 EXPECT_TRUE(resolver.GetProxiesForUrlWithSettings("http://foo.com", |
78 "{\"mode\":1}", | 78 "{\"mode\":1}", |
79 &out)); | 79 &out)); |
80 EXPECT_EQ(1, out.size()); | 80 EXPECT_EQ(1, out.size()); |
81 EXPECT_EQ(kNoProxy, out[0]); | 81 EXPECT_EQ(kNoProxy, out[0]); |
82 } | 82 } |
83 | 83 |
| 84 namespace { |
| 85 void DbusInterfaceTestResolved(const std::deque<std::string>& proxies, |
| 86 void* data) { |
| 87 EXPECT_EQ(2, proxies.size()); |
| 88 EXPECT_EQ("socks5://192.168.52.83:5555", proxies[0]); |
| 89 EXPECT_EQ(kNoProxy, proxies[1]); |
| 90 g_main_loop_quit(reinterpret_cast<GMainLoop*>(data)); |
| 91 } |
| 92 } |
| 93 |
84 TEST(ChromeProxyResolverTest, DbusInterfaceTest) { | 94 TEST(ChromeProxyResolverTest, DbusInterfaceTest) { |
85 long number = 1; | 95 long number = 1; |
86 DBusGConnection* kMockSystemBus = | 96 DBusGConnection* kMockSystemBus = |
87 reinterpret_cast<DBusGConnection*>(number++); | 97 reinterpret_cast<DBusGConnection*>(number++); |
88 DBusGProxy* kMockSessionManagerProxy = | 98 DBusGProxy* kMockSessionManagerProxy = |
89 reinterpret_cast<DBusGProxy*>(number++); | 99 reinterpret_cast<DBusGProxy*>(number++); |
90 | 100 |
91 const char settings[] = | 101 const char settings[] = |
92 "{\"mode\":4,\"socks\":{\"server\":\"socks5://192.168.52.83:5555\"," | 102 "{\"mode\":4,\"socks\":{\"server\":\"socks5://192.168.52.83:5555\"," |
93 "\"src\":0}}"; | 103 "\"src\":0}}"; |
(...skipping 18 matching lines...) Expand all Loading... |
112 StrEq(kSessionManagerRetrievePropertyMethod), | 122 StrEq(kSessionManagerRetrievePropertyMethod), |
113 _, | 123 _, |
114 G_TYPE_STRING, StrEq(kSessionManagerProxySettingsKey), | 124 G_TYPE_STRING, StrEq(kSessionManagerProxySettingsKey), |
115 G_TYPE_INVALID, | 125 G_TYPE_INVALID, |
116 G_TYPE_STRING, _, | 126 G_TYPE_STRING, _, |
117 DBUS_TYPE_G_UCHAR_ARRAY, _)) | 127 DBUS_TYPE_G_UCHAR_ARRAY, _)) |
118 .WillOnce(DoAll(SetArgumentPointee<7>(strdup(settings)), | 128 .WillOnce(DoAll(SetArgumentPointee<7>(strdup(settings)), |
119 SetArgumentPointee<9>(ret_array), | 129 SetArgumentPointee<9>(ret_array), |
120 Return(TRUE))); | 130 Return(TRUE))); |
121 | 131 |
122 deque<string> proxies; | 132 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 133 |
123 EXPECT_TRUE(resolver.GetProxiesForUrl("http://user:pass@foo.com:22", | 134 EXPECT_TRUE(resolver.GetProxiesForUrl("http://user:pass@foo.com:22", |
124 &proxies)); | 135 &DbusInterfaceTestResolved, |
125 EXPECT_EQ(2, proxies.size()); | 136 loop)); |
126 EXPECT_EQ("socks5://192.168.52.83:5555", proxies[0]); | 137 g_main_loop_run(loop); |
127 EXPECT_EQ(kNoProxy, proxies[1]); | 138 g_main_loop_unref(loop); |
128 } | 139 } |
129 | 140 |
130 TEST(ChromeProxyResolverTest, GetProxyTypeTest) { | 141 TEST(ChromeProxyResolverTest, GetProxyTypeTest) { |
131 curl_proxytype type; | 142 curl_proxytype type; |
132 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("socks://f.ru", &type)); | 143 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("socks://f.ru", &type)); |
133 EXPECT_EQ(CURLPROXY_SOCKS5_HOSTNAME, type); | 144 EXPECT_EQ(CURLPROXY_SOCKS5_HOSTNAME, type); |
134 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("socks5://f.ru:9", &type)); | 145 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("socks5://f.ru:9", &type)); |
135 EXPECT_EQ(CURLPROXY_SOCKS5_HOSTNAME, type); | 146 EXPECT_EQ(CURLPROXY_SOCKS5_HOSTNAME, type); |
136 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("socks4://f.ru:9", &type)); | 147 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("socks4://f.ru:9", &type)); |
137 EXPECT_EQ(CURLPROXY_SOCKS4A, type); | 148 EXPECT_EQ(CURLPROXY_SOCKS4A, type); |
138 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("http://f.no:88", &type)); | 149 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("http://f.no:88", &type)); |
139 EXPECT_EQ(CURLPROXY_HTTP, type); | 150 EXPECT_EQ(CURLPROXY_HTTP, type); |
140 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("https://f.no:88", &type)); | 151 EXPECT_TRUE(ChromeProxyResolver::GetProxyType("https://f.no:88", &type)); |
141 EXPECT_EQ(CURLPROXY_HTTP, type); | 152 EXPECT_EQ(CURLPROXY_HTTP, type); |
142 EXPECT_FALSE(ChromeProxyResolver::GetProxyType(kNoProxy, &type)); | 153 EXPECT_FALSE(ChromeProxyResolver::GetProxyType(kNoProxy, &type)); |
143 EXPECT_FALSE(ChromeProxyResolver::GetProxyType("foo://", &type)); | 154 EXPECT_FALSE(ChromeProxyResolver::GetProxyType("foo://", &type)); |
144 EXPECT_FALSE(ChromeProxyResolver::GetProxyType("missing.com:8", &type)); | 155 EXPECT_FALSE(ChromeProxyResolver::GetProxyType("missing.com:8", &type)); |
145 } | 156 } |
146 | 157 |
147 } // namespace chromeos_update_engine | 158 } // namespace chromeos_update_engine |
OLD | NEW |