| 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 "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "net/http/http_stream_factory_impl.h" | 10 #include "net/http/http_stream_factory_impl.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 EXPECT_EQ(MEDIUM, job_controller->main_job()->priority()); | 57 EXPECT_EQ(MEDIUM, job_controller->main_job()->priority()); |
| 58 | 58 |
| 59 EXPECT_CALL(request_delegate, OnStreamFailed(_, _, SSL_FAILURE_NONE)) | 59 EXPECT_CALL(request_delegate, OnStreamFailed(_, _, SSL_FAILURE_NONE)) |
| 60 .Times(1); | 60 .Times(1); |
| 61 job_controller->OnStreamFailed(job_factory.main_job(), ERR_FAILED, | 61 job_controller->OnStreamFailed(job_factory.main_job(), ERR_FAILED, |
| 62 SSLConfig(), SSL_FAILURE_NONE); | 62 SSLConfig(), SSL_FAILURE_NONE); |
| 63 | 63 |
| 64 request->SetPriority(IDLE); | 64 request->SetPriority(IDLE); |
| 65 EXPECT_EQ(IDLE, job_controller->main_job()->priority()); | 65 EXPECT_EQ(IDLE, job_controller->main_job()->priority()); |
| 66 } | 66 } |
| 67 | |
| 68 TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) { | |
| 69 SpdySessionDependencies session_deps(GetParam(), | |
| 70 ProxyService::CreateDirect()); | |
| 71 | |
| 72 std::unique_ptr<HttpNetworkSession> session = | |
| 73 SpdySessionDependencies::SpdyCreateSession(&session_deps); | |
| 74 | |
| 75 StaticSocketDataProvider socket_data; | |
| 76 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); | |
| 77 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 78 | |
| 79 HttpStreamFactoryImpl* factory = | |
| 80 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); | |
| 81 MockHttpStreamRequestDelegate request_delegate; | |
| 82 HttpStreamFactoryImpl::JobFactory* job_factory = | |
| 83 HttpStreamFactoryImplPeer::GetDefaultJobFactory(factory); | |
| 84 HttpStreamFactoryImpl::JobController* job_controller = | |
| 85 new HttpStreamFactoryImpl::JobController(factory, &request_delegate, | |
| 86 session.get(), job_factory); | |
| 87 factory->job_controller_set_.insert(base::WrapUnique(job_controller)); | |
| 88 | |
| 89 HttpRequestInfo request_info; | |
| 90 request_info.method = "GET"; | |
| 91 request_info.url = GURL("http://www.google.com"); | |
| 92 | |
| 93 HttpStreamFactoryImpl::Request request( | |
| 94 request_info.url, job_controller, &request_delegate, nullptr, | |
| 95 BoundNetLog(), HttpStreamFactoryImpl::Request::HTTP_STREAM); | |
| 96 job_controller->request_ = &request; | |
| 97 | |
| 98 HostPortPair server = HostPortPair::FromURL(request_info.url); | |
| 99 GURL original_url = | |
| 100 job_controller->ApplyHostMappingRules(request_info.url, &server); | |
| 101 | |
| 102 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( | |
| 103 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info, | |
| 104 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url, | |
| 105 nullptr); | |
| 106 job_controller->main_job_.reset(job); | |
| 107 job_controller->AttachJob(job); | |
| 108 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | |
| 109 | |
| 110 AlternativeService alternative_service(net::NPN_HTTP_2, server); | |
| 111 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( | |
| 112 job_controller, HttpStreamFactoryImpl::ALTERNATIVE, session.get(), | |
| 113 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, | |
| 114 original_url, alternative_service, nullptr); | |
| 115 job_controller->alternative_job_.reset(alternative_job); | |
| 116 job_controller->AttachJob(alternative_job); | |
| 117 | |
| 118 job->WaitFor(alternative_job); | |
| 119 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); | |
| 120 | |
| 121 // Test |alternative_job| resuming the |job| after delay. | |
| 122 int wait_time = 1; | |
| 123 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); | |
| 124 job->Resume(alternative_job, delay); | |
| 125 | |
| 126 // Verify |job| has |wait_time_| and there is no |blocking_job_| | |
| 127 EXPECT_EQ(delay, job->wait_time_); | |
| 128 EXPECT_TRUE(!job->blocking_job_); | |
| 129 | |
| 130 // Start the |job| and verify |job|'s |wait_time_| is cleared. | |
| 131 job->Start(request.stream_type()); | |
| 132 | |
| 133 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); | |
| 134 base::RunLoop().RunUntilIdle(); | |
| 135 | |
| 136 EXPECT_NE(delay, job->wait_time_); | |
| 137 EXPECT_TRUE(job->wait_time_.is_zero()); | |
| 138 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, | |
| 139 job->next_state_); | |
| 140 } | |
| 141 | |
| 142 } // namespace net | 67 } // namespace net |
| OLD | NEW |