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

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 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, NULL, 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, NULL);
92 request.AttachJob(job); 99 job_controller->main_job_.reset(job);
100 job_controller->AttachJob(job);
93 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 101 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
94 102
95 request.SetPriority(MEDIUM); 103 request.SetPriority(MEDIUM);
96 EXPECT_EQ(MEDIUM, job->priority()); 104 EXPECT_EQ(MEDIUM, job->priority());
97 105
98 // Make |job| the bound job. 106 // Make |job| the bound job.
99 request.OnStreamFailed(job, ERR_FAILED, SSLConfig(), SSL_FAILURE_NONE); 107 job_controller->OnStreamFailed(job, ERR_FAILED, SSLConfig(),
100 108 SSL_FAILURE_NONE);
101 request.SetPriority(IDLE); 109 request.SetPriority(IDLE);
102 EXPECT_EQ(IDLE, job->priority()); 110 EXPECT_EQ(IDLE, job->priority());
103 } 111 }
104 112
105 TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) { 113 TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) {
106 SpdySessionDependencies session_deps(GetParam(), 114 SpdySessionDependencies session_deps(GetParam(),
107 ProxyService::CreateDirect()); 115 ProxyService::CreateDirect());
108 116
109 std::unique_ptr<HttpNetworkSession> session = 117 std::unique_ptr<HttpNetworkSession> session =
110 SpdySessionDependencies::SpdyCreateSession(&session_deps); 118 SpdySessionDependencies::SpdyCreateSession(&session_deps);
111 119
112 StaticSocketDataProvider socket_data; 120 StaticSocketDataProvider socket_data;
113 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); 121 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING));
114 session_deps.socket_factory->AddSocketDataProvider(&socket_data); 122 session_deps.socket_factory->AddSocketDataProvider(&socket_data);
115 123
116 HttpStreamFactoryImpl* factory = 124 HttpStreamFactoryImpl* factory =
117 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); 125 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory());
126 DoNothingRequestDelegate request_delegate;
127 HttpStreamFactoryImpl::JobController* job_controller =
128 new HttpStreamFactoryImpl::JobController(factory, &request_delegate,
129 session.get());
130 factory->job_controller_set_.insert(base::WrapUnique(job_controller));
118 131
119 DoNothingRequestDelegate request_delegate;
120 HttpRequestInfo request_info; 132 HttpRequestInfo request_info;
121 request_info.method = "GET"; 133 request_info.method = "GET";
122 request_info.url = GURL("http://www.google.com"); 134 request_info.url = GURL("http://www.google.com");
123 135
124 HttpStreamFactoryImpl::Request request( 136 HttpStreamFactoryImpl::Request request(
125 request_info.url, factory, &request_delegate, NULL, BoundNetLog(), 137 request_info.url, job_controller, &request_delegate, NULL, BoundNetLog(),
126 HttpStreamFactoryImpl::Request::HTTP_STREAM); 138 HttpStreamFactoryImpl::Request::HTTP_STREAM);
139 job_controller->request_ = &request;
127 140
128 HostPortPair server = HostPortPair::FromURL(request_info.url); 141 HostPortPair server = HostPortPair::FromURL(request_info.url);
129 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); 142 GURL original_url =
143 job_controller->ApplyHostMappingRules(request_info.url, &server);
130 144
131 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( 145 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job(
132 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), 146 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info,
133 SSLConfig(), server, original_url, NULL); 147 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url, NULL);
134 request.AttachJob(job); 148 job_controller->main_job_.reset(job);
149 job_controller->AttachJob(job);
135 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 150 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
136 151
137 AlternativeService alternative_service(net::NPN_HTTP_2, server); 152 AlternativeService alternative_service(net::NPN_HTTP_2, server);
138 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( 153 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job(
139 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), 154 job_controller, HttpStreamFactoryImpl::ALTERNATIVE, session.get(),
140 SSLConfig(), server, original_url, alternative_service, NULL); 155 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server,
141 request.AttachJob(alternative_job); 156 original_url, alternative_service, NULL);
157 job_controller->alternative_job_.reset(alternative_job);
158 job_controller->AttachJob(alternative_job);
142 159
143 job->WaitFor(alternative_job); 160 job->WaitFor(alternative_job);
144 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); 161 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_);
145 162
146 // Test |alternative_job| resuming the |job| after delay. 163 // Test |alternative_job| resuming the |job| after delay.
147 int wait_time = 1; 164 int wait_time = 1;
148 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); 165 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time);
149 job->Resume(alternative_job, delay); 166 job->Resume(alternative_job, delay);
150 167
151 // Verify |job| has |wait_time_| and there is no |blocking_job_| 168 // Verify |job| has |wait_time_| and there is no |blocking_job_|
152 EXPECT_EQ(delay, job->wait_time_); 169 EXPECT_EQ(delay, job->wait_time_);
153 EXPECT_TRUE(!job->blocking_job_); 170 EXPECT_TRUE(!job->blocking_job_);
154 171
155 // Start the |job| and verify |job|'s |wait_time_| is cleared. 172 // Start the |job| and verify |job|'s |wait_time_| is cleared.
156 job->Start(&request); 173 job->Start(request.stream_type());
157 174
158 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); 175 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1));
159 base::MessageLoop::current()->RunUntilIdle(); 176 base::MessageLoop::current()->RunUntilIdle();
160 177
161 EXPECT_NE(delay, job->wait_time_); 178 EXPECT_NE(delay, job->wait_time_);
162 EXPECT_TRUE(job->wait_time_.is_zero()); 179 EXPECT_TRUE(job->wait_time_.is_zero());
163 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, 180 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE,
164 job->next_state_); 181 job->next_state_);
165 } 182 }
166 183
167 } // namespace net 184 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698