| 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/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 explicit RuleBasedProxyScriptFetcher(const Rules* rules) | 100 explicit RuleBasedProxyScriptFetcher(const Rules* rules) |
| 101 : rules_(rules), request_context_(NULL) {} | 101 : rules_(rules), request_context_(NULL) {} |
| 102 | 102 |
| 103 virtual void SetRequestContext(URLRequestContext* context) { | 103 virtual void SetRequestContext(URLRequestContext* context) { |
| 104 request_context_ = context; | 104 request_context_ = context; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // ProxyScriptFetcher implementation. | 107 // ProxyScriptFetcher implementation. |
| 108 virtual int Fetch(const GURL& url, | 108 virtual int Fetch(const GURL& url, |
| 109 base::string16* text, | 109 base::string16* text, |
| 110 const CompletionCallback& callback) OVERRIDE { | 110 const CompletionCallback& callback) override { |
| 111 const Rules::Rule& rule = rules_->GetRuleByUrl(url); | 111 const Rules::Rule& rule = rules_->GetRuleByUrl(url); |
| 112 int rv = rule.fetch_error; | 112 int rv = rule.fetch_error; |
| 113 EXPECT_NE(ERR_UNEXPECTED, rv); | 113 EXPECT_NE(ERR_UNEXPECTED, rv); |
| 114 if (rv == OK) | 114 if (rv == OK) |
| 115 *text = rule.text(); | 115 *text = rule.text(); |
| 116 return rv; | 116 return rv; |
| 117 } | 117 } |
| 118 | 118 |
| 119 virtual void Cancel() OVERRIDE {} | 119 virtual void Cancel() override {} |
| 120 | 120 |
| 121 virtual URLRequestContext* GetRequestContext() const OVERRIDE { | 121 virtual URLRequestContext* GetRequestContext() const override { |
| 122 return request_context_; | 122 return request_context_; |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 const Rules* rules_; | 126 const Rules* rules_; |
| 127 URLRequestContext* request_context_; | 127 URLRequestContext* request_context_; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 // A mock retriever, returns asynchronously when CompleteRequests() is called. | 130 // A mock retriever, returns asynchronously when CompleteRequests() is called. |
| 131 class MockDhcpProxyScriptFetcher : public DhcpProxyScriptFetcher { | 131 class MockDhcpProxyScriptFetcher : public DhcpProxyScriptFetcher { |
| 132 public: | 132 public: |
| 133 MockDhcpProxyScriptFetcher(); | 133 MockDhcpProxyScriptFetcher(); |
| 134 virtual ~MockDhcpProxyScriptFetcher(); | 134 virtual ~MockDhcpProxyScriptFetcher(); |
| 135 | 135 |
| 136 virtual int Fetch(base::string16* utf16_text, | 136 virtual int Fetch(base::string16* utf16_text, |
| 137 const CompletionCallback& callback) OVERRIDE; | 137 const CompletionCallback& callback) override; |
| 138 virtual void Cancel() OVERRIDE; | 138 virtual void Cancel() override; |
| 139 virtual const GURL& GetPacURL() const OVERRIDE; | 139 virtual const GURL& GetPacURL() const override; |
| 140 | 140 |
| 141 virtual void SetPacURL(const GURL& url); | 141 virtual void SetPacURL(const GURL& url); |
| 142 | 142 |
| 143 virtual void CompleteRequests(int result, const base::string16& script); | 143 virtual void CompleteRequests(int result, const base::string16& script); |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 CompletionCallback callback_; | 146 CompletionCallback callback_; |
| 147 base::string16* utf16_text_; | 147 base::string16* utf16_text_; |
| 148 GURL gurl_; | 148 GURL gurl_; |
| 149 DISALLOW_COPY_AND_ASSIGN(MockDhcpProxyScriptFetcher); | 149 DISALLOW_COPY_AND_ASSIGN(MockDhcpProxyScriptFetcher); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 EXPECT_TRUE(decider.effective_config().has_pac_url()); | 303 EXPECT_TRUE(decider.effective_config().has_pac_url()); |
| 304 EXPECT_EQ(rule.url, decider.effective_config().pac_url()); | 304 EXPECT_EQ(rule.url, decider.effective_config().pac_url()); |
| 305 } | 305 } |
| 306 | 306 |
| 307 class ProxyScriptDeciderQuickCheckTest : public ::testing::Test { | 307 class ProxyScriptDeciderQuickCheckTest : public ::testing::Test { |
| 308 public: | 308 public: |
| 309 ProxyScriptDeciderQuickCheckTest() | 309 ProxyScriptDeciderQuickCheckTest() |
| 310 : rule_(rules_.AddSuccessRule("http://wpad/wpad.dat")), | 310 : rule_(rules_.AddSuccessRule("http://wpad/wpad.dat")), |
| 311 fetcher_(&rules_) { } | 311 fetcher_(&rules_) { } |
| 312 | 312 |
| 313 virtual void SetUp() OVERRIDE { | 313 virtual void SetUp() override { |
| 314 request_context_.set_host_resolver(&resolver_); | 314 request_context_.set_host_resolver(&resolver_); |
| 315 fetcher_.SetRequestContext(&request_context_); | 315 fetcher_.SetRequestContext(&request_context_); |
| 316 config_.set_auto_detect(true); | 316 config_.set_auto_detect(true); |
| 317 decider_.reset(new ProxyScriptDecider(&fetcher_, &dhcp_fetcher_, NULL)); | 317 decider_.reset(new ProxyScriptDecider(&fetcher_, &dhcp_fetcher_, NULL)); |
| 318 } | 318 } |
| 319 | 319 |
| 320 int StartDecider() { | 320 int StartDecider() { |
| 321 return decider_->Start(config_, base::TimeDelta(), true, | 321 return decider_->Start(config_, base::TimeDelta(), true, |
| 322 callback_.callback()); | 322 callback_.callback()); |
| 323 } | 323 } |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 entries, 3, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); | 636 entries, 3, NetLog::TYPE_PROXY_SCRIPT_DECIDER)); |
| 637 } | 637 } |
| 638 | 638 |
| 639 class SynchronousSuccessDhcpFetcher : public DhcpProxyScriptFetcher { | 639 class SynchronousSuccessDhcpFetcher : public DhcpProxyScriptFetcher { |
| 640 public: | 640 public: |
| 641 explicit SynchronousSuccessDhcpFetcher(const base::string16& expected_text) | 641 explicit SynchronousSuccessDhcpFetcher(const base::string16& expected_text) |
| 642 : gurl_("http://dhcppac/"), expected_text_(expected_text) { | 642 : gurl_("http://dhcppac/"), expected_text_(expected_text) { |
| 643 } | 643 } |
| 644 | 644 |
| 645 virtual int Fetch(base::string16* utf16_text, | 645 virtual int Fetch(base::string16* utf16_text, |
| 646 const CompletionCallback& callback) OVERRIDE { | 646 const CompletionCallback& callback) override { |
| 647 *utf16_text = expected_text_; | 647 *utf16_text = expected_text_; |
| 648 return OK; | 648 return OK; |
| 649 } | 649 } |
| 650 | 650 |
| 651 virtual void Cancel() OVERRIDE { | 651 virtual void Cancel() override { |
| 652 } | 652 } |
| 653 | 653 |
| 654 virtual const GURL& GetPacURL() const OVERRIDE { | 654 virtual const GURL& GetPacURL() const override { |
| 655 return gurl_; | 655 return gurl_; |
| 656 } | 656 } |
| 657 | 657 |
| 658 const base::string16& expected_text() const { | 658 const base::string16& expected_text() const { |
| 659 return expected_text_; | 659 return expected_text_; |
| 660 } | 660 } |
| 661 | 661 |
| 662 private: | 662 private: |
| 663 GURL gurl_; | 663 GURL gurl_; |
| 664 base::string16 expected_text_; | 664 base::string16 expected_text_; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 } | 718 } |
| 719 | 719 |
| 720 class AsyncFailDhcpFetcher | 720 class AsyncFailDhcpFetcher |
| 721 : public DhcpProxyScriptFetcher, | 721 : public DhcpProxyScriptFetcher, |
| 722 public base::SupportsWeakPtr<AsyncFailDhcpFetcher> { | 722 public base::SupportsWeakPtr<AsyncFailDhcpFetcher> { |
| 723 public: | 723 public: |
| 724 AsyncFailDhcpFetcher() {} | 724 AsyncFailDhcpFetcher() {} |
| 725 virtual ~AsyncFailDhcpFetcher() {} | 725 virtual ~AsyncFailDhcpFetcher() {} |
| 726 | 726 |
| 727 virtual int Fetch(base::string16* utf16_text, | 727 virtual int Fetch(base::string16* utf16_text, |
| 728 const CompletionCallback& callback) OVERRIDE { | 728 const CompletionCallback& callback) override { |
| 729 callback_ = callback; | 729 callback_ = callback; |
| 730 base::MessageLoop::current()->PostTask( | 730 base::MessageLoop::current()->PostTask( |
| 731 FROM_HERE, | 731 FROM_HERE, |
| 732 base::Bind(&AsyncFailDhcpFetcher::CallbackWithFailure, AsWeakPtr())); | 732 base::Bind(&AsyncFailDhcpFetcher::CallbackWithFailure, AsWeakPtr())); |
| 733 return ERR_IO_PENDING; | 733 return ERR_IO_PENDING; |
| 734 } | 734 } |
| 735 | 735 |
| 736 virtual void Cancel() OVERRIDE { | 736 virtual void Cancel() override { |
| 737 callback_.Reset(); | 737 callback_.Reset(); |
| 738 } | 738 } |
| 739 | 739 |
| 740 virtual const GURL& GetPacURL() const OVERRIDE { | 740 virtual const GURL& GetPacURL() const override { |
| 741 return dummy_gurl_; | 741 return dummy_gurl_; |
| 742 } | 742 } |
| 743 | 743 |
| 744 void CallbackWithFailure() { | 744 void CallbackWithFailure() { |
| 745 if (!callback_.is_null()) | 745 if (!callback_.is_null()) |
| 746 callback_.Run(ERR_PAC_NOT_IN_DHCP); | 746 callback_.Run(ERR_PAC_NOT_IN_DHCP); |
| 747 } | 747 } |
| 748 | 748 |
| 749 private: | 749 private: |
| 750 GURL dummy_gurl_; | 750 GURL dummy_gurl_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 775 | 775 |
| 776 // Run the message loop to let the DHCP fetch complete and post the results | 776 // Run the message loop to let the DHCP fetch complete and post the results |
| 777 // back. Before the fix linked to above, this would try to invoke on | 777 // back. Before the fix linked to above, this would try to invoke on |
| 778 // the callback object provided by ProxyScriptDecider after it was | 778 // the callback object provided by ProxyScriptDecider after it was |
| 779 // no longer valid. | 779 // no longer valid. |
| 780 base::MessageLoop::current()->RunUntilIdle(); | 780 base::MessageLoop::current()->RunUntilIdle(); |
| 781 } | 781 } |
| 782 | 782 |
| 783 } // namespace | 783 } // namespace |
| 784 } // namespace net | 784 } // namespace net |
| OLD | NEW |