Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: net/http/http_stream_factory_impl_request_unittest.cc

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment/naming fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 DoNothingRequestDelegate request_delegate;
80 HttpStreamFactoryImpl::JobController* job_controller =
81 new HttpStreamFactoryImpl::JobController(factory, &request_delegate,
82 session.get());
83 factory->job_controller_set_.insert(base::WrapUnique(job_controller));
78 84
79 DoNothingRequestDelegate request_delegate;
80 HttpStreamFactoryImpl::Request request( 85 HttpStreamFactoryImpl::Request request(
81 GURL(), factory, &request_delegate, NULL, BoundNetLog(), 86 GURL(), job_controller, &request_delegate, nullptr, BoundNetLog(),
82 HttpStreamFactoryImpl::Request::HTTP_STREAM); 87 HttpStreamFactoryImpl::Request::HTTP_STREAM);
88 job_controller->request_ = &request;
83 89
84 HttpRequestInfo request_info; 90 HttpRequestInfo request_info;
85 91
86 HostPortPair server = HostPortPair::FromURL(request_info.url); 92 HostPortPair server = HostPortPair::FromURL(request_info.url);
87 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); 93 GURL original_url =
94 job_controller->ApplyHostMappingRules(request_info.url, &server);
88 95
89 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( 96 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job(
90 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), 97 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info,
91 SSLConfig(), server, original_url, NULL); 98 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url,
92 request.AttachJob(job); 99 nullptr);
100 job_controller->main_job_.reset(job);
101 job_controller->AttachJob(job);
93 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 102 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
94 103
95 request.SetPriority(MEDIUM); 104 request.SetPriority(MEDIUM);
96 EXPECT_EQ(MEDIUM, job->priority()); 105 EXPECT_EQ(MEDIUM, job->priority());
97 106
98 // Make |job| the bound job. 107 // Make |job| the bound job.
99 request.OnStreamFailed(job, ERR_FAILED, SSLConfig(), SSL_FAILURE_NONE); 108 job_controller->OnStreamFailed(job, ERR_FAILED, SSLConfig(),
100 109 SSL_FAILURE_NONE);
101 request.SetPriority(IDLE); 110 request.SetPriority(IDLE);
102 EXPECT_EQ(IDLE, job->priority()); 111 EXPECT_EQ(IDLE, job->priority());
103 } 112 }
104 113
105 TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) { 114 TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) {
106 SpdySessionDependencies session_deps(GetParam(), 115 SpdySessionDependencies session_deps(GetParam(),
107 ProxyService::CreateDirect()); 116 ProxyService::CreateDirect());
108 117
109 std::unique_ptr<HttpNetworkSession> session = 118 std::unique_ptr<HttpNetworkSession> session =
110 SpdySessionDependencies::SpdyCreateSession(&session_deps); 119 SpdySessionDependencies::SpdyCreateSession(&session_deps);
111 120
112 StaticSocketDataProvider socket_data; 121 StaticSocketDataProvider socket_data;
113 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); 122 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING));
114 session_deps.socket_factory->AddSocketDataProvider(&socket_data); 123 session_deps.socket_factory->AddSocketDataProvider(&socket_data);
115 124
116 HttpStreamFactoryImpl* factory = 125 HttpStreamFactoryImpl* factory =
117 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); 126 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory());
127 DoNothingRequestDelegate request_delegate;
128 HttpStreamFactoryImpl::JobController* job_controller =
129 new HttpStreamFactoryImpl::JobController(factory, &request_delegate,
130 session.get());
131 factory->job_controller_set_.insert(base::WrapUnique(job_controller));
118 132
119 DoNothingRequestDelegate request_delegate;
120 HttpRequestInfo request_info; 133 HttpRequestInfo request_info;
121 request_info.method = "GET"; 134 request_info.method = "GET";
122 request_info.url = GURL("http://www.google.com"); 135 request_info.url = GURL("http://www.google.com");
123 136
124 HttpStreamFactoryImpl::Request request( 137 HttpStreamFactoryImpl::Request request(
125 request_info.url, factory, &request_delegate, NULL, BoundNetLog(), 138 request_info.url, job_controller, &request_delegate, nullptr,
126 HttpStreamFactoryImpl::Request::HTTP_STREAM); 139 BoundNetLog(), HttpStreamFactoryImpl::Request::HTTP_STREAM);
140 job_controller->request_ = &request;
127 141
128 HostPortPair server = HostPortPair::FromURL(request_info.url); 142 HostPortPair server = HostPortPair::FromURL(request_info.url);
129 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); 143 GURL original_url =
144 job_controller->ApplyHostMappingRules(request_info.url, &server);
130 145
131 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( 146 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job(
132 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), 147 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info,
133 SSLConfig(), server, original_url, NULL); 148 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url,
134 request.AttachJob(job); 149 nullptr);
150 job_controller->main_job_.reset(job);
151 job_controller->AttachJob(job);
135 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 152 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
136 153
137 AlternativeService alternative_service(net::NPN_HTTP_2, server); 154 AlternativeService alternative_service(net::NPN_HTTP_2, server);
138 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( 155 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job(
139 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), 156 job_controller, HttpStreamFactoryImpl::ALTERNATIVE, session.get(),
140 SSLConfig(), server, original_url, alternative_service, NULL); 157 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server,
141 request.AttachJob(alternative_job); 158 original_url, alternative_service, nullptr);
159 job_controller->alternative_job_.reset(alternative_job);
160 job_controller->AttachJob(alternative_job);
142 161
143 job->WaitFor(alternative_job); 162 job->WaitFor(alternative_job);
144 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); 163 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_);
145 164
146 // Test |alternative_job| resuming the |job| after delay. 165 // Test |alternative_job| resuming the |job| after delay.
147 int wait_time = 1; 166 int wait_time = 1;
148 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); 167 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time);
149 job->Resume(alternative_job, delay); 168 job->Resume(alternative_job, delay);
150 169
151 // Verify |job| has |wait_time_| and there is no |blocking_job_| 170 // Verify |job| has |wait_time_| and there is no |blocking_job_|
152 EXPECT_EQ(delay, job->wait_time_); 171 EXPECT_EQ(delay, job->wait_time_);
153 EXPECT_TRUE(!job->blocking_job_); 172 EXPECT_TRUE(!job->blocking_job_);
154 173
155 // Start the |job| and verify |job|'s |wait_time_| is cleared. 174 // Start the |job| and verify |job|'s |wait_time_| is cleared.
156 job->Start(&request); 175 job->Start(request.stream_type());
157 176
158 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); 177 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1));
159 base::MessageLoop::current()->RunUntilIdle(); 178 base::MessageLoop::current()->RunUntilIdle();
160 179
161 EXPECT_NE(delay, job->wait_time_); 180 EXPECT_NE(delay, job->wait_time_);
162 EXPECT_TRUE(job->wait_time_.is_zero()); 181 EXPECT_TRUE(job->wait_time_.is_zero());
163 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, 182 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE,
164 job->next_state_); 183 job->next_state_);
165 } 184 }
166 185
167 } // namespace net 186 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698