| 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 | 6 |
| 7 #include "net/base/net_errors.h" |
| 7 #include "net/base/net_log.h" | 8 #include "net/base/net_log.h" |
| 8 #include "net/proxy/proxy_retry_info.h" | 9 #include "net/proxy/proxy_retry_info.h" |
| 9 #include "net/proxy/proxy_server.h" | 10 #include "net/proxy/proxy_server.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace net { | 13 namespace net { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // Test parsing from a PAC string. | 17 // Test parsing from a PAC string. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 166 } |
| 166 } | 167 } |
| 167 | 168 |
| 168 TEST(ProxyListTest, UpdateRetryInfoOnFallback) { | 169 TEST(ProxyListTest, UpdateRetryInfoOnFallback) { |
| 169 ProxyRetryInfo proxy_retry_info; | 170 ProxyRetryInfo proxy_retry_info; |
| 170 // Retrying should put the first proxy on the retry list. | 171 // Retrying should put the first proxy on the retry list. |
| 171 { | 172 { |
| 172 ProxyList list; | 173 ProxyList list; |
| 173 ProxyRetryInfoMap retry_info_map; | 174 ProxyRetryInfoMap retry_info_map; |
| 174 BoundNetLog net_log; | 175 BoundNetLog net_log; |
| 176 ProxyServer proxy_server( |
| 177 ProxyServer::FromURI("foopy1:80", ProxyServer::SCHEME_HTTP)); |
| 175 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); | 178 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); |
| 176 list.UpdateRetryInfoOnFallback(&retry_info_map, | 179 list.UpdateRetryInfoOnFallback(&retry_info_map, |
| 177 base::TimeDelta::FromSeconds(60), | 180 base::TimeDelta::FromSeconds(60), |
| 178 true, | 181 true, |
| 179 ProxyServer(), | 182 proxy_server, |
| 183 ERR_PROXY_CONNECTION_FAILED, |
| 180 net_log); | 184 net_log); |
| 181 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); | 185 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); |
| 186 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
| 187 retry_info_map[proxy_server.ToURI()].net_error); |
| 182 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); | 188 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); |
| 183 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); | 189 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); |
| 184 } | 190 } |
| 185 // Including another bad proxy should put both the first and the specified | 191 // Including another bad proxy should put both the first and the specified |
| 186 // proxy on the retry list. | 192 // proxy on the retry list. |
| 187 { | 193 { |
| 188 ProxyList list; | 194 ProxyList list; |
| 189 ProxyRetryInfoMap retry_info_map; | 195 ProxyRetryInfoMap retry_info_map; |
| 190 BoundNetLog net_log; | 196 BoundNetLog net_log; |
| 191 ProxyServer proxy_server = ProxyServer::FromURI("foopy3:80", | 197 ProxyServer proxy_server = ProxyServer::FromURI("foopy3:80", |
| 192 ProxyServer::SCHEME_HTTP); | 198 ProxyServer::SCHEME_HTTP); |
| 193 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); | 199 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); |
| 194 list.UpdateRetryInfoOnFallback(&retry_info_map, | 200 list.UpdateRetryInfoOnFallback(&retry_info_map, |
| 195 base::TimeDelta::FromSeconds(60), | 201 base::TimeDelta::FromSeconds(60), |
| 196 true, | 202 true, |
| 197 proxy_server, | 203 proxy_server, |
| 204 ERR_NAME_RESOLUTION_FAILED, |
| 198 net_log); | 205 net_log); |
| 199 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); | 206 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); |
| 207 EXPECT_EQ(ERR_NAME_RESOLUTION_FAILED, |
| 208 retry_info_map[proxy_server.ToURI()].net_error); |
| 200 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); | 209 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); |
| 201 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy3:80")); | 210 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy3:80")); |
| 202 } | 211 } |
| 203 // If the first proxy is DIRECT, nothing is added to the retry list, even | 212 // If the first proxy is DIRECT, nothing is added to the retry list, even |
| 204 // if another bad proxy is specified. | 213 // if another bad proxy is specified. |
| 205 { | 214 { |
| 206 ProxyList list; | 215 ProxyList list; |
| 207 ProxyRetryInfoMap retry_info_map; | 216 ProxyRetryInfoMap retry_info_map; |
| 208 BoundNetLog net_log; | 217 BoundNetLog net_log; |
| 209 ProxyServer proxy_server = ProxyServer::FromURI("foopy2:80", | 218 ProxyServer proxy_server = ProxyServer::FromURI("foopy2:80", |
| 210 ProxyServer::SCHEME_HTTP); | 219 ProxyServer::SCHEME_HTTP); |
| 211 list.SetFromPacString("DIRECT;PROXY foopy2:80;PROXY foopy3:80"); | 220 list.SetFromPacString("DIRECT;PROXY foopy2:80;PROXY foopy3:80"); |
| 212 list.UpdateRetryInfoOnFallback(&retry_info_map, | 221 list.UpdateRetryInfoOnFallback(&retry_info_map, |
| 213 base::TimeDelta::FromSeconds(60), | 222 base::TimeDelta::FromSeconds(60), |
| 214 true, | 223 true, |
| 215 proxy_server, | 224 proxy_server, |
| 225 ERR_PROXY_CONNECTION_FAILED, |
| 216 net_log); | 226 net_log); |
| 217 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); | 227 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); |
| 218 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); | 228 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); |
| 219 } | 229 } |
| 220 } | 230 } |
| 221 | 231 |
| 222 } // namesapce | 232 } // namesapce |
| 223 | 233 |
| 224 } // namespace net | 234 } // namespace net |
| OLD | NEW |