summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/http/http_network_layer.cc20
-rw-r--r--net/http/http_network_layer.h11
-rw-r--r--net/http/http_network_layer_unittest.cc41
-rw-r--r--net/tools/fetch/fetch_client.cc10
4 files changed, 51 insertions, 31 deletions
diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc
index 3a8122f..ddaefb1 100644
--- a/net/http/http_network_layer.cc
+++ b/net/http/http_network_layer.cc
@@ -19,7 +19,8 @@ HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
ProxyService* proxy_service) {
DCHECK(proxy_service);
- return new HttpNetworkLayer(host_resolver, proxy_service);
+ return new HttpNetworkLayer(ClientSocketFactory::GetDefaultFactory(),
+ host_resolver, proxy_service);
}
// static
@@ -32,9 +33,11 @@ HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
//-----------------------------------------------------------------------------
-HttpNetworkLayer::HttpNetworkLayer(HostResolver* host_resolver,
+HttpNetworkLayer::HttpNetworkLayer(ClientSocketFactory* socket_factory,
+ HostResolver* host_resolver,
ProxyService* proxy_service)
- : host_resolver_(host_resolver),
+ : socket_factory_(socket_factory),
+ host_resolver_(host_resolver),
proxy_service_(proxy_service),
session_(NULL),
suspended_(false) {
@@ -42,7 +45,11 @@ HttpNetworkLayer::HttpNetworkLayer(HostResolver* host_resolver,
}
HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session)
- : proxy_service_(NULL), session_(session), suspended_(false) {
+ : socket_factory_(ClientSocketFactory::GetDefaultFactory()),
+ host_resolver_(NULL),
+ proxy_service_(NULL),
+ session_(session),
+ suspended_(false) {
DCHECK(session_.get());
}
@@ -53,8 +60,7 @@ HttpTransaction* HttpNetworkLayer::CreateTransaction() {
if (suspended_)
return NULL;
- return new HttpNetworkTransaction(
- GetSession(), ClientSocketFactory::GetDefaultFactory());
+ return new HttpNetworkTransaction(GetSession(), socket_factory_);
}
HttpCache* HttpNetworkLayer::GetCache() {
@@ -72,7 +78,7 @@ HttpNetworkSession* HttpNetworkLayer::GetSession() {
if (!session_) {
DCHECK(proxy_service_);
session_ = new HttpNetworkSession(host_resolver_, proxy_service_,
- ClientSocketFactory::GetDefaultFactory());
+ socket_factory_);
}
return session_;
}
diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h
index acee57e..74cf3df 100644
--- a/net/http/http_network_layer.h
+++ b/net/http/http_network_layer.h
@@ -11,6 +11,7 @@
namespace net {
+class ClientSocketFactory;
class HostResolver;
class HttpNetworkSession;
class ProxyInfo;
@@ -18,9 +19,10 @@ class ProxyService;
class HttpNetworkLayer : public HttpTransactionFactory {
public:
- // |proxy_service| and |host_resolver| must remain valid for the lifetime of
- // HttpNetworkLayer.
- HttpNetworkLayer(HostResolver* host_resolver, ProxyService* proxy_service);
+ // |socket_factory|, |proxy_service| and |host_resolver| must remain valid
+ // for the lifetime of HttpNetworkLayer.
+ HttpNetworkLayer(ClientSocketFactory* socket_factory,
+ HostResolver* host_resolver, ProxyService* proxy_service);
// Construct a HttpNetworkLayer with an existing HttpNetworkSession which
// contains a valid ProxyService.
explicit HttpNetworkLayer(HttpNetworkSession* session);
@@ -46,6 +48,9 @@ class HttpNetworkLayer : public HttpTransactionFactory {
HttpNetworkSession* GetSession();
private:
+ // The factory we will use to create network sockets.
+ ClientSocketFactory* socket_factory_;
+
// The host resolver being used for the session.
HostResolver* host_resolver_;
diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc
index 46e0f8d..a85821e 100644
--- a/net/http/http_network_layer_unittest.cc
+++ b/net/http/http_network_layer_unittest.cc
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/ref_counted.h"
-#include "net/base/host_resolver_unittest.h"
+#include "net/base/host_resolver.h"
+#include "net/base/socket_test_util.h"
#include "net/http/http_network_layer.h"
#include "net/http/http_transaction_unittest.h"
#include "net/proxy/proxy_service.h"
@@ -11,24 +11,12 @@
#include "testing/platform_test.h"
class HttpNetworkLayerTest : public PlatformTest {
- public:
- HttpNetworkLayerTest()
- : host_mapper_(new net::RuleBasedHostMapper()),
- scoped_host_mapper_(host_mapper_.get()) {
- // TODO(darin): kill this exception once we have a way to test out the
- // HttpNetworkLayer class using loopback connections.
- host_mapper_->AllowDirectLookup("www.google.com");
- }
-
- private:
- scoped_refptr<net::RuleBasedHostMapper> host_mapper_;
- net::ScopedHostMapper scoped_host_mapper_;
};
TEST_F(HttpNetworkLayerTest, CreateAndDestroy) {
net::HostResolver host_resolver;
scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull());
- net::HttpNetworkLayer factory(&host_resolver, proxy_service.get());
+ net::HttpNetworkLayer factory(NULL, &host_resolver, proxy_service.get());
scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction());
}
@@ -36,7 +24,7 @@ TEST_F(HttpNetworkLayerTest, CreateAndDestroy) {
TEST_F(HttpNetworkLayerTest, Suspend) {
net::HostResolver host_resolver;
scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull());
- net::HttpNetworkLayer factory(&host_resolver, proxy_service.get());
+ net::HttpNetworkLayer factory(NULL, &host_resolver, proxy_service.get());
scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction());
trans.reset();
@@ -51,10 +39,26 @@ TEST_F(HttpNetworkLayerTest, Suspend) {
trans.reset(factory.CreateTransaction());
}
-TEST_F(HttpNetworkLayerTest, GoogleGET) {
+TEST_F(HttpNetworkLayerTest, GET) {
+ net::MockClientSocketFactory mock_socket_factory;
+ net::MockRead data_reads[] = {
+ net::MockRead("HTTP/1.0 200 OK\r\n\r\n"),
+ net::MockRead("hello world"),
+ net::MockRead(false, net::OK),
+ };
+ net::MockWrite data_writes[] = {
+ net::MockWrite("GET / HTTP/1.1\r\n"
+ "Host: www.google.com\r\n"
+ "Connection: keep-alive\r\n"
+ "User-Agent: Foo/1.0\r\n\r\n"),
+ };
+ net::StaticMockSocket data(data_reads, data_writes);
+ mock_socket_factory.AddMockSocket(&data);
+
net::HostResolver host_resolver;
scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull());
- net::HttpNetworkLayer factory(&host_resolver, proxy_service.get());
+ net::HttpNetworkLayer factory(&mock_socket_factory, &host_resolver,
+ proxy_service.get());
TestCompletionCallback callback;
@@ -74,4 +78,5 @@ TEST_F(HttpNetworkLayerTest, GoogleGET) {
std::string contents;
rv = ReadTransaction(trans.get(), &contents);
EXPECT_EQ(net::OK, rv);
+ EXPECT_EQ("hello world", contents);
}
diff --git a/net/tools/fetch/fetch_client.cc b/net/tools/fetch/fetch_client.cc
index 349eed9..6e86a88 100644
--- a/net/tools/fetch/fetch_client.cc
+++ b/net/tools/fetch/fetch_client.cc
@@ -8,6 +8,7 @@
#include "base/singleton.h"
#include "base/stats_counters.h"
#include "base/string_util.h"
+#include "net/base/client_socket_factory.h"
#include "net/base/completion_callback.h"
#include "net/base/host_resolver.h"
#include "net/base/io_buffer.h"
@@ -129,10 +130,13 @@ int main(int argc, char**argv) {
net::HostResolver host_resolver;
scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull());
net::HttpTransactionFactory* factory = NULL;
- if (use_cache)
+ if (use_cache) {
factory = new net::HttpCache(&host_resolver, proxy_service.get(), 0);
- else
- factory = new net::HttpNetworkLayer(&host_resolver, proxy_service.get());
+ } else {
+ factory = new net::HttpNetworkLayer(
+ net::ClientSocketFactory::GetDefaultFactory(), &host_resolver,
+ proxy_service.get());
+ }
{
StatsCounterTimer driver_time("FetchClient.total_time");