| 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_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" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); | 101 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); |
| 102 int rv = service->ResolveProxy(url, &info, &callback, NULL, log); | 102 int rv = service->ResolveProxy(url, &info, &callback, NULL, log); |
| 103 EXPECT_EQ(OK, rv); | 103 EXPECT_EQ(OK, rv); |
| 104 EXPECT_TRUE(resolver->pending_requests().empty()); | 104 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 105 EXPECT_TRUE(NULL == service->init_proxy_resolver_log()); | 105 EXPECT_TRUE(NULL == service->init_proxy_resolver_log()); |
| 106 | 106 |
| 107 EXPECT_TRUE(info.is_direct()); | 107 EXPECT_TRUE(info.is_direct()); |
| 108 | 108 |
| 109 // Check the LoadLog was filled correctly. | 109 // Check the LoadLog was filled correctly. |
| 110 EXPECT_EQ(5u, log->entries().size()); | 110 EXPECT_EQ(5u, log->entries().size()); |
| 111 ExpectLogContains(log, 0, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_BEGIN); | 111 EXPECT_TRUE(LogContainsBeginEvent(*log, 0, LoadLog::TYPE_PROXY_SERVICE)); |
| 112 ExpectLogContains(log, 4, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_END); | 112 EXPECT_TRUE(LogContainsEndEvent(*log, 4, LoadLog::TYPE_PROXY_SERVICE)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 TEST(ProxyServiceTest, PAC) { | 115 TEST(ProxyServiceTest, PAC) { |
| 116 MockProxyConfigService* config_service = | 116 MockProxyConfigService* config_service = |
| 117 new MockProxyConfigService("http://foopy/proxy.pac"); | 117 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 118 | 118 |
| 119 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 119 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 120 | 120 |
| 121 scoped_refptr<ProxyService> service( | 121 scoped_refptr<ProxyService> service( |
| 122 new ProxyService(config_service, resolver, NULL)); | 122 new ProxyService(config_service, resolver, NULL)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 140 // Set the result in proxy resolver. | 140 // Set the result in proxy resolver. |
| 141 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); | 141 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); |
| 142 resolver->pending_requests()[0]->CompleteNow(OK); | 142 resolver->pending_requests()[0]->CompleteNow(OK); |
| 143 | 143 |
| 144 EXPECT_EQ(OK, callback.WaitForResult()); | 144 EXPECT_EQ(OK, callback.WaitForResult()); |
| 145 EXPECT_FALSE(info.is_direct()); | 145 EXPECT_FALSE(info.is_direct()); |
| 146 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); | 146 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); |
| 147 | 147 |
| 148 // Check the LoadLog was filled correctly. | 148 // Check the LoadLog was filled correctly. |
| 149 EXPECT_EQ(7u, log->entries().size()); | 149 EXPECT_EQ(7u, log->entries().size()); |
| 150 ExpectLogContains(log, 0, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_BEGIN); | 150 EXPECT_TRUE(LogContainsBeginEvent(*log, 0, LoadLog::TYPE_PROXY_SERVICE)); |
| 151 ExpectLogContains(log, 3, LoadLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC, | 151 EXPECT_TRUE(LogContainsBeginEvent( |
| 152 LoadLog::PHASE_BEGIN); | 152 *log, 3, LoadLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
| 153 ExpectLogContains(log, 4, LoadLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC, | 153 EXPECT_TRUE(LogContainsEndEvent( |
| 154 LoadLog::PHASE_END); | 154 *log, 4, LoadLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
| 155 ExpectLogContains(log, 6, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_END); | 155 EXPECT_TRUE(LogContainsEndEvent(*log, 6, LoadLog::TYPE_PROXY_SERVICE)); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Test that the proxy resolver does not see the URL's username/password | 158 // Test that the proxy resolver does not see the URL's username/password |
| 159 // or its reference section. | 159 // or its reference section. |
| 160 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { | 160 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { |
| 161 MockProxyConfigService* config_service = | 161 MockProxyConfigService* config_service = |
| 162 new MockProxyConfigService("http://foopy/proxy.pac"); | 162 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 163 | 163 |
| 164 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 164 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 165 | 165 |
| (...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 EXPECT_EQ(OK, callback3.WaitForResult()); | 1260 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 1261 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 1261 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
| 1262 | 1262 |
| 1263 EXPECT_TRUE(resolver->cancelled_requests().empty()); | 1263 EXPECT_TRUE(resolver->cancelled_requests().empty()); |
| 1264 | 1264 |
| 1265 EXPECT_FALSE(callback1.have_result()); // Cancelled. | 1265 EXPECT_FALSE(callback1.have_result()); // Cancelled. |
| 1266 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 1266 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
| 1267 | 1267 |
| 1268 // Check the LoadLog for request 1 (which was cancelled) got filled properly. | 1268 // Check the LoadLog for request 1 (which was cancelled) got filled properly. |
| 1269 EXPECT_EQ(6u, log1->entries().size()); | 1269 EXPECT_EQ(6u, log1->entries().size()); |
| 1270 ExpectLogContains(log1, 0, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_BEGIN); | 1270 EXPECT_TRUE(LogContainsBeginEvent(*log1, 0, LoadLog::TYPE_PROXY_SERVICE)); |
| 1271 ExpectLogContains(log1, 3, LoadLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC, | 1271 EXPECT_TRUE(LogContainsBeginEvent( |
| 1272 LoadLog::PHASE_BEGIN); | 1272 *log1, 3, LoadLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
| 1273 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before | 1273 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before |
| 1274 // the cancellation occured. | 1274 // the cancellation occured. |
| 1275 ExpectLogContains(log1, 4, LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); | 1275 EXPECT_TRUE(LogContainsEvent( |
| 1276 ExpectLogContains(log1, 5, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_END); | 1276 *log1, 4, LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE)); |
| 1277 EXPECT_TRUE(LogContainsEndEvent(*log1, 5, LoadLog::TYPE_PROXY_SERVICE)); |
| 1277 } | 1278 } |
| 1278 | 1279 |
| 1279 // Test that if auto-detect fails, we fall-back to the custom pac. | 1280 // Test that if auto-detect fails, we fall-back to the custom pac. |
| 1280 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { | 1281 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { |
| 1281 ProxyConfig config; | 1282 ProxyConfig config; |
| 1282 config.auto_detect = true; | 1283 config.auto_detect = true; |
| 1283 config.pac_url = GURL("http://foopy/proxy.pac"); | 1284 config.pac_url = GURL("http://foopy/proxy.pac"); |
| 1284 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used. | 1285 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used. |
| 1285 | 1286 |
| 1286 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1287 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 // Complete the pending second request. | 1872 // Complete the pending second request. |
| 1872 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 1873 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 1873 resolver->pending_requests()[0]->CompleteNow(OK); | 1874 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1874 | 1875 |
| 1875 // Wait for completion callback, and verify that the request ran as expected. | 1876 // Wait for completion callback, and verify that the request ran as expected. |
| 1876 EXPECT_EQ(OK, callback2.WaitForResult()); | 1877 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1877 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1878 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 1878 } | 1879 } |
| 1879 | 1880 |
| 1880 } // namespace net | 1881 } // namespace net |
| OLD | NEW |