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

Side by Side Diff: blimp/net/tcp_transport_unittest.cc

Issue 1962393004: Added a debug info UI for Blimp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Kevin's comments Created 4 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "blimp/common/create_blimp_message.h" 9 #include "blimp/common/create_blimp_message.h"
10 #include "blimp/common/proto/blimp_message.pb.h" 10 #include "blimp/common/proto/blimp_message.pb.h"
11 #include "blimp/common/proto/protocol_control.pb.h" 11 #include "blimp/common/proto/protocol_control.pb.h"
12 #include "blimp/net/blimp_connection.h" 12 #include "blimp/net/blimp_connection.h"
13 #include "blimp/net/blimp_connection_statistics.h"
13 #include "blimp/net/tcp_client_transport.h" 14 #include "blimp/net/tcp_client_transport.h"
14 #include "blimp/net/tcp_engine_transport.h" 15 #include "blimp/net/tcp_engine_transport.h"
15 #include "blimp/net/test_common.h" 16 #include "blimp/net/test_common.h"
16 #include "net/base/address_list.h" 17 #include "net/base/address_list.h"
17 #include "net/base/ip_address.h" 18 #include "net/base/ip_address.h"
18 #include "net/base/ip_endpoint.h" 19 #include "net/base/ip_endpoint.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
20 #include "net/base/test_completion_callback.h" 21 #include "net/base/test_completion_callback.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
(...skipping 16 matching lines...) Expand all
39 net::IPEndPoint local_address; 40 net::IPEndPoint local_address;
40 CHECK_EQ(net::OK, engine_->GetLocalAddress(&local_address)); 41 CHECK_EQ(net::OK, engine_->GetLocalAddress(&local_address));
41 return local_address; 42 return local_address;
42 } 43 }
43 44
44 base::MessageLoopForIO message_loop_; 45 base::MessageLoopForIO message_loop_;
45 std::unique_ptr<TCPEngineTransport> engine_; 46 std::unique_ptr<TCPEngineTransport> engine_;
46 }; 47 };
47 48
48 TEST_F(TCPTransportTest, Connect) { 49 TEST_F(TCPTransportTest, Connect) {
50 BlimpConnectionStatistics statistics;
49 net::TestCompletionCallback accept_callback; 51 net::TestCompletionCallback accept_callback;
50 engine_->Connect(accept_callback.callback()); 52 engine_->Connect(accept_callback.callback());
51 53
52 net::TestCompletionCallback connect_callback; 54 net::TestCompletionCallback connect_callback;
53 TCPClientTransport client(GetLocalEndpoint(), nullptr); 55 TCPClientTransport client(GetLocalEndpoint(), &statistics, nullptr);
54 client.Connect(connect_callback.callback()); 56 client.Connect(connect_callback.callback());
55 57
56 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); 58 EXPECT_EQ(net::OK, connect_callback.WaitForResult());
57 EXPECT_EQ(net::OK, accept_callback.WaitForResult()); 59 EXPECT_EQ(net::OK, accept_callback.WaitForResult());
58 EXPECT_TRUE(engine_->TakeConnection() != nullptr); 60 EXPECT_TRUE(engine_->TakeConnection() != nullptr);
59 } 61 }
60 62
61 TEST_F(TCPTransportTest, TwoClientConnections) { 63 TEST_F(TCPTransportTest, TwoClientConnections) {
64 BlimpConnectionStatistics statistics;
62 net::TestCompletionCallback accept_callback1; 65 net::TestCompletionCallback accept_callback1;
63 engine_->Connect(accept_callback1.callback()); 66 engine_->Connect(accept_callback1.callback());
64 67
65 net::TestCompletionCallback connect_callback1; 68 net::TestCompletionCallback connect_callback1;
66 TCPClientTransport client1(GetLocalEndpoint(), nullptr); 69 TCPClientTransport client1(GetLocalEndpoint(), &statistics, nullptr);
67 client1.Connect(connect_callback1.callback()); 70 client1.Connect(connect_callback1.callback());
68 71
69 net::TestCompletionCallback connect_callback2; 72 net::TestCompletionCallback connect_callback2;
70 TCPClientTransport client2(GetLocalEndpoint(), nullptr); 73 TCPClientTransport client2(GetLocalEndpoint(), &statistics, nullptr);
71 client2.Connect(connect_callback2.callback()); 74 client2.Connect(connect_callback2.callback());
72 75
73 EXPECT_EQ(net::OK, connect_callback1.WaitForResult()); 76 EXPECT_EQ(net::OK, connect_callback1.WaitForResult());
74 EXPECT_EQ(net::OK, accept_callback1.WaitForResult()); 77 EXPECT_EQ(net::OK, accept_callback1.WaitForResult());
75 EXPECT_TRUE(engine_->TakeConnection() != nullptr); 78 EXPECT_TRUE(engine_->TakeConnection() != nullptr);
76 79
77 net::TestCompletionCallback accept_callback2; 80 net::TestCompletionCallback accept_callback2;
78 engine_->Connect(accept_callback2.callback()); 81 engine_->Connect(accept_callback2.callback());
79 EXPECT_EQ(net::OK, connect_callback2.WaitForResult()); 82 EXPECT_EQ(net::OK, connect_callback2.WaitForResult());
80 EXPECT_EQ(net::OK, accept_callback2.WaitForResult()); 83 EXPECT_EQ(net::OK, accept_callback2.WaitForResult());
81 EXPECT_TRUE(engine_->TakeConnection() != nullptr); 84 EXPECT_TRUE(engine_->TakeConnection() != nullptr);
82 } 85 }
83 86
84 TEST_F(TCPTransportTest, ExchangeMessages) { 87 TEST_F(TCPTransportTest, ExchangeMessages) {
88 BlimpConnectionStatistics statistics;
89
85 // Start the Engine transport and connect a client to it. 90 // Start the Engine transport and connect a client to it.
86 net::TestCompletionCallback accept_callback; 91 net::TestCompletionCallback accept_callback;
87 engine_->Connect(accept_callback.callback()); 92 engine_->Connect(accept_callback.callback());
88 net::TestCompletionCallback client_connect_callback; 93 net::TestCompletionCallback client_connect_callback;
89 TCPClientTransport client(GetLocalEndpoint(), nullptr /* NetLog */); 94 TCPClientTransport client(GetLocalEndpoint(), &statistics,
95 nullptr /* NetLog */);
90 client.Connect(client_connect_callback.callback()); 96 client.Connect(client_connect_callback.callback());
91 EXPECT_EQ(net::OK, client_connect_callback.WaitForResult()); 97 EXPECT_EQ(net::OK, client_connect_callback.WaitForResult());
92 EXPECT_EQ(net::OK, accept_callback.WaitForResult()); 98 EXPECT_EQ(net::OK, accept_callback.WaitForResult());
93 99
94 // Expect the engine to get two messages from the client, and the client to 100 // Expect the engine to get two messages from the client, and the client to
95 // get one from the engine. 101 // get one from the engine.
96 MockBlimpMessageProcessor engine_incoming_processor; 102 MockBlimpMessageProcessor engine_incoming_processor;
97 MockBlimpMessageProcessor client_incoming_processor; 103 MockBlimpMessageProcessor client_incoming_processor;
98 net::CompletionCallback engine_process_message_cb; 104 net::CompletionCallback engine_process_message_cb;
99 std::unique_ptr<BlimpMessage> client_message1 = 105 std::unique_ptr<BlimpMessage> client_message1 =
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Client sends the second message. 143 // Client sends the second message.
138 net::TestCompletionCallback client_send_callback2; 144 net::TestCompletionCallback client_send_callback2;
139 client_connnection->GetOutgoingMessageProcessor()->ProcessMessage( 145 client_connnection->GetOutgoingMessageProcessor()->ProcessMessage(
140 std::move(client_message2), client_send_callback2.callback()); 146 std::move(client_message2), client_send_callback2.callback());
141 EXPECT_EQ(net::OK, client_send_callback2.WaitForResult()); 147 EXPECT_EQ(net::OK, client_send_callback2.WaitForResult());
142 } 148 }
143 149
144 } // namespace 150 } // namespace
145 151
146 } // namespace blimp 152 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698