OLD | NEW |
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 "blimp/net/engine_connection_manager.h" | 5 #include "blimp/net/engine_connection_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
| 10 #include <utility> |
10 | 11 |
11 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
15 #include "blimp/net/blimp_connection.h" | 16 #include "blimp/net/blimp_connection.h" |
16 #include "blimp/net/blimp_transport.h" | 17 #include "blimp/net/blimp_transport.h" |
17 #include "blimp/net/common.h" | 18 #include "blimp/net/common.h" |
18 #include "blimp/net/connection_error_observer.h" | 19 #include "blimp/net/connection_error_observer.h" |
19 #include "blimp/net/test_common.h" | 20 #include "blimp/net/test_common.h" |
(...skipping 12 matching lines...) Expand all Loading... |
32 namespace blimp { | 33 namespace blimp { |
33 | 34 |
34 class EngineConnectionManagerTest : public testing::Test { | 35 class EngineConnectionManagerTest : public testing::Test { |
35 public: | 36 public: |
36 EngineConnectionManagerTest() | 37 EngineConnectionManagerTest() |
37 : manager_(new EngineConnectionManager(&connection_handler_)) {} | 38 : manager_(new EngineConnectionManager(&connection_handler_)) {} |
38 | 39 |
39 ~EngineConnectionManagerTest() override {} | 40 ~EngineConnectionManagerTest() override {} |
40 | 41 |
41 std::unique_ptr<BlimpConnection> CreateConnection() { | 42 std::unique_ptr<BlimpConnection> CreateConnection() { |
42 return base::WrapUnique( | 43 return base::MakeUnique<BlimpConnection>( |
43 new BlimpConnection(base::WrapUnique(new MockPacketReader), | 44 base::MakeUnique<MessagePort>(base::MakeUnique<MockPacketReader>(), |
44 base::WrapUnique(new MockPacketWriter))); | 45 base::MakeUnique<MockPacketWriter>())); |
45 } | 46 } |
46 | 47 |
47 protected: | 48 protected: |
48 base::MessageLoopForIO message_loop_; | |
49 testing::StrictMock<MockConnectionHandler> connection_handler_; | 49 testing::StrictMock<MockConnectionHandler> connection_handler_; |
50 std::unique_ptr<EngineConnectionManager> manager_; | 50 std::unique_ptr<EngineConnectionManager> manager_; |
51 }; | 51 }; |
52 | 52 |
53 TEST_F(EngineConnectionManagerTest, ConnectionSucceeds) { | 53 TEST_F(EngineConnectionManagerTest, ConnectionSucceeds) { |
54 std::unique_ptr<testing::StrictMock<MockTransport>> transport1( | 54 std::unique_ptr<testing::StrictMock<MockTransport>> transport1( |
55 new testing::StrictMock<MockTransport>); | 55 new testing::StrictMock<MockTransport>()); |
56 std::unique_ptr<testing::StrictMock<MockTransport>> transport2( | 56 std::unique_ptr<testing::StrictMock<MockTransport>> transport2( |
57 new testing::StrictMock<MockTransport>); | 57 new testing::StrictMock<MockTransport>()); |
58 | 58 |
59 std::unique_ptr<BlimpConnection> connection1 = CreateConnection(); | |
60 net::CompletionCallback connect_cb_1; | 59 net::CompletionCallback connect_cb_1; |
| 60 net::CompletionCallback connect_cb_2; |
61 EXPECT_CALL(*transport1, Connect(_)) | 61 EXPECT_CALL(*transport1, Connect(_)) |
62 .Times(2) | 62 .Times(2) |
63 .WillRepeatedly(SaveArg<0>(&connect_cb_1)); | 63 .WillRepeatedly(SaveArg<0>(&connect_cb_1)); |
64 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection1.get()))); | |
65 EXPECT_CALL(*transport1, TakeConnectionPtr()) | |
66 .WillOnce(Return(connection1.release())); | |
67 | |
68 std::unique_ptr<BlimpConnection> connection2 = CreateConnection(); | |
69 net::CompletionCallback connect_cb_2; | |
70 EXPECT_CALL(*transport2, Connect(_)) | 64 EXPECT_CALL(*transport2, Connect(_)) |
71 .Times(2) | 65 .Times(2) |
72 .WillRepeatedly(SaveArg<0>(&connect_cb_2)); | 66 .WillRepeatedly(SaveArg<0>(&connect_cb_2)); |
73 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection2.get()))); | 67 |
74 EXPECT_CALL(*transport2, TakeConnectionPtr()) | 68 std::unique_ptr<MessagePort> port1 = |
75 .WillOnce(Return(connection2.release())); | 69 base::MakeUnique<MessagePort>(base::MakeUnique<MockPacketReader>(), |
| 70 base::MakeUnique<MockPacketWriter>()); |
| 71 std::unique_ptr<MessagePort> port2 = |
| 72 base::MakeUnique<MessagePort>(base::MakeUnique<MockPacketReader>(), |
| 73 base::MakeUnique<MockPacketWriter>()); |
| 74 EXPECT_CALL(connection_handler_, HandleConnectionPtr(_)).Times(2); |
| 75 |
| 76 EXPECT_CALL(*transport1, TakeMessagePortPtr()) |
| 77 .WillOnce(Return(port1.release())); |
| 78 EXPECT_CALL(*transport2, TakeMessagePortPtr()) |
| 79 .WillOnce(Return(port2.release())); |
76 | 80 |
77 ASSERT_TRUE(connect_cb_1.is_null()); | 81 ASSERT_TRUE(connect_cb_1.is_null()); |
78 manager_->AddTransport(std::move(transport1)); | 82 manager_->AddTransport(std::move(transport1)); |
79 ASSERT_FALSE(connect_cb_1.is_null()); | 83 ASSERT_FALSE(connect_cb_1.is_null()); |
80 | 84 |
81 ASSERT_TRUE(connect_cb_2.is_null()); | 85 ASSERT_TRUE(connect_cb_2.is_null()); |
82 manager_->AddTransport(std::move(transport2)); | 86 manager_->AddTransport(std::move(transport2)); |
83 ASSERT_FALSE(connect_cb_2.is_null()); | 87 ASSERT_FALSE(connect_cb_2.is_null()); |
84 | 88 |
85 base::ResetAndReturn(&connect_cb_1).Run(net::OK); | 89 base::ResetAndReturn(&connect_cb_1).Run(net::OK); |
86 base::ResetAndReturn(&connect_cb_2).Run(net::OK); | 90 base::ResetAndReturn(&connect_cb_2).Run(net::OK); |
87 ASSERT_FALSE(connect_cb_1.is_null()); | 91 ASSERT_FALSE(connect_cb_1.is_null()); |
88 ASSERT_FALSE(connect_cb_2.is_null()); | 92 ASSERT_FALSE(connect_cb_2.is_null()); |
89 } | 93 } |
90 | 94 |
91 } // namespace blimp | 95 } // namespace blimp |
OLD | NEW |