OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <memory> | 10 #include <memory> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "net/http/http_transaction_test_util.h" | 22 #include "net/http/http_transaction_test_util.h" |
23 #include "net/log/net_log_event_type.h" | 23 #include "net/log/net_log_event_type.h" |
24 #include "net/log/test_net_log.h" | 24 #include "net/log/test_net_log.h" |
25 #include "net/log/test_net_log_entry.h" | 25 #include "net/log/test_net_log_entry.h" |
26 #include "net/log/test_net_log_util.h" | 26 #include "net/log/test_net_log_util.h" |
27 #include "net/socket/socket_test_util.h" | 27 #include "net/socket/socket_test_util.h" |
28 #include "net/test/cert_test_util.h" | 28 #include "net/test/cert_test_util.h" |
29 #include "net/test/gtest_util.h" | 29 #include "net/test/gtest_util.h" |
30 #include "net/test/test_data_directory.h" | 30 #include "net/test/test_data_directory.h" |
31 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
| 32 #include "net/url_request/url_request_intercepting_job_factory.h" |
32 #include "net/url_request/url_request_job_factory_impl.h" | 33 #include "net/url_request/url_request_job_factory_impl.h" |
33 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
34 #include "net/url_request/url_request_test_util.h" | 35 #include "net/url_request/url_request_test_util.h" |
35 #include "net/websockets/websocket_handshake_stream_base.h" | 36 #include "net/websockets/websocket_handshake_stream_base.h" |
36 #include "testing/gmock/include/gmock/gmock.h" | 37 #include "testing/gmock/include/gmock/gmock.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
38 #include "url/gurl.h" | 39 #include "url/gurl.h" |
39 #include "url/url_constants.h" | 40 #include "url/url_constants.h" |
40 | 41 |
41 using net::test::IsError; | 42 using net::test::IsError; |
(...skipping 15 matching lines...) Expand all Loading... |
57 ~TestURLRequestHttpJob() override {} | 58 ~TestURLRequestHttpJob() override {} |
58 | 59 |
59 using URLRequestHttpJob::SetPriority; | 60 using URLRequestHttpJob::SetPriority; |
60 using URLRequestHttpJob::Start; | 61 using URLRequestHttpJob::Start; |
61 using URLRequestHttpJob::Kill; | 62 using URLRequestHttpJob::Kill; |
62 using URLRequestHttpJob::priority; | 63 using URLRequestHttpJob::priority; |
63 }; | 64 }; |
64 | 65 |
65 class URLRequestHttpJobTest : public ::testing::Test { | 66 class URLRequestHttpJobTest : public ::testing::Test { |
66 protected: | 67 protected: |
67 URLRequestHttpJobTest() : context_(true) { | 68 URLRequestHttpJobTest() : test_job_factory_(nullptr), context_(true) { |
68 context_.set_http_transaction_factory(&network_layer_); | 69 context_.set_http_transaction_factory(&network_layer_); |
69 | 70 |
70 // The |test_job_factory_| takes ownership of the interceptor. | 71 // The |test_job_factory_| takes ownership of the interceptor. |
71 test_job_interceptor_ = new TestJobInterceptor(); | 72 test_job_interceptor_ = new TestJobInterceptor(); |
72 EXPECT_TRUE(test_job_factory_.SetProtocolHandler( | 73 test_job_factory_.reset(new URLRequestInterceptingJobFactory( |
73 url::kHttpScheme, base::WrapUnique(test_job_interceptor_))); | 74 URLRequestJobFactoryImpl::CreateWithHttpProtocolHandlers(), |
74 context_.set_job_factory(&test_job_factory_); | 75 base::WrapUnique(test_job_interceptor_))); |
| 76 context_.set_job_factory(test_job_factory_.get()); |
75 context_.set_net_log(&net_log_); | 77 context_.set_net_log(&net_log_); |
76 context_.Init(); | 78 context_.Init(); |
77 | 79 |
78 req_ = context_.CreateRequest(GURL("http://www.example.com"), | 80 req_ = context_.CreateRequest(GURL("http://www.example.com"), |
79 DEFAULT_PRIORITY, &delegate_); | 81 DEFAULT_PRIORITY, &delegate_); |
80 } | 82 } |
81 | 83 |
82 bool TransactionAcceptsSdchEncoding() { | 84 bool TransactionAcceptsSdchEncoding() { |
83 base::WeakPtr<MockNetworkTransaction> transaction( | 85 base::WeakPtr<MockNetworkTransaction> transaction( |
84 network_layer_.last_transaction()); | 86 network_layer_.last_transaction()); |
(...skipping 22 matching lines...) Expand all Loading... |
107 } | 109 } |
108 | 110 |
109 void EnableSdch() { | 111 void EnableSdch() { |
110 context_.SetSdchManager(std::unique_ptr<SdchManager>(new SdchManager)); | 112 context_.SetSdchManager(std::unique_ptr<SdchManager>(new SdchManager)); |
111 } | 113 } |
112 | 114 |
113 MockNetworkLayer network_layer_; | 115 MockNetworkLayer network_layer_; |
114 | 116 |
115 // |test_job_interceptor_| is owned by |test_job_factory_|. | 117 // |test_job_interceptor_| is owned by |test_job_factory_|. |
116 TestJobInterceptor* test_job_interceptor_; | 118 TestJobInterceptor* test_job_interceptor_; |
117 URLRequestJobFactoryImpl test_job_factory_; | 119 std::unique_ptr<URLRequestJobFactory> test_job_factory_; |
118 | 120 |
119 TestURLRequestContext context_; | 121 TestURLRequestContext context_; |
120 TestDelegate delegate_; | 122 TestDelegate delegate_; |
121 TestNetLog net_log_; | 123 TestNetLog net_log_; |
122 std::unique_ptr<URLRequest> req_; | 124 std::unique_ptr<URLRequest> req_; |
123 }; | 125 }; |
124 | 126 |
125 class URLRequestHttpJobWithMockSocketsTest : public ::testing::Test { | 127 class URLRequestHttpJobWithMockSocketsTest : public ::testing::Test { |
126 protected: | 128 protected: |
127 URLRequestHttpJobWithMockSocketsTest() | 129 URLRequestHttpJobWithMockSocketsTest() |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 base::RunLoop().RunUntilIdle(); | 942 base::RunLoop().RunUntilIdle(); |
941 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); | 943 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); |
942 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 944 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
943 } | 945 } |
944 | 946 |
945 #endif // defined(ENABLE_WEBSOCKETS) | 947 #endif // defined(ENABLE_WEBSOCKETS) |
946 | 948 |
947 } // namespace | 949 } // namespace |
948 | 950 |
949 } // namespace net | 951 } // namespace net |
OLD | NEW |