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

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

Issue 222009: Replace some net::ERR_FAILED generic error codes with more specific codes.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address wtc's comments Created 11 years, 3 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
« no previous file with comments | « net/http/http_network_layer.cc ('k') | net/http/http_transaction_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/ssl_config_service_defaults.h" 6 #include "net/base/ssl_config_service_defaults.h"
7 #include "net/http/http_network_layer.h" 7 #include "net/http/http_network_layer.h"
8 #include "net/http/http_transaction_unittest.h" 8 #include "net/http/http_transaction_unittest.h"
9 #include "net/proxy/proxy_service.h" 9 #include "net/proxy/proxy_service.h"
10 #include "net/socket/socket_test_util.h" 10 #include "net/socket/socket_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
13 13
14 class HttpNetworkLayerTest : public PlatformTest { 14 class HttpNetworkLayerTest : public PlatformTest {
15 }; 15 };
16 16
17 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { 17 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) {
18 net::HttpNetworkLayer factory( 18 net::HttpNetworkLayer factory(
19 NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), 19 NULL, new net::MockHostResolver, net::ProxyService::CreateNull(),
20 new net::SSLConfigServiceDefaults); 20 new net::SSLConfigServiceDefaults);
21 21
22 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); 22 scoped_ptr<net::HttpTransaction> trans;
23 int rv = factory.CreateTransaction(&trans);
24 EXPECT_EQ(net::OK, rv);
25 EXPECT_TRUE(trans.get() != NULL);
23 } 26 }
24 27
25 TEST_F(HttpNetworkLayerTest, Suspend) { 28 TEST_F(HttpNetworkLayerTest, Suspend) {
26 net::HttpNetworkLayer factory( 29 net::HttpNetworkLayer factory(
27 NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), 30 NULL, new net::MockHostResolver, net::ProxyService::CreateNull(),
28 new net::SSLConfigServiceDefaults); 31 new net::SSLConfigServiceDefaults);
29 32
30 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); 33 scoped_ptr<net::HttpTransaction> trans;
34 int rv = factory.CreateTransaction(&trans);
35 EXPECT_EQ(net::OK, rv);
36
31 trans.reset(); 37 trans.reset();
32 38
33 factory.Suspend(true); 39 factory.Suspend(true);
34 40
35 trans.reset(factory.CreateTransaction()); 41 rv = factory.CreateTransaction(&trans);
42 EXPECT_EQ(net::ERR_NETWORK_IO_SUSPENDED, rv);
43
36 ASSERT_TRUE(trans == NULL); 44 ASSERT_TRUE(trans == NULL);
37 45
38 factory.Suspend(false); 46 factory.Suspend(false);
39 47
40 trans.reset(factory.CreateTransaction()); 48 rv = factory.CreateTransaction(&trans);
49 EXPECT_EQ(net::OK, rv);
41 } 50 }
42 51
43 TEST_F(HttpNetworkLayerTest, GET) { 52 TEST_F(HttpNetworkLayerTest, GET) {
44 net::MockClientSocketFactory mock_socket_factory; 53 net::MockClientSocketFactory mock_socket_factory;
45 net::MockRead data_reads[] = { 54 net::MockRead data_reads[] = {
46 net::MockRead("HTTP/1.0 200 OK\r\n\r\n"), 55 net::MockRead("HTTP/1.0 200 OK\r\n\r\n"),
47 net::MockRead("hello world"), 56 net::MockRead("hello world"),
48 net::MockRead(false, net::OK), 57 net::MockRead(false, net::OK),
49 }; 58 };
50 net::MockWrite data_writes[] = { 59 net::MockWrite data_writes[] = {
51 net::MockWrite("GET / HTTP/1.1\r\n" 60 net::MockWrite("GET / HTTP/1.1\r\n"
52 "Host: www.google.com\r\n" 61 "Host: www.google.com\r\n"
53 "Connection: keep-alive\r\n" 62 "Connection: keep-alive\r\n"
54 "User-Agent: Foo/1.0\r\n\r\n"), 63 "User-Agent: Foo/1.0\r\n\r\n"),
55 }; 64 };
56 net::StaticMockSocket data(data_reads, data_writes); 65 net::StaticMockSocket data(data_reads, data_writes);
57 mock_socket_factory.AddMockSocket(&data); 66 mock_socket_factory.AddMockSocket(&data);
58 67
59 net::HttpNetworkLayer factory(&mock_socket_factory, new net::MockHostResolver, 68 net::HttpNetworkLayer factory(&mock_socket_factory, new net::MockHostResolver,
60 net::ProxyService::CreateNull(), 69 net::ProxyService::CreateNull(),
61 new net::SSLConfigServiceDefaults); 70 new net::SSLConfigServiceDefaults);
62 71
63 TestCompletionCallback callback; 72 TestCompletionCallback callback;
64 73
65 scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); 74 scoped_ptr<net::HttpTransaction> trans;
75 int rv = factory.CreateTransaction(&trans);
76 EXPECT_EQ(net::OK, rv);
66 77
67 net::HttpRequestInfo request_info; 78 net::HttpRequestInfo request_info;
68 request_info.url = GURL("http://www.google.com/"); 79 request_info.url = GURL("http://www.google.com/");
69 request_info.method = "GET"; 80 request_info.method = "GET";
70 request_info.user_agent = "Foo/1.0"; 81 request_info.user_agent = "Foo/1.0";
71 request_info.load_flags = net::LOAD_NORMAL; 82 request_info.load_flags = net::LOAD_NORMAL;
72 83
73 int rv = trans->Start(&request_info, &callback, NULL); 84 rv = trans->Start(&request_info, &callback, NULL);
74 if (rv == net::ERR_IO_PENDING) 85 if (rv == net::ERR_IO_PENDING)
75 rv = callback.WaitForResult(); 86 rv = callback.WaitForResult();
76 ASSERT_EQ(net::OK, rv); 87 ASSERT_EQ(net::OK, rv);
77 88
78 std::string contents; 89 std::string contents;
79 rv = ReadTransaction(trans.get(), &contents); 90 rv = ReadTransaction(trans.get(), &contents);
80 EXPECT_EQ(net::OK, rv); 91 EXPECT_EQ(net::OK, rv);
81 EXPECT_EQ("hello world", contents); 92 EXPECT_EQ("hello world", contents);
82 } 93 }
OLDNEW
« no previous file with comments | « net/http/http_network_layer.cc ('k') | net/http/http_transaction_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698