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

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc

Issue 13584008: Send notification about outgoing p2p packets from browser to renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 "content/browser/renderer_host/p2p/socket_host_tcp.h" 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h"
6 6
7 #include <deque> 7 #include <deque>
8 8
9 #include "base/sys_byteorder.h" 9 #include "base/sys_byteorder.h"
10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" 10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 net::IPEndPoint local_address_; 56 net::IPEndPoint local_address_;
57 57
58 net::IPEndPoint dest_; 58 net::IPEndPoint dest_;
59 net::IPEndPoint dest2_; 59 net::IPEndPoint dest2_;
60 }; 60 };
61 61
62 // Verify that we can send STUN message and that they are formatted 62 // Verify that we can send STUN message and that they are formatted
63 // properly. 63 // properly.
64 TEST_F(P2PSocketHostTcpTest, SendStunNoAuth) { 64 TEST_F(P2PSocketHostTcpTest, SendStunNoAuth) {
65 EXPECT_CALL(sender_, Send(
66 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
67 .Times(3)
68 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
69
65 std::vector<char> packet1; 70 std::vector<char> packet1;
66 CreateStunRequest(&packet1); 71 CreateStunRequest(&packet1);
67 socket_host_->Send(dest_, packet1); 72 socket_host_->Send(dest_, packet1);
68 73
69 std::vector<char> packet2; 74 std::vector<char> packet2;
70 CreateStunResponse(&packet2); 75 CreateStunResponse(&packet2);
71 socket_host_->Send(dest_, packet2); 76 socket_host_->Send(dest_, packet2);
72 77
73 std::vector<char> packet3; 78 std::vector<char> packet3;
74 CreateStunError(&packet3); 79 CreateStunError(&packet3);
75 socket_host_->Send(dest_, packet3); 80 socket_host_->Send(dest_, packet3);
76 81
77 std::string expected_data; 82 std::string expected_data;
78 expected_data.append(IntToSize(packet1.size())); 83 expected_data.append(IntToSize(packet1.size()));
79 expected_data.append(packet1.begin(), packet1.end()); 84 expected_data.append(packet1.begin(), packet1.end());
80 expected_data.append(IntToSize(packet2.size())); 85 expected_data.append(IntToSize(packet2.size()));
81 expected_data.append(packet2.begin(), packet2.end()); 86 expected_data.append(packet2.begin(), packet2.end());
82 expected_data.append(IntToSize(packet3.size())); 87 expected_data.append(IntToSize(packet3.size()));
83 expected_data.append(packet3.begin(), packet3.end()); 88 expected_data.append(packet3.begin(), packet3.end());
84 89
85 EXPECT_EQ(expected_data, sent_data_); 90 EXPECT_EQ(expected_data, sent_data_);
86 } 91 }
87 92
88 // Verify that we can receive STUN messages from the socket, and that 93 // Verify that we can receive STUN messages from the socket, and that
89 // the messages are parsed properly. 94 // the messages are parsed properly.
90 TEST_F(P2PSocketHostTcpTest, ReceiveStun) { 95 TEST_F(P2PSocketHostTcpTest, ReceiveStun) {
96 EXPECT_CALL(sender_, Send(
97 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
98 .Times(3)
99 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
100
91 std::vector<char> packet1; 101 std::vector<char> packet1;
92 CreateStunRequest(&packet1); 102 CreateStunRequest(&packet1);
93 socket_host_->Send(dest_, packet1); 103 socket_host_->Send(dest_, packet1);
94 104
95 std::vector<char> packet2; 105 std::vector<char> packet2;
96 CreateStunResponse(&packet2); 106 CreateStunResponse(&packet2);
97 socket_host_->Send(dest_, packet2); 107 socket_host_->Send(dest_, packet2);
98 108
99 std::vector<char> packet3; 109 std::vector<char> packet3;
100 CreateStunError(&packet3); 110 CreateStunError(&packet3);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // from the other side. 155 // from the other side.
146 TEST_F(P2PSocketHostTcpTest, SendAfterStunRequest) { 156 TEST_F(P2PSocketHostTcpTest, SendAfterStunRequest) {
147 // Receive packet from |dest_|. 157 // Receive packet from |dest_|.
148 std::vector<char> request_packet; 158 std::vector<char> request_packet;
149 CreateStunRequest(&request_packet); 159 CreateStunRequest(&request_packet);
150 160
151 std::string received_data; 161 std::string received_data;
152 received_data.append(IntToSize(request_packet.size())); 162 received_data.append(IntToSize(request_packet.size()));
153 received_data.append(request_packet.begin(), request_packet.end()); 163 received_data.append(request_packet.begin(), request_packet.end());
154 164
165 EXPECT_CALL(sender_, Send(
166 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
167 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
155 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 168 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
156 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 169 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
157 socket_->AppendInputData(&received_data[0], received_data.size()); 170 socket_->AppendInputData(&received_data[0], received_data.size());
158 171
159 // Now we should be able to send any data to |dest_|. 172 // Now we should be able to send any data to |dest_|.
160 std::vector<char> packet; 173 std::vector<char> packet;
161 CreateRandomPacket(&packet); 174 CreateRandomPacket(&packet);
162 socket_host_->Send(dest_, packet); 175 socket_host_->Send(dest_, packet);
163 176
164 std::string expected_data; 177 std::string expected_data;
165 expected_data.append(IntToSize(packet.size())); 178 expected_data.append(IntToSize(packet.size()));
166 expected_data.append(packet.begin(), packet.end()); 179 expected_data.append(packet.begin(), packet.end());
167 180
168 EXPECT_EQ(expected_data, sent_data_); 181 EXPECT_EQ(expected_data, sent_data_);
169 } 182 }
170 183
171 } // namespace content 184 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698