Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "remoting/protocol/channel_multiplexer.h" | 5 #include "remoting/protocol/channel_multiplexer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 std::unique_ptr<P2PStreamSocket>* host_socket, | 92 std::unique_ptr<P2PStreamSocket>* host_socket, |
| 93 std::unique_ptr<P2PStreamSocket>* client_socket) { | 93 std::unique_ptr<P2PStreamSocket>* client_socket) { |
| 94 int counter = 2; | 94 int counter = 2; |
| 95 host_mux_->CreateChannel(name, base::Bind( | 95 host_mux_->CreateChannel(name, base::Bind( |
| 96 &ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this), | 96 &ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this), |
| 97 host_socket, &counter)); | 97 host_socket, &counter)); |
| 98 client_mux_->CreateChannel(name, base::Bind( | 98 client_mux_->CreateChannel(name, base::Bind( |
| 99 &ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this), | 99 &ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this), |
| 100 client_socket, &counter)); | 100 client_socket, &counter)); |
| 101 | 101 |
| 102 message_loop_.Run(); | 102 base::RunLoop().Run(); |
| 103 | 103 |
| 104 EXPECT_TRUE(host_socket->get()); | 104 EXPECT_TRUE(host_socket->get()); |
| 105 EXPECT_TRUE(client_socket->get()); | 105 EXPECT_TRUE(client_socket->get()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void OnChannelConnected(std::unique_ptr<P2PStreamSocket>* storage, | 108 void OnChannelConnected(std::unique_ptr<P2PStreamSocket>* storage, |
| 109 int* counter, | 109 int* counter, |
| 110 std::unique_ptr<P2PStreamSocket> socket) { | 110 std::unique_ptr<P2PStreamSocket> socket) { |
| 111 *storage = std::move(socket); | 111 *storage = std::move(socket); |
| 112 --(*counter); | 112 --(*counter); |
| 113 EXPECT_GE(*counter, 0); | 113 EXPECT_GE(*counter, 0); |
| 114 if (*counter == 0) | 114 if (*counter == 0) |
| 115 QuitCurrentThread(); | 115 QuitCurrentThread(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 scoped_refptr<net::IOBufferWithSize> CreateTestBuffer(int size) { | 118 scoped_refptr<net::IOBufferWithSize> CreateTestBuffer(int size) { |
| 119 scoped_refptr<net::IOBufferWithSize> result = | 119 scoped_refptr<net::IOBufferWithSize> result = |
| 120 new net::IOBufferWithSize(size); | 120 new net::IOBufferWithSize(size); |
| 121 for (int i = 0; i< size; ++i) { | 121 for (int i = 0; i< size; ++i) { |
| 122 result->data()[i] = rand() % 256; | 122 result->data()[i] = rand() % 256; |
| 123 } | 123 } |
| 124 return result; | 124 return result; |
| 125 } | 125 } |
| 126 | 126 |
| 127 base::MessageLoop message_loop_; | 127 base::MessageLoop message_loop_; |
|
gab
2016/06/30 20:28:18
Can be made private now
fdoray
2016/07/04 13:59:46
Done.
| |
| 128 | 128 |
| 129 FakeStreamChannelFactory host_channel_factory_; | 129 FakeStreamChannelFactory host_channel_factory_; |
| 130 FakeStreamChannelFactory client_channel_factory_; | 130 FakeStreamChannelFactory client_channel_factory_; |
| 131 | 131 |
| 132 std::unique_ptr<ChannelMultiplexer> host_mux_; | 132 std::unique_ptr<ChannelMultiplexer> host_mux_; |
| 133 std::unique_ptr<ChannelMultiplexer> client_mux_; | 133 std::unique_ptr<ChannelMultiplexer> client_mux_; |
| 134 | 134 |
| 135 std::unique_ptr<P2PStreamSocket> host_socket1_; | 135 std::unique_ptr<P2PStreamSocket> host_socket1_; |
| 136 std::unique_ptr<P2PStreamSocket> client_socket1_; | 136 std::unique_ptr<P2PStreamSocket> client_socket1_; |
| 137 std::unique_ptr<P2PStreamSocket> host_socket2_; | 137 std::unique_ptr<P2PStreamSocket> host_socket2_; |
| 138 std::unique_ptr<P2PStreamSocket> client_socket2_; | 138 std::unique_ptr<P2PStreamSocket> client_socket2_; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 | 141 |
| 142 TEST_F(ChannelMultiplexerTest, OneChannel) { | 142 TEST_F(ChannelMultiplexerTest, OneChannel) { |
| 143 std::unique_ptr<P2PStreamSocket> host_socket; | 143 std::unique_ptr<P2PStreamSocket> host_socket; |
| 144 std::unique_ptr<P2PStreamSocket> client_socket; | 144 std::unique_ptr<P2PStreamSocket> client_socket; |
| 145 ASSERT_NO_FATAL_FAILURE( | 145 ASSERT_NO_FATAL_FAILURE( |
| 146 CreateChannel(kTestChannelName, &host_socket, &client_socket)); | 146 CreateChannel(kTestChannelName, &host_socket, &client_socket)); |
| 147 | 147 |
| 148 StreamConnectionTester tester(host_socket.get(), client_socket.get(), | 148 StreamConnectionTester tester(host_socket.get(), client_socket.get(), |
| 149 kMessageSize, kMessages); | 149 kMessageSize, kMessages); |
| 150 tester.Start(); | 150 tester.Start(); |
| 151 message_loop_.Run(); | 151 base::RunLoop().Run(); |
| 152 tester.CheckResults(); | 152 tester.CheckResults(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST_F(ChannelMultiplexerTest, TwoChannels) { | 155 TEST_F(ChannelMultiplexerTest, TwoChannels) { |
| 156 std::unique_ptr<P2PStreamSocket> host_socket1_; | 156 std::unique_ptr<P2PStreamSocket> host_socket1_; |
| 157 std::unique_ptr<P2PStreamSocket> client_socket1_; | 157 std::unique_ptr<P2PStreamSocket> client_socket1_; |
| 158 ASSERT_NO_FATAL_FAILURE( | 158 ASSERT_NO_FATAL_FAILURE( |
| 159 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_)); | 159 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_)); |
| 160 | 160 |
| 161 std::unique_ptr<P2PStreamSocket> host_socket2_; | 161 std::unique_ptr<P2PStreamSocket> host_socket2_; |
| 162 std::unique_ptr<P2PStreamSocket> client_socket2_; | 162 std::unique_ptr<P2PStreamSocket> client_socket2_; |
| 163 ASSERT_NO_FATAL_FAILURE( | 163 ASSERT_NO_FATAL_FAILURE( |
| 164 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_)); | 164 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_)); |
| 165 | 165 |
| 166 StreamConnectionTester tester1(host_socket1_.get(), client_socket1_.get(), | 166 StreamConnectionTester tester1(host_socket1_.get(), client_socket1_.get(), |
| 167 kMessageSize, kMessages); | 167 kMessageSize, kMessages); |
| 168 StreamConnectionTester tester2(host_socket2_.get(), client_socket2_.get(), | 168 StreamConnectionTester tester2(host_socket2_.get(), client_socket2_.get(), |
| 169 kMessageSize, kMessages); | 169 kMessageSize, kMessages); |
| 170 tester1.Start(); | 170 tester1.Start(); |
| 171 tester2.Start(); | 171 tester2.Start(); |
| 172 while (!tester1.done() || !tester2.done()) { | 172 while (!tester1.done() || !tester2.done()) { |
| 173 message_loop_.Run(); | 173 base::RunLoop().Run(); |
| 174 } | 174 } |
| 175 tester1.CheckResults(); | 175 tester1.CheckResults(); |
| 176 tester2.CheckResults(); | 176 tester2.CheckResults(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Four channels, two in each direction | 179 // Four channels, two in each direction |
| 180 TEST_F(ChannelMultiplexerTest, FourChannels) { | 180 TEST_F(ChannelMultiplexerTest, FourChannels) { |
| 181 std::unique_ptr<P2PStreamSocket> host_socket1_; | 181 std::unique_ptr<P2PStreamSocket> host_socket1_; |
| 182 std::unique_ptr<P2PStreamSocket> client_socket1_; | 182 std::unique_ptr<P2PStreamSocket> client_socket1_; |
| 183 ASSERT_NO_FATAL_FAILURE( | 183 ASSERT_NO_FATAL_FAILURE( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 205 StreamConnectionTester tester3(client_socket3.get(), host_socket3.get(), | 205 StreamConnectionTester tester3(client_socket3.get(), host_socket3.get(), |
| 206 kMessageSize, kMessages); | 206 kMessageSize, kMessages); |
| 207 StreamConnectionTester tester4(client_socket4.get(), host_socket4.get(), | 207 StreamConnectionTester tester4(client_socket4.get(), host_socket4.get(), |
| 208 kMessageSize, kMessages); | 208 kMessageSize, kMessages); |
| 209 tester1.Start(); | 209 tester1.Start(); |
| 210 tester2.Start(); | 210 tester2.Start(); |
| 211 tester3.Start(); | 211 tester3.Start(); |
| 212 tester4.Start(); | 212 tester4.Start(); |
| 213 while (!tester1.done() || !tester2.done() || | 213 while (!tester1.done() || !tester2.done() || |
| 214 !tester3.done() || !tester4.done()) { | 214 !tester3.done() || !tester4.done()) { |
| 215 message_loop_.Run(); | 215 base::RunLoop().Run(); |
| 216 } | 216 } |
| 217 tester1.CheckResults(); | 217 tester1.CheckResults(); |
| 218 tester2.CheckResults(); | 218 tester2.CheckResults(); |
| 219 tester3.CheckResults(); | 219 tester3.CheckResults(); |
| 220 tester4.CheckResults(); | 220 tester4.CheckResults(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(ChannelMultiplexerTest, WriteFailSync) { | 223 TEST_F(ChannelMultiplexerTest, WriteFailSync) { |
| 224 std::unique_ptr<P2PStreamSocket> host_socket1_; | 224 std::unique_ptr<P2PStreamSocket> host_socket1_; |
| 225 std::unique_ptr<P2PStreamSocket> client_socket1_; | 225 std::unique_ptr<P2PStreamSocket> client_socket1_; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 .WillOnce(InvokeWithoutArgs( | 347 .WillOnce(InvokeWithoutArgs( |
| 348 this, &ChannelMultiplexerTest::DeleteAfterSessionFail)); | 348 this, &ChannelMultiplexerTest::DeleteAfterSessionFail)); |
| 349 EXPECT_CALL(cb2, OnConnectedPtr(_)) | 349 EXPECT_CALL(cb2, OnConnectedPtr(_)) |
| 350 .Times(0); | 350 .Times(0); |
| 351 | 351 |
| 352 base::RunLoop().RunUntilIdle(); | 352 base::RunLoop().RunUntilIdle(); |
| 353 } | 353 } |
| 354 | 354 |
| 355 } // namespace protocol | 355 } // namespace protocol |
| 356 } // namespace remoting | 356 } // namespace remoting |
| OLD | NEW |