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

Unified Diff: net/http/http_network_transaction_unittest.cc

Issue 2910463004: Revert "Revert CLs landed in HttpStreamFactoryImpl to track down a crasher" (Closed)
Patch Set: rebased Created 3 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_network_transaction.cc ('k') | net/http/http_stream_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_network_transaction_unittest.cc
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 24fafb279b244777d8149f5411b765db7170f757..e267038145768a011ca23bbbb9e27dd1109a3e7a 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -71,6 +71,7 @@
#include "net/proxy/proxy_config_service_fixed.h"
#include "net/proxy/proxy_info.h"
#include "net/proxy/proxy_resolver.h"
+#include "net/proxy/proxy_resolver_factory.h"
#include "net/proxy/proxy_server.h"
#include "net/proxy/proxy_service.h"
#include "net/socket/client_socket_factory.h"
@@ -376,6 +377,20 @@ std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler(
return session;
}
+class FailingProxyResolverFactory : public ProxyResolverFactory {
+ public:
+ FailingProxyResolverFactory() : ProxyResolverFactory(false) {}
+
+ // ProxyResolverFactory override.
+ int CreateProxyResolver(
+ const scoped_refptr<ProxyResolverScriptData>& script_data,
+ std::unique_ptr<ProxyResolver>* result,
+ const CompletionCallback& callback,
+ std::unique_ptr<Request>* request) override {
+ return ERR_PAC_SCRIPT_FAILED;
+ }
+};
+
} // namespace
class HttpNetworkTransactionTest : public PlatformTest {
@@ -15183,20 +15198,21 @@ class FakeStreamFactory : public HttpStreamFactory {
return last_stream_request_;
}
- HttpStreamRequest* RequestStream(const HttpRequestInfo& info,
- RequestPriority priority,
- const SSLConfig& server_ssl_config,
- const SSLConfig& proxy_ssl_config,
- HttpStreamRequest::Delegate* delegate,
- bool enable_ip_based_pooling,
- bool enable_alternative_services,
- const NetLogWithSource& net_log) override {
- FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate);
+ std::unique_ptr<HttpStreamRequest> RequestStream(
+ const HttpRequestInfo& info,
+ RequestPriority priority,
+ const SSLConfig& server_ssl_config,
+ const SSLConfig& proxy_ssl_config,
+ HttpStreamRequest::Delegate* delegate,
+ bool enable_ip_based_pooling,
+ bool enable_alternative_services,
+ const NetLogWithSource& net_log) override {
+ auto fake_request = base::MakeUnique<FakeStreamRequest>(priority, delegate);
last_stream_request_ = fake_request->AsWeakPtr();
- return fake_request;
+ return std::move(fake_request);
}
- HttpStreamRequest* RequestBidirectionalStreamImpl(
+ std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl(
const HttpRequestInfo& info,
RequestPriority priority,
const SSLConfig& server_ssl_config,
@@ -15209,7 +15225,7 @@ class FakeStreamFactory : public HttpStreamFactory {
return nullptr;
}
- HttpStreamRequest* RequestWebSocketHandshakeStream(
+ std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream(
const HttpRequestInfo& info,
RequestPriority priority,
const SSLConfig& server_ssl_config,
@@ -15219,10 +15235,10 @@ class FakeStreamFactory : public HttpStreamFactory {
bool enable_ip_based_pooling,
bool enable_alternative_services,
const NetLogWithSource& net_log) override {
- FakeStreamRequest* fake_request =
- new FakeStreamRequest(priority, delegate, create_helper);
+ auto fake_request =
+ base::MakeUnique<FakeStreamRequest>(priority, delegate, create_helper);
last_stream_request_ = fake_request->AsWeakPtr();
- return fake_request;
+ return std::move(fake_request);
}
void PreconnectStreams(int num_streams,
@@ -16833,4 +16849,73 @@ TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) {
"www.foo.com/other", true);
}
+TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) {
+ ProxyConfig proxy_config;
+ proxy_config.set_pac_url(GURL("http://fooproxyurl"));
+ proxy_config.set_pac_mandatory(true);
+ MockAsyncProxyResolver resolver;
+ session_deps_.proxy_service.reset(new ProxyService(
+ base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
+ base::WrapUnique(new FailingProxyResolverFactory), nullptr));
+
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.example.org/");
+
+ std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
+ HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
+
+ TestCompletionCallback callback;
+
+ int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
+ EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
+ EXPECT_THAT(callback.WaitForResult(),
+ IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED));
+}
+
+TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) {
+ ProxyConfig proxy_config;
+ proxy_config.set_pac_url(GURL("http://fooproxyurl"));
+ proxy_config.set_pac_mandatory(true);
+ MockAsyncProxyResolverFactory* proxy_resolver_factory =
+ new MockAsyncProxyResolverFactory(false);
+ MockAsyncProxyResolver resolver;
+ session_deps_.proxy_service.reset(
+ new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
+ base::WrapUnique(proxy_resolver_factory), nullptr));
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.example.org/");
+
+ std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
+ HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
+
+ TestCompletionCallback callback;
+ int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
+ EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
+
+ proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder(
+ ERR_FAILED, &resolver);
+ EXPECT_THAT(callback.WaitForResult(),
+ IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED));
+}
+
+TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) {
+ session_deps_.proxy_service =
+ ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443");
+ session_deps_.enable_quic = false;
+ std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
+
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.example.org/");
+
+ TestCompletionCallback callback;
+ HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
+ int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
+ EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
+
+ EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES));
+}
+
} // namespace net
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_stream_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698