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 private: | |
| 127 base::MessageLoop message_loop_; | 128 base::MessageLoop message_loop_; |
|
gab
2016/07/04 14:47:06
ditto
fdoray
2016/07/04 16:33:59
Doesn't work because the constructor of FakeStream
gab
2016/07/04 17:24:14
Ok, thanks for adding justification comment.
| |
| 128 | 129 |
| 130 protected: | |
| 129 FakeStreamChannelFactory host_channel_factory_; | 131 FakeStreamChannelFactory host_channel_factory_; |
| 130 FakeStreamChannelFactory client_channel_factory_; | 132 FakeStreamChannelFactory client_channel_factory_; |
| 131 | 133 |
| 132 std::unique_ptr<ChannelMultiplexer> host_mux_; | 134 std::unique_ptr<ChannelMultiplexer> host_mux_; |
| 133 std::unique_ptr<ChannelMultiplexer> client_mux_; | 135 std::unique_ptr<ChannelMultiplexer> client_mux_; |
| 134 | 136 |
| 135 std::unique_ptr<P2PStreamSocket> host_socket1_; | 137 std::unique_ptr<P2PStreamSocket> host_socket1_; |
| 136 std::unique_ptr<P2PStreamSocket> client_socket1_; | 138 std::unique_ptr<P2PStreamSocket> client_socket1_; |
| 137 std::unique_ptr<P2PStreamSocket> host_socket2_; | 139 std::unique_ptr<P2PStreamSocket> host_socket2_; |
| 138 std::unique_ptr<P2PStreamSocket> client_socket2_; | 140 std::unique_ptr<P2PStreamSocket> client_socket2_; |
| 139 }; | 141 }; |
| 140 | 142 |
| 141 | 143 |
| 142 TEST_F(ChannelMultiplexerTest, OneChannel) { | 144 TEST_F(ChannelMultiplexerTest, OneChannel) { |
| 143 std::unique_ptr<P2PStreamSocket> host_socket; | 145 std::unique_ptr<P2PStreamSocket> host_socket; |
| 144 std::unique_ptr<P2PStreamSocket> client_socket; | 146 std::unique_ptr<P2PStreamSocket> client_socket; |
| 145 ASSERT_NO_FATAL_FAILURE( | 147 ASSERT_NO_FATAL_FAILURE( |
| 146 CreateChannel(kTestChannelName, &host_socket, &client_socket)); | 148 CreateChannel(kTestChannelName, &host_socket, &client_socket)); |
| 147 | 149 |
| 148 StreamConnectionTester tester(host_socket.get(), client_socket.get(), | 150 StreamConnectionTester tester(host_socket.get(), client_socket.get(), |
| 149 kMessageSize, kMessages); | 151 kMessageSize, kMessages); |
| 150 tester.Start(); | 152 tester.Start(); |
| 151 message_loop_.Run(); | 153 base::RunLoop().Run(); |
| 152 tester.CheckResults(); | 154 tester.CheckResults(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 TEST_F(ChannelMultiplexerTest, TwoChannels) { | 157 TEST_F(ChannelMultiplexerTest, TwoChannels) { |
| 156 std::unique_ptr<P2PStreamSocket> host_socket1_; | 158 std::unique_ptr<P2PStreamSocket> host_socket1_; |
| 157 std::unique_ptr<P2PStreamSocket> client_socket1_; | 159 std::unique_ptr<P2PStreamSocket> client_socket1_; |
| 158 ASSERT_NO_FATAL_FAILURE( | 160 ASSERT_NO_FATAL_FAILURE( |
| 159 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_)); | 161 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_)); |
| 160 | 162 |
| 161 std::unique_ptr<P2PStreamSocket> host_socket2_; | 163 std::unique_ptr<P2PStreamSocket> host_socket2_; |
| 162 std::unique_ptr<P2PStreamSocket> client_socket2_; | 164 std::unique_ptr<P2PStreamSocket> client_socket2_; |
| 163 ASSERT_NO_FATAL_FAILURE( | 165 ASSERT_NO_FATAL_FAILURE( |
| 164 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_)); | 166 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_)); |
| 165 | 167 |
| 166 StreamConnectionTester tester1(host_socket1_.get(), client_socket1_.get(), | 168 StreamConnectionTester tester1(host_socket1_.get(), client_socket1_.get(), |
| 167 kMessageSize, kMessages); | 169 kMessageSize, kMessages); |
| 168 StreamConnectionTester tester2(host_socket2_.get(), client_socket2_.get(), | 170 StreamConnectionTester tester2(host_socket2_.get(), client_socket2_.get(), |
| 169 kMessageSize, kMessages); | 171 kMessageSize, kMessages); |
| 170 tester1.Start(); | 172 tester1.Start(); |
| 171 tester2.Start(); | 173 tester2.Start(); |
| 172 while (!tester1.done() || !tester2.done()) { | 174 while (!tester1.done() || !tester2.done()) { |
| 173 message_loop_.Run(); | 175 base::RunLoop().Run(); |
| 174 } | 176 } |
| 175 tester1.CheckResults(); | 177 tester1.CheckResults(); |
| 176 tester2.CheckResults(); | 178 tester2.CheckResults(); |
| 177 } | 179 } |
| 178 | 180 |
| 179 // Four channels, two in each direction | 181 // Four channels, two in each direction |
| 180 TEST_F(ChannelMultiplexerTest, FourChannels) { | 182 TEST_F(ChannelMultiplexerTest, FourChannels) { |
| 181 std::unique_ptr<P2PStreamSocket> host_socket1_; | 183 std::unique_ptr<P2PStreamSocket> host_socket1_; |
| 182 std::unique_ptr<P2PStreamSocket> client_socket1_; | 184 std::unique_ptr<P2PStreamSocket> client_socket1_; |
| 183 ASSERT_NO_FATAL_FAILURE( | 185 ASSERT_NO_FATAL_FAILURE( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 205 StreamConnectionTester tester3(client_socket3.get(), host_socket3.get(), | 207 StreamConnectionTester tester3(client_socket3.get(), host_socket3.get(), |
| 206 kMessageSize, kMessages); | 208 kMessageSize, kMessages); |
| 207 StreamConnectionTester tester4(client_socket4.get(), host_socket4.get(), | 209 StreamConnectionTester tester4(client_socket4.get(), host_socket4.get(), |
| 208 kMessageSize, kMessages); | 210 kMessageSize, kMessages); |
| 209 tester1.Start(); | 211 tester1.Start(); |
| 210 tester2.Start(); | 212 tester2.Start(); |
| 211 tester3.Start(); | 213 tester3.Start(); |
| 212 tester4.Start(); | 214 tester4.Start(); |
| 213 while (!tester1.done() || !tester2.done() || | 215 while (!tester1.done() || !tester2.done() || |
| 214 !tester3.done() || !tester4.done()) { | 216 !tester3.done() || !tester4.done()) { |
| 215 message_loop_.Run(); | 217 base::RunLoop().Run(); |
| 216 } | 218 } |
| 217 tester1.CheckResults(); | 219 tester1.CheckResults(); |
| 218 tester2.CheckResults(); | 220 tester2.CheckResults(); |
| 219 tester3.CheckResults(); | 221 tester3.CheckResults(); |
| 220 tester4.CheckResults(); | 222 tester4.CheckResults(); |
| 221 } | 223 } |
| 222 | 224 |
| 223 TEST_F(ChannelMultiplexerTest, WriteFailSync) { | 225 TEST_F(ChannelMultiplexerTest, WriteFailSync) { |
| 224 std::unique_ptr<P2PStreamSocket> host_socket1_; | 226 std::unique_ptr<P2PStreamSocket> host_socket1_; |
| 225 std::unique_ptr<P2PStreamSocket> client_socket1_; | 227 std::unique_ptr<P2PStreamSocket> client_socket1_; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 .WillOnce(InvokeWithoutArgs( | 349 .WillOnce(InvokeWithoutArgs( |
| 348 this, &ChannelMultiplexerTest::DeleteAfterSessionFail)); | 350 this, &ChannelMultiplexerTest::DeleteAfterSessionFail)); |
| 349 EXPECT_CALL(cb2, OnConnectedPtr(_)) | 351 EXPECT_CALL(cb2, OnConnectedPtr(_)) |
| 350 .Times(0); | 352 .Times(0); |
| 351 | 353 |
| 352 base::RunLoop().RunUntilIdle(); | 354 base::RunLoop().RunUntilIdle(); |
| 353 } | 355 } |
| 354 | 356 |
| 355 } // namespace protocol | 357 } // namespace protocol |
| 356 } // namespace remoting | 358 } // namespace remoting |
| OLD | NEW |