| OLD | NEW |
| 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 "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
| 16 #include "net/base/net_log_unittest.h" | 16 #include "net/base/net_log_unittest.h" |
| 17 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
| 18 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
| 18 #include "net/proxy/mock_proxy_resolver.h" | 19 #include "net/proxy/mock_proxy_resolver.h" |
| 20 #include "net/proxy/mock_proxy_script_fetcher.h" |
| 19 #include "net/proxy/proxy_config_service.h" | 21 #include "net/proxy/proxy_config_service.h" |
| 20 #include "net/proxy/proxy_resolver.h" | 22 #include "net/proxy/proxy_resolver.h" |
| 21 #include "net/proxy/proxy_script_fetcher.h" | 23 #include "net/proxy/proxy_script_fetcher.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 25 |
| 24 // TODO(eroman): Write a test which exercises | 26 // TODO(eroman): Write a test which exercises |
| 25 // ProxyService::SuspendAllPendingRequests(). | 27 // ProxyService::SuspendAllPendingRequests(). |
| 26 namespace net { | 28 namespace net { |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 62 } |
| 61 | 63 |
| 62 private: | 64 private: |
| 63 ConfigAvailability availability_; | 65 ConfigAvailability availability_; |
| 64 ProxyConfig config_; | 66 ProxyConfig config_; |
| 65 ObserverList<Observer, true> observers_; | 67 ObserverList<Observer, true> observers_; |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 } // namespace | 70 } // namespace |
| 69 | 71 |
| 70 // A mock ProxyScriptFetcher. No result will be returned to the fetch client | |
| 71 // until we call NotifyFetchCompletion() to set the results. | |
| 72 class MockProxyScriptFetcher : public ProxyScriptFetcher { | |
| 73 public: | |
| 74 MockProxyScriptFetcher() | |
| 75 : pending_request_callback_(NULL), pending_request_text_(NULL) { | |
| 76 } | |
| 77 | |
| 78 // ProxyScriptFetcher implementation. | |
| 79 virtual int Fetch(const GURL& url, | |
| 80 string16* text, | |
| 81 CompletionCallback* callback) { | |
| 82 DCHECK(!has_pending_request()); | |
| 83 | |
| 84 // Save the caller's information, and have them wait. | |
| 85 pending_request_url_ = url; | |
| 86 pending_request_callback_ = callback; | |
| 87 pending_request_text_ = text; | |
| 88 return ERR_IO_PENDING; | |
| 89 } | |
| 90 | |
| 91 void NotifyFetchCompletion(int result, const std::string& ascii_text) { | |
| 92 DCHECK(has_pending_request()); | |
| 93 *pending_request_text_ = ASCIIToUTF16(ascii_text); | |
| 94 CompletionCallback* callback = pending_request_callback_; | |
| 95 pending_request_callback_ = NULL; | |
| 96 callback->Run(result); | |
| 97 } | |
| 98 | |
| 99 virtual void Cancel() {} | |
| 100 | |
| 101 virtual URLRequestContext* GetRequestContext() { return NULL; } | |
| 102 | |
| 103 const GURL& pending_request_url() const { | |
| 104 return pending_request_url_; | |
| 105 } | |
| 106 | |
| 107 bool has_pending_request() const { | |
| 108 return pending_request_callback_ != NULL; | |
| 109 } | |
| 110 | |
| 111 private: | |
| 112 GURL pending_request_url_; | |
| 113 CompletionCallback* pending_request_callback_; | |
| 114 string16* pending_request_text_; | |
| 115 }; | |
| 116 | |
| 117 TEST(ProxyServiceTest, Direct) { | 72 TEST(ProxyServiceTest, Direct) { |
| 118 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 73 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 119 ProxyService service(new MockProxyConfigService( | 74 ProxyService service(new MockProxyConfigService( |
| 120 ProxyConfig::CreateDirect()), resolver, NULL); | 75 ProxyConfig::CreateDirect()), resolver, NULL); |
| 121 | 76 |
| 122 GURL url("http://www.google.com/"); | 77 GURL url("http://www.google.com/"); |
| 123 | 78 |
| 124 ProxyInfo info; | 79 ProxyInfo info; |
| 125 TestCompletionCallback callback; | 80 TestCompletionCallback callback; |
| 126 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 81 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 TEST(ProxyServiceTest, InitialPACScriptDownload) { | 894 TEST(ProxyServiceTest, InitialPACScriptDownload) { |
| 940 MockProxyConfigService* config_service = | 895 MockProxyConfigService* config_service = |
| 941 new MockProxyConfigService("http://foopy/proxy.pac"); | 896 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 942 | 897 |
| 943 MockAsyncProxyResolverExpectsBytes* resolver = | 898 MockAsyncProxyResolverExpectsBytes* resolver = |
| 944 new MockAsyncProxyResolverExpectsBytes; | 899 new MockAsyncProxyResolverExpectsBytes; |
| 945 | 900 |
| 946 ProxyService service(config_service, resolver, NULL); | 901 ProxyService service(config_service, resolver, NULL); |
| 947 | 902 |
| 948 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 903 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 949 service.SetProxyScriptFetcher(fetcher); | 904 service.SetProxyScriptFetchers(fetcher, |
| 905 new DoNothingDhcpProxyScriptFetcher()); |
| 950 | 906 |
| 951 // Start 3 requests. | 907 // Start 3 requests. |
| 952 | 908 |
| 953 ProxyInfo info1; | 909 ProxyInfo info1; |
| 954 TestCompletionCallback callback1; | 910 TestCompletionCallback callback1; |
| 955 int rv = service.ResolveProxy( | 911 int rv = service.ResolveProxy( |
| 956 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 912 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); |
| 957 EXPECT_EQ(ERR_IO_PENDING, rv); | 913 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 958 | 914 |
| 959 // The first request should have triggered download of PAC script. | 915 // The first request should have triggered download of PAC script. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { | 974 TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { |
| 1019 MockProxyConfigService* config_service = | 975 MockProxyConfigService* config_service = |
| 1020 new MockProxyConfigService("http://foopy/proxy.pac"); | 976 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1021 | 977 |
| 1022 MockAsyncProxyResolverExpectsBytes* resolver = | 978 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1023 new MockAsyncProxyResolverExpectsBytes; | 979 new MockAsyncProxyResolverExpectsBytes; |
| 1024 | 980 |
| 1025 ProxyService service(config_service, resolver, NULL); | 981 ProxyService service(config_service, resolver, NULL); |
| 1026 | 982 |
| 1027 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 983 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1028 service.SetProxyScriptFetcher(fetcher); | 984 service.SetProxyScriptFetchers(fetcher, |
| 985 new DoNothingDhcpProxyScriptFetcher()); |
| 1029 | 986 |
| 1030 // Start 2 requests. | 987 // Start 2 requests. |
| 1031 | 988 |
| 1032 ProxyInfo info1; | 989 ProxyInfo info1; |
| 1033 TestCompletionCallback callback1; | 990 TestCompletionCallback callback1; |
| 1034 int rv = service.ResolveProxy( | 991 int rv = service.ResolveProxy( |
| 1035 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 992 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); |
| 1036 EXPECT_EQ(ERR_IO_PENDING, rv); | 993 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1037 | 994 |
| 1038 // The first request should have triggered download of PAC script. | 995 // The first request should have triggered download of PAC script. |
| 1039 EXPECT_TRUE(fetcher->has_pending_request()); | 996 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1040 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 997 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1041 | 998 |
| 1042 ProxyInfo info2; | 999 ProxyInfo info2; |
| 1043 TestCompletionCallback callback2; | 1000 TestCompletionCallback callback2; |
| 1044 rv = service.ResolveProxy( | 1001 rv = service.ResolveProxy( |
| 1045 GURL("http://request2"), &info2, &callback2, NULL, BoundNetLog()); | 1002 GURL("http://request2"), &info2, &callback2, NULL, BoundNetLog()); |
| 1046 EXPECT_EQ(ERR_IO_PENDING, rv); | 1003 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1047 | 1004 |
| 1048 // At this point the ProxyService should be waiting for the | 1005 // At this point the ProxyService should be waiting for the |
| 1049 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1006 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 1050 // PAC script download completion. | 1007 // PAC script download completion. |
| 1051 | 1008 |
| 1052 // We now change out the ProxyService's script fetcher. We should restart | 1009 // We now change out the ProxyService's script fetcher. We should restart |
| 1053 // the initialization with the new fetcher. | 1010 // the initialization with the new fetcher. |
| 1054 | 1011 |
| 1055 fetcher = new MockProxyScriptFetcher; | 1012 fetcher = new MockProxyScriptFetcher; |
| 1056 service.SetProxyScriptFetcher(fetcher); | 1013 service.SetProxyScriptFetchers(fetcher, |
| 1014 new DoNothingDhcpProxyScriptFetcher()); |
| 1057 | 1015 |
| 1058 // Nothing has been sent to the resolver yet. | 1016 // Nothing has been sent to the resolver yet. |
| 1059 EXPECT_TRUE(resolver->pending_requests().empty()); | 1017 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1060 | 1018 |
| 1061 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 1019 fetcher->NotifyFetchCompletion(OK, "pac-v1"); |
| 1062 | 1020 |
| 1063 // Now that the PAC script is downloaded, it will have been sent to the proxy | 1021 // Now that the PAC script is downloaded, it will have been sent to the proxy |
| 1064 // resolver. | 1022 // resolver. |
| 1065 EXPECT_EQ(ASCIIToUTF16("pac-v1"), | 1023 EXPECT_EQ(ASCIIToUTF16("pac-v1"), |
| 1066 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1024 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1067 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1025 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1068 | 1026 |
| 1069 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1027 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 1070 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1028 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1071 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1029 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 1072 } | 1030 } |
| 1073 | 1031 |
| 1074 // Test cancellation of a request, while the PAC script is being fetched. | 1032 // Test cancellation of a request, while the PAC script is being fetched. |
| 1075 TEST(ProxyServiceTest, CancelWhilePACFetching) { | 1033 TEST(ProxyServiceTest, CancelWhilePACFetching) { |
| 1076 MockProxyConfigService* config_service = | 1034 MockProxyConfigService* config_service = |
| 1077 new MockProxyConfigService("http://foopy/proxy.pac"); | 1035 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1078 | 1036 |
| 1079 MockAsyncProxyResolverExpectsBytes* resolver = | 1037 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1080 new MockAsyncProxyResolverExpectsBytes; | 1038 new MockAsyncProxyResolverExpectsBytes; |
| 1081 | 1039 |
| 1082 ProxyService service(config_service, resolver, NULL); | 1040 ProxyService service(config_service, resolver, NULL); |
| 1083 | 1041 |
| 1084 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1042 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1085 service.SetProxyScriptFetcher(fetcher); | 1043 service.SetProxyScriptFetchers(fetcher, |
| 1044 new DoNothingDhcpProxyScriptFetcher()); |
| 1086 | 1045 |
| 1087 // Start 3 requests. | 1046 // Start 3 requests. |
| 1088 ProxyInfo info1; | 1047 ProxyInfo info1; |
| 1089 TestCompletionCallback callback1; | 1048 TestCompletionCallback callback1; |
| 1090 ProxyService::PacRequest* request1; | 1049 ProxyService::PacRequest* request1; |
| 1091 CapturingBoundNetLog log1(CapturingNetLog::kUnbounded); | 1050 CapturingBoundNetLog log1(CapturingNetLog::kUnbounded); |
| 1092 int rv = service.ResolveProxy( | 1051 int rv = service.ResolveProxy( |
| 1093 GURL("http://request1"), &info1, &callback1, &request1, log1.bound()); | 1052 GURL("http://request1"), &info1, &callback1, &request1, log1.bound()); |
| 1094 EXPECT_EQ(ERR_IO_PENDING, rv); | 1053 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1095 | 1054 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 config.set_auto_detect(true); | 1125 config.set_auto_detect(true); |
| 1167 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1126 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 1168 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. | 1127 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. |
| 1169 | 1128 |
| 1170 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1129 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1171 MockAsyncProxyResolverExpectsBytes* resolver = | 1130 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1172 new MockAsyncProxyResolverExpectsBytes; | 1131 new MockAsyncProxyResolverExpectsBytes; |
| 1173 ProxyService service(config_service, resolver, NULL); | 1132 ProxyService service(config_service, resolver, NULL); |
| 1174 | 1133 |
| 1175 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1134 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1176 service.SetProxyScriptFetcher(fetcher); | 1135 service.SetProxyScriptFetchers(fetcher, |
| 1136 new DoNothingDhcpProxyScriptFetcher()); |
| 1177 | 1137 |
| 1178 // Start 2 requests. | 1138 // Start 2 requests. |
| 1179 | 1139 |
| 1180 ProxyInfo info1; | 1140 ProxyInfo info1; |
| 1181 TestCompletionCallback callback1; | 1141 TestCompletionCallback callback1; |
| 1182 int rv = service.ResolveProxy( | 1142 int rv = service.ResolveProxy( |
| 1183 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1143 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); |
| 1184 EXPECT_EQ(ERR_IO_PENDING, rv); | 1144 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1185 | 1145 |
| 1186 ProxyInfo info2; | 1146 ProxyInfo info2; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 config.set_auto_detect(true); | 1196 config.set_auto_detect(true); |
| 1237 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1197 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 1238 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. | 1198 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. |
| 1239 | 1199 |
| 1240 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1200 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1241 MockAsyncProxyResolverExpectsBytes* resolver = | 1201 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1242 new MockAsyncProxyResolverExpectsBytes; | 1202 new MockAsyncProxyResolverExpectsBytes; |
| 1243 ProxyService service(config_service, resolver, NULL); | 1203 ProxyService service(config_service, resolver, NULL); |
| 1244 | 1204 |
| 1245 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1205 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1246 service.SetProxyScriptFetcher(fetcher); | 1206 service.SetProxyScriptFetchers(fetcher, |
| 1207 new DoNothingDhcpProxyScriptFetcher()); |
| 1247 | 1208 |
| 1248 // Start 2 requests. | 1209 // Start 2 requests. |
| 1249 | 1210 |
| 1250 ProxyInfo info1; | 1211 ProxyInfo info1; |
| 1251 TestCompletionCallback callback1; | 1212 TestCompletionCallback callback1; |
| 1252 int rv = service.ResolveProxy( | 1213 int rv = service.ResolveProxy( |
| 1253 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1214 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); |
| 1254 EXPECT_EQ(ERR_IO_PENDING, rv); | 1215 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1255 | 1216 |
| 1256 ProxyInfo info2; | 1217 ProxyInfo info2; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 config.set_auto_detect(true); | 1272 config.set_auto_detect(true); |
| 1312 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1273 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 1313 config.proxy_rules().ParseFromString("http=foopy:80"); | 1274 config.proxy_rules().ParseFromString("http=foopy:80"); |
| 1314 | 1275 |
| 1315 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1276 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1316 MockAsyncProxyResolverExpectsBytes* resolver = | 1277 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1317 new MockAsyncProxyResolverExpectsBytes; | 1278 new MockAsyncProxyResolverExpectsBytes; |
| 1318 ProxyService service(config_service, resolver, NULL); | 1279 ProxyService service(config_service, resolver, NULL); |
| 1319 | 1280 |
| 1320 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1281 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1321 service.SetProxyScriptFetcher(fetcher); | 1282 service.SetProxyScriptFetchers(fetcher, |
| 1283 new DoNothingDhcpProxyScriptFetcher()); |
| 1322 | 1284 |
| 1323 // Start 2 requests. | 1285 // Start 2 requests. |
| 1324 | 1286 |
| 1325 ProxyInfo info1; | 1287 ProxyInfo info1; |
| 1326 TestCompletionCallback callback1; | 1288 TestCompletionCallback callback1; |
| 1327 int rv = service.ResolveProxy( | 1289 int rv = service.ResolveProxy( |
| 1328 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1290 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); |
| 1329 EXPECT_EQ(ERR_IO_PENDING, rv); | 1291 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1330 | 1292 |
| 1331 ProxyInfo info2; | 1293 ProxyInfo info2; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1330 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 1369 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used. | 1331 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used. |
| 1370 config.proxy_rules().bypass_rules.ParseFromString("www.google.com"); | 1332 config.proxy_rules().bypass_rules.ParseFromString("www.google.com"); |
| 1371 | 1333 |
| 1372 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1334 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1373 MockAsyncProxyResolverExpectsBytes* resolver = | 1335 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1374 new MockAsyncProxyResolverExpectsBytes; | 1336 new MockAsyncProxyResolverExpectsBytes; |
| 1375 ProxyService service(config_service, resolver, NULL); | 1337 ProxyService service(config_service, resolver, NULL); |
| 1376 | 1338 |
| 1377 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1339 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1378 service.SetProxyScriptFetcher(fetcher); | 1340 service.SetProxyScriptFetchers(fetcher, |
| 1341 new DoNothingDhcpProxyScriptFetcher()); |
| 1379 | 1342 |
| 1380 // Start 1 requests. | 1343 // Start 1 requests. |
| 1381 | 1344 |
| 1382 ProxyInfo info1; | 1345 ProxyInfo info1; |
| 1383 TestCompletionCallback callback1; | 1346 TestCompletionCallback callback1; |
| 1384 int rv = service.ResolveProxy( | 1347 int rv = service.ResolveProxy( |
| 1385 GURL("http://www.google.com"), &info1, &callback1, NULL, BoundNetLog()); | 1348 GURL("http://www.google.com"), &info1, &callback1, NULL, BoundNetLog()); |
| 1386 EXPECT_EQ(ERR_IO_PENDING, rv); | 1349 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1387 | 1350 |
| 1388 // Check that nothing has been sent to the proxy resolver yet. | 1351 // Check that nothing has been sent to the proxy resolver yet. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1435 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { | 1398 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { |
| 1436 ProxyConfig config = | 1399 ProxyConfig config = |
| 1437 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 1400 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
| 1438 | 1401 |
| 1439 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1402 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1440 MockAsyncProxyResolverExpectsBytes* resolver = | 1403 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1441 new MockAsyncProxyResolverExpectsBytes; | 1404 new MockAsyncProxyResolverExpectsBytes; |
| 1442 ProxyService service(config_service, resolver, NULL); | 1405 ProxyService service(config_service, resolver, NULL); |
| 1443 | 1406 |
| 1444 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1407 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1445 service.SetProxyScriptFetcher(fetcher); | 1408 service.SetProxyScriptFetchers(fetcher, |
| 1409 new DoNothingDhcpProxyScriptFetcher()); |
| 1446 | 1410 |
| 1447 // Start 1 request. | 1411 // Start 1 request. |
| 1448 | 1412 |
| 1449 ProxyInfo info1; | 1413 ProxyInfo info1; |
| 1450 TestCompletionCallback callback1; | 1414 TestCompletionCallback callback1; |
| 1451 int rv = service.ResolveProxy( | 1415 int rv = service.ResolveProxy( |
| 1452 GURL("http://www.google.com"), &info1, &callback1, NULL, BoundNetLog()); | 1416 GURL("http://www.google.com"), &info1, &callback1, NULL, BoundNetLog()); |
| 1453 EXPECT_EQ(ERR_IO_PENDING, rv); | 1417 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1454 | 1418 |
| 1455 // Check that nothing has been sent to the proxy resolver yet. | 1419 // Check that nothing has been sent to the proxy resolver yet. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 new MockProxyConfigService("http://foopy/proxy.pac"); | 1530 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1567 | 1531 |
| 1568 MockAsyncProxyResolverExpectsBytes* resolver = | 1532 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1569 new MockAsyncProxyResolverExpectsBytes; | 1533 new MockAsyncProxyResolverExpectsBytes; |
| 1570 | 1534 |
| 1571 CapturingNetLog log(CapturingNetLog::kUnbounded); | 1535 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 1572 | 1536 |
| 1573 ProxyService service(config_service, resolver, &log); | 1537 ProxyService service(config_service, resolver, &log); |
| 1574 | 1538 |
| 1575 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1539 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1576 service.SetProxyScriptFetcher(fetcher); | 1540 service.SetProxyScriptFetchers(fetcher, |
| 1541 new DoNothingDhcpProxyScriptFetcher()); |
| 1577 | 1542 |
| 1578 // Disable the "wait after IP address changes" hack, so this unit-test can | 1543 // Disable the "wait after IP address changes" hack, so this unit-test can |
| 1579 // complete quickly. | 1544 // complete quickly. |
| 1580 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 1545 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
| 1581 | 1546 |
| 1582 // Start 1 request. | 1547 // Start 1 request. |
| 1583 | 1548 |
| 1584 ProxyInfo info1; | 1549 ProxyInfo info1; |
| 1585 TestCompletionCallback callback1; | 1550 TestCompletionCallback callback1; |
| 1586 int rv = service.ResolveProxy( | 1551 int rv = service.ResolveProxy( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 log.GetEntries(&entries); | 1631 log.GetEntries(&entries); |
| 1667 | 1632 |
| 1668 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, | 1633 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, |
| 1669 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 1634 NetLog::TYPE_PROXY_CONFIG_CHANGED)); |
| 1670 ASSERT_EQ(13u, entries.size()); | 1635 ASSERT_EQ(13u, entries.size()); |
| 1671 for (size_t i = 1; i < entries.size(); ++i) | 1636 for (size_t i = 1; i < entries.size(); ++i) |
| 1672 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); | 1637 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); |
| 1673 } | 1638 } |
| 1674 | 1639 |
| 1675 } // namespace net | 1640 } // namespace net |
| OLD | NEW |