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

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

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

Powered by Google App Engine
This is Rietveld 408576698