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

Side by Side Diff: chrome/browser/extensions/api/socket/tcp_socket_unittest.cc

Issue 10134008: Add bind(), recvFrom(), sendTo() for UDP socket. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/socket/tcp_socket.h" 5 #include "chrome/browser/extensions/api/socket/tcp_socket.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" 8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h"
9 #include "net/base/address_list.h" 9 #include "net/base/address_list.h"
10 #include "net/base/completion_callback.h" 10 #include "net/base/completion_callback.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const std::string& message)); 45 const std::string& message));
46 MOCK_METHOD1(OnWriteComplete, void(int result_code)); 46 MOCK_METHOD1(OnWriteComplete, void(int result_code));
47 }; 47 };
48 48
49 TEST(SocketTest, TestTCPSocketRead) { 49 TEST(SocketTest, TestTCPSocketRead) {
50 net::AddressList address_list; 50 net::AddressList address_list;
51 MockTCPSocket* tcp_client_socket = new MockTCPSocket(address_list); 51 MockTCPSocket* tcp_client_socket = new MockTCPSocket(address_list);
52 APIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier(); 52 APIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier();
53 53
54 scoped_ptr<TCPSocket> socket(TCPSocket::CreateSocketForTesting( 54 scoped_ptr<TCPSocket> socket(TCPSocket::CreateSocketForTesting(
55 tcp_client_socket, "1.2.3.4", 1, notifier)); 55 tcp_client_socket, notifier));
56 56
57 EXPECT_CALL(*tcp_client_socket, Read(_, _, _)) 57 EXPECT_CALL(*tcp_client_socket, Read(_, _, _))
58 .Times(1); 58 .Times(1);
59 59
60 scoped_refptr<net::IOBufferWithSize> io_buffer( 60 scoped_refptr<net::IOBufferWithSize> io_buffer(
61 new net::IOBufferWithSize(512)); 61 new net::IOBufferWithSize(512));
62 socket->Read(io_buffer.get(), io_buffer->size()); 62 socket->Read(io_buffer.get(), io_buffer->size());
63 } 63 }
64 64
65 TEST(SocketTest, TestTCPSocketWrite) { 65 TEST(SocketTest, TestTCPSocketWrite) {
66 net::AddressList address_list; 66 net::AddressList address_list;
67 MockTCPSocket* tcp_client_socket = new MockTCPSocket(address_list); 67 MockTCPSocket* tcp_client_socket = new MockTCPSocket(address_list);
68 APIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier(); 68 APIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier();
69 69
70 scoped_ptr<TCPSocket> socket(TCPSocket::CreateSocketForTesting( 70 scoped_ptr<TCPSocket> socket(TCPSocket::CreateSocketForTesting(
71 tcp_client_socket, "1.2.3.4", 1, notifier)); 71 tcp_client_socket, notifier));
72 72
73 EXPECT_CALL(*tcp_client_socket, Write(_, _, _)) 73 EXPECT_CALL(*tcp_client_socket, Write(_, _, _))
74 .Times(1); 74 .Times(1);
75 75
76 scoped_refptr<net::IOBufferWithSize> io_buffer( 76 scoped_refptr<net::IOBufferWithSize> io_buffer(
77 new net::IOBufferWithSize(256)); 77 new net::IOBufferWithSize(256));
78 socket->Write(io_buffer.get(), io_buffer->size()); 78 socket->Write(io_buffer.get(), io_buffer->size());
79 } 79 }
80 80
81 TEST(SocketTest, TestTCPSocketBlockedWrite) { 81 TEST(SocketTest, TestTCPSocketBlockedWrite) {
82 net::AddressList address_list; 82 net::AddressList address_list;
83 MockTCPSocket* tcp_client_socket = new MockTCPSocket(address_list); 83 MockTCPSocket* tcp_client_socket = new MockTCPSocket(address_list);
84 MockAPIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier(); 84 MockAPIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier();
85 85
86 scoped_ptr<TCPSocket> socket(TCPSocket::CreateSocketForTesting( 86 scoped_ptr<TCPSocket> socket(TCPSocket::CreateSocketForTesting(
87 tcp_client_socket, "1.2.3.4", 1, notifier)); 87 tcp_client_socket, notifier));
88 88
89 net::CompletionCallback callback; 89 net::CompletionCallback callback;
90 EXPECT_CALL(*tcp_client_socket, Write(_, _, _)) 90 EXPECT_CALL(*tcp_client_socket, Write(_, _, _))
91 .Times(1) 91 .Times(1)
92 .WillOnce(testing::DoAll(SaveArg<2>(&callback), 92 .WillOnce(testing::DoAll(SaveArg<2>(&callback),
93 Return(net::ERR_IO_PENDING))); 93 Return(net::ERR_IO_PENDING)));
94 94
95 scoped_refptr<net::IOBufferWithSize> io_buffer(new net::IOBufferWithSize( 95 scoped_refptr<net::IOBufferWithSize> io_buffer(new net::IOBufferWithSize(
96 1)); 96 1));
97 ASSERT_EQ(net::ERR_IO_PENDING, socket->Write(io_buffer.get(), 97 ASSERT_EQ(net::ERR_IO_PENDING, socket->Write(io_buffer.get(),
98 io_buffer->size())); 98 io_buffer->size()));
99 99
100 // Good. Original call came back unable to complete. Now pretend the socket 100 // Good. Original call came back unable to complete. Now pretend the socket
101 // finished, and confirm that we passed the error back. 101 // finished, and confirm that we passed the error back.
102 EXPECT_CALL(*notifier, OnWriteComplete(42)) 102 EXPECT_CALL(*notifier, OnWriteComplete(42))
103 .Times(1); 103 .Times(1);
104 callback.Run(42); 104 callback.Run(42);
105 } 105 }
106 106
107 } // namespace extensions 107 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/socket/tcp_socket.cc ('k') | chrome/browser/extensions/api/socket/udp_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698