| 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/http/http_stream_factory_impl_job_controller.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 GURL(), job_controller, &request_delegate, NULL, BoundNetLog(), | 85 GURL(), job_controller, &request_delegate, NULL, BoundNetLog(), |
| 86 HttpStreamFactoryImpl::Request::HTTP_STREAM); | 86 HttpStreamFactoryImpl::Request::HTTP_STREAM); |
| 87 job_controller->request_ = &request; | 87 job_controller->request_ = &request; |
| 88 | 88 |
| 89 HttpRequestInfo request_info; | 89 HttpRequestInfo request_info; |
| 90 | 90 |
| 91 HostPortPair server = HostPortPair::FromURL(request_info.url); | 91 HostPortPair server = HostPortPair::FromURL(request_info.url); |
| 92 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); | 92 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); |
| 93 | 93 |
| 94 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( | 94 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( |
| 95 job_controller, session.get(), request_info, DEFAULT_PRIORITY, | 95 job_controller, HttpStreamFactoryImpl::NON_ALTERNATIVE, session.get(), |
| 96 SSLConfig(), SSLConfig(), server, original_url, NULL); | 96 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, |
| 97 original_url, NULL); |
| 97 job_controller->AttachJob(job); | 98 job_controller->AttachJob(job); |
| 99 job_controller->main_job_ = job; |
| 100 |
| 98 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 101 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 99 | 102 |
| 100 request.SetPriority(MEDIUM); | 103 request.SetPriority(MEDIUM); |
| 101 EXPECT_EQ(MEDIUM, job->priority()); | 104 EXPECT_EQ(MEDIUM, job->priority()); |
| 102 | 105 |
| 103 // Make |job| the bound job. | 106 // Make |job| the bound job. |
| 104 job_controller->OnStreamFailed(job, ERR_FAILED, SSLConfig(), | 107 job_controller->OnStreamFailed(job, ERR_FAILED, SSLConfig(), |
| 105 SSL_FAILURE_NONE); | 108 SSL_FAILURE_NONE); |
| 106 request.SetPriority(IDLE); | 109 request.SetPriority(IDLE); |
| 107 EXPECT_EQ(IDLE, job->priority()); | 110 EXPECT_EQ(IDLE, job->priority()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 131 | 134 |
| 132 HttpStreamFactoryImpl::Request request( | 135 HttpStreamFactoryImpl::Request request( |
| 133 request_info.url, job_controller, &request_delegate, NULL, BoundNetLog(), | 136 request_info.url, job_controller, &request_delegate, NULL, BoundNetLog(), |
| 134 HttpStreamFactoryImpl::Request::HTTP_STREAM); | 137 HttpStreamFactoryImpl::Request::HTTP_STREAM); |
| 135 job_controller->request_ = &request; | 138 job_controller->request_ = &request; |
| 136 | 139 |
| 137 HostPortPair server = HostPortPair::FromURL(request_info.url); | 140 HostPortPair server = HostPortPair::FromURL(request_info.url); |
| 138 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); | 141 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); |
| 139 | 142 |
| 140 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( | 143 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( |
| 141 job_controller, session.get(), request_info, DEFAULT_PRIORITY, | 144 job_controller, HttpStreamFactoryImpl::NON_ALTERNATIVE, session.get(), |
| 142 SSLConfig(), SSLConfig(), server, original_url, NULL); | 145 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, |
| 146 original_url, NULL); |
| 143 job_controller->AttachJob(job); | 147 job_controller->AttachJob(job); |
| 148 job_controller->main_job_ = job; |
| 149 |
| 144 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 150 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 145 | 151 |
| 146 AlternativeService alternative_service(net::NPN_HTTP_2, server); | 152 AlternativeService alternative_service(net::NPN_HTTP_2, server); |
| 147 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( | 153 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( |
| 148 job_controller, session.get(), request_info, DEFAULT_PRIORITY, | 154 job_controller, HttpStreamFactoryImpl::ALTERNATIVE, session.get(), |
| 149 SSLConfig(), SSLConfig(), server, original_url, alternative_service, | 155 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, |
| 150 NULL); | 156 original_url, alternative_service, NULL); |
| 151 job_controller->AttachJob(alternative_job); | 157 job_controller->AttachJob(alternative_job); |
| 158 job_controller->alternative_job_ = alternative_job; |
| 152 | 159 |
| 153 job->WaitFor(alternative_job); | 160 job_controller->racing_ = true; |
| 154 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); | 161 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); |
| 155 | 162 |
| 156 // Test |alternative_job| resuming the |job| after delay. | 163 // Test |alternative_job| resuming the |job| after delay. |
| 157 int wait_time = 1; | 164 int wait_time = 1; |
| 158 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); | 165 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); |
| 159 job->Resume(alternative_job, delay); | 166 job_controller->MaybeResumeOtherJob(alternative_job, delay); |
| 160 | 167 |
| 161 // Verify |job| has |wait_time_| and there is no |blocking_job_| | 168 // Verify |job| has |wait_time_| and there is no blocking job. |
| 162 EXPECT_EQ(delay, job->wait_time_); | 169 EXPECT_EQ(delay, job->wait_time_); |
| 163 EXPECT_TRUE(!job->blocking_job_); | 170 EXPECT_TRUE(!job_controller->racing()); |
| 164 | 171 |
| 165 // Start the |job| and verify |job|'s |wait_time_| is cleared. | 172 // Start the |job| and verify |job|'s |wait_time_| is cleared. |
| 166 job->Start(&request); | 173 job->Start(&request); |
| 167 | 174 |
| 168 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); | 175 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); |
| 169 base::MessageLoop::current()->RunUntilIdle(); | 176 base::MessageLoop::current()->RunUntilIdle(); |
| 170 | 177 |
| 171 EXPECT_NE(delay, job->wait_time_); | 178 EXPECT_NE(delay, job->wait_time_); |
| 172 EXPECT_TRUE(job->wait_time_.is_zero()); | 179 EXPECT_TRUE(job->wait_time_.is_zero()); |
| 173 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, | 180 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, |
| 174 job->next_state_); | 181 job->next_state_); |
| 175 } | 182 } |
| 176 | 183 |
| 177 } // namespace net | 184 } // namespace net |
| OLD | NEW |