| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 HostPortPair server = HostPortPair::FromURL(request_info.url); | 92 HostPortPair server = HostPortPair::FromURL(request_info.url); |
| 93 GURL original_url = | 93 GURL original_url = |
| 94 job_controller->ApplyHostMappingRules(request_info.url, &server); | 94 job_controller->ApplyHostMappingRules(request_info.url, &server); |
| 95 | 95 |
| 96 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( | 96 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( |
| 97 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info, | 97 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info, |
| 98 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url, | 98 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url, |
| 99 nullptr); | 99 nullptr); |
| 100 job_controller->main_job_.reset(job); | 100 job_controller->main_job_.reset(job); |
| 101 job_controller->AttachJob(job); | 101 job_controller->AttachJob(job); |
| 102 |
| 102 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 103 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 103 | 104 |
| 104 request.SetPriority(MEDIUM); | 105 request.SetPriority(MEDIUM); |
| 105 EXPECT_EQ(MEDIUM, job->priority()); | 106 EXPECT_EQ(MEDIUM, job->priority()); |
| 106 | 107 |
| 107 // Make |job| the bound job. | 108 // Make |job| the bound job. |
| 108 job_controller->OnStreamFailed(job, ERR_FAILED, SSLConfig(), | 109 job_controller->OnStreamFailed(job, ERR_FAILED, SSLConfig(), |
| 109 SSL_FAILURE_NONE); | 110 SSL_FAILURE_NONE); |
| 110 request.SetPriority(IDLE); | 111 request.SetPriority(IDLE); |
| 111 EXPECT_EQ(IDLE, job->priority()); | 112 EXPECT_EQ(IDLE, job->priority()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 142 HostPortPair server = HostPortPair::FromURL(request_info.url); | 143 HostPortPair server = HostPortPair::FromURL(request_info.url); |
| 143 GURL original_url = | 144 GURL original_url = |
| 144 job_controller->ApplyHostMappingRules(request_info.url, &server); | 145 job_controller->ApplyHostMappingRules(request_info.url, &server); |
| 145 | 146 |
| 146 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( | 147 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( |
| 147 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info, | 148 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info, |
| 148 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url, | 149 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url, |
| 149 nullptr); | 150 nullptr); |
| 150 job_controller->main_job_.reset(job); | 151 job_controller->main_job_.reset(job); |
| 151 job_controller->AttachJob(job); | 152 job_controller->AttachJob(job); |
| 153 |
| 152 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 154 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 153 | 155 |
| 154 AlternativeService alternative_service(net::NPN_HTTP_2, server); | 156 AlternativeService alternative_service(net::NPN_HTTP_2, server); |
| 155 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( | 157 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( |
| 156 job_controller, HttpStreamFactoryImpl::ALTERNATIVE, session.get(), | 158 job_controller, HttpStreamFactoryImpl::ALTERNATIVE, session.get(), |
| 157 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, | 159 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, |
| 158 original_url, alternative_service, nullptr); | 160 original_url, alternative_service, nullptr); |
| 159 job_controller->alternative_job_.reset(alternative_job); | 161 job_controller->alternative_job_.reset(alternative_job); |
| 160 job_controller->AttachJob(alternative_job); | 162 job_controller->AttachJob(alternative_job); |
| 161 | 163 |
| 162 job->WaitFor(alternative_job); | 164 job_controller->blocking_ = true; |
| 163 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); | 165 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); |
| 164 | 166 |
| 165 // Test |alternative_job| resuming the |job| after delay. | 167 // Test |alternative_job| resuming the |job| after delay. |
| 166 int wait_time = 1; | 168 int wait_time = 1; |
| 167 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); | 169 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); |
| 168 job->Resume(alternative_job, delay); | 170 job_controller->MaybeResumeOtherJob(alternative_job, delay); |
| 169 | 171 |
| 170 // Verify |job| has |wait_time_| and there is no |blocking_job_| | 172 // Verify |job| has |wait_time_| and there is no blocking job. |
| 171 EXPECT_EQ(delay, job->wait_time_); | 173 EXPECT_EQ(delay, job_controller->GetWaitTime()); |
| 172 EXPECT_TRUE(!job->blocking_job_); | 174 EXPECT_TRUE(!job_controller->blocking()); |
| 173 | 175 |
| 174 // Start the |job| and verify |job|'s |wait_time_| is cleared. | 176 // Start the |job| and verify |job|'s |wait_time_| is cleared. |
| 175 job->Start(request.stream_type()); | 177 job->Start(request.stream_type()); |
| 176 | 178 |
| 177 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); | 179 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); |
| 178 base::MessageLoop::current()->RunUntilIdle(); | 180 base::MessageLoop::current()->RunUntilIdle(); |
| 179 | 181 |
| 180 EXPECT_NE(delay, job->wait_time_); | 182 EXPECT_NE(delay, job_controller->GetWaitTime()); |
| 181 EXPECT_TRUE(job->wait_time_.is_zero()); | 183 EXPECT_TRUE(job_controller->GetWaitTime().is_zero()); |
| 182 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, | 184 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, |
| 183 job->next_state_); | 185 job->next_state_); |
| 184 } | 186 } |
| 185 | 187 |
| 186 } // namespace net | 188 } // namespace net |
| OLD | NEW |