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" | 26 #include "base/message_loop/message_loop.h" |
27 #include "base/run_loop.h" | 27 #include "base/run_loop.h" |
28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
29 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
30 #include "base/test/scoped_task_scheduler.h" | 30 #include "base/task_scheduler/task_scheduler.h" |
31 #include "base/test/test_file_util.h" | 31 #include "base/test/test_file_util.h" |
32 #include "base/threading/thread_task_runner_handle.h" | 32 #include "base/threading/thread_task_runner_handle.h" |
33 #include "net/base/auth.h" | 33 #include "net/base/auth.h" |
34 #include "net/base/chunked_upload_data_stream.h" | 34 #include "net/base/chunked_upload_data_stream.h" |
35 #include "net/base/completion_callback.h" | 35 #include "net/base/completion_callback.h" |
36 #include "net/base/elements_upload_data_stream.h" | 36 #include "net/base/elements_upload_data_stream.h" |
37 #include "net/base/load_timing_info.h" | 37 #include "net/base/load_timing_info.h" |
38 #include "net/base/load_timing_info_test_util.h" | 38 #include "net/base/load_timing_info_test_util.h" |
39 #include "net/base/net_errors.h" | 39 #include "net/base/net_errors.h" |
40 #include "net/base/network_throttle_manager.h" | 40 #include "net/base/network_throttle_manager.h" |
(...skipping 16714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16755 | 16755 |
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 | |
16766 namespace { | |
16767 | |
16768 // TODO(fdoray): Use ScopedTaskEnvironment::RunUntilIdle() instead of this once | |
16769 // implemented. https://crbug.com/708584 | |
16770 class TaskObserver : public base::MessageLoop::TaskObserver { | |
16771 public: | |
16772 TaskObserver() : ran_task_(false) {} | |
16773 ~TaskObserver() override {} | |
16774 | |
16775 // MessageLoop::TaskObserver overrides. | |
16776 void WillProcessTask(const base::PendingTask& pending_task) override {} | |
16777 void DidProcessTask(const base::PendingTask& pending_task) override { | |
16778 ran_task_ = true; | |
16779 } | |
16780 | |
16781 bool ran_task() const { return ran_task_; } | |
16782 | |
16783 private: | |
16784 bool ran_task_ = false; | |
16785 DISALLOW_COPY_AND_ASSIGN(TaskObserver); | |
16786 }; | |
16787 | |
16788 // Run tasks on the main thread until there are no more main thread or | |
16789 // TaskScheduler tasks. | |
16790 void RunMainThreadAndTaskSchedulerUntilIdle() { | |
16791 for (;;) { | |
16792 base::TaskScheduler::GetInstance()->FlushForTesting(); | |
mmenke
2017/05/09 15:40:44
Why are both this and RunUntilIdle needed?
fdoray
2017/05/09 21:43:47
n/a with latest patch set
| |
16793 | |
16794 // Setup a task observer to determine if main thread tasks have run in the | |
16795 // current loop iteration. | |
16796 TaskObserver task_observer; | |
16797 base::MessageLoop::current()->AddTaskObserver(&task_observer); | |
16798 base::RunLoop().RunUntilIdle(); | |
16799 base::MessageLoop::current()->RemoveTaskObserver(&task_observer); | |
16800 | |
16801 if (!task_observer.ran_task()) | |
16802 break; | |
16803 } | |
16804 } | |
16805 | |
16806 } // namespace | |
16807 | |
16765 TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { | 16808 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"; | 16809 const std::string https_url = "https://www.example.com"; |
16771 HttpRequestInfo request; | 16810 HttpRequestInfo request; |
16772 request.url = GURL(https_url); | 16811 request.url = GURL(https_url); |
16773 request.method = "GET"; | 16812 request.method = "GET"; |
16774 | 16813 |
16775 SSLSocketDataProvider ssl(ASYNC, OK); | 16814 SSLSocketDataProvider ssl(ASYNC, OK); |
16776 ssl.token_binding_negotiated = true; | 16815 ssl.token_binding_negotiated = true; |
16777 ssl.token_binding_key_param = TB_PARAM_ECDSAP256; | 16816 ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
16778 ssl.next_proto = kProtoHTTP2; | 16817 ssl.next_proto = kProtoHTTP2; |
16779 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 16818 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
16780 | 16819 |
16781 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); | 16820 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
16782 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); | 16821 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
16783 MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), | 16822 MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
16784 MockRead(ASYNC, ERR_IO_PENDING)}; | 16823 MockRead(ASYNC, ERR_IO_PENDING)}; |
16785 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); | 16824 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
16786 session_deps_.socket_factory->AddSocketDataProvider(&data); | 16825 session_deps_.socket_factory->AddSocketDataProvider(&data); |
16787 session_deps_.channel_id_service.reset( | 16826 session_deps_.channel_id_service.reset( |
16788 new ChannelIDService(new DefaultChannelIDStore(nullptr))); | 16827 new ChannelIDService(new DefaultChannelIDStore(nullptr))); |
16789 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 16828 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
16790 | 16829 |
16791 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | 16830 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
16792 TestCompletionCallback callback; | 16831 TestCompletionCallback callback; |
16793 EXPECT_EQ(ERR_IO_PENDING, | 16832 EXPECT_EQ(ERR_IO_PENDING, |
16794 trans.Start(&request, callback.callback(), NetLogWithSource())); | 16833 trans.Start(&request, callback.callback(), NetLogWithSource())); |
16795 base::RunLoop().RunUntilIdle(); | 16834 |
16835 RunMainThreadAndTaskSchedulerUntilIdle(); | |
16796 | 16836 |
16797 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16837 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
16798 HttpRequestHeaders headers; | 16838 HttpRequestHeaders headers; |
16799 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16839 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
16800 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16840 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
16801 } | 16841 } |
16802 #endif // !defined(OS_IOS) | 16842 #endif // !defined(OS_IOS) |
16803 | 16843 |
16804 void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, | 16844 void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
16805 const std::string& accept_encoding, | 16845 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", | 16908 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
16869 "", false); | 16909 "", false); |
16870 } | 16910 } |
16871 | 16911 |
16872 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { | 16912 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
16873 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", | 16913 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
16874 "www.foo.com/other", true); | 16914 "www.foo.com/other", true); |
16875 } | 16915 } |
16876 | 16916 |
16877 } // namespace net | 16917 } // namespace net |
OLD | NEW |