| 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/net_log.h" | 8 #include "net/base/net_log.h" |
| 9 #include "net/base/net_log_unittest.h" | 9 #include "net/base/net_log_unittest.h" |
| 10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 Rules rules; | 164 Rules rules; |
| 165 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 165 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 166 RuleBasedProxyScriptFetcher fetcher(&rules); | 166 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 167 | 167 |
| 168 ProxyConfig config; | 168 ProxyConfig config; |
| 169 config.set_pac_url(GURL("http://custom/proxy.pac")); | 169 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 170 | 170 |
| 171 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 171 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 172 | 172 |
| 173 TestCompletionCallback callback; | 173 TestCompletionCallback callback; |
| 174 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 174 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 175 InitProxyResolver init(&resolver, &fetcher); | 175 InitProxyResolver init(&resolver, &fetcher, &log); |
| 176 EXPECT_EQ(OK, init.Init(config, &callback, log.bound())); | 176 EXPECT_EQ(OK, init.Init(config, &callback)); |
| 177 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); | 177 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); |
| 178 | 178 |
| 179 // Check the NetLog was filled correctly. | 179 // Check the NetLog was filled correctly. |
| 180 EXPECT_EQ(6u, log.entries().size()); | 180 EXPECT_EQ(6u, log.entries().size()); |
| 181 EXPECT_TRUE(LogContainsBeginEvent( | 181 EXPECT_TRUE(LogContainsBeginEvent( |
| 182 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); | 182 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 183 EXPECT_TRUE(LogContainsBeginEvent( | 183 EXPECT_TRUE(LogContainsBeginEvent( |
| 184 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 184 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 185 EXPECT_TRUE(LogContainsEndEvent( | 185 EXPECT_TRUE(LogContainsEndEvent( |
| 186 log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 186 log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 207 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 208 InitProxyResolver init(&resolver, &fetcher); | 208 InitProxyResolver init(&resolver, &fetcher, &log); |
| 209 EXPECT_EQ(kFailedDownloading, init.Init(config, &callback, log.bound())); | 209 EXPECT_EQ(kFailedDownloading, init.Init(config, &callback)); |
| 210 EXPECT_EQ("", resolver.pac_bytes()); | 210 EXPECT_EQ("", resolver.pac_bytes()); |
| 211 | 211 |
| 212 // Check the NetLog was filled correctly. | 212 // Check the NetLog was filled correctly. |
| 213 EXPECT_EQ(4u, log.entries().size()); | 213 EXPECT_EQ(4u, log.entries().size()); |
| 214 EXPECT_TRUE(LogContainsBeginEvent( | 214 EXPECT_TRUE(LogContainsBeginEvent( |
| 215 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); | 215 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 216 EXPECT_TRUE(LogContainsBeginEvent( | 216 EXPECT_TRUE(LogContainsBeginEvent( |
| 217 log.entries(), 1, NetLog::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.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 219 log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| 220 EXPECT_TRUE(LogContainsEndEvent( | 220 EXPECT_TRUE(LogContainsEndEvent( |
| 221 log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER)); | 221 log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 // Fail parsing the custom PAC script. | 224 // Fail parsing the custom PAC script. |
| 225 TEST(InitProxyResolverTest, CustomPacFails2) { | 225 TEST(InitProxyResolverTest, CustomPacFails2) { |
| 226 Rules rules; | 226 Rules rules; |
| 227 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 227 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 228 RuleBasedProxyScriptFetcher fetcher(&rules); | 228 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 229 | 229 |
| 230 ProxyConfig config; | 230 ProxyConfig config; |
| 231 config.set_pac_url(GURL("http://custom/proxy.pac")); | 231 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 232 | 232 |
| 233 rules.AddFailParsingRule("http://custom/proxy.pac"); | 233 rules.AddFailParsingRule("http://custom/proxy.pac"); |
| 234 | 234 |
| 235 TestCompletionCallback callback; | 235 TestCompletionCallback callback; |
| 236 InitProxyResolver init(&resolver, &fetcher); | 236 InitProxyResolver init(&resolver, &fetcher, NULL); |
| 237 EXPECT_EQ(kFailedParsing, init.Init(config, &callback, NULL)); | 237 EXPECT_EQ(kFailedParsing, init.Init(config, &callback)); |
| 238 EXPECT_EQ("", resolver.pac_bytes()); | 238 EXPECT_EQ("", resolver.pac_bytes()); |
| 239 } | 239 } |
| 240 | 240 |
| 241 // Fail downloading the custom PAC script, because the fetcher was NULL. | 241 // Fail downloading the custom PAC script, because the fetcher was NULL. |
| 242 TEST(InitProxyResolverTest, HasNullProxyScriptFetcher) { | 242 TEST(InitProxyResolverTest, HasNullProxyScriptFetcher) { |
| 243 Rules rules; | 243 Rules rules; |
| 244 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 244 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 245 | 245 |
| 246 ProxyConfig config; | 246 ProxyConfig config; |
| 247 config.set_pac_url(GURL("http://custom/proxy.pac")); | 247 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 248 | 248 |
| 249 TestCompletionCallback callback; | 249 TestCompletionCallback callback; |
| 250 InitProxyResolver init(&resolver, NULL); | 250 InitProxyResolver init(&resolver, NULL, NULL); |
| 251 EXPECT_EQ(ERR_UNEXPECTED, init.Init(config, &callback, NULL)); | 251 EXPECT_EQ(ERR_UNEXPECTED, init.Init(config, &callback)); |
| 252 EXPECT_EQ("", resolver.pac_bytes()); | 252 EXPECT_EQ("", resolver.pac_bytes()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Succeeds in choosing autodetect (wpad). | 255 // Succeeds in choosing autodetect (wpad). |
| 256 TEST(InitProxyResolverTest, AutodetectSuccess) { | 256 TEST(InitProxyResolverTest, AutodetectSuccess) { |
| 257 Rules rules; | 257 Rules rules; |
| 258 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 258 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 259 RuleBasedProxyScriptFetcher fetcher(&rules); | 259 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 260 | 260 |
| 261 ProxyConfig config; | 261 ProxyConfig config; |
| 262 config.set_auto_detect(true); | 262 config.set_auto_detect(true); |
| 263 | 263 |
| 264 Rules::Rule rule = rules.AddSuccessRule("http://wpad/wpad.dat"); | 264 Rules::Rule rule = rules.AddSuccessRule("http://wpad/wpad.dat"); |
| 265 | 265 |
| 266 TestCompletionCallback callback; | 266 TestCompletionCallback callback; |
| 267 InitProxyResolver init(&resolver, &fetcher); | 267 InitProxyResolver init(&resolver, &fetcher, NULL); |
| 268 EXPECT_EQ(OK, init.Init(config, &callback, NULL)); | 268 EXPECT_EQ(OK, init.Init(config, &callback)); |
| 269 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); | 269 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); |
| 270 } | 270 } |
| 271 | 271 |
| 272 // Fails at WPAD (downloading), but succeeds in choosing the custom PAC. | 272 // Fails at WPAD (downloading), but succeeds in choosing the custom PAC. |
| 273 TEST(InitProxyResolverTest, AutodetectFailCustomSuccess1) { | 273 TEST(InitProxyResolverTest, AutodetectFailCustomSuccess1) { |
| 274 Rules rules; | 274 Rules rules; |
| 275 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 275 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 276 RuleBasedProxyScriptFetcher fetcher(&rules); | 276 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 277 | 277 |
| 278 ProxyConfig config; | 278 ProxyConfig config; |
| 279 config.set_auto_detect(true); | 279 config.set_auto_detect(true); |
| 280 config.set_pac_url(GURL("http://custom/proxy.pac")); | 280 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 281 | 281 |
| 282 rules.AddFailDownloadRule("http://wpad/wpad.dat"); | 282 rules.AddFailDownloadRule("http://wpad/wpad.dat"); |
| 283 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 283 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 284 | 284 |
| 285 TestCompletionCallback callback; | 285 TestCompletionCallback callback; |
| 286 InitProxyResolver init(&resolver, &fetcher); | 286 InitProxyResolver init(&resolver, &fetcher, NULL); |
| 287 EXPECT_EQ(OK, init.Init(config, &callback, NULL)); | 287 EXPECT_EQ(OK, init.Init(config, &callback)); |
| 288 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); | 288 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); |
| 289 } | 289 } |
| 290 | 290 |
| 291 // Fails at WPAD (parsing), but succeeds in choosing the custom PAC. | 291 // Fails at WPAD (parsing), but succeeds in choosing the custom PAC. |
| 292 TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2) { | 292 TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2) { |
| 293 Rules rules; | 293 Rules rules; |
| 294 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 294 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 295 RuleBasedProxyScriptFetcher fetcher(&rules); | 295 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 296 | 296 |
| 297 ProxyConfig config; | 297 ProxyConfig config; |
| 298 config.set_auto_detect(true); | 298 config.set_auto_detect(true); |
| 299 config.set_pac_url(GURL("http://custom/proxy.pac")); | 299 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 300 | 300 |
| 301 rules.AddFailParsingRule("http://wpad/wpad.dat"); | 301 rules.AddFailParsingRule("http://wpad/wpad.dat"); |
| 302 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 302 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 303 | 303 |
| 304 TestCompletionCallback callback; | 304 TestCompletionCallback callback; |
| 305 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 305 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 306 InitProxyResolver init(&resolver, &fetcher); | 306 InitProxyResolver init(&resolver, &fetcher, &log); |
| 307 EXPECT_EQ(OK, init.Init(config, &callback, log.bound())); | 307 EXPECT_EQ(OK, init.Init(config, &callback)); |
| 308 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); | 308 EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); |
| 309 | 309 |
| 310 // Check the NetLog was filled correctly. | 310 // Check the NetLog was filled correctly. |
| 311 // (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 |
| 312 // PAC scripts are tried). | 312 // PAC scripts are tried). |
| 313 EXPECT_EQ(11u, log.entries().size()); | 313 EXPECT_EQ(11u, log.entries().size()); |
| 314 EXPECT_TRUE(LogContainsBeginEvent( | 314 EXPECT_TRUE(LogContainsBeginEvent( |
| 315 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); | 315 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); |
| 316 EXPECT_TRUE(LogContainsBeginEvent( | 316 EXPECT_TRUE(LogContainsBeginEvent( |
| 317 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); | 317 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 344 RuleBasedProxyScriptFetcher fetcher(&rules); | 344 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 345 | 345 |
| 346 ProxyConfig config; | 346 ProxyConfig config; |
| 347 config.set_auto_detect(true); | 347 config.set_auto_detect(true); |
| 348 config.set_pac_url(GURL("http://custom/proxy.pac")); | 348 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 349 | 349 |
| 350 rules.AddFailDownloadRule("http://wpad/wpad.dat"); | 350 rules.AddFailDownloadRule("http://wpad/wpad.dat"); |
| 351 rules.AddFailDownloadRule("http://custom/proxy.pac"); | 351 rules.AddFailDownloadRule("http://custom/proxy.pac"); |
| 352 | 352 |
| 353 TestCompletionCallback callback; | 353 TestCompletionCallback callback; |
| 354 InitProxyResolver init(&resolver, &fetcher); | 354 InitProxyResolver init(&resolver, &fetcher, NULL); |
| 355 EXPECT_EQ(kFailedDownloading, init.Init(config, &callback, NULL)); | 355 EXPECT_EQ(kFailedDownloading, init.Init(config, &callback)); |
| 356 EXPECT_EQ("", resolver.pac_bytes()); | 356 EXPECT_EQ("", resolver.pac_bytes()); |
| 357 } | 357 } |
| 358 | 358 |
| 359 // Fails at WPAD (downloading), and fails at custom PAC (parsing). | 359 // Fails at WPAD (downloading), and fails at custom PAC (parsing). |
| 360 TEST(InitProxyResolverTest, AutodetectFailCustomFails2) { | 360 TEST(InitProxyResolverTest, AutodetectFailCustomFails2) { |
| 361 Rules rules; | 361 Rules rules; |
| 362 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); | 362 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); |
| 363 RuleBasedProxyScriptFetcher fetcher(&rules); | 363 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 364 | 364 |
| 365 ProxyConfig config; | 365 ProxyConfig config; |
| 366 config.set_auto_detect(true); | 366 config.set_auto_detect(true); |
| 367 config.set_pac_url(GURL("http://custom/proxy.pac")); | 367 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 368 | 368 |
| 369 rules.AddFailDownloadRule("http://wpad/wpad.dat"); | 369 rules.AddFailDownloadRule("http://wpad/wpad.dat"); |
| 370 rules.AddFailParsingRule("http://custom/proxy.pac"); | 370 rules.AddFailParsingRule("http://custom/proxy.pac"); |
| 371 | 371 |
| 372 TestCompletionCallback callback; | 372 TestCompletionCallback callback; |
| 373 InitProxyResolver init(&resolver, &fetcher); | 373 InitProxyResolver init(&resolver, &fetcher, NULL); |
| 374 EXPECT_EQ(kFailedParsing, init.Init(config, &callback, NULL)); | 374 EXPECT_EQ(kFailedParsing, init.Init(config, &callback)); |
| 375 EXPECT_EQ("", resolver.pac_bytes()); | 375 EXPECT_EQ("", resolver.pac_bytes()); |
| 376 } | 376 } |
| 377 | 377 |
| 378 // Fails at WPAD (parsing), but succeeds in choosing the custom PAC. | 378 // Fails at WPAD (parsing), but succeeds in choosing the custom PAC. |
| 379 // This is the same as AutodetectFailCustomSuccess2, but using a ProxyResolver | 379 // This is the same as AutodetectFailCustomSuccess2, but using a ProxyResolver |
| 380 // that doesn't |expects_pac_bytes|. | 380 // that doesn't |expects_pac_bytes|. |
| 381 TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2_NoFetch) { | 381 TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2_NoFetch) { |
| 382 Rules rules; | 382 Rules rules; |
| 383 RuleBasedProxyResolver resolver(&rules, false /*expects_pac_bytes*/); | 383 RuleBasedProxyResolver resolver(&rules, false /*expects_pac_bytes*/); |
| 384 RuleBasedProxyScriptFetcher fetcher(&rules); | 384 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 385 | 385 |
| 386 ProxyConfig config; | 386 ProxyConfig config; |
| 387 config.set_auto_detect(true); | 387 config.set_auto_detect(true); |
| 388 config.set_pac_url(GURL("http://custom/proxy.pac")); | 388 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 389 | 389 |
| 390 rules.AddFailParsingRule(""); // Autodetect. | 390 rules.AddFailParsingRule(""); // Autodetect. |
| 391 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); | 391 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); |
| 392 | 392 |
| 393 TestCompletionCallback callback; | 393 TestCompletionCallback callback; |
| 394 InitProxyResolver init(&resolver, &fetcher); | 394 InitProxyResolver init(&resolver, &fetcher, NULL); |
| 395 EXPECT_EQ(OK, init.Init(config, &callback, NULL)); | 395 EXPECT_EQ(OK, init.Init(config, &callback)); |
| 396 EXPECT_EQ(rule.url, resolver.pac_url()); | 396 EXPECT_EQ(rule.url, resolver.pac_url()); |
| 397 } | 397 } |
| 398 | 398 |
| 399 } // namespace | 399 } // namespace |
| 400 } // namespace net | 400 } // namespace net |
| OLD | NEW |