| 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/http/http_stream_factory_impl_request.h" | 5 #include "net/http/http_stream_factory_impl_request.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "net/http/http_stream_factory_impl_job.h" | 9 #include "net/http/http_stream_factory_impl_job.h" |
| 10 #include "net/http/http_stream_factory_impl_job_controller.h" |
| 10 #include "net/proxy/proxy_info.h" | 11 #include "net/proxy/proxy_info.h" |
| 11 #include "net/proxy/proxy_service.h" | 12 #include "net/proxy/proxy_service.h" |
| 12 #include "net/spdy/spdy_test_util_common.h" | 13 #include "net/spdy/spdy_test_util_common.h" |
| 13 #include "net/ssl/ssl_failure_state.h" | 14 #include "net/ssl/ssl_failure_state.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 class HttpStreamFactoryImplRequestTest | 19 class HttpStreamFactoryImplRequestTest |
| 19 : public ::testing::Test, | 20 : public ::testing::Test, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 69 |
| 69 // Make sure that Request passes on its priority updates to its jobs. | 70 // Make sure that Request passes on its priority updates to its jobs. |
| 70 TEST_P(HttpStreamFactoryImplRequestTest, SetPriority) { | 71 TEST_P(HttpStreamFactoryImplRequestTest, SetPriority) { |
| 71 SpdySessionDependencies session_deps(GetParam(), | 72 SpdySessionDependencies session_deps(GetParam(), |
| 72 ProxyService::CreateDirect()); | 73 ProxyService::CreateDirect()); |
| 73 | 74 |
| 74 std::unique_ptr<HttpNetworkSession> session = | 75 std::unique_ptr<HttpNetworkSession> session = |
| 75 SpdySessionDependencies::SpdyCreateSession(&session_deps); | 76 SpdySessionDependencies::SpdyCreateSession(&session_deps); |
| 76 HttpStreamFactoryImpl* factory = | 77 HttpStreamFactoryImpl* factory = |
| 77 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); | 78 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); |
| 79 HttpStreamFactoryImpl::JobController* job_controller = |
| 80 new HttpStreamFactoryImpl::JobController(factory); |
| 81 factory->job_controller_set_.insert(job_controller); |
| 78 | 82 |
| 79 DoNothingRequestDelegate request_delegate; | 83 DoNothingRequestDelegate request_delegate; |
| 80 HttpStreamFactoryImpl::Request request( | 84 HttpStreamFactoryImpl::Request request( |
| 81 GURL(), factory, &request_delegate, NULL, BoundNetLog(), | 85 GURL(), job_controller, &request_delegate, NULL, BoundNetLog(), |
| 82 HttpStreamFactoryImpl::Request::HTTP_STREAM); | 86 HttpStreamFactoryImpl::Request::HTTP_STREAM); |
| 87 job_controller->request_ = &request; |
| 83 | 88 |
| 84 HttpRequestInfo request_info; | 89 HttpRequestInfo request_info; |
| 85 | 90 |
| 86 HostPortPair server = HostPortPair::FromURL(request_info.url); | 91 HostPortPair server = HostPortPair::FromURL(request_info.url); |
| 87 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); | 92 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); |
| 88 | 93 |
| 89 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( | 94 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( |
| 90 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), | 95 job_controller, session.get(), request_info, DEFAULT_PRIORITY, |
| 91 SSLConfig(), server, original_url, NULL); | 96 SSLConfig(), SSLConfig(), server, original_url, NULL); |
| 92 request.AttachJob(job); | 97 job_controller->AttachJob(job); |
| 93 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 98 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 94 | 99 |
| 95 request.SetPriority(MEDIUM); | 100 request.SetPriority(MEDIUM); |
| 96 EXPECT_EQ(MEDIUM, job->priority()); | 101 EXPECT_EQ(MEDIUM, job->priority()); |
| 97 | 102 |
| 98 // Make |job| the bound job. | 103 // Make |job| the bound job. |
| 99 request.OnStreamFailed(job, ERR_FAILED, SSLConfig(), SSL_FAILURE_NONE); | 104 job_controller->OnStreamFailed(job, ERR_FAILED, SSLConfig(), |
| 100 | 105 SSL_FAILURE_NONE); |
| 101 request.SetPriority(IDLE); | 106 request.SetPriority(IDLE); |
| 102 EXPECT_EQ(IDLE, job->priority()); | 107 EXPECT_EQ(IDLE, job->priority()); |
| 103 } | 108 } |
| 104 | 109 |
| 105 TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) { | 110 TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) { |
| 106 SpdySessionDependencies session_deps(GetParam(), | 111 SpdySessionDependencies session_deps(GetParam(), |
| 107 ProxyService::CreateDirect()); | 112 ProxyService::CreateDirect()); |
| 108 | 113 |
| 109 std::unique_ptr<HttpNetworkSession> session = | 114 std::unique_ptr<HttpNetworkSession> session = |
| 110 SpdySessionDependencies::SpdyCreateSession(&session_deps); | 115 SpdySessionDependencies::SpdyCreateSession(&session_deps); |
| 111 | 116 |
| 112 StaticSocketDataProvider socket_data; | 117 StaticSocketDataProvider socket_data; |
| 113 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); | 118 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 114 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | 119 session_deps.socket_factory->AddSocketDataProvider(&socket_data); |
| 115 | 120 |
| 116 HttpStreamFactoryImpl* factory = | 121 HttpStreamFactoryImpl* factory = |
| 117 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); | 122 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); |
| 123 HttpStreamFactoryImpl::JobController* job_controller = |
| 124 new HttpStreamFactoryImpl::JobController(factory); |
| 125 factory->job_controller_set_.insert(job_controller); |
| 118 | 126 |
| 119 DoNothingRequestDelegate request_delegate; | 127 DoNothingRequestDelegate request_delegate; |
| 120 HttpRequestInfo request_info; | 128 HttpRequestInfo request_info; |
| 121 request_info.method = "GET"; | 129 request_info.method = "GET"; |
| 122 request_info.url = GURL("http://www.google.com"); | 130 request_info.url = GURL("http://www.google.com"); |
| 123 | 131 |
| 124 HttpStreamFactoryImpl::Request request( | 132 HttpStreamFactoryImpl::Request request( |
| 125 request_info.url, factory, &request_delegate, NULL, BoundNetLog(), | 133 request_info.url, job_controller, &request_delegate, NULL, BoundNetLog(), |
| 126 HttpStreamFactoryImpl::Request::HTTP_STREAM); | 134 HttpStreamFactoryImpl::Request::HTTP_STREAM); |
| 135 job_controller->request_ = &request; |
| 127 | 136 |
| 128 HostPortPair server = HostPortPair::FromURL(request_info.url); | 137 HostPortPair server = HostPortPair::FromURL(request_info.url); |
| 129 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); | 138 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); |
| 130 | 139 |
| 131 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( | 140 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( |
| 132 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), | 141 job_controller, session.get(), request_info, DEFAULT_PRIORITY, |
| 133 SSLConfig(), server, original_url, NULL); | 142 SSLConfig(), SSLConfig(), server, original_url, NULL); |
| 134 request.AttachJob(job); | 143 job_controller->AttachJob(job); |
| 135 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 144 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 136 | 145 |
| 137 AlternativeService alternative_service(net::NPN_HTTP_2, server); | 146 AlternativeService alternative_service(net::NPN_HTTP_2, server); |
| 138 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( | 147 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( |
| 139 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), | 148 job_controller, session.get(), request_info, DEFAULT_PRIORITY, |
| 140 SSLConfig(), server, original_url, alternative_service, NULL); | 149 SSLConfig(), SSLConfig(), server, original_url, alternative_service, |
| 141 request.AttachJob(alternative_job); | 150 NULL); |
| 151 job_controller->AttachJob(alternative_job); |
| 142 | 152 |
| 143 job->WaitFor(alternative_job); | 153 job->WaitFor(alternative_job); |
| 144 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); | 154 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); |
| 145 | 155 |
| 146 // Test |alternative_job| resuming the |job| after delay. | 156 // Test |alternative_job| resuming the |job| after delay. |
| 147 int wait_time = 1; | 157 int wait_time = 1; |
| 148 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); | 158 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); |
| 149 job->Resume(alternative_job, delay); | 159 job->Resume(alternative_job, delay); |
| 150 | 160 |
| 151 // Verify |job| has |wait_time_| and there is no |blocking_job_| | 161 // Verify |job| has |wait_time_| and there is no |blocking_job_| |
| 152 EXPECT_EQ(delay, job->wait_time_); | 162 EXPECT_EQ(delay, job->wait_time_); |
| 153 EXPECT_TRUE(!job->blocking_job_); | 163 EXPECT_TRUE(!job->blocking_job_); |
| 154 | 164 |
| 155 // Start the |job| and verify |job|'s |wait_time_| is cleared. | 165 // Start the |job| and verify |job|'s |wait_time_| is cleared. |
| 156 job->Start(&request); | 166 job->Start(&request); |
| 157 | 167 |
| 158 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); | 168 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); |
| 159 base::MessageLoop::current()->RunUntilIdle(); | 169 base::MessageLoop::current()->RunUntilIdle(); |
| 160 | 170 |
| 161 EXPECT_NE(delay, job->wait_time_); | 171 EXPECT_NE(delay, job->wait_time_); |
| 162 EXPECT_TRUE(job->wait_time_.is_zero()); | 172 EXPECT_TRUE(job->wait_time_.is_zero()); |
| 163 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, | 173 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, |
| 164 job->next_state_); | 174 job->next_state_); |
| 165 } | 175 } |
| 166 | 176 |
| 167 } // namespace net | 177 } // namespace net |
| OLD | NEW |