| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "net/base/load_log.h" | 8 #include "net/base/net_log.h" |
| 9 #include "net/base/load_log_util.h" | 9 #include "net/base/net_log_unittest.h" |
| 10 #include "net/base/load_log_unittest.h" | |
| 11 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| 12 #include "net/proxy/init_proxy_resolver.h" | 11 #include "net/proxy/init_proxy_resolver.h" |
| 13 #include "net/proxy/proxy_config.h" | 12 #include "net/proxy/proxy_config.h" |
| 14 #include "net/proxy/proxy_resolver.h" | 13 #include "net/proxy/proxy_resolver.h" |
| 15 #include "net/proxy/proxy_script_fetcher.h" | 14 #include "net/proxy/proxy_script_fetcher.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 16 |
| 18 namespace net { | 17 namespace net { |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 class RuleBasedProxyResolver : public ProxyResolver { | 112 class RuleBasedProxyResolver : public ProxyResolver { |
| 114 public: | 113 public: |
| 115 RuleBasedProxyResolver(const Rules* rules, bool expects_pac_bytes) | 114 RuleBasedProxyResolver(const Rules* rules, bool expects_pac_bytes) |
| 116 : ProxyResolver(expects_pac_bytes), rules_(rules) {} | 115 : ProxyResolver(expects_pac_bytes), rules_(rules) {} |
| 117 | 116 |
| 118 // ProxyResolver implementation: | 117 // ProxyResolver implementation: |
| 119 virtual int GetProxyForURL(const GURL& /*url*/, | 118 virtual int GetProxyForURL(const GURL& /*url*/, |
| 120 ProxyInfo* /*results*/, | 119 ProxyInfo* /*results*/, |
| 121 CompletionCallback* /*callback*/, | 120 CompletionCallback* /*callback*/, |
| 122 RequestHandle* /*request_handle*/, | 121 RequestHandle* /*request_handle*/, |
| 123 LoadLog* /*load_log*/) { | 122 const BoundNetLog& /*net_log*/) { |
| 124 NOTREACHED(); | 123 NOTREACHED(); |
| 125 return ERR_UNEXPECTED; | 124 return ERR_UNEXPECTED; |
| 126 } | 125 } |
| 127 | 126 |
| 128 virtual void CancelRequest(RequestHandle request_handle) { | 127 virtual void CancelRequest(RequestHandle request_handle) { |
| 129 NOTREACHED(); | 128 NOTREACHED(); |
| 130 } | 129 } |
| 131 | 130 |
| 132 virtual int SetPacScript(const GURL& pac_url, | 131 virtual int SetPacScript(const GURL& pac_url, |
| 133 const std::string& pac_bytes, | 132 const std::string& pac_bytes, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 Rules rules; | 164 Rules rules; |
| 166 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 165 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 167 RuleBasedProxyScriptFetcher fetcher(&rules); | 166 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 168 | 167 |
| 169 ProxyConfig config; | 168 ProxyConfig config; |
| 170 config.set_pac_url(GURL("http://custom/proxy.pac")); | 169 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 171 | 170 |
| 172 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 171 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 173 | 172 |
| 174 TestCompletionCallback callback; | 173 TestCompletionCallback callback; |
| 175 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); | 174 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 176 InitProxyResolver init(&resolver, &fetcher); | 175 InitProxyResolver init(&resolver, &fetcher); |
| 177 EXPECT_EQ(OK, init.Init(config, &callback, log)); | 176 EXPECT_EQ(OK, init.Init(config, &callback, log.bound())); |
| 178 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); | 177 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); |
| 179 | 178 |
| 180 // Check the LoadLog was filled correctly. | 179 // Check the NetLog was filled correctly. |
| 181 EXPECT_EQ(9u, log->entries().size()); | 180 EXPECT_EQ(9u, log.entries().size()); |
| 182 EXPECT_TRUE(LogContainsBeginEvent( | 181 EXPECT_TRUE(LogContainsBeginEvent( |
| 183 *log, 0, LoadLog::TYPE_INIT_PROXY_RESOLVER)); | 182 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 184 EXPECT_TRUE(LogContainsBeginEvent( | 183 EXPECT_TRUE(LogContainsBeginEvent( |
| 185 *log, 1, LoadLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 184 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 186 EXPECT_TRUE(LogContainsEndEvent( | 185 EXPECT_TRUE(LogContainsEndEvent( |
| 187 *log, 4, LoadLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 186 log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 188 EXPECT_TRUE(LogContainsBeginEvent( | 187 EXPECT_TRUE(LogContainsBeginEvent( |
| 189 *log, 5, LoadLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); | 188 log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); |
| 190 EXPECT_TRUE(LogContainsEndEvent( | 189 EXPECT_TRUE(LogContainsEndEvent( |
| 191 *log, 7, LoadLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); | 190 log.entries(), 7, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); |
| 192 EXPECT_TRUE(LogContainsEndEvent(*log, 8, LoadLog::TYPE_INIT_PROXY_RESOLVER)); | 191 EXPECT_TRUE(LogContainsEndEvent( |
| 192 log.entries(), 8, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Fail downloading the custom PAC script. | 195 // Fail downloading the custom PAC script. |
| 196 TEST(InitProxyResolverTest, CustomPacFails1) { | 196 TEST(InitProxyResolverTest, CustomPacFails1) { |
| 197 Rules rules; | 197 Rules rules; |
| 198 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 198 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 199 RuleBasedProxyScriptFetcher fetcher(&rules); | 199 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 200 | 200 |
| 201 ProxyConfig config; | 201 ProxyConfig config; |
| 202 config.set_pac_url(GURL("http://custom/proxy.pac")); | 202 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 203 | 203 |
| 204 rules.AddFailDownloadRule("http://custom/proxy.pac"); | 204 rules.AddFailDownloadRule("http://custom/proxy.pac"); |
| 205 | 205 |
| 206 TestCompletionCallback callback; | 206 TestCompletionCallback callback; |
| 207 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); | 207 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 208 InitProxyResolver init(&resolver, &fetcher); | 208 InitProxyResolver init(&resolver, &fetcher); |
| 209 EXPECT_EQ(kFailedDownloading, init.Init(config, &callback, log)); | 209 EXPECT_EQ(kFailedDownloading, init.Init(config, &callback, log.bound())); |
| 210 EXPECT_EQ("", resolver.pac_bytes()); | 210 EXPECT_EQ("", resolver.pac_bytes()); |
| 211 | 211 |
| 212 // Check the LoadLog was filled correctly. | 212 // Check the NetLog was filled correctly. |
| 213 EXPECT_EQ(6u, log->entries().size()); | 213 EXPECT_EQ(6u, log.entries().size()); |
| 214 EXPECT_TRUE(LogContainsBeginEvent( | 214 EXPECT_TRUE(LogContainsBeginEvent( |
| 215 *log, 0, LoadLog::TYPE_INIT_PROXY_RESOLVER)); | 215 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 216 EXPECT_TRUE(LogContainsBeginEvent( | 216 EXPECT_TRUE(LogContainsBeginEvent( |
| 217 *log, 1, LoadLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 217 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 218 EXPECT_TRUE(LogContainsEndEvent( | 218 EXPECT_TRUE(LogContainsEndEvent( |
| 219 *log, 4, LoadLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 219 log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 220 EXPECT_TRUE(LogContainsEndEvent(*log, 5, LoadLog::TYPE_INIT_PROXY_RESOLVER)); | 220 EXPECT_TRUE(LogContainsEndEvent( |
| 221 log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 221 } | 222 } |
| 222 | 223 |
| 223 // Fail parsing the custom PAC script. | 224 // Fail parsing the custom PAC script. |
| 224 TEST(InitProxyResolverTest, CustomPacFails2) { | 225 TEST(InitProxyResolverTest, CustomPacFails2) { |
| 225 Rules rules; | 226 Rules rules; |
| 226 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 227 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 227 RuleBasedProxyScriptFetcher fetcher(&rules); | 228 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 228 | 229 |
| 229 ProxyConfig config; | 230 ProxyConfig config; |
| 230 config.set_pac_url(GURL("http://custom/proxy.pac")); | 231 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 RuleBasedProxyScriptFetcher fetcher(&rules); | 295 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 295 | 296 |
| 296 ProxyConfig config; | 297 ProxyConfig config; |
| 297 config.set_auto_detect(true); | 298 config.set_auto_detect(true); |
| 298 config.set_pac_url(GURL("http://custom/proxy.pac")); | 299 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 299 | 300 |
| 300 rules.AddFailParsingRule("http://wpad/wpad.dat"); | 301 rules.AddFailParsingRule("http://wpad/wpad.dat"); |
| 301 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 302 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 302 | 303 |
| 303 TestCompletionCallback callback; | 304 TestCompletionCallback callback; |
| 304 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); | 305 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 305 InitProxyResolver init(&resolver, &fetcher); | 306 InitProxyResolver init(&resolver, &fetcher); |
| 306 EXPECT_EQ(OK, init.Init(config, &callback, log)); | 307 EXPECT_EQ(OK, init.Init(config, &callback, log.bound())); |
| 307 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); | 308 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); |
| 308 | 309 |
| 309 // Check the LoadLog was filled correctly. | 310 // Check the NetLog was filled correctly. |
| 310 // (Note that the Fetch and Set states are repeated since both WPAD and custom | 311 // (Note that the Fetch and Set states are repeated since both WPAD and custom |
| 311 // PAC scripts are tried). | 312 // PAC scripts are tried). |
| 312 EXPECT_EQ(17u, log->entries().size()); | 313 EXPECT_EQ(17u, log.entries().size()); |
| 313 EXPECT_TRUE(LogContainsBeginEvent( | 314 EXPECT_TRUE(LogContainsBeginEvent( |
| 314 *log, 0, LoadLog::TYPE_INIT_PROXY_RESOLVER)); | 315 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 315 EXPECT_TRUE(LogContainsBeginEvent( | 316 EXPECT_TRUE(LogContainsBeginEvent( |
| 316 *log, 1, LoadLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 317 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 317 EXPECT_TRUE(LogContainsEndEvent( | 318 EXPECT_TRUE(LogContainsEndEvent( |
| 318 *log, 4, LoadLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 319 log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 319 EXPECT_TRUE(LogContainsBeginEvent( | 320 EXPECT_TRUE(LogContainsBeginEvent( |
| 320 *log, 5, LoadLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); | 321 log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); |
| 321 EXPECT_TRUE(LogContainsEndEvent( | 322 EXPECT_TRUE(LogContainsEndEvent( |
| 322 *log, 7, LoadLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); | 323 log.entries(), 7, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); |
| 323 EXPECT_TRUE(LogContainsBeginEvent( | 324 EXPECT_TRUE(LogContainsBeginEvent( |
| 324 *log, 9, LoadLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 325 log.entries(), 9, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 325 EXPECT_TRUE(LogContainsEndEvent( | 326 EXPECT_TRUE(LogContainsEndEvent( |
| 326 *log, 12, LoadLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 327 log.entries(), 12, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 327 EXPECT_TRUE(LogContainsBeginEvent( | 328 EXPECT_TRUE(LogContainsBeginEvent( |
| 328 *log, 13, LoadLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); | 329 log.entries(), 13, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); |
| 329 EXPECT_TRUE(LogContainsEndEvent( | 330 EXPECT_TRUE(LogContainsEndEvent( |
| 330 *log, 15, LoadLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); | 331 log.entries(), 15, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); |
| 331 EXPECT_TRUE(LogContainsEndEvent(*log, 16, LoadLog::TYPE_INIT_PROXY_RESOLVER)); | 332 EXPECT_TRUE(LogContainsEndEvent( |
| 333 log.entries(), 16, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 332 } | 334 } |
| 333 | 335 |
| 334 // Fails at WPAD (downloading), and fails at custom PAC (downloading). | 336 // Fails at WPAD (downloading), and fails at custom PAC (downloading). |
| 335 TEST(InitProxyResolverTest, AutodetectFailCustomFails1) { | 337 TEST(InitProxyResolverTest, AutodetectFailCustomFails1) { |
| 336 Rules rules; | 338 Rules rules; |
| 337 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 339 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 338 RuleBasedProxyScriptFetcher fetcher(&rules); | 340 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 339 | 341 |
| 340 ProxyConfig config; | 342 ProxyConfig config; |
| 341 config.set_auto_detect(true); | 343 config.set_auto_detect(true); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 387 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 386 | 388 |
| 387 TestCompletionCallback callback; | 389 TestCompletionCallback callback; |
| 388 InitProxyResolver init(&resolver, &fetcher); | 390 InitProxyResolver init(&resolver, &fetcher); |
| 389 EXPECT_EQ(OK, init.Init(config, &callback, NULL)); | 391 EXPECT_EQ(OK, init.Init(config, &callback, NULL)); |
| 390 EXPECT_EQ(rule.url, resolver.pac_url()); | 392 EXPECT_EQ(rule.url, resolver.pac_url()); |
| 391 } | 393 } |
| 392 | 394 |
| 393 } // namespace | 395 } // namespace |
| 394 } // namespace net | 396 } // namespace net |
| OLD | NEW |