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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/test/test_file_util.h" | 21 #include "base/test/test_file_util.h" |
21 #include "net/base/auth.h" | 22 #include "net/base/auth.h" |
22 #include "net/base/capturing_net_log.h" | 23 #include "net/base/capturing_net_log.h" |
23 #include "net/base/completion_callback.h" | 24 #include "net/base/completion_callback.h" |
24 #include "net/base/load_timing_info.h" | 25 #include "net/base/load_timing_info.h" |
25 #include "net/base/load_timing_info_test_util.h" | 26 #include "net/base/load_timing_info_test_util.h" |
26 #include "net/base/net_log.h" | 27 #include "net/base/net_log.h" |
27 #include "net/base/net_log_unittest.h" | 28 #include "net/base/net_log_unittest.h" |
(...skipping 11645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11673 rv = callback.WaitForResult(); | 11674 rv = callback.WaitForResult(); |
11674 EXPECT_EQ(OK, rv); | 11675 EXPECT_EQ(OK, rv); |
11675 | 11676 |
11676 HttpRequestHeaders request_headers; | 11677 HttpRequestHeaders request_headers; |
11677 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); | 11678 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
11678 std::string foo; | 11679 std::string foo; |
11679 EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); | 11680 EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
11680 EXPECT_EQ("bar", foo); | 11681 EXPECT_EQ("bar", foo); |
11681 } | 11682 } |
11682 | 11683 |
| 11684 namespace { |
| 11685 |
| 11686 // Fake HttpStreamRequest that simply records calls to SetPriority(). |
| 11687 class FakeStreamRequest : public HttpStreamRequest, |
| 11688 public base::SupportsWeakPtr<FakeStreamRequest> { |
| 11689 public: |
| 11690 explicit FakeStreamRequest(RequestPriority priority) : priority_(priority) {} |
| 11691 virtual ~FakeStreamRequest() {} |
| 11692 |
| 11693 RequestPriority priority() const { return priority_; } |
| 11694 |
| 11695 virtual int RestartTunnelWithProxyAuth( |
| 11696 const AuthCredentials& credentials) OVERRIDE { |
| 11697 ADD_FAILURE(); |
| 11698 return ERR_UNEXPECTED; |
| 11699 } |
| 11700 |
| 11701 virtual LoadState GetLoadState() const OVERRIDE { |
| 11702 ADD_FAILURE(); |
| 11703 return LoadState(); |
| 11704 } |
| 11705 |
| 11706 virtual void SetPriority(RequestPriority priority) OVERRIDE { |
| 11707 priority_ = priority; |
| 11708 } |
| 11709 |
| 11710 virtual bool was_npn_negotiated() const OVERRIDE { |
| 11711 ADD_FAILURE(); |
| 11712 return false; |
| 11713 } |
| 11714 |
| 11715 virtual NextProto protocol_negotiated() const OVERRIDE { |
| 11716 ADD_FAILURE(); |
| 11717 return kProtoUnknown; |
| 11718 } |
| 11719 |
| 11720 virtual bool using_spdy() const OVERRIDE { |
| 11721 ADD_FAILURE(); |
| 11722 return false; |
| 11723 } |
| 11724 |
| 11725 private: |
| 11726 RequestPriority priority_; |
| 11727 |
| 11728 DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 11729 }; |
| 11730 |
| 11731 // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 11732 class FakeStreamFactory : public HttpStreamFactory { |
| 11733 public: |
| 11734 FakeStreamFactory() {} |
| 11735 virtual ~FakeStreamFactory() {} |
| 11736 |
| 11737 // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 11738 // RequestStream() (which may be NULL if it was destroyed already). |
| 11739 base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 11740 return last_stream_request_; |
| 11741 } |
| 11742 |
| 11743 virtual HttpStreamRequest* RequestStream( |
| 11744 const HttpRequestInfo& info, |
| 11745 RequestPriority priority, |
| 11746 const SSLConfig& server_ssl_config, |
| 11747 const SSLConfig& proxy_ssl_config, |
| 11748 HttpStreamRequest::Delegate* delegate, |
| 11749 const BoundNetLog& net_log) OVERRIDE { |
| 11750 FakeStreamRequest* fake_request = new FakeStreamRequest(priority); |
| 11751 last_stream_request_ = fake_request->AsWeakPtr(); |
| 11752 return fake_request; |
| 11753 } |
| 11754 |
| 11755 virtual HttpStreamRequest* RequestWebSocketStream( |
| 11756 const HttpRequestInfo& info, |
| 11757 RequestPriority priority, |
| 11758 const SSLConfig& server_ssl_config, |
| 11759 const SSLConfig& proxy_ssl_config, |
| 11760 HttpStreamRequest::Delegate* delegate, |
| 11761 WebSocketStreamBase::Factory* factory, |
| 11762 const BoundNetLog& net_log) OVERRIDE { |
| 11763 ADD_FAILURE(); |
| 11764 return NULL; |
| 11765 } |
| 11766 |
| 11767 virtual void PreconnectStreams(int num_streams, |
| 11768 const HttpRequestInfo& info, |
| 11769 RequestPriority priority, |
| 11770 const SSLConfig& server_ssl_config, |
| 11771 const SSLConfig& proxy_ssl_config) OVERRIDE { |
| 11772 ADD_FAILURE(); |
| 11773 } |
| 11774 |
| 11775 virtual base::Value* PipelineInfoToValue() const OVERRIDE { |
| 11776 ADD_FAILURE(); |
| 11777 return NULL; |
| 11778 } |
| 11779 |
| 11780 virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE { |
| 11781 ADD_FAILURE(); |
| 11782 return NULL; |
| 11783 } |
| 11784 |
| 11785 private: |
| 11786 base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 11787 |
| 11788 DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 11789 }; |
| 11790 |
| 11791 } // namespace |
| 11792 |
| 11793 // Make sure that HttpNetworkTransaction passes on its priority to its |
| 11794 // stream request on start. |
| 11795 TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 11796 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11797 HttpNetworkSessionPeer peer(session); |
| 11798 FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 11799 peer.SetHttpStreamFactory(fake_factory); |
| 11800 |
| 11801 HttpNetworkTransaction trans(LOW, session); |
| 11802 |
| 11803 ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 11804 |
| 11805 HttpRequestInfo request; |
| 11806 TestCompletionCallback callback; |
| 11807 EXPECT_EQ(ERR_IO_PENDING, |
| 11808 trans.Start(&request, callback.callback(), BoundNetLog())); |
| 11809 |
| 11810 base::WeakPtr<FakeStreamRequest> fake_request = |
| 11811 fake_factory->last_stream_request(); |
| 11812 ASSERT_TRUE(fake_request != NULL); |
| 11813 EXPECT_EQ(LOW, fake_request->priority()); |
| 11814 } |
| 11815 |
| 11816 // Make sure that HttpNetworkTransaction passes on its priority |
| 11817 // updates to its stream request. |
| 11818 TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 11819 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11820 HttpNetworkSessionPeer peer(session); |
| 11821 FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 11822 peer.SetHttpStreamFactory(fake_factory); |
| 11823 |
| 11824 HttpNetworkTransaction trans(LOW, session); |
| 11825 |
| 11826 HttpRequestInfo request; |
| 11827 TestCompletionCallback callback; |
| 11828 EXPECT_EQ(ERR_IO_PENDING, |
| 11829 trans.Start(&request, callback.callback(), BoundNetLog())); |
| 11830 |
| 11831 base::WeakPtr<FakeStreamRequest> fake_request = |
| 11832 fake_factory->last_stream_request(); |
| 11833 ASSERT_TRUE(fake_request != NULL); |
| 11834 EXPECT_EQ(LOW, fake_request->priority()); |
| 11835 |
| 11836 trans.SetPriority(LOWEST); |
| 11837 ASSERT_TRUE(fake_request != NULL); |
| 11838 EXPECT_EQ(LOWEST, fake_request->priority()); |
| 11839 } |
| 11840 |
11683 } // namespace net | 11841 } // namespace net |
OLD | NEW |