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

Side by Side Diff: net/http/http_network_layer_unittest.cc

Issue 2802015: Massively simplify the NetworkChangeNotifier infrastructure:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/mock_host_resolver.h" 5 #include "net/base/mock_host_resolver.h"
6 #include "net/base/net_log.h" 6 #include "net/base/net_log.h"
7 #include "net/base/ssl_config_service_defaults.h" 7 #include "net/base/ssl_config_service_defaults.h"
8 #include "net/http/http_network_layer.h" 8 #include "net/http/http_network_layer.h"
9 #include "net/http/http_transaction_unittest.h" 9 #include "net/http/http_transaction_unittest.h"
10 #include "net/proxy/proxy_service.h" 10 #include "net/proxy/proxy_service.h"
11 #include "net/socket/socket_test_util.h" 11 #include "net/socket/socket_test_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
14 14
15 class HttpNetworkLayerTest : public PlatformTest { 15 class HttpNetworkLayerTest : public PlatformTest {
16 }; 16 };
17 17
18 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { 18 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) {
19 net::HttpNetworkLayer factory( 19 net::HttpNetworkLayer factory(NULL, new net::MockHostResolver,
20 NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), 20 net::ProxyService::CreateNull(), new net::SSLConfigServiceDefaults, NULL,
21 new net::SSLConfigServiceDefaults, NULL, NULL, NULL); 21 NULL, NULL);
22 22
23 scoped_ptr<net::HttpTransaction> trans; 23 scoped_ptr<net::HttpTransaction> trans;
24 int rv = factory.CreateTransaction(&trans); 24 int rv = factory.CreateTransaction(&trans);
25 EXPECT_EQ(net::OK, rv); 25 EXPECT_EQ(net::OK, rv);
26 EXPECT_TRUE(trans.get() != NULL); 26 EXPECT_TRUE(trans.get() != NULL);
27 } 27 }
28 28
29 TEST_F(HttpNetworkLayerTest, Suspend) { 29 TEST_F(HttpNetworkLayerTest, Suspend) {
30 net::HttpNetworkLayer factory( 30 net::HttpNetworkLayer factory(NULL, new net::MockHostResolver,
31 NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), 31 net::ProxyService::CreateNull(), new net::SSLConfigServiceDefaults, NULL,
32 new net::SSLConfigServiceDefaults, NULL, NULL, NULL); 32 NULL, NULL);
33 33
34 scoped_ptr<net::HttpTransaction> trans; 34 scoped_ptr<net::HttpTransaction> trans;
35 int rv = factory.CreateTransaction(&trans); 35 int rv = factory.CreateTransaction(&trans);
36 EXPECT_EQ(net::OK, rv); 36 EXPECT_EQ(net::OK, rv);
37 37
38 trans.reset(); 38 trans.reset();
39 39
40 factory.Suspend(true); 40 factory.Suspend(true);
41 41
42 rv = factory.CreateTransaction(&trans); 42 rv = factory.CreateTransaction(&trans);
(...skipping 17 matching lines...) Expand all
60 net::MockWrite data_writes[] = { 60 net::MockWrite data_writes[] = {
61 net::MockWrite("GET / HTTP/1.1\r\n" 61 net::MockWrite("GET / HTTP/1.1\r\n"
62 "Host: www.google.com\r\n" 62 "Host: www.google.com\r\n"
63 "Connection: keep-alive\r\n" 63 "Connection: keep-alive\r\n"
64 "User-Agent: Foo/1.0\r\n\r\n"), 64 "User-Agent: Foo/1.0\r\n\r\n"),
65 }; 65 };
66 net::StaticSocketDataProvider data(data_reads, arraysize(data_reads), 66 net::StaticSocketDataProvider data(data_reads, arraysize(data_reads),
67 data_writes, arraysize(data_reads)); 67 data_writes, arraysize(data_reads));
68 mock_socket_factory.AddSocketDataProvider(&data); 68 mock_socket_factory.AddSocketDataProvider(&data);
69 69
70 net::HttpNetworkLayer factory(&mock_socket_factory, NULL, 70 net::HttpNetworkLayer factory(&mock_socket_factory, new net::MockHostResolver,
71 new net::MockHostResolver, 71 net::ProxyService::CreateNull(), new net::SSLConfigServiceDefaults, NULL,
72 net::ProxyService::CreateNull(), 72 NULL, NULL);
73 new net::SSLConfigServiceDefaults,
74 NULL, NULL, NULL);
75 73
76 TestCompletionCallback callback; 74 TestCompletionCallback callback;
77 75
78 scoped_ptr<net::HttpTransaction> trans; 76 scoped_ptr<net::HttpTransaction> trans;
79 int rv = factory.CreateTransaction(&trans); 77 int rv = factory.CreateTransaction(&trans);
80 EXPECT_EQ(net::OK, rv); 78 EXPECT_EQ(net::OK, rv);
81 79
82 net::HttpRequestInfo request_info; 80 net::HttpRequestInfo request_info;
83 request_info.url = GURL("http://www.google.com/"); 81 request_info.url = GURL("http://www.google.com/");
84 request_info.method = "GET"; 82 request_info.method = "GET";
85 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, 83 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent,
86 "Foo/1.0"); 84 "Foo/1.0");
87 request_info.load_flags = net::LOAD_NORMAL; 85 request_info.load_flags = net::LOAD_NORMAL;
88 86
89 rv = trans->Start(&request_info, &callback, net::BoundNetLog()); 87 rv = trans->Start(&request_info, &callback, net::BoundNetLog());
90 if (rv == net::ERR_IO_PENDING) 88 if (rv == net::ERR_IO_PENDING)
91 rv = callback.WaitForResult(); 89 rv = callback.WaitForResult();
92 ASSERT_EQ(net::OK, rv); 90 ASSERT_EQ(net::OK, rv);
93 91
94 std::string contents; 92 std::string contents;
95 rv = ReadTransaction(trans.get(), &contents); 93 rv = ReadTransaction(trans.get(), &contents);
96 EXPECT_EQ(net::OK, rv); 94 EXPECT_EQ(net::OK, rv);
97 EXPECT_EQ("hello world", contents); 95 EXPECT_EQ("hello world", contents);
98 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698