Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Side by Side Diff: net/proxy/proxy_script_decider_unittest.cc

Issue 667923003: Standardize usage of virtual/override/final in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/proxy/proxy_resolver_v8_unittest.cc ('k') | net/proxy/proxy_script_fetcher_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 class RuleBasedProxyScriptFetcher : public ProxyScriptFetcher { 98 class RuleBasedProxyScriptFetcher : public ProxyScriptFetcher {
99 public: 99 public:
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 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 void Cancel() override {}
120 120
121 virtual URLRequestContext* GetRequestContext() const override { 121 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 ~MockDhcpProxyScriptFetcher() override;
135 135
136 virtual int Fetch(base::string16* utf16_text, 136 int Fetch(base::string16* utf16_text,
137 const CompletionCallback& callback) override; 137 const CompletionCallback& callback) override;
138 virtual void Cancel() override; 138 void Cancel() override;
139 virtual const GURL& GetPacURL() const override; 139 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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 EXPECT_TRUE(LogContainsEndEvent( 635 EXPECT_TRUE(LogContainsEndEvent(
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 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 void Cancel() override {}
652 }
653 652
654 virtual const GURL& GetPacURL() const override { 653 const GURL& GetPacURL() const override { return gurl_; }
655 return gurl_;
656 }
657 654
658 const base::string16& expected_text() const { 655 const base::string16& expected_text() const {
659 return expected_text_; 656 return expected_text_;
660 } 657 }
661 658
662 private: 659 private:
663 GURL gurl_; 660 GURL gurl_;
664 base::string16 expected_text_; 661 base::string16 expected_text_;
665 662
666 DISALLOW_COPY_AND_ASSIGN(SynchronousSuccessDhcpFetcher); 663 DISALLOW_COPY_AND_ASSIGN(SynchronousSuccessDhcpFetcher);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 EXPECT_EQ(NULL, decider.script_data()); 712 EXPECT_EQ(NULL, decider.script_data());
716 713
717 EXPECT_FALSE(decider.effective_config().has_pac_url()); 714 EXPECT_FALSE(decider.effective_config().has_pac_url());
718 } 715 }
719 716
720 class AsyncFailDhcpFetcher 717 class AsyncFailDhcpFetcher
721 : public DhcpProxyScriptFetcher, 718 : public DhcpProxyScriptFetcher,
722 public base::SupportsWeakPtr<AsyncFailDhcpFetcher> { 719 public base::SupportsWeakPtr<AsyncFailDhcpFetcher> {
723 public: 720 public:
724 AsyncFailDhcpFetcher() {} 721 AsyncFailDhcpFetcher() {}
725 virtual ~AsyncFailDhcpFetcher() {} 722 ~AsyncFailDhcpFetcher() override {}
726 723
727 virtual int Fetch(base::string16* utf16_text, 724 int Fetch(base::string16* utf16_text,
728 const CompletionCallback& callback) override { 725 const CompletionCallback& callback) override {
729 callback_ = callback; 726 callback_ = callback;
730 base::MessageLoop::current()->PostTask( 727 base::MessageLoop::current()->PostTask(
731 FROM_HERE, 728 FROM_HERE,
732 base::Bind(&AsyncFailDhcpFetcher::CallbackWithFailure, AsWeakPtr())); 729 base::Bind(&AsyncFailDhcpFetcher::CallbackWithFailure, AsWeakPtr()));
733 return ERR_IO_PENDING; 730 return ERR_IO_PENDING;
734 } 731 }
735 732
736 virtual void Cancel() override { 733 void Cancel() override { callback_.Reset(); }
737 callback_.Reset();
738 }
739 734
740 virtual const GURL& GetPacURL() const override { 735 const GURL& GetPacURL() const override { return dummy_gurl_; }
741 return dummy_gurl_;
742 }
743 736
744 void CallbackWithFailure() { 737 void CallbackWithFailure() {
745 if (!callback_.is_null()) 738 if (!callback_.is_null())
746 callback_.Run(ERR_PAC_NOT_IN_DHCP); 739 callback_.Run(ERR_PAC_NOT_IN_DHCP);
747 } 740 }
748 741
749 private: 742 private:
750 GURL dummy_gurl_; 743 GURL dummy_gurl_;
751 CompletionCallback callback_; 744 CompletionCallback callback_;
752 }; 745 };
(...skipping 22 matching lines...) Expand all
775 768
776 // Run the message loop to let the DHCP fetch complete and post the results 769 // 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 770 // back. Before the fix linked to above, this would try to invoke on
778 // the callback object provided by ProxyScriptDecider after it was 771 // the callback object provided by ProxyScriptDecider after it was
779 // no longer valid. 772 // no longer valid.
780 base::MessageLoop::current()->RunUntilIdle(); 773 base::MessageLoop::current()->RunUntilIdle();
781 } 774 }
782 775
783 } // namespace 776 } // namespace
784 } // namespace net 777 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_v8_unittest.cc ('k') | net/proxy/proxy_script_fetcher_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698