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

Side by Side Diff: net/socket/tcp_client_socket_unittest.cc

Issue 848006: Generalize the net module's LoadLog facility from a passive container, to an event stream (NetLog). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Split up RequestTracker into ConnectJobTracker+RequestTracker+RequestTrackerBase, address comments Created 10 years, 9 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/socket/tcp_client_socket_pool_unittest.cc ('k') | net/socket/tcp_client_socket_win.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-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/socket/tcp_client_socket.h" 5 #include "net/socket/tcp_client_socket.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "net/base/address_list.h" 8 #include "net/base/address_list.h"
9 #include "net/base/host_resolver.h" 9 #include "net/base/host_resolver.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
11 #include "net/base/listen_socket.h" 11 #include "net/base/listen_socket.h"
12 #include "net/base/load_log.h" 12 #include "net/base/net_log.h"
13 #include "net/base/load_log_unittest.h" 13 #include "net/base/net_log_unittest.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/base/test_completion_callback.h" 15 #include "net/base/test_completion_callback.h"
16 #include "net/base/winsock_init.h" 16 #include "net/base/winsock_init.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/platform_test.h" 18 #include "testing/platform_test.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 namespace { 22 namespace {
23 23
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 HostResolver::RequestInfo info("localhost", listen_port_); 92 HostResolver::RequestInfo info("localhost", listen_port_);
93 int rv = resolver->Resolve(info, &addr, NULL, NULL, NULL); 93 int rv = resolver->Resolve(info, &addr, NULL, NULL, NULL);
94 CHECK_EQ(rv, OK); 94 CHECK_EQ(rv, OK);
95 sock_.reset(new TCPClientSocket(addr)); 95 sock_.reset(new TCPClientSocket(addr));
96 } 96 }
97 97
98 TEST_F(TCPClientSocketTest, Connect) { 98 TEST_F(TCPClientSocketTest, Connect) {
99 TestCompletionCallback callback; 99 TestCompletionCallback callback;
100 EXPECT_FALSE(sock_->IsConnected()); 100 EXPECT_FALSE(sock_->IsConnected());
101 101
102 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); 102 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
103 int rv = sock_->Connect(&callback, log); 103 int rv = sock_->Connect(&callback, log.bound());
104 EXPECT_TRUE(net::LogContainsBeginEvent( 104 EXPECT_TRUE(net::LogContainsBeginEvent(
105 *log, 0, net::LoadLog::TYPE_TCP_CONNECT)); 105 log.entries(), 0, net::NetLog::TYPE_TCP_CONNECT));
106 if (rv != OK) { 106 if (rv != OK) {
107 ASSERT_EQ(rv, ERR_IO_PENDING); 107 ASSERT_EQ(rv, ERR_IO_PENDING);
108 EXPECT_FALSE(net::LogContainsEndEvent( 108 EXPECT_FALSE(net::LogContainsEndEvent(
109 *log, -1, net::LoadLog::TYPE_TCP_CONNECT)); 109 log.entries(), -1, net::NetLog::TYPE_TCP_CONNECT));
110 110
111 rv = callback.WaitForResult(); 111 rv = callback.WaitForResult();
112 EXPECT_EQ(rv, OK); 112 EXPECT_EQ(rv, OK);
113 } 113 }
114 114
115 EXPECT_TRUE(sock_->IsConnected()); 115 EXPECT_TRUE(sock_->IsConnected());
116 EXPECT_TRUE(net::LogContainsEndEvent( 116 EXPECT_TRUE(net::LogContainsEndEvent(
117 *log, -1, net::LoadLog::TYPE_TCP_CONNECT)); 117 log.entries(), -1, net::NetLog::TYPE_TCP_CONNECT));
118 118
119 sock_->Disconnect(); 119 sock_->Disconnect();
120 EXPECT_FALSE(sock_->IsConnected()); 120 EXPECT_FALSE(sock_->IsConnected());
121 } 121 }
122 122
123 // TODO(wtc): Add unit tests for IsConnectedAndIdle: 123 // TODO(wtc): Add unit tests for IsConnectedAndIdle:
124 // - Server closes a connection. 124 // - Server closes a connection.
125 // - Server sends data unexpectedly. 125 // - Server sends data unexpectedly.
126 126
127 TEST_F(TCPClientSocketTest, Read) { 127 TEST_F(TCPClientSocketTest, Read) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // Close the server socket, so there will at least be a 0-byte read. 339 // Close the server socket, so there will at least be a 0-byte read.
340 CloseServerSocket(); 340 CloseServerSocket();
341 341
342 rv = callback.WaitForResult(); 342 rv = callback.WaitForResult();
343 EXPECT_GE(rv, 0); 343 EXPECT_GE(rv, 0);
344 } 344 }
345 345
346 } // namespace 346 } // namespace
347 347
348 } // namespace net 348 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_client_socket_pool_unittest.cc ('k') | net/socket/tcp_client_socket_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698