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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 8533011: Remove unused HostResolver::Observer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 5776 matching lines...) Expand 10 before | Expand all | Expand 10 after
5787 5787
5788 TestOldCompletionCallback callback; 5788 TestOldCompletionCallback callback;
5789 5789
5790 int rv = trans->Start(&request, &callback, BoundNetLog()); 5790 int rv = trans->Start(&request, &callback, BoundNetLog());
5791 EXPECT_EQ(ERR_IO_PENDING, rv); 5791 EXPECT_EQ(ERR_IO_PENDING, rv);
5792 5792
5793 rv = callback.WaitForResult(); 5793 rv = callback.WaitForResult();
5794 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); 5794 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv);
5795 } 5795 }
5796 5796
5797 // Host resolution observer used by 5797 // Forwards all calls to MockHostResolverBase but notes RequestInfo::referrer().
5798 // HttpNetworkTransactionTest.ResolveMadeWithReferrer to check that host 5798 // Used by HttpNetworkTransactionTest.ResolveMadeWithReferrer to check that host
5799 // resovle requests are issued with a referrer of |expected_referrer|. 5799 // resolve requests are issued with a referrer of |expected_referrer|.
5800 class ResolutionReferrerObserver : public HostResolver::Observer { 5800 class ObservingHostResolver : public MockHostResolverBase {
5801 public: 5801 public:
5802 explicit ResolutionReferrerObserver(const GURL& expected_referrer) 5802 explicit ObservingHostResolver(const GURL& expected_referrer)
5803 : expected_referrer_(expected_referrer), 5803 : MockHostResolverBase(false /* use_caching */),
5804 expected_referrer_(expected_referrer),
5804 called_start_with_referrer_(false), 5805 called_start_with_referrer_(false),
5805 called_finish_with_referrer_(false) { 5806 called_finish_with_referrer_(false),
5807 ALLOW_THIS_IN_INITIALIZER_LIST(
5808 callback_(this,
5809 &ObservingHostResolver::OnFinishResolutionWithStatus)) {
5806 } 5810 }
5807 5811
5808 virtual void OnStartResolution(int id, 5812 virtual int Resolve(const RequestInfo& info,
5809 const HostResolver::RequestInfo& info) { 5813 AddressList* addresses,
5810 if (info.referrer() == expected_referrer_) 5814 OldCompletionCallback* callback,
5815 RequestHandle* out_req,
5816 const BoundNetLog& net_log) OVERRIDE {
5817 if (info.referrer() == expected_referrer_) {
5811 called_start_with_referrer_ = true; 5818 called_start_with_referrer_ = true;
5819 callback_forwarded_ = callback;
5820 callback = &callback_;
5821 }
5822 return MockHostResolverBase::Resolve(info, addresses, callback, out_req,
5823 net_log);
5812 } 5824 }
5813 5825
5814 virtual void OnFinishResolutionWithStatus( 5826 void OnFinishResolutionWithStatus(int result) {
5815 int id, bool was_resolved, const HostResolver::RequestInfo& info ) { 5827 called_finish_with_referrer_ = true;
5816 if (info.referrer() == expected_referrer_) 5828 callback_forwarded_->Run(result);
5817 called_finish_with_referrer_ = true;
5818 } 5829 }
5819 5830
5820 virtual void OnCancelResolution(int id, 5831 virtual void CancelRequest(RequestHandle handle) OVERRIDE {
5821 const HostResolver::RequestInfo& info ) {
5822 FAIL() << "Should not be cancelling any requests!"; 5832 FAIL() << "Should not be cancelling any requests!";
5823 } 5833 }
5824 5834
5825 bool did_complete_with_expected_referrer() const { 5835 bool did_complete_with_expected_referrer() const {
5826 return called_start_with_referrer_ && called_finish_with_referrer_; 5836 return called_start_with_referrer_ && called_finish_with_referrer_;
5827 } 5837 }
5828 5838
5829 private: 5839 private:
5830 GURL expected_referrer_; 5840 GURL expected_referrer_;
5831 bool called_start_with_referrer_; 5841 bool called_start_with_referrer_;
5832 bool called_finish_with_referrer_; 5842 bool called_finish_with_referrer_;
5843 OldCompletionCallbackImpl<ObservingHostResolver> callback_;
5844 OldCompletionCallback* callback_forwarded_;
5833 5845
5834 DISALLOW_COPY_AND_ASSIGN(ResolutionReferrerObserver); 5846 DISALLOW_COPY_AND_ASSIGN(ObservingHostResolver);
5835 }; 5847 };
5836 5848
5837 // Make sure that when HostResolver::Resolve() is invoked, it passes through 5849 // Make sure that when HostResolver::Resolve() is invoked, it passes through
5838 // the "referrer". This is depended on by the DNS prefetch observer. 5850 // the "referrer". This is depended on by the DNS prefetch observer.
5839 TEST_F(HttpNetworkTransactionTest, ResolveMadeWithReferrer) { 5851 TEST_F(HttpNetworkTransactionTest, ResolveMadeWithReferrer) {
5840 GURL referrer = GURL("http://expected-referrer/"); 5852 GURL referrer = GURL("http://expected-referrer/");
5841 EXPECT_TRUE(referrer.is_valid()); 5853 EXPECT_TRUE(referrer.is_valid());
5842 ResolutionReferrerObserver resolution_observer(referrer);
5843 5854
5844 // Issue a request, containing an HTTP referrer. 5855 // Issue a request, containing an HTTP referrer.
5845 HttpRequestInfo request; 5856 HttpRequestInfo request;
5846 request.method = "GET"; 5857 request.method = "GET";
5847 request.url = GURL("http://www.google.com/"); 5858 request.url = GURL("http://www.google.com/");
5848 request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, 5859 request.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
5849 referrer.spec()); 5860 referrer.spec());
5850 5861
5851 SessionDependencies session_deps; 5862 SessionDependencies session_deps;
5863 // Attach an observer to watch the host resolutions being made.
5864 ObservingHostResolver* observing_resolver =
5865 new ObservingHostResolver(referrer);
5866 session_deps.host_resolver.reset(observing_resolver);
5867
5852 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( 5868 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(
5853 CreateSession(&session_deps))); 5869 CreateSession(&session_deps)));
5854 5870
5855 // Attach an observer to watch the host resolutions being made.
5856 session_deps.host_resolver->AddObserver(&resolution_observer);
5857
5858 // Connect up a mock socket which will fail when reading. 5871 // Connect up a mock socket which will fail when reading.
5859 MockRead data_reads[] = { 5872 MockRead data_reads[] = {
5860 MockRead(false, ERR_FAILED), 5873 MockRead(false, ERR_FAILED),
5861 }; 5874 };
5862 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); 5875 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
5863 session_deps.socket_factory.AddSocketDataProvider(&data); 5876 session_deps.socket_factory.AddSocketDataProvider(&data);
5864 5877
5865 // Run the request until it fails reading from the socket. 5878 // Run the request until it fails reading from the socket.
5866 TestOldCompletionCallback callback; 5879 TestOldCompletionCallback callback;
5867 int rv = trans->Start(&request, &callback, BoundNetLog()); 5880 int rv = trans->Start(&request, &callback, BoundNetLog());
5868 EXPECT_EQ(ERR_IO_PENDING, rv); 5881 EXPECT_EQ(ERR_IO_PENDING, rv);
5869 rv = callback.WaitForResult(); 5882 rv = callback.WaitForResult();
5870 EXPECT_EQ(ERR_FAILED, rv); 5883 EXPECT_EQ(ERR_FAILED, rv);
5871 5884
5872 // Check that the host resolution observer saw |referrer|. 5885 // Check that the host resolution observer saw |referrer|.
5873 EXPECT_TRUE(resolution_observer.did_complete_with_expected_referrer()); 5886 EXPECT_TRUE(observing_resolver->did_complete_with_expected_referrer());
5874 } 5887 }
5875 5888
5876 // Base test to make sure that when the load flags for a request specify to 5889 // Base test to make sure that when the load flags for a request specify to
5877 // bypass the cache, the DNS cache is not used. 5890 // bypass the cache, the DNS cache is not used.
5878 void BypassHostCacheOnRefreshHelper(int load_flags) { 5891 void BypassHostCacheOnRefreshHelper(int load_flags) {
5879 // Issue a request, asking to bypass the cache(s). 5892 // Issue a request, asking to bypass the cache(s).
5880 HttpRequestInfo request; 5893 HttpRequestInfo request;
5881 request.method = "GET"; 5894 request.method = "GET";
5882 request.load_flags = load_flags; 5895 request.load_flags = load_flags;
5883 request.url = GURL("http://www.google.com/"); 5896 request.url = GURL("http://www.google.com/");
(...skipping 3248 matching lines...) Expand 10 before | Expand all | Expand 10 after
9132 int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); 9145 int rv = host_resolver_.ResolveFromCache(info, addresses, net_log);
9133 if (rv == OK && info.host_port_pair().Equals(host_port_)) 9146 if (rv == OK && info.host_port_pair().Equals(host_port_))
9134 host_resolver_.GetHostCache()->clear(); 9147 host_resolver_.GetHostCache()->clear();
9135 return rv; 9148 return rv;
9136 } 9149 }
9137 9150
9138 virtual void CancelRequest(RequestHandle req) OVERRIDE { 9151 virtual void CancelRequest(RequestHandle req) OVERRIDE {
9139 host_resolver_.CancelRequest(req); 9152 host_resolver_.CancelRequest(req);
9140 } 9153 }
9141 9154
9142 virtual void AddObserver(Observer* observer) OVERRIDE {
9143 return host_resolver_.AddObserver(observer);
9144 }
9145
9146 virtual void RemoveObserver(Observer* observer) OVERRIDE {
9147 return host_resolver_.RemoveObserver(observer);
9148 }
9149
9150 MockCachingHostResolver* GetMockHostResolver() { 9155 MockCachingHostResolver* GetMockHostResolver() {
9151 return &host_resolver_; 9156 return &host_resolver_;
9152 } 9157 }
9153 9158
9154 private: 9159 private:
9155 MockCachingHostResolver host_resolver_; 9160 MockCachingHostResolver host_resolver_;
9156 const HostPortPair host_port_; 9161 const HostPortPair host_port_;
9157 }; 9162 };
9158 9163
9159 TEST_F(HttpNetworkTransactionTest, 9164 TEST_F(HttpNetworkTransactionTest,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
9309 StaticSocketDataProvider* data[] = { &data1, &data2 }; 9314 StaticSocketDataProvider* data[] = { &data1, &data2 };
9310 9315
9311 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); 9316 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data));
9312 9317
9313 EXPECT_EQ(OK, out.rv); 9318 EXPECT_EQ(OK, out.rv);
9314 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); 9319 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
9315 EXPECT_EQ("hello world", out.response_data); 9320 EXPECT_EQ("hello world", out.response_data);
9316 } 9321 }
9317 9322
9318 } // namespace net 9323 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698