OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "blimp/net/engine_connection_manager.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include <string> | |
10 #include <utility> | |
11 | |
12 #include "base/callback_helpers.h" | |
13 #include "base/memory/ptr_util.h" | |
14 #include "base/message_loop/message_loop.h" | |
15 #include "base/run_loop.h" | |
16 #include "blimp/net/blimp_transport.h" | |
17 #include "blimp/net/common.h" | |
18 #include "blimp/net/connection_error_observer.h" | |
19 #include "blimp/net/tcp_client_transport.h" | |
20 #include "blimp/net/tcp_connection.h" | |
21 #include "blimp/net/test_common.h" | |
22 #include "net/base/completion_callback.h" | |
23 #include "net/base/io_buffer.h" | |
24 #include "net/base/ip_address.h" | |
25 #include "net/base/net_errors.h" | |
26 #include "net/base/test_completion_callback.h" | |
27 #include "testing/gmock/include/gmock/gmock.h" | |
28 #include "testing/gtest/include/gtest/gtest.h" | |
29 | |
30 using testing::_; | |
31 using testing::Eq; | |
32 using testing::Return; | |
33 using testing::SaveArg; | |
34 | |
35 namespace blimp { | |
36 | |
37 class EngineConnectionManagerTest : public testing::Test { | |
38 public: | |
39 EngineConnectionManagerTest() | |
40 : manager_(new EngineConnectionManager(&connection_handler_, nullptr)) {} | |
41 | |
42 ~EngineConnectionManagerTest() override {} | |
43 | |
44 protected: | |
45 testing::StrictMock<MockConnectionHandler> connection_handler_; | |
46 std::unique_ptr<EngineConnectionManager> manager_; | |
47 base::MessageLoopForIO message_loop_; | |
48 }; | |
49 | |
50 TEST_F(EngineConnectionManagerTest, ConnectionSucceeds) { | |
51 EXPECT_CALL(connection_handler_, HandleConnectionPtr(_)).Times(1); | |
52 | |
53 net::IPAddress ip_addr(net::IPAddress::IPv4Localhost()); | |
54 net::IPEndPoint engine_endpoint(ip_addr, 0); | |
55 | |
56 manager_->ConnectTransport(&engine_endpoint, | |
57 EngineConnectionManager::EngineTransportType::TCP); | |
58 | |
59 net::TestCompletionCallback connect_callback; | |
60 TCPClientTransport client(engine_endpoint, nullptr); | |
61 client.Connect(connect_callback.callback()); | |
62 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); | |
63 } | |
64 | |
65 TEST_F(EngineConnectionManagerTest, TwoConnectionsSucceed) { | |
66 EXPECT_CALL(connection_handler_, HandleConnectionPtr(_)).Times(2); | |
67 | |
68 net::IPAddress ip_addr(net::IPAddress::IPv4Localhost()); | |
69 net::IPEndPoint engine_endpoint(ip_addr, 0); | |
70 | |
71 manager_->ConnectTransport(&engine_endpoint, | |
72 EngineConnectionManager::EngineTransportType::TCP); | |
73 | |
74 net::TestCompletionCallback connect_callback; | |
75 TCPClientTransport client(engine_endpoint, nullptr); | |
76 | |
77 client.Connect(connect_callback.callback()); | |
78 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); | |
79 std::unique_ptr<BlimpConnection> connection = client.MakeConnection(); | |
80 | |
81 client.Connect(connect_callback.callback()); | |
82 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); | |
83 } | |
84 | |
85 } // namespace blimp | |
OLD | NEW |