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

Unified Diff: net/http/http_stream_factory_test_util.h

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge unittests to this CL 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_stream_factory_test_util.h
diff --git a/net/http/http_stream_factory_test_util.h b/net/http/http_stream_factory_test_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..f5b0ccdc9143fa740960a7ba2dbd774c92a58963
--- /dev/null
+++ b/net/http/http_stream_factory_test_util.h
@@ -0,0 +1,176 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_HTTP_HTTP_STREAM_FACTORY_TEST_UTIL_H_
+#define NET_HTTP_HTTP_STREAM_FACTORY_TEST_UTIL_H_
+
+#include "base/memory/ptr_util.h"
+#include "net/http/http_stream.h"
+#include "net/http/http_stream_factory.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/proxy/proxy_info.h"
+#include "net/proxy/proxy_service.h"
+#include "net/spdy/spdy_test_util_common.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace net {
+
+// This delegate does nothing when called.
+class TestHttpStreamRequestDelegate : public HttpStreamRequest::Delegate {
+ public:
+ TestHttpStreamRequestDelegate();
+
+ ~TestHttpStreamRequestDelegate() override;
+
+ MOCK_METHOD3(OnStreamReady,
+ void(const SSLConfig& used_ssl_config,
+ const ProxyInfo& used_proxy_info,
+ HttpStream* stream));
+
+ 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 {}
+
+ MOCK_METHOD3(OnStreamFailed,
+ void(int status,
+ const SSLConfig& used_ssl_config,
+ SSLFailureState ssl_failure_state));
+
+ MOCK_METHOD3(OnCertificateError,
+ void(int status,
+ const SSLConfig& used_ssl_config,
+ const SSLInfo& ssl_info));
+
+ MOCK_METHOD4(OnNeedsProxyAuth,
+ void(const HttpResponseInfo& proxy_response,
+ const SSLConfig& used_ssl_config,
+ const ProxyInfo& used_proxy_info,
+ HttpAuthController* auth_controller));
+
+ MOCK_METHOD2(OnNeedsClientAuth,
+ void(const SSLConfig& used_ssl_config,
+ SSLCertRequestInfo* cert_info));
+
+ MOCK_METHOD4(OnHttpsProxyTunnelResponse,
+ void(const HttpResponseInfo& response_info,
+ const SSLConfig& used_ssl_config,
+ const ProxyInfo& used_proxy_info,
+ HttpStream* stream));
+
+ MOCK_METHOD0(OnQuicBroken, void());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestHttpStreamRequestDelegate);
+};
+
+class TestHttpStreamFactoryImplJob : public HttpStreamFactoryImpl::Job {
+ public:
+ TestHttpStreamFactoryImplJob(HttpStreamFactoryImpl::Job::Delegate* delegate,
+ HttpStreamFactoryImpl::JobType job_type,
+ HttpNetworkSession* session,
+ const HttpRequestInfo& request_info,
+ RequestPriority priority,
+ const SSLConfig& server_ssl_config,
+ const SSLConfig& proxy_ssl_config,
+ HostPortPair destination,
+ GURL origin_url,
+ NetLog* net_log);
+
+ TestHttpStreamFactoryImplJob(HttpStreamFactoryImpl::Job::Delegate* delegate,
+ HttpStreamFactoryImpl::JobType job_type,
+ HttpNetworkSession* session,
+ const HttpRequestInfo& request_info,
+ RequestPriority priority,
+ const SSLConfig& server_ssl_config,
+ const SSLConfig& proxy_ssl_config,
+ HostPortPair destination,
+ GURL origin_url,
+ AlternativeService alternative_service,
+ NetLog* net_log);
+
+ ~TestHttpStreamFactoryImplJob() override;
+
+ MOCK_METHOD1(MarkOtherJobComplete, void(const Job& job));
+
+ MOCK_METHOD0(Orphan, void());
+};
+
+class TestJobControllerPeer {
+ public:
+ TestJobControllerPeer(NextProto protocol,
+ TestHttpStreamRequestDelegate* request_delegate);
+
+ ~TestJobControllerPeer();
+
+ void CreateRequest(HttpRequestInfo request_info);
+
+ void CancelRequest() { request_.reset(); }
+
+ GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint);
+
+ void ClearMainJob();
+
+ void SetMainJob(HttpStreamFactoryImpl::Job* main_job);
+
+ void SetAlternativeJob(HttpStreamFactoryImpl::Job* main_job);
+
+ void OnStreamFailed(HttpStreamFactoryImpl::Job* job,
+ int status,
+ const SSLConfig& used_ssl_config,
+ SSLFailureState ssl_failure_state);
+
+ void OnStreamReady(HttpStreamFactoryImpl::Job* job,
+ const SSLConfig& used_ssl_config,
+ const ProxyInfo& used_proxy_info);
+
+ void MaybeNotifyFactoryOfCompletion();
+
+ bool IsJobControllerDeleted() {
+ return factory_->job_controller_set_.empty();
+ }
+
+ HttpNetworkSession* session() { return session_.get(); }
+
+ HttpStreamFactoryImpl::JobController* job_controller() {
+ return job_controller_;
+ }
+
+ bool job_bound() { return job_controller_->job_bound_; }
+
+ HttpStreamFactoryImpl::Job* bound_job() {
+ return job_controller_->bound_job_;
+ }
+
+ HttpStreamFactoryImpl::Job* alternative_job() {
+ return job_controller_->alternative_job_.get();
+ }
+
+ HttpStreamFactoryImpl::Job* main_job() {
+ return job_controller_->main_job_.get();
+ }
+
+ private:
+ SpdySessionDependencies session_deps_;
+ TestHttpStreamRequestDelegate* request_delegate_;
+ std::unique_ptr<HttpNetworkSession> session_;
+ HttpStreamFactoryImpl* factory_;
+ HttpStreamFactoryImpl::JobController* job_controller_;
+ std::unique_ptr<HttpStreamFactoryImpl::Request> request_;
+ TestHttpStreamFactoryImplJob* main_job_;
+ TestHttpStreamFactoryImplJob* alternative_job_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestJobControllerPeer);
+};
+
+} // namespace net
+
+#endif // NET_HTTP_HTTP_STREAM_FACTORY_TEST_UTIL_H_

Powered by Google App Engine
This is Rietveld 408576698