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

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: add JobFactory interface in JobController, remove JobControllerPeer Created 4 years, 6 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"
11 #include "net/http/http_stream_factory_impl_job_factory_impl.h"
12 #include "net/http/http_stream_factory_test_util.h"
10 #include "net/proxy/proxy_info.h" 13 #include "net/proxy/proxy_info.h"
11 #include "net/proxy/proxy_service.h" 14 #include "net/proxy/proxy_service.h"
12 #include "net/spdy/spdy_test_util_common.h" 15 #include "net/spdy/spdy_test_util_common.h"
13 #include "net/ssl/ssl_failure_state.h" 16 #include "net/ssl/ssl_failure_state.h"
14 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
15 18
16 namespace net { 19 namespace net {
17 20
18 class HttpStreamFactoryImplRequestTest 21 class HttpStreamFactoryImplRequestTest
19 : public ::testing::Test, 22 : public ::testing::Test,
20 public ::testing::WithParamInterface<NextProto> {}; 23 public ::testing::WithParamInterface<NextProto> {};
21 24
22 INSTANTIATE_TEST_CASE_P(NextProto, 25 INSTANTIATE_TEST_CASE_P(NextProto,
23 HttpStreamFactoryImplRequestTest, 26 HttpStreamFactoryImplRequestTest,
24 testing::Values(kProtoSPDY31, 27 testing::Values(kProtoSPDY31,
25 kProtoHTTP2)); 28 kProtoHTTP2));
26 29
27 namespace {
28
29 class DoNothingRequestDelegate : public HttpStreamRequest::Delegate {
30 public:
31 DoNothingRequestDelegate() {}
32
33 ~DoNothingRequestDelegate() override {}
34
35 // HttpStreamRequest::Delegate
36 void OnStreamReady(const SSLConfig& used_ssl_config,
37 const ProxyInfo& used_proxy_info,
38 HttpStream* stream) override {}
39 void OnBidirectionalStreamImplReady(
40 const SSLConfig& used_ssl_config,
41 const ProxyInfo& used_proxy_info,
42 BidirectionalStreamImpl* stream) override {}
43
44 void OnWebSocketHandshakeStreamReady(
45 const SSLConfig& used_ssl_config,
46 const ProxyInfo& used_proxy_info,
47 WebSocketHandshakeStreamBase* stream) override {}
48 void OnStreamFailed(int status,
49 const SSLConfig& used_ssl_config,
50 SSLFailureState ssl_failure_state) override {}
51 void OnCertificateError(int status,
52 const SSLConfig& used_ssl_config,
53 const SSLInfo& ssl_info) override {}
54 void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
55 const SSLConfig& used_ssl_config,
56 const ProxyInfo& used_proxy_info,
57 HttpAuthController* auth_controller) override {}
58 void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
59 SSLCertRequestInfo* cert_info) override {}
60 void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info,
61 const SSLConfig& used_ssl_config,
62 const ProxyInfo& used_proxy_info,
63 HttpStream* stream) override {}
64 void OnQuicBroken() override {}
65 };
66
67 } // namespace
68
69 // Make sure that Request passes on its priority updates to its jobs. 30 // Make sure that Request passes on its priority updates to its jobs.
70 TEST_P(HttpStreamFactoryImplRequestTest, SetPriority) { 31 TEST_P(HttpStreamFactoryImplRequestTest, SetPriority) {
71 SpdySessionDependencies session_deps(GetParam(), 32 SpdySessionDependencies session_deps(GetParam(),
72 ProxyService::CreateDirect()); 33 ProxyService::CreateDirect());
73 34
74 std::unique_ptr<HttpNetworkSession> session = 35 std::unique_ptr<HttpNetworkSession> session =
75 SpdySessionDependencies::SpdyCreateSession(&session_deps); 36 SpdySessionDependencies::SpdyCreateSession(&session_deps);
76 HttpStreamFactoryImpl* factory = 37 HttpStreamFactoryImpl* factory =
77 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); 38 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory());
39 TestHttpStreamRequestDelegate request_delegate;
40 HttpStreamFactoryImpl::JobFactoryImpl job_factory;
41 HttpStreamFactoryImpl::JobController* job_controller =
42 new HttpStreamFactoryImpl::JobController(factory, &request_delegate,
43 session.get(), &job_factory);
44 factory->job_controller_set_.insert(base::WrapUnique(job_controller));
78 45
79 DoNothingRequestDelegate request_delegate;
80 HttpStreamFactoryImpl::Request request( 46 HttpStreamFactoryImpl::Request request(
81 GURL(), factory, &request_delegate, NULL, BoundNetLog(), 47 GURL(), job_controller, &request_delegate, nullptr, BoundNetLog(),
82 HttpStreamFactoryImpl::Request::HTTP_STREAM); 48 HttpStreamFactoryImpl::Request::HTTP_STREAM);
49 job_controller->request_ = &request;
83 50
84 HttpRequestInfo request_info; 51 HttpRequestInfo request_info;
85 52
86 HostPortPair server = HostPortPair::FromURL(request_info.url); 53 HostPortPair server = HostPortPair::FromURL(request_info.url);
87 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); 54 GURL original_url =
55 job_controller->ApplyHostMappingRules(request_info.url, &server);
88 56
89 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( 57 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job(
90 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), 58 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info,
91 SSLConfig(), server, original_url, NULL); 59 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url,
92 request.AttachJob(job); 60 nullptr);
61 job_controller->main_job_.reset(job);
62
63 job_controller->AttachJob(job);
93 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 64 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
94 65
95 request.SetPriority(MEDIUM); 66 request.SetPriority(MEDIUM);
96 EXPECT_EQ(MEDIUM, job->priority()); 67 EXPECT_EQ(MEDIUM, job->priority());
97 68
98 // Make |job| the bound job. 69 // Make |job| the bound job.
99 request.OnStreamFailed(job, ERR_FAILED, SSLConfig(), SSL_FAILURE_NONE); 70 job_controller->OnStreamFailed(job, ERR_FAILED, SSLConfig(),
100 71 SSL_FAILURE_NONE);
101 request.SetPriority(IDLE); 72 request.SetPriority(IDLE);
102 EXPECT_EQ(IDLE, job->priority()); 73 EXPECT_EQ(IDLE, job->priority());
103 } 74 }
104 75
105 TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) { 76 TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) {
106 SpdySessionDependencies session_deps(GetParam(), 77 SpdySessionDependencies session_deps(GetParam(),
107 ProxyService::CreateDirect()); 78 ProxyService::CreateDirect());
108 79
109 std::unique_ptr<HttpNetworkSession> session = 80 std::unique_ptr<HttpNetworkSession> session =
110 SpdySessionDependencies::SpdyCreateSession(&session_deps); 81 SpdySessionDependencies::SpdyCreateSession(&session_deps);
111 82
112 StaticSocketDataProvider socket_data; 83 StaticSocketDataProvider socket_data;
113 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); 84 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING));
114 session_deps.socket_factory->AddSocketDataProvider(&socket_data); 85 session_deps.socket_factory->AddSocketDataProvider(&socket_data);
115 86
116 HttpStreamFactoryImpl* factory = 87 HttpStreamFactoryImpl* factory =
117 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()); 88 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory());
89 TestHttpStreamRequestDelegate request_delegate;
90 HttpStreamFactoryImpl::JobFactoryImpl job_factory;
91 HttpStreamFactoryImpl::JobController* job_controller =
92 new HttpStreamFactoryImpl::JobController(factory, &request_delegate,
93 session.get(), &job_factory);
94 factory->job_controller_set_.insert(base::WrapUnique(job_controller));
118 95
119 DoNothingRequestDelegate request_delegate;
120 HttpRequestInfo request_info; 96 HttpRequestInfo request_info;
121 request_info.method = "GET"; 97 request_info.method = "GET";
122 request_info.url = GURL("http://www.google.com"); 98 request_info.url = GURL("http://www.google.com");
123 99
124 HttpStreamFactoryImpl::Request request( 100 HttpStreamFactoryImpl::Request request(
125 request_info.url, factory, &request_delegate, NULL, BoundNetLog(), 101 request_info.url, job_controller, &request_delegate, nullptr,
126 HttpStreamFactoryImpl::Request::HTTP_STREAM); 102 BoundNetLog(), HttpStreamFactoryImpl::Request::HTTP_STREAM);
103 job_controller->request_ = &request;
127 104
128 HostPortPair server = HostPortPair::FromURL(request_info.url); 105 HostPortPair server = HostPortPair::FromURL(request_info.url);
129 GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server); 106 GURL original_url =
107 job_controller->ApplyHostMappingRules(request_info.url, &server);
130 108
131 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job( 109 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job(
132 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), 110 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info,
133 SSLConfig(), server, original_url, NULL); 111 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url,
134 request.AttachJob(job); 112 nullptr);
113 job_controller->main_job_.reset(job);
114 job_controller->AttachJob(job);
135 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 115 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
136 116
137 AlternativeService alternative_service(net::NPN_HTTP_2, server); 117 AlternativeService alternative_service(net::NPN_HTTP_2, server);
138 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job( 118 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job(
139 factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(), 119 job_controller, HttpStreamFactoryImpl::ALTERNATIVE, session.get(),
140 SSLConfig(), server, original_url, alternative_service, NULL); 120 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server,
141 request.AttachJob(alternative_job); 121 original_url, alternative_service, nullptr);
122 job_controller->alternative_job_.reset(alternative_job);
123 job_controller->AttachJob(alternative_job);
142 124
143 job->WaitFor(alternative_job); 125 job->WaitFor(alternative_job);
144 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_); 126 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_);
145 127
146 // Test |alternative_job| resuming the |job| after delay. 128 // Test |alternative_job| resuming the |job| after delay.
147 int wait_time = 1; 129 int wait_time = 1;
148 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time); 130 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time);
149 job->Resume(alternative_job, delay); 131 job->Resume(alternative_job, delay);
150 132
151 // Verify |job| has |wait_time_| and there is no |blocking_job_| 133 // Verify |job| has |wait_time_| and there is no |blocking_job_|
152 EXPECT_EQ(delay, job->wait_time_); 134 EXPECT_EQ(delay, job->wait_time_);
153 EXPECT_TRUE(!job->blocking_job_); 135 EXPECT_TRUE(!job->blocking_job_);
154 136
155 // Start the |job| and verify |job|'s |wait_time_| is cleared. 137 // Start the |job| and verify |job|'s |wait_time_| is cleared.
156 job->Start(&request); 138 job->Start(request.stream_type());
157 139
158 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1)); 140 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1));
159 base::MessageLoop::current()->RunUntilIdle(); 141 base::MessageLoop::current()->RunUntilIdle();
160 142
161 EXPECT_NE(delay, job->wait_time_); 143 EXPECT_NE(delay, job->wait_time_);
162 EXPECT_TRUE(job->wait_time_.is_zero()); 144 EXPECT_TRUE(job->wait_time_.is_zero());
163 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE, 145 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE,
164 job->next_state_); 146 job->next_state_);
165 } 147 }
166 148
167 } // namespace net 149 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698