summaryrefslogtreecommitdiffstats
path: root/net/http/http_network_layer_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/http/http_network_layer_unittest.cc')
-rw-r--r--net/http/http_network_layer_unittest.cc41
1 files changed, 23 insertions, 18 deletions
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);
}