| 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 |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <utility> | 15 #include <utility> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
| 21 #include "base/json/json_writer.h" | 21 #include "base/json/json_writer.h" |
| 22 #include "base/logging.h" | 22 #include "base/logging.h" |
| 23 #include "base/macros.h" | 23 #include "base/macros.h" |
| 24 #include "base/memory/ptr_util.h" | 24 #include "base/memory/ptr_util.h" |
| 25 #include "base/memory/weak_ptr.h" | 25 #include "base/memory/weak_ptr.h" |
| 26 #include "base/message_loop/message_loop.h" | |
| 27 #include "base/run_loop.h" | 26 #include "base/run_loop.h" |
| 28 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 29 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 30 #include "base/test/scoped_task_scheduler.h" | 29 #include "base/test/scoped_task_environment.h" |
| 31 #include "base/test/test_file_util.h" | 30 #include "base/test/test_file_util.h" |
| 32 #include "base/threading/thread_task_runner_handle.h" | 31 #include "base/threading/thread_task_runner_handle.h" |
| 33 #include "net/base/auth.h" | 32 #include "net/base/auth.h" |
| 34 #include "net/base/chunked_upload_data_stream.h" | 33 #include "net/base/chunked_upload_data_stream.h" |
| 35 #include "net/base/completion_callback.h" | 34 #include "net/base/completion_callback.h" |
| 36 #include "net/base/elements_upload_data_stream.h" | 35 #include "net/base/elements_upload_data_stream.h" |
| 37 #include "net/base/load_timing_info.h" | 36 #include "net/base/load_timing_info.h" |
| 38 #include "net/base/load_timing_info_test_util.h" | 37 #include "net/base/load_timing_info_test_util.h" |
| 39 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
| 40 #include "net/base/network_throttle_manager.h" | 39 #include "net/base/network_throttle_manager.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 #include "net/spdy/chromium/spdy_test_util_common.h" | 87 #include "net/spdy/chromium/spdy_test_util_common.h" |
| 89 #include "net/spdy/core/spdy_framer.h" | 88 #include "net/spdy/core/spdy_framer.h" |
| 90 #include "net/ssl/default_channel_id_store.h" | 89 #include "net/ssl/default_channel_id_store.h" |
| 91 #include "net/ssl/ssl_cert_request_info.h" | 90 #include "net/ssl/ssl_cert_request_info.h" |
| 92 #include "net/ssl/ssl_config_service.h" | 91 #include "net/ssl/ssl_config_service.h" |
| 93 #include "net/ssl/ssl_config_service_defaults.h" | 92 #include "net/ssl/ssl_config_service_defaults.h" |
| 94 #include "net/ssl/ssl_info.h" | 93 #include "net/ssl/ssl_info.h" |
| 95 #include "net/ssl/ssl_private_key.h" | 94 #include "net/ssl/ssl_private_key.h" |
| 96 #include "net/test/cert_test_util.h" | 95 #include "net/test/cert_test_util.h" |
| 97 #include "net/test/gtest_util.h" | 96 #include "net/test/gtest_util.h" |
| 97 #include "net/test/net_test_suite.h" |
| 98 #include "net/test/test_data_directory.h" | 98 #include "net/test/test_data_directory.h" |
| 99 #include "net/websockets/websocket_handshake_stream_base.h" | 99 #include "net/websockets/websocket_handshake_stream_base.h" |
| 100 #include "testing/gmock/include/gmock/gmock.h" | 100 #include "testing/gmock/include/gmock/gmock.h" |
| 101 #include "testing/gtest/include/gtest/gtest.h" | 101 #include "testing/gtest/include/gtest/gtest.h" |
| 102 #include "testing/platform_test.h" | 102 #include "testing/platform_test.h" |
| 103 #include "url/gurl.h" | 103 #include "url/gurl.h" |
| 104 | 104 |
| 105 using net::test::IsError; | 105 using net::test::IsError; |
| 106 using net::test::IsOk; | 106 using net::test::IsOk; |
| 107 | 107 |
| (...skipping 16648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16756 // Call it and check results (partially a "doesn't crash" test). | 16756 // Call it and check results (partially a "doesn't crash" test). |
| 16757 trans_ptr->SetPriority(IDLE); | 16757 trans_ptr->SetPriority(IDLE); |
| 16758 trans_ptr = nullptr; // No longer a valid pointer. | 16758 trans_ptr = nullptr; // No longer a valid pointer. |
| 16759 | 16759 |
| 16760 base::RunLoop().RunUntilIdle(); | 16760 base::RunLoop().RunUntilIdle(); |
| 16761 ASSERT_FALSE(callback.have_result()); | 16761 ASSERT_FALSE(callback.have_result()); |
| 16762 } | 16762 } |
| 16763 | 16763 |
| 16764 #if !defined(OS_IOS) | 16764 #if !defined(OS_IOS) |
| 16765 TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { | 16765 TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
| 16766 // Required by ChannelIDService. | |
| 16767 base::test::ScopedTaskScheduler scoped_task_scheduler( | |
| 16768 base::MessageLoop::current()); | |
| 16769 | |
| 16770 const std::string https_url = "https://www.example.com"; | 16766 const std::string https_url = "https://www.example.com"; |
| 16771 HttpRequestInfo request; | 16767 HttpRequestInfo request; |
| 16772 request.url = GURL(https_url); | 16768 request.url = GURL(https_url); |
| 16773 request.method = "GET"; | 16769 request.method = "GET"; |
| 16774 | 16770 |
| 16775 SSLSocketDataProvider ssl(ASYNC, OK); | 16771 SSLSocketDataProvider ssl(ASYNC, OK); |
| 16776 ssl.token_binding_negotiated = true; | 16772 ssl.token_binding_negotiated = true; |
| 16777 ssl.token_binding_key_param = TB_PARAM_ECDSAP256; | 16773 ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
| 16778 ssl.next_proto = kProtoHTTP2; | 16774 ssl.next_proto = kProtoHTTP2; |
| 16779 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 16775 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16780 | 16776 |
| 16781 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); | 16777 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16782 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); | 16778 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16783 MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), | 16779 MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
| 16784 MockRead(ASYNC, ERR_IO_PENDING)}; | 16780 MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16785 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); | 16781 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16786 session_deps_.socket_factory->AddSocketDataProvider(&data); | 16782 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16787 session_deps_.channel_id_service.reset( | 16783 session_deps_.channel_id_service.reset( |
| 16788 new ChannelIDService(new DefaultChannelIDStore(nullptr))); | 16784 new ChannelIDService(new DefaultChannelIDStore(nullptr))); |
| 16789 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 16785 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16790 | 16786 |
| 16791 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | 16787 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16792 TestCompletionCallback callback; | 16788 TestCompletionCallback callback; |
| 16793 EXPECT_EQ(ERR_IO_PENDING, | 16789 EXPECT_EQ(ERR_IO_PENDING, |
| 16794 trans.Start(&request, callback.callback(), NetLogWithSource())); | 16790 trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 16795 base::RunLoop().RunUntilIdle(); | 16791 |
| 16792 NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
| 16796 | 16793 |
| 16797 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16794 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16798 HttpRequestHeaders headers; | 16795 HttpRequestHeaders headers; |
| 16799 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16796 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16800 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16797 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16801 } | 16798 } |
| 16802 #endif // !defined(OS_IOS) | 16799 #endif // !defined(OS_IOS) |
| 16803 | 16800 |
| 16804 void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, | 16801 void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 16805 const std::string& accept_encoding, | 16802 const std::string& accept_encoding, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16868 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", | 16865 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16869 "", false); | 16866 "", false); |
| 16870 } | 16867 } |
| 16871 | 16868 |
| 16872 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { | 16869 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 16873 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", | 16870 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16874 "www.foo.com/other", true); | 16871 "www.foo.com/other", true); |
| 16875 } | 16872 } |
| 16876 | 16873 |
| 16877 } // namespace net | 16874 } // namespace net |
| OLD | NEW |