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

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

Powered by Google App Engine
This is Rietveld 408576698