Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 17 #include "net/base/auth.h" | 17 #include "net/base/auth.h" |
| 18 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
| 19 #include "net/base/sdch_observer.h" | 19 #include "net/base/sdch_observer.h" |
| 20 #include "net/base/test_data_directory.h" | 20 #include "net/base/test_data_directory.h" |
| 21 #include "net/cookies/cookie_store_test_helpers.h" | 21 #include "net/cookies/cookie_store_test_helpers.h" |
| 22 #include "net/http/http_transaction_factory.h" | 22 #include "net/http/http_transaction_factory.h" |
| 23 #include "net/http/http_transaction_test_util.h" | 23 #include "net/http/http_transaction_test_util.h" |
| 24 #include "net/socket/socket_test_util.h" | 24 #include "net/socket/socket_test_util.h" |
| 25 #include "net/test/cert_test_util.h" | 25 #include "net/test/cert_test_util.h" |
| 26 #include "net/url_request/url_request.h" | 26 #include "net/url_request/url_request.h" |
| 27 #include "net/url_request/url_request_intercepting_job_factory.h" | |
| 27 #include "net/url_request/url_request_job_factory_impl.h" | 28 #include "net/url_request/url_request_job_factory_impl.h" |
| 28 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
| 29 #include "net/url_request/url_request_test_util.h" | 30 #include "net/url_request/url_request_test_util.h" |
| 30 #include "net/websockets/websocket_handshake_stream_base.h" | 31 #include "net/websockets/websocket_handshake_stream_base.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 #include "url/url_constants.h" | 35 #include "url/url_constants.h" |
| 35 | 36 |
| 36 namespace net { | 37 namespace net { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 49 ~TestURLRequestHttpJob() override {} | 50 ~TestURLRequestHttpJob() override {} |
| 50 | 51 |
| 51 using URLRequestHttpJob::SetPriority; | 52 using URLRequestHttpJob::SetPriority; |
| 52 using URLRequestHttpJob::Start; | 53 using URLRequestHttpJob::Start; |
| 53 using URLRequestHttpJob::Kill; | 54 using URLRequestHttpJob::Kill; |
| 54 using URLRequestHttpJob::priority; | 55 using URLRequestHttpJob::priority; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 class URLRequestHttpJobTest : public ::testing::Test { | 58 class URLRequestHttpJobTest : public ::testing::Test { |
| 58 protected: | 59 protected: |
| 59 URLRequestHttpJobTest() : context_(true) { | 60 URLRequestHttpJobTest() |
| 61 : test_job_factory_( | |
| 62 URLRequestJobFactoryImpl::CreateWithHttpProtocolHandlers()), | |
| 63 context_(true) { | |
| 60 context_.set_http_transaction_factory(&network_layer_); | 64 context_.set_http_transaction_factory(&network_layer_); |
| 61 | 65 |
| 62 // The |test_job_factory_| takes ownership of the interceptor. | 66 // The |test_job_factory_| takes ownership of the interceptor. |
| 63 test_job_interceptor_ = new TestJobInterceptor(); | 67 test_job_interceptor_ = new TestJobInterceptor(); |
| 64 EXPECT_TRUE(test_job_factory_.SetProtocolHandler( | 68 test_job_factory_.reset(new URLRequestInterceptingJobFactory( |
| 65 url::kHttpScheme, base::WrapUnique(test_job_interceptor_))); | 69 std::move(test_job_factory_), base::WrapUnique(test_job_interceptor_))); |
|
mmenke
2016/04/28 16:52:41
Suggest just inlining URLRequestJobFactoryImpl::Cr
mgersh
2016/04/28 20:36:30
Done.
| |
| 66 context_.set_job_factory(&test_job_factory_); | 70 context_.set_job_factory(test_job_factory_.get()); |
| 67 | 71 |
| 68 context_.Init(); | 72 context_.Init(); |
| 69 | 73 |
| 70 req_ = context_.CreateRequest(GURL("http://www.example.com"), | 74 req_ = context_.CreateRequest(GURL("http://www.example.com"), |
| 71 DEFAULT_PRIORITY, &delegate_); | 75 DEFAULT_PRIORITY, &delegate_); |
| 72 } | 76 } |
| 73 | 77 |
| 74 bool TransactionAcceptsSdchEncoding() { | 78 bool TransactionAcceptsSdchEncoding() { |
| 75 base::WeakPtr<MockNetworkTransaction> transaction( | 79 base::WeakPtr<MockNetworkTransaction> transaction( |
| 76 network_layer_.last_transaction()); | 80 network_layer_.last_transaction()); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 99 } | 103 } |
| 100 | 104 |
| 101 void EnableSdch() { | 105 void EnableSdch() { |
| 102 context_.SetSdchManager(std::unique_ptr<SdchManager>(new SdchManager)); | 106 context_.SetSdchManager(std::unique_ptr<SdchManager>(new SdchManager)); |
| 103 } | 107 } |
| 104 | 108 |
| 105 MockNetworkLayer network_layer_; | 109 MockNetworkLayer network_layer_; |
| 106 | 110 |
| 107 // |test_job_interceptor_| is owned by |test_job_factory_|. | 111 // |test_job_interceptor_| is owned by |test_job_factory_|. |
| 108 TestJobInterceptor* test_job_interceptor_; | 112 TestJobInterceptor* test_job_interceptor_; |
| 109 URLRequestJobFactoryImpl test_job_factory_; | 113 std::unique_ptr<URLRequestJobFactory> test_job_factory_; |
| 110 | 114 |
| 111 TestURLRequestContext context_; | 115 TestURLRequestContext context_; |
| 112 TestDelegate delegate_; | 116 TestDelegate delegate_; |
| 113 std::unique_ptr<URLRequest> req_; | 117 std::unique_ptr<URLRequest> req_; |
| 114 }; | 118 }; |
| 115 | 119 |
| 116 class URLRequestHttpJobWithMockSocketsTest : public ::testing::Test { | 120 class URLRequestHttpJobWithMockSocketsTest : public ::testing::Test { |
| 117 protected: | 121 protected: |
| 118 URLRequestHttpJobWithMockSocketsTest() | 122 URLRequestHttpJobWithMockSocketsTest() |
| 119 : context_(new TestURLRequestContext(true)) { | 123 : context_(new TestURLRequestContext(true)) { |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 base::RunLoop().RunUntilIdle(); | 944 base::RunLoop().RunUntilIdle(); |
| 941 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 945 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
| 942 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 946 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 943 } | 947 } |
| 944 | 948 |
| 945 #endif // !defined(OS_IOS) | 949 #endif // !defined(OS_IOS) |
| 946 | 950 |
| 947 } // namespace | 951 } // namespace |
| 948 | 952 |
| 949 } // namespace net | 953 } // namespace net |
| OLD | NEW |