Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 13823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13834 ASSERT_TRUE(response); | 13834 ASSERT_TRUE(response); |
| 13835 ASSERT_TRUE(response->headers); | 13835 ASSERT_TRUE(response->headers); |
| 13836 EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); | 13836 EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 13837 EXPECT_TRUE(response->was_fetched_via_spdy); | 13837 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13838 EXPECT_TRUE(response->was_alpn_negotiated); | 13838 EXPECT_TRUE(response->was_alpn_negotiated); |
| 13839 EXPECT_TRUE(response->ssl_info.cert); | 13839 EXPECT_TRUE(response->ssl_info.cert); |
| 13840 ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); | 13840 ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13841 EXPECT_EQ("hello!", response_data); | 13841 EXPECT_EQ("hello!", response_data); |
| 13842 } | 13842 } |
| 13843 | 13843 |
| 13844 class OneTimeCachingHostResolver : public HostResolver { | 13844 class OneTimeCachingHostResolver : public MockHostResolverBase { |
|
Bence
2017/05/25 15:46:02
Make this class inherit from MockHostResolverBase
| |
| 13845 public: | 13845 public: |
| 13846 explicit OneTimeCachingHostResolver(const HostPortPair& host_port) | 13846 explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 13847 : host_port_(host_port) {} | 13847 : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
| 13848 ~OneTimeCachingHostResolver() override {} | 13848 ~OneTimeCachingHostResolver() override {} |
| 13849 | 13849 |
| 13850 RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } | |
|
Bence
2017/05/25 15:46:02
Remove unused method.
| |
| 13851 | |
| 13852 // HostResolver methods: | |
| 13853 int Resolve(const RequestInfo& info, | |
|
Bence
2017/05/25 15:46:02
Remove method that would trivially call into base
| |
| 13854 RequestPriority priority, | |
| 13855 AddressList* addresses, | |
| 13856 const CompletionCallback& callback, | |
| 13857 std::unique_ptr<Request>* out_req, | |
| 13858 const NetLogWithSource& net_log) override { | |
| 13859 return host_resolver_.Resolve( | |
| 13860 info, priority, addresses, callback, out_req, net_log); | |
| 13861 } | |
| 13862 | |
| 13863 int ResolveFromCache(const RequestInfo& info, | 13850 int ResolveFromCache(const RequestInfo& info, |
| 13864 AddressList* addresses, | 13851 AddressList* addresses, |
| 13865 const NetLogWithSource& net_log) override { | 13852 const NetLogWithSource& net_log) override { |
| 13866 int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); | 13853 int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
| 13867 if (rv == OK && info.host_port_pair().Equals(host_port_)) | 13854 if (rv == OK && info.host_port_pair().Equals(host_port_)) |
| 13868 host_resolver_.GetHostCache()->clear(); | 13855 GetHostCache()->clear(); |
| 13869 return rv; | 13856 return rv; |
| 13870 } | 13857 } |
| 13871 | 13858 |
| 13872 MockCachingHostResolver* GetMockHostResolver() { | |
|
Bence
2017/05/25 15:46:02
Remove unused method. This is my favorite part!
| |
| 13873 return &host_resolver_; | |
| 13874 } | |
| 13875 | |
| 13876 private: | 13859 private: |
| 13877 MockCachingHostResolver host_resolver_; | |
| 13878 const HostPortPair host_port_; | 13860 const HostPortPair host_port_; |
| 13879 }; | 13861 }; |
| 13880 | 13862 |
| 13881 TEST_F(HttpNetworkTransactionTest, | 13863 TEST_F(HttpNetworkTransactionTest, |
| 13882 UseIPConnectionPoolingWithHostCacheExpiration) { | 13864 UseIPConnectionPoolingWithHostCacheExpiration) { |
| 13883 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. | 13865 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
| 13884 OneTimeCachingHostResolver host_resolver( | 13866 session_deps_.host_resolver = base::MakeUnique<OneTimeCachingHostResolver>( |
| 13885 HostPortPair("mail.example.com", 443)); | 13867 HostPortPair("mail.example.com", 443)); |
| 13886 HttpNetworkSession::Params params = | |
| 13887 SpdySessionDependencies::CreateSessionParams(&session_deps_); | |
| 13888 params.host_resolver = &host_resolver; | |
| 13889 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 13868 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13890 | 13869 |
| 13891 AddSSLSocketData(); | 13870 AddSSLSocketData(); |
| 13892 | 13871 |
| 13893 SpdySerializedFrame host1_req( | 13872 SpdySerializedFrame host1_req( |
| 13894 spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); | 13873 spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13895 spdy_util_.UpdateWithStreamDestruction(1); | 13874 spdy_util_.UpdateWithStreamDestruction(1); |
| 13896 SpdySerializedFrame host2_req( | 13875 SpdySerializedFrame host2_req( |
| 13897 spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); | 13876 spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
| 13898 MockWrite spdy_writes[] = { | 13877 MockWrite spdy_writes[] = { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13933 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); | 13912 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13934 | 13913 |
| 13935 std::string response_data; | 13914 std::string response_data; |
| 13936 ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); | 13915 ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13937 EXPECT_EQ("hello!", response_data); | 13916 EXPECT_EQ("hello!", response_data); |
| 13938 | 13917 |
| 13939 // Preload cache entries into HostCache. | 13918 // Preload cache entries into HostCache. |
| 13940 HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); | 13919 HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
| 13941 AddressList ignored; | 13920 AddressList ignored; |
| 13942 std::unique_ptr<HostResolver::Request> request; | 13921 std::unique_ptr<HostResolver::Request> request; |
| 13943 rv = host_resolver.Resolve(resolve_info, DEFAULT_PRIORITY, &ignored, | 13922 rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13944 callback.callback(), &request, NetLogWithSource()); | 13923 &ignored, callback.callback(), |
| 13924 &request, NetLogWithSource()); | |
| 13945 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 13925 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13946 rv = callback.WaitForResult(); | 13926 rv = callback.WaitForResult(); |
| 13947 EXPECT_THAT(rv, IsOk()); | 13927 EXPECT_THAT(rv, IsOk()); |
| 13948 | 13928 |
| 13949 HttpRequestInfo request2; | 13929 HttpRequestInfo request2; |
| 13950 request2.method = "GET"; | 13930 request2.method = "GET"; |
| 13951 request2.url = GURL("https://mail.example.com/"); | 13931 request2.url = GURL("https://mail.example.com/"); |
| 13952 request2.load_flags = 0; | 13932 request2.load_flags = 0; |
| 13953 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); | 13933 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13954 | 13934 |
| (...skipping 2892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16847 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", | 16827 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16848 "", false); | 16828 "", false); |
| 16849 } | 16829 } |
| 16850 | 16830 |
| 16851 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { | 16831 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 16852 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", | 16832 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16853 "www.foo.com/other", true); | 16833 "www.foo.com/other", true); |
| 16854 } | 16834 } |
| 16855 | 16835 |
| 16856 } // namespace net | 16836 } // namespace net |
| OLD | NEW |