| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 config.set_pac_url(GURL("http://custom/proxy.pac")); | 228 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 229 | 229 |
| 230 rules.AddFailDownloadRule("http://custom/proxy.pac"); | 230 rules.AddFailDownloadRule("http://custom/proxy.pac"); |
| 231 | 231 |
| 232 TestCompletionCallback callback; | 232 TestCompletionCallback callback; |
| 233 TestNetLog log; | 233 TestNetLog log; |
| 234 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 234 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 235 EXPECT_EQ(kFailedDownloading, | 235 EXPECT_EQ(kFailedDownloading, |
| 236 decider.Start(config, base::TimeDelta(), true, | 236 decider.Start(config, base::TimeDelta(), true, |
| 237 callback.callback())); | 237 callback.callback())); |
| 238 EXPECT_EQ(nullptr, decider.script_data()); | 238 EXPECT_FALSE(decider.script_data()); |
| 239 | 239 |
| 240 // Check the NetLog was filled correctly. | 240 // Check the NetLog was filled correctly. |
| 241 TestNetLogEntry::List entries; | 241 TestNetLogEntry::List entries; |
| 242 log.GetEntries(&entries); | 242 log.GetEntries(&entries); |
| 243 | 243 |
| 244 EXPECT_EQ(4u, entries.size()); | 244 EXPECT_EQ(4u, entries.size()); |
| 245 EXPECT_TRUE(LogContainsBeginEvent( | 245 EXPECT_TRUE(LogContainsBeginEvent( |
| 246 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 246 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 247 EXPECT_TRUE(LogContainsBeginEvent( | 247 EXPECT_TRUE(LogContainsBeginEvent( |
| 248 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 248 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 263 ProxyConfig config; | 263 ProxyConfig config; |
| 264 config.set_pac_url(GURL("http://custom/proxy.pac")); | 264 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 265 | 265 |
| 266 rules.AddFailParsingRule("http://custom/proxy.pac"); | 266 rules.AddFailParsingRule("http://custom/proxy.pac"); |
| 267 | 267 |
| 268 TestCompletionCallback callback; | 268 TestCompletionCallback callback; |
| 269 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, NULL); | 269 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, NULL); |
| 270 EXPECT_EQ(kFailedParsing, | 270 EXPECT_EQ(kFailedParsing, |
| 271 decider.Start(config, base::TimeDelta(), true, | 271 decider.Start(config, base::TimeDelta(), true, |
| 272 callback.callback())); | 272 callback.callback())); |
| 273 EXPECT_EQ(nullptr, decider.script_data()); | 273 EXPECT_FALSE(decider.script_data()); |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Fail downloading the custom PAC script, because the fetcher was NULL. | 276 // Fail downloading the custom PAC script, because the fetcher was NULL. |
| 277 TEST(ProxyScriptDeciderTest, HasNullProxyScriptFetcher) { | 277 TEST(ProxyScriptDeciderTest, HasNullProxyScriptFetcher) { |
| 278 Rules rules; | 278 Rules rules; |
| 279 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; | 279 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; |
| 280 | 280 |
| 281 ProxyConfig config; | 281 ProxyConfig config; |
| 282 config.set_pac_url(GURL("http://custom/proxy.pac")); | 282 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 283 | 283 |
| 284 TestCompletionCallback callback; | 284 TestCompletionCallback callback; |
| 285 ProxyScriptDecider decider(NULL, &dhcp_fetcher, NULL); | 285 ProxyScriptDecider decider(NULL, &dhcp_fetcher, NULL); |
| 286 EXPECT_EQ(ERR_UNEXPECTED, | 286 EXPECT_EQ(ERR_UNEXPECTED, |
| 287 decider.Start(config, base::TimeDelta(), true, | 287 decider.Start(config, base::TimeDelta(), true, |
| 288 callback.callback())); | 288 callback.callback())); |
| 289 EXPECT_EQ(nullptr, decider.script_data()); | 289 EXPECT_FALSE(decider.script_data()); |
| 290 } | 290 } |
| 291 | 291 |
| 292 // Succeeds in choosing autodetect (WPAD DNS). | 292 // Succeeds in choosing autodetect (WPAD DNS). |
| 293 TEST(ProxyScriptDeciderTest, AutodetectSuccess) { | 293 TEST(ProxyScriptDeciderTest, AutodetectSuccess) { |
| 294 Rules rules; | 294 Rules rules; |
| 295 RuleBasedProxyScriptFetcher fetcher(&rules); | 295 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 296 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; | 296 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; |
| 297 | 297 |
| 298 ProxyConfig config; | 298 ProxyConfig config; |
| 299 config.set_auto_detect(true); | 299 config.set_auto_detect(true); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 config.set_pac_url(GURL("http://custom/proxy.pac")); | 543 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 544 | 544 |
| 545 rules.AddFailDownloadRule("http://wpad/wpad.dat"); | 545 rules.AddFailDownloadRule("http://wpad/wpad.dat"); |
| 546 rules.AddFailDownloadRule("http://custom/proxy.pac"); | 546 rules.AddFailDownloadRule("http://custom/proxy.pac"); |
| 547 | 547 |
| 548 TestCompletionCallback callback; | 548 TestCompletionCallback callback; |
| 549 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, NULL); | 549 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, NULL); |
| 550 EXPECT_EQ(kFailedDownloading, | 550 EXPECT_EQ(kFailedDownloading, |
| 551 decider.Start(config, base::TimeDelta(), true, | 551 decider.Start(config, base::TimeDelta(), true, |
| 552 callback.callback())); | 552 callback.callback())); |
| 553 EXPECT_EQ(nullptr, decider.script_data()); | 553 EXPECT_FALSE(decider.script_data()); |
| 554 } | 554 } |
| 555 | 555 |
| 556 // Fails at WPAD (downloading), and fails at custom PAC (parsing). | 556 // Fails at WPAD (downloading), and fails at custom PAC (parsing). |
| 557 TEST(ProxyScriptDeciderTest, AutodetectFailCustomFails2) { | 557 TEST(ProxyScriptDeciderTest, AutodetectFailCustomFails2) { |
| 558 Rules rules; | 558 Rules rules; |
| 559 RuleBasedProxyScriptFetcher fetcher(&rules); | 559 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 560 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; | 560 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; |
| 561 | 561 |
| 562 ProxyConfig config; | 562 ProxyConfig config; |
| 563 config.set_auto_detect(true); | 563 config.set_auto_detect(true); |
| 564 config.set_pac_url(GURL("http://custom/proxy.pac")); | 564 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 565 | 565 |
| 566 rules.AddFailDownloadRule("http://wpad/wpad.dat"); | 566 rules.AddFailDownloadRule("http://wpad/wpad.dat"); |
| 567 rules.AddFailParsingRule("http://custom/proxy.pac"); | 567 rules.AddFailParsingRule("http://custom/proxy.pac"); |
| 568 | 568 |
| 569 TestCompletionCallback callback; | 569 TestCompletionCallback callback; |
| 570 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, NULL); | 570 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, NULL); |
| 571 EXPECT_EQ(kFailedParsing, | 571 EXPECT_EQ(kFailedParsing, |
| 572 decider.Start(config, base::TimeDelta(), true, | 572 decider.Start(config, base::TimeDelta(), true, |
| 573 callback.callback())); | 573 callback.callback())); |
| 574 EXPECT_EQ(nullptr, decider.script_data()); | 574 EXPECT_FALSE(decider.script_data()); |
| 575 } | 575 } |
| 576 | 576 |
| 577 // This is a copy-paste of CustomPacFails1, with the exception that we give it | 577 // This is a copy-paste of CustomPacFails1, with the exception that we give it |
| 578 // a 1 millisecond delay. This means it will now complete asynchronously. | 578 // a 1 millisecond delay. This means it will now complete asynchronously. |
| 579 // Moreover, we test the NetLog to make sure it logged the pause. | 579 // Moreover, we test the NetLog to make sure it logged the pause. |
| 580 TEST(ProxyScriptDeciderTest, CustomPacFails1_WithPositiveDelay) { | 580 TEST(ProxyScriptDeciderTest, CustomPacFails1_WithPositiveDelay) { |
| 581 Rules rules; | 581 Rules rules; |
| 582 RuleBasedProxyScriptFetcher fetcher(&rules); | 582 RuleBasedProxyScriptFetcher fetcher(&rules); |
| 583 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; | 583 DoNothingDhcpProxyScriptFetcher dhcp_fetcher; |
| 584 | 584 |
| 585 ProxyConfig config; | 585 ProxyConfig config; |
| 586 config.set_pac_url(GURL("http://custom/proxy.pac")); | 586 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 587 | 587 |
| 588 rules.AddFailDownloadRule("http://custom/proxy.pac"); | 588 rules.AddFailDownloadRule("http://custom/proxy.pac"); |
| 589 | 589 |
| 590 TestCompletionCallback callback; | 590 TestCompletionCallback callback; |
| 591 TestNetLog log; | 591 TestNetLog log; |
| 592 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 592 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 593 EXPECT_EQ(ERR_IO_PENDING, | 593 EXPECT_EQ(ERR_IO_PENDING, |
| 594 decider.Start(config, base::TimeDelta::FromMilliseconds(1), | 594 decider.Start(config, base::TimeDelta::FromMilliseconds(1), |
| 595 true, callback.callback())); | 595 true, callback.callback())); |
| 596 | 596 |
| 597 EXPECT_EQ(kFailedDownloading, callback.WaitForResult()); | 597 EXPECT_EQ(kFailedDownloading, callback.WaitForResult()); |
| 598 EXPECT_EQ(nullptr, decider.script_data()); | 598 EXPECT_FALSE(decider.script_data()); |
| 599 | 599 |
| 600 // Check the NetLog was filled correctly. | 600 // Check the NetLog was filled correctly. |
| 601 TestNetLogEntry::List entries; | 601 TestNetLogEntry::List entries; |
| 602 log.GetEntries(&entries); | 602 log.GetEntries(&entries); |
| 603 | 603 |
| 604 EXPECT_EQ(6u, entries.size()); | 604 EXPECT_EQ(6u, entries.size()); |
| 605 EXPECT_TRUE(LogContainsBeginEvent( | 605 EXPECT_TRUE(LogContainsBeginEvent( |
| 606 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 606 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 607 EXPECT_TRUE(LogContainsBeginEvent( | 607 EXPECT_TRUE(LogContainsBeginEvent( |
| 608 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); | 608 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 628 config.set_pac_url(GURL("http://custom/proxy.pac")); | 628 config.set_pac_url(GURL("http://custom/proxy.pac")); |
| 629 | 629 |
| 630 rules.AddFailDownloadRule("http://custom/proxy.pac"); | 630 rules.AddFailDownloadRule("http://custom/proxy.pac"); |
| 631 | 631 |
| 632 TestCompletionCallback callback; | 632 TestCompletionCallback callback; |
| 633 TestNetLog log; | 633 TestNetLog log; |
| 634 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); | 634 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, &log); |
| 635 EXPECT_EQ(kFailedDownloading, | 635 EXPECT_EQ(kFailedDownloading, |
| 636 decider.Start(config, base::TimeDelta::FromSeconds(-5), | 636 decider.Start(config, base::TimeDelta::FromSeconds(-5), |
| 637 true, callback.callback())); | 637 true, callback.callback())); |
| 638 EXPECT_EQ(nullptr, decider.script_data()); | 638 EXPECT_FALSE(decider.script_data()); |
| 639 | 639 |
| 640 // Check the NetLog was filled correctly. | 640 // Check the NetLog was filled correctly. |
| 641 TestNetLogEntry::List entries; | 641 TestNetLogEntry::List entries; |
| 642 log.GetEntries(&entries); | 642 log.GetEntries(&entries); |
| 643 | 643 |
| 644 EXPECT_EQ(4u, entries.size()); | 644 EXPECT_EQ(4u, entries.size()); |
| 645 EXPECT_TRUE(LogContainsBeginEvent( | 645 EXPECT_TRUE(LogContainsBeginEvent( |
| 646 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 646 entries, 0, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 647 EXPECT_TRUE(LogContainsBeginEvent( | 647 EXPECT_TRUE(LogContainsBeginEvent( |
| 648 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); | 648 entries, 1, NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 | 718 |
| 719 rules.AddFailParsingRule("http://bingo/"); | 719 rules.AddFailParsingRule("http://bingo/"); |
| 720 rules.AddFailDownloadRule("http://wpad/wpad.dat"); | 720 rules.AddFailDownloadRule("http://wpad/wpad.dat"); |
| 721 | 721 |
| 722 TestCompletionCallback callback; | 722 TestCompletionCallback callback; |
| 723 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, NULL); | 723 ProxyScriptDecider decider(&fetcher, &dhcp_fetcher, NULL); |
| 724 // Since there is fallback to DNS-based WPAD, the final error will be that | 724 // Since there is fallback to DNS-based WPAD, the final error will be that |
| 725 // it failed downloading, not that it failed parsing. | 725 // it failed downloading, not that it failed parsing. |
| 726 EXPECT_EQ(kFailedDownloading, | 726 EXPECT_EQ(kFailedDownloading, |
| 727 decider.Start(config, base::TimeDelta(), true, callback.callback())); | 727 decider.Start(config, base::TimeDelta(), true, callback.callback())); |
| 728 EXPECT_EQ(nullptr, decider.script_data()); | 728 EXPECT_FALSE(decider.script_data()); |
| 729 | 729 |
| 730 EXPECT_FALSE(decider.effective_config().has_pac_url()); | 730 EXPECT_FALSE(decider.effective_config().has_pac_url()); |
| 731 } | 731 } |
| 732 | 732 |
| 733 class AsyncFailDhcpFetcher | 733 class AsyncFailDhcpFetcher |
| 734 : public DhcpProxyScriptFetcher, | 734 : public DhcpProxyScriptFetcher, |
| 735 public base::SupportsWeakPtr<AsyncFailDhcpFetcher> { | 735 public base::SupportsWeakPtr<AsyncFailDhcpFetcher> { |
| 736 public: | 736 public: |
| 737 AsyncFailDhcpFetcher() {} | 737 AsyncFailDhcpFetcher() {} |
| 738 ~AsyncFailDhcpFetcher() override {} | 738 ~AsyncFailDhcpFetcher() override {} |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 785 |
| 786 // Run the message loop to let the DHCP fetch complete and post the results | 786 // Run the message loop to let the DHCP fetch complete and post the results |
| 787 // back. Before the fix linked to above, this would try to invoke on | 787 // back. Before the fix linked to above, this would try to invoke on |
| 788 // the callback object provided by ProxyScriptDecider after it was | 788 // the callback object provided by ProxyScriptDecider after it was |
| 789 // no longer valid. | 789 // no longer valid. |
| 790 base::MessageLoop::current()->RunUntilIdle(); | 790 base::MessageLoop::current()->RunUntilIdle(); |
| 791 } | 791 } |
| 792 | 792 |
| 793 } // namespace | 793 } // namespace |
| 794 } // namespace net | 794 } // namespace net |
| OLD | NEW |