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

Unified 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: address nits 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_stream_factory_impl_request_unittest.cc
diff --git a/net/http/http_stream_factory_impl_request_unittest.cc b/net/http/http_stream_factory_impl_request_unittest.cc
index 5079cc1492e8266629432061d1c74a6091157c4f..e6a37d10462f1e408643c32f2fea96a228955f52 100644
--- a/net/http/http_stream_factory_impl_request_unittest.cc
+++ b/net/http/http_stream_factory_impl_request_unittest.cc
@@ -7,13 +7,18 @@
#include <memory>
#include "base/run_loop.h"
+#include "net/http/http_stream_factory_impl.h"
#include "net/http/http_stream_factory_impl_job.h"
+#include "net/http/http_stream_factory_impl_job_controller.h"
+#include "net/http/http_stream_factory_test_util.h"
#include "net/proxy/proxy_info.h"
#include "net/proxy/proxy_service.h"
#include "net/spdy/spdy_test_util_common.h"
#include "net/ssl/ssl_failure_state.h"
#include "testing/gtest/include/gtest/gtest.h"
+using testing::_;
+
namespace net {
class HttpStreamFactoryImplRequestTest
@@ -25,82 +30,39 @@ INSTANTIATE_TEST_CASE_P(NextProto,
testing::Values(kProtoSPDY31,
kProtoHTTP2));
-namespace {
-
-class DoNothingRequestDelegate : public HttpStreamRequest::Delegate {
- public:
- DoNothingRequestDelegate() {}
-
- ~DoNothingRequestDelegate() override {}
-
- // HttpStreamRequest::Delegate
- void OnStreamReady(const SSLConfig& used_ssl_config,
- const ProxyInfo& used_proxy_info,
- HttpStream* stream) override {}
- void OnBidirectionalStreamImplReady(
- const SSLConfig& used_ssl_config,
- const ProxyInfo& used_proxy_info,
- BidirectionalStreamImpl* stream) override {}
-
- void OnWebSocketHandshakeStreamReady(
- const SSLConfig& used_ssl_config,
- const ProxyInfo& used_proxy_info,
- WebSocketHandshakeStreamBase* stream) override {}
- void OnStreamFailed(int status,
- const SSLConfig& used_ssl_config,
- SSLFailureState ssl_failure_state) override {}
- void OnCertificateError(int status,
- const SSLConfig& used_ssl_config,
- const SSLInfo& ssl_info) override {}
- void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
- const SSLConfig& used_ssl_config,
- const ProxyInfo& used_proxy_info,
- HttpAuthController* auth_controller) override {}
- void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
- SSLCertRequestInfo* cert_info) override {}
- void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info,
- const SSLConfig& used_ssl_config,
- const ProxyInfo& used_proxy_info,
- HttpStream* stream) override {}
- void OnQuicBroken() override {}
-};
-
-} // namespace
-
// Make sure that Request passes on its priority updates to its jobs.
TEST_P(HttpStreamFactoryImplRequestTest, SetPriority) {
SpdySessionDependencies session_deps(GetParam(),
ProxyService::CreateDirect());
-
std::unique_ptr<HttpNetworkSession> session =
SpdySessionDependencies::SpdyCreateSession(&session_deps);
HttpStreamFactoryImpl* factory =
static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory());
-
- DoNothingRequestDelegate request_delegate;
- HttpStreamFactoryImpl::Request request(
- GURL(), factory, &request_delegate, NULL, BoundNetLog(),
- HttpStreamFactoryImpl::Request::HTTP_STREAM);
+ MockHttpStreamRequestDelegate request_delegate;
+ TestJobFactory job_factory;
+ HttpStreamFactoryImpl::JobController* job_controller =
+ new HttpStreamFactoryImpl::JobController(factory, &request_delegate,
+ session.get(), &job_factory);
+ factory->job_controller_set_.insert(base::WrapUnique(job_controller));
HttpRequestInfo request_info;
-
- HostPortPair server = HostPortPair::FromURL(request_info.url);
- GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server);
-
- HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job(
- factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(),
- SSLConfig(), server, original_url, NULL);
- request.AttachJob(job);
- EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
-
- request.SetPriority(MEDIUM);
- EXPECT_EQ(MEDIUM, job->priority());
-
- // Make |job| the bound job.
- request.OnStreamFailed(job, ERR_FAILED, SSLConfig(), SSL_FAILURE_NONE);
-
- request.SetPriority(IDLE);
- EXPECT_EQ(IDLE, job->priority());
+ std::unique_ptr<HttpStreamFactoryImpl::Request> request(
+ job_controller->Start(request_info, &request_delegate, nullptr,
+ BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
+ DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
+ EXPECT_TRUE(job_controller->main_job());
+ EXPECT_EQ(DEFAULT_PRIORITY, job_controller->main_job()->priority());
+
+ request->SetPriority(MEDIUM);
+ EXPECT_EQ(MEDIUM, job_controller->main_job()->priority());
+
+ EXPECT_CALL(request_delegate, OnStreamFailed(_, _, SSL_FAILURE_NONE))
+ .Times(1);
+ job_controller->OnStreamFailed(job_factory.main_job(), ERR_FAILED,
+ SSLConfig(), SSL_FAILURE_NONE);
+
+ request->SetPriority(IDLE);
+ EXPECT_EQ(IDLE, job_controller->main_job()->priority());
}
TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) {
@@ -116,30 +78,42 @@ TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) {
HttpStreamFactoryImpl* factory =
static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory());
+ MockHttpStreamRequestDelegate request_delegate;
+ HttpStreamFactoryImpl::JobFactory* job_factory =
+ HttpStreamFactoryImplPeer::GetDefaultJobFactory(factory);
+ HttpStreamFactoryImpl::JobController* job_controller =
+ new HttpStreamFactoryImpl::JobController(factory, &request_delegate,
+ session.get(), job_factory);
+ factory->job_controller_set_.insert(base::WrapUnique(job_controller));
- DoNothingRequestDelegate request_delegate;
HttpRequestInfo request_info;
request_info.method = "GET";
request_info.url = GURL("http://www.google.com");
HttpStreamFactoryImpl::Request request(
- request_info.url, factory, &request_delegate, NULL, BoundNetLog(),
- HttpStreamFactoryImpl::Request::HTTP_STREAM);
+ request_info.url, job_controller, &request_delegate, nullptr,
+ BoundNetLog(), HttpStreamFactoryImpl::Request::HTTP_STREAM);
+ job_controller->request_ = &request;
HostPortPair server = HostPortPair::FromURL(request_info.url);
- GURL original_url = factory->ApplyHostMappingRules(request_info.url, &server);
+ GURL original_url =
+ job_controller->ApplyHostMappingRules(request_info.url, &server);
HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job(
- factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(),
- SSLConfig(), server, original_url, NULL);
- request.AttachJob(job);
+ job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info,
+ DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url,
+ nullptr);
+ job_controller->main_job_.reset(job);
+ job_controller->AttachJob(job);
EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
AlternativeService alternative_service(net::NPN_HTTP_2, server);
HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job(
- factory, session.get(), request_info, DEFAULT_PRIORITY, SSLConfig(),
- SSLConfig(), server, original_url, alternative_service, NULL);
- request.AttachJob(alternative_job);
+ job_controller, HttpStreamFactoryImpl::ALTERNATIVE, session.get(),
+ request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server,
+ original_url, alternative_service, nullptr);
+ job_controller->alternative_job_.reset(alternative_job);
+ job_controller->AttachJob(alternative_job);
job->WaitFor(alternative_job);
EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_);
@@ -154,7 +128,7 @@ TEST_P(HttpStreamFactoryImplRequestTest, DelayMainJob) {
EXPECT_TRUE(!job->blocking_job_);
// Start the |job| and verify |job|'s |wait_time_| is cleared.
- job->Start(&request);
+ job->Start(request.stream_type());
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1));
base::RunLoop().RunUntilIdle();
« 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