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

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: Added empty implementation for linux client Created 4 years, 6 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
« no previous file with comments | « blimp/net/tcp_engine_transport.cc ('k') | cc/trees/remote_channel_impl.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 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
23 using testing::_; 24 using testing::_;
24 using testing::SaveArg; 25 using testing::SaveArg;
25 26
26 namespace blimp { 27 namespace blimp {
27 28
28 namespace { 29 namespace {
29 30
30 // Integration test for TCPEngineTransport and TCPClientTransport. 31 // Integration test for TCPEngineTransport and TCPClientTransport.
31 class TCPTransportTest : public testing::Test { 32 class TCPTransportTest : public testing::Test {
32 protected: 33 protected:
33 TCPTransportTest() { 34 TCPTransportTest() {
34 net::IPEndPoint local_address(net::IPAddress(127, 0, 0, 1), 0); 35 net::IPEndPoint local_address(net::IPAddress(127, 0, 0, 1), 0);
35 engine_.reset(new TCPEngineTransport(local_address, nullptr)); 36 engine_.reset(new TCPEngineTransport(local_address, &statistics_, nullptr));
36 } 37 }
37 38
38 net::IPEndPoint GetLocalEndpoint() const { 39 net::IPEndPoint GetLocalEndpoint() const {
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_;
46 BlimpConnectionStatistics statistics_;
45 std::unique_ptr<TCPEngineTransport> engine_; 47 std::unique_ptr<TCPEngineTransport> engine_;
46 }; 48 };
47 49
48 TEST_F(TCPTransportTest, Connect) { 50 TEST_F(TCPTransportTest, Connect) {
51 BlimpConnectionStatistics statistics;
49 net::TestCompletionCallback accept_callback; 52 net::TestCompletionCallback accept_callback;
50 engine_->Connect(accept_callback.callback()); 53 engine_->Connect(accept_callback.callback());
51 54
52 net::TestCompletionCallback connect_callback; 55 net::TestCompletionCallback connect_callback;
53 TCPClientTransport client(GetLocalEndpoint(), nullptr); 56 TCPClientTransport client(GetLocalEndpoint(), &statistics, nullptr);
54 client.Connect(connect_callback.callback()); 57 client.Connect(connect_callback.callback());
55 58
56 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); 59 EXPECT_EQ(net::OK, connect_callback.WaitForResult());
57 EXPECT_EQ(net::OK, accept_callback.WaitForResult()); 60 EXPECT_EQ(net::OK, accept_callback.WaitForResult());
58 EXPECT_TRUE(engine_->TakeConnection() != nullptr); 61 EXPECT_TRUE(engine_->TakeConnection() != nullptr);
59 } 62 }
60 63
61 TEST_F(TCPTransportTest, TwoClientConnections) { 64 TEST_F(TCPTransportTest, TwoClientConnections) {
65 BlimpConnectionStatistics statistics;
62 net::TestCompletionCallback accept_callback1; 66 net::TestCompletionCallback accept_callback1;
63 engine_->Connect(accept_callback1.callback()); 67 engine_->Connect(accept_callback1.callback());
64 68
65 net::TestCompletionCallback connect_callback1; 69 net::TestCompletionCallback connect_callback1;
66 TCPClientTransport client1(GetLocalEndpoint(), nullptr); 70 TCPClientTransport client1(GetLocalEndpoint(), &statistics, nullptr);
67 client1.Connect(connect_callback1.callback()); 71 client1.Connect(connect_callback1.callback());
68 72
69 net::TestCompletionCallback connect_callback2; 73 net::TestCompletionCallback connect_callback2;
70 TCPClientTransport client2(GetLocalEndpoint(), nullptr); 74 TCPClientTransport client2(GetLocalEndpoint(), &statistics, nullptr);
71 client2.Connect(connect_callback2.callback()); 75 client2.Connect(connect_callback2.callback());
72 76
73 EXPECT_EQ(net::OK, connect_callback1.WaitForResult()); 77 EXPECT_EQ(net::OK, connect_callback1.WaitForResult());
74 EXPECT_EQ(net::OK, accept_callback1.WaitForResult()); 78 EXPECT_EQ(net::OK, accept_callback1.WaitForResult());
75 EXPECT_TRUE(engine_->TakeConnection() != nullptr); 79 EXPECT_TRUE(engine_->TakeConnection() != nullptr);
76 80
77 net::TestCompletionCallback accept_callback2; 81 net::TestCompletionCallback accept_callback2;
78 engine_->Connect(accept_callback2.callback()); 82 engine_->Connect(accept_callback2.callback());
79 EXPECT_EQ(net::OK, connect_callback2.WaitForResult()); 83 EXPECT_EQ(net::OK, connect_callback2.WaitForResult());
80 EXPECT_EQ(net::OK, accept_callback2.WaitForResult()); 84 EXPECT_EQ(net::OK, accept_callback2.WaitForResult());
81 EXPECT_TRUE(engine_->TakeConnection() != nullptr); 85 EXPECT_TRUE(engine_->TakeConnection() != nullptr);
82 } 86 }
83 87
84 TEST_F(TCPTransportTest, ExchangeMessages) { 88 TEST_F(TCPTransportTest, ExchangeMessages) {
89 BlimpConnectionStatistics statistics;
90
85 // Start the Engine transport and connect a client to it. 91 // Start the Engine transport and connect a client to it.
86 net::TestCompletionCallback accept_callback; 92 net::TestCompletionCallback accept_callback;
87 engine_->Connect(accept_callback.callback()); 93 engine_->Connect(accept_callback.callback());
88 net::TestCompletionCallback client_connect_callback; 94 net::TestCompletionCallback client_connect_callback;
89 TCPClientTransport client(GetLocalEndpoint(), nullptr /* NetLog */); 95 TCPClientTransport client(GetLocalEndpoint(), &statistics,
96 nullptr /* NetLog */);
90 client.Connect(client_connect_callback.callback()); 97 client.Connect(client_connect_callback.callback());
91 EXPECT_EQ(net::OK, client_connect_callback.WaitForResult()); 98 EXPECT_EQ(net::OK, client_connect_callback.WaitForResult());
92 EXPECT_EQ(net::OK, accept_callback.WaitForResult()); 99 EXPECT_EQ(net::OK, accept_callback.WaitForResult());
93 100
94 // Expect the engine to get two messages from the client, and the client to 101 // Expect the engine to get two messages from the client, and the client to
95 // get one from the engine. 102 // get one from the engine.
96 MockBlimpMessageProcessor engine_incoming_processor; 103 MockBlimpMessageProcessor engine_incoming_processor;
97 MockBlimpMessageProcessor client_incoming_processor; 104 MockBlimpMessageProcessor client_incoming_processor;
98 net::CompletionCallback engine_process_message_cb; 105 net::CompletionCallback engine_process_message_cb;
99 std::unique_ptr<BlimpMessage> client_message1 = 106 std::unique_ptr<BlimpMessage> client_message1 =
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Client sends the second message. 144 // Client sends the second message.
138 net::TestCompletionCallback client_send_callback2; 145 net::TestCompletionCallback client_send_callback2;
139 client_connnection->GetOutgoingMessageProcessor()->ProcessMessage( 146 client_connnection->GetOutgoingMessageProcessor()->ProcessMessage(
140 std::move(client_message2), client_send_callback2.callback()); 147 std::move(client_message2), client_send_callback2.callback());
141 EXPECT_EQ(net::OK, client_send_callback2.WaitForResult()); 148 EXPECT_EQ(net::OK, client_send_callback2.WaitForResult());
142 } 149 }
143 150
144 } // namespace 151 } // namespace
145 152
146 } // namespace blimp 153 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/tcp_engine_transport.cc ('k') | cc/trees/remote_channel_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698