| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 ProxyInfo info; | 123 ProxyInfo info; |
| 124 TestCompletionCallback callback; | 124 TestCompletionCallback callback; |
| 125 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 125 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 126 int rv = service->ResolveProxy(url, &info, &callback, NULL, log.bound()); | 126 int rv = service->ResolveProxy(url, &info, &callback, NULL, log.bound()); |
| 127 EXPECT_EQ(OK, rv); | 127 EXPECT_EQ(OK, rv); |
| 128 EXPECT_TRUE(resolver->pending_requests().empty()); | 128 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 129 | 129 |
| 130 EXPECT_TRUE(info.is_direct()); | 130 EXPECT_TRUE(info.is_direct()); |
| 131 | 131 |
| 132 // Check the NetLog was filled correctly. | 132 // Check the NetLog was filled correctly. |
| 133 EXPECT_EQ(3u, log.entries().size()); | 133 net::CapturingNetLog::EntryList entries; |
| 134 log.GetEntries(&entries); |
| 135 |
| 136 EXPECT_EQ(3u, entries.size()); |
| 134 EXPECT_TRUE(LogContainsBeginEvent( | 137 EXPECT_TRUE(LogContainsBeginEvent( |
| 135 log.entries(), 0, NetLog::TYPE_PROXY_SERVICE)); | 138 entries, 0, NetLog::TYPE_PROXY_SERVICE)); |
| 136 EXPECT_TRUE(LogContainsEvent( | 139 EXPECT_TRUE(LogContainsEvent( |
| 137 log.entries(), 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 140 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
| 138 NetLog::PHASE_NONE)); | 141 NetLog::PHASE_NONE)); |
| 139 EXPECT_TRUE(LogContainsEndEvent( | 142 EXPECT_TRUE(LogContainsEndEvent( |
| 140 log.entries(), 2, NetLog::TYPE_PROXY_SERVICE)); | 143 entries, 2, NetLog::TYPE_PROXY_SERVICE)); |
| 141 } | 144 } |
| 142 | 145 |
| 143 TEST(ProxyServiceTest, PAC) { | 146 TEST(ProxyServiceTest, PAC) { |
| 144 MockProxyConfigService* config_service = | 147 MockProxyConfigService* config_service = |
| 145 new MockProxyConfigService("http://foopy/proxy.pac"); | 148 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 146 | 149 |
| 147 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 150 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 148 | 151 |
| 149 scoped_refptr<ProxyService> service( | 152 scoped_refptr<ProxyService> service( |
| 150 new ProxyService(config_service, resolver, NULL)); | 153 new ProxyService(config_service, resolver, NULL)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 167 | 170 |
| 168 // Set the result in proxy resolver. | 171 // Set the result in proxy resolver. |
| 169 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); | 172 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); |
| 170 resolver->pending_requests()[0]->CompleteNow(OK); | 173 resolver->pending_requests()[0]->CompleteNow(OK); |
| 171 | 174 |
| 172 EXPECT_EQ(OK, callback.WaitForResult()); | 175 EXPECT_EQ(OK, callback.WaitForResult()); |
| 173 EXPECT_FALSE(info.is_direct()); | 176 EXPECT_FALSE(info.is_direct()); |
| 174 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); | 177 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); |
| 175 | 178 |
| 176 // Check the NetLog was filled correctly. | 179 // Check the NetLog was filled correctly. |
| 177 EXPECT_EQ(5u, log.entries().size()); | 180 net::CapturingNetLog::EntryList entries; |
| 181 log.GetEntries(&entries); |
| 182 |
| 183 EXPECT_EQ(5u, entries.size()); |
| 178 EXPECT_TRUE(LogContainsBeginEvent( | 184 EXPECT_TRUE(LogContainsBeginEvent( |
| 179 log.entries(), 0, NetLog::TYPE_PROXY_SERVICE)); | 185 entries, 0, NetLog::TYPE_PROXY_SERVICE)); |
| 180 EXPECT_TRUE(LogContainsBeginEvent( | 186 EXPECT_TRUE(LogContainsBeginEvent( |
| 181 log.entries(), 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 187 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
| 182 EXPECT_TRUE(LogContainsEndEvent( | 188 EXPECT_TRUE(LogContainsEndEvent( |
| 183 log.entries(), 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 189 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
| 184 EXPECT_TRUE(LogContainsEndEvent( | 190 EXPECT_TRUE(LogContainsEndEvent( |
| 185 log.entries(), 4, NetLog::TYPE_PROXY_SERVICE)); | 191 entries, 4, NetLog::TYPE_PROXY_SERVICE)); |
| 186 } | 192 } |
| 187 | 193 |
| 188 // Test that the proxy resolver does not see the URL's username/password | 194 // Test that the proxy resolver does not see the URL's username/password |
| 189 // or its reference section. | 195 // or its reference section. |
| 190 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { | 196 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { |
| 191 MockProxyConfigService* config_service = | 197 MockProxyConfigService* config_service = |
| 192 new MockProxyConfigService("http://foopy/proxy.pac"); | 198 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 193 | 199 |
| 194 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 200 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 195 | 201 |
| (...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 resolver->pending_requests()[0]->CompleteNow(OK); | 1148 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1143 | 1149 |
| 1144 EXPECT_EQ(OK, callback3.WaitForResult()); | 1150 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 1145 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 1151 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
| 1146 | 1152 |
| 1147 EXPECT_TRUE(resolver->cancelled_requests().empty()); | 1153 EXPECT_TRUE(resolver->cancelled_requests().empty()); |
| 1148 | 1154 |
| 1149 EXPECT_FALSE(callback1.have_result()); // Cancelled. | 1155 EXPECT_FALSE(callback1.have_result()); // Cancelled. |
| 1150 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 1156 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
| 1151 | 1157 |
| 1158 net::CapturingNetLog::EntryList entries1; |
| 1159 log1.GetEntries(&entries1); |
| 1160 |
| 1152 // Check the NetLog for request 1 (which was cancelled) got filled properly. | 1161 // Check the NetLog for request 1 (which was cancelled) got filled properly. |
| 1153 EXPECT_EQ(4u, log1.entries().size()); | 1162 EXPECT_EQ(4u, entries1.size()); |
| 1154 EXPECT_TRUE(LogContainsBeginEvent( | 1163 EXPECT_TRUE(LogContainsBeginEvent( |
| 1155 log1.entries(), 0, NetLog::TYPE_PROXY_SERVICE)); | 1164 entries1, 0, NetLog::TYPE_PROXY_SERVICE)); |
| 1156 EXPECT_TRUE(LogContainsBeginEvent( | 1165 EXPECT_TRUE(LogContainsBeginEvent( |
| 1157 log1.entries(), 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 1166 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
| 1158 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before | 1167 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before |
| 1159 // the cancellation occured. | 1168 // the cancellation occured. |
| 1160 EXPECT_TRUE(LogContainsEvent( | 1169 EXPECT_TRUE(LogContainsEvent( |
| 1161 log1.entries(), 2, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); | 1170 entries1, 2, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); |
| 1162 EXPECT_TRUE(LogContainsEndEvent( | 1171 EXPECT_TRUE(LogContainsEndEvent( |
| 1163 log1.entries(), 3, NetLog::TYPE_PROXY_SERVICE)); | 1172 entries1, 3, NetLog::TYPE_PROXY_SERVICE)); |
| 1164 } | 1173 } |
| 1165 | 1174 |
| 1166 // Test that if auto-detect fails, we fall-back to the custom pac. | 1175 // Test that if auto-detect fails, we fall-back to the custom pac. |
| 1167 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { | 1176 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { |
| 1168 ProxyConfig config; | 1177 ProxyConfig config; |
| 1169 config.set_auto_detect(true); | 1178 config.set_auto_detect(true); |
| 1170 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1179 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 1171 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. | 1180 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. |
| 1172 | 1181 |
| 1173 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1182 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 resolver->pending_requests()[0]->CompleteNow(OK); | 1681 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1673 | 1682 |
| 1674 // Wait for completion callback, and verify that the request ran as expected. | 1683 // Wait for completion callback, and verify that the request ran as expected. |
| 1675 EXPECT_EQ(OK, callback2.WaitForResult()); | 1684 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1676 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1685 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 1677 | 1686 |
| 1678 // Check that the expected events were outputted to the log stream. | 1687 // Check that the expected events were outputted to the log stream. |
| 1679 // In particular, PROXY_CONFIG_CHANGED should have only been emitted once | 1688 // In particular, PROXY_CONFIG_CHANGED should have only been emitted once |
| 1680 // (for the initial setup), and NOT a second time when the IP address | 1689 // (for the initial setup), and NOT a second time when the IP address |
| 1681 // changed. | 1690 // changed. |
| 1682 EXPECT_TRUE(LogContainsEntryWithType(log.entries(), 0, | 1691 net::CapturingNetLog::EntryList entries; |
| 1692 log.GetEntries(&entries); |
| 1693 |
| 1694 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, |
| 1683 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 1695 NetLog::TYPE_PROXY_CONFIG_CHANGED)); |
| 1684 ASSERT_EQ(13u, log.entries().size()); | 1696 ASSERT_EQ(13u, entries.size()); |
| 1685 for (size_t i = 1; i < log.entries().size(); ++i) | 1697 for (size_t i = 1; i < entries.size(); ++i) |
| 1686 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, log.entries()[i].type); | 1698 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); |
| 1687 } | 1699 } |
| 1688 | 1700 |
| 1689 } // namespace net | 1701 } // namespace net |
| OLD | NEW |