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 "remoting/protocol/webrtc_transport.h" | 5 #include "remoting/protocol/webrtc_transport.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "jingle/glue/thread_wrapper.h" | 12 #include "jingle/glue/thread_wrapper.h" |
13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
14 #include "net/url_request/url_request_context_getter.h" | 14 #include "net/url_request/url_request_context_getter.h" |
15 #include "remoting/protocol/chromium_port_allocator.h" | |
16 #include "remoting/protocol/connection_tester.h" | 15 #include "remoting/protocol/connection_tester.h" |
17 #include "remoting/protocol/fake_authenticator.h" | 16 #include "remoting/protocol/fake_authenticator.h" |
| 17 #include "remoting/protocol/message_channel_factory.h" |
| 18 #include "remoting/protocol/message_pipe.h" |
18 #include "remoting/protocol/network_settings.h" | 19 #include "remoting/protocol/network_settings.h" |
19 #include "remoting/protocol/p2p_stream_socket.h" | |
20 #include "remoting/protocol/transport_context.h" | 20 #include "remoting/protocol/transport_context.h" |
21 #include "remoting/signaling/fake_signal_strategy.h" | 21 #include "remoting/signaling/fake_signal_strategy.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 23 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
24 | 24 |
25 namespace remoting { | 25 namespace remoting { |
26 namespace protocol { | 26 namespace protocol { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 class WebrtcTransportTest : public testing::Test { | 78 class WebrtcTransportTest : public testing::Test { |
79 public: | 79 public: |
80 WebrtcTransportTest() { | 80 WebrtcTransportTest() { |
81 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 81 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
82 network_settings_ = | 82 network_settings_ = |
83 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); | 83 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_OUTGOING); |
84 } | 84 } |
85 | 85 |
86 void TearDown() override { | 86 void TearDown() override { |
87 run_loop_.reset(); | 87 run_loop_.reset(); |
88 client_socket_.reset(); | 88 client_message_pipe_.reset(); |
89 client_transport_.reset(); | 89 client_transport_.reset(); |
90 host_socket_.reset(); | 90 host_message_pipe_.reset(); |
91 host_transport_.reset(); | 91 host_transport_.reset(); |
92 base::RunLoop().RunUntilIdle(); | 92 base::RunLoop().RunUntilIdle(); |
93 } | 93 } |
94 | 94 |
95 void ProcessTransportInfo(scoped_ptr<WebrtcTransport>* target_transport, | 95 void ProcessTransportInfo(scoped_ptr<WebrtcTransport>* target_transport, |
96 scoped_ptr<buzz::XmlElement> transport_info) { | 96 scoped_ptr<buzz::XmlElement> transport_info) { |
97 ASSERT_TRUE(target_transport); | 97 ASSERT_TRUE(target_transport); |
98 EXPECT_TRUE((*target_transport) | 98 EXPECT_TRUE((*target_transport) |
99 ->ProcessTransportInfo(transport_info.get())); | 99 ->ProcessTransportInfo(transport_info.get())); |
100 } | 100 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 kChannelName, base::Bind(&WebrtcTransportTest::OnClientChannelCreated, | 158 kChannelName, base::Bind(&WebrtcTransportTest::OnClientChannelCreated, |
159 base::Unretained(this))); | 159 base::Unretained(this))); |
160 } | 160 } |
161 | 161 |
162 void CreateHostDataStream() { | 162 void CreateHostDataStream() { |
163 host_transport_->outgoing_channel_factory()->CreateChannel( | 163 host_transport_->outgoing_channel_factory()->CreateChannel( |
164 kChannelName, base::Bind(&WebrtcTransportTest::OnHostChannelCreated, | 164 kChannelName, base::Bind(&WebrtcTransportTest::OnHostChannelCreated, |
165 base::Unretained(this))); | 165 base::Unretained(this))); |
166 } | 166 } |
167 | 167 |
168 void OnClientChannelCreated(scoped_ptr<P2PStreamSocket> socket) { | 168 void OnClientChannelCreated(scoped_ptr<MessagePipe> pipe) { |
169 client_socket_ = std::move(socket); | 169 client_message_pipe_ = std::move(pipe); |
170 if (run_loop_ && host_socket_) | 170 if (run_loop_ && host_message_pipe_) |
171 run_loop_->Quit(); | 171 run_loop_->Quit(); |
172 } | 172 } |
173 | 173 |
174 void OnHostChannelCreated(scoped_ptr<P2PStreamSocket> socket) { | 174 void OnHostChannelCreated(scoped_ptr<MessagePipe> pipe) { |
175 host_socket_ = std::move(socket); | 175 host_message_pipe_ = std::move(pipe); |
176 if (run_loop_ && client_socket_) | 176 if (run_loop_ && client_message_pipe_) |
177 run_loop_->Quit(); | 177 run_loop_->Quit(); |
178 } | 178 } |
179 | 179 |
180 void OnSessionError(ErrorCode error) { | 180 void OnSessionError(ErrorCode error) { |
181 error_ = error; | 181 error_ = error; |
182 run_loop_->Quit(); | 182 run_loop_->Quit(); |
183 } | 183 } |
184 | 184 |
185 void QuitRunLoopOnCounter(int* counter) { | 185 void QuitRunLoopOnCounter(int* counter) { |
186 --(*counter); | 186 --(*counter); |
187 if (*counter == 0) | 187 if (*counter == 0) |
188 run_loop_->Quit(); | 188 run_loop_->Quit(); |
189 } | 189 } |
190 | 190 |
191 protected: | 191 protected: |
192 base::MessageLoopForIO message_loop_; | 192 base::MessageLoopForIO message_loop_; |
193 scoped_ptr<base::RunLoop> run_loop_; | 193 scoped_ptr<base::RunLoop> run_loop_; |
194 | 194 |
195 NetworkSettings network_settings_; | 195 NetworkSettings network_settings_; |
196 | 196 |
197 scoped_ptr<WebrtcTransport> host_transport_; | 197 scoped_ptr<WebrtcTransport> host_transport_; |
198 TestTransportEventHandler host_event_handler_; | 198 TestTransportEventHandler host_event_handler_; |
199 scoped_ptr<FakeAuthenticator> host_authenticator_; | 199 scoped_ptr<FakeAuthenticator> host_authenticator_; |
200 | 200 |
201 scoped_ptr<WebrtcTransport> client_transport_; | 201 scoped_ptr<WebrtcTransport> client_transport_; |
202 TestTransportEventHandler client_event_handler_; | 202 TestTransportEventHandler client_event_handler_; |
203 scoped_ptr<FakeAuthenticator> client_authenticator_; | 203 scoped_ptr<FakeAuthenticator> client_authenticator_; |
204 | 204 |
205 scoped_ptr<P2PStreamSocket> client_socket_; | 205 scoped_ptr<MessagePipe> client_message_pipe_; |
206 scoped_ptr<P2PStreamSocket> host_socket_; | 206 scoped_ptr<MessagePipe> host_message_pipe_; |
207 | 207 |
208 ErrorCode error_ = OK; | 208 ErrorCode error_ = OK; |
209 }; | 209 }; |
210 | 210 |
211 TEST_F(WebrtcTransportTest, Connects) { | 211 TEST_F(WebrtcTransportTest, Connects) { |
212 InitializeConnection(); | 212 InitializeConnection(); |
213 StartConnection(); | 213 StartConnection(); |
214 WaitUntilConnected(); | 214 WaitUntilConnected(); |
215 } | 215 } |
216 | 216 |
217 TEST_F(WebrtcTransportTest, DataStream) { | 217 TEST_F(WebrtcTransportTest, DataStream) { |
218 client_event_handler_.set_connecting_callback(base::Bind( | 218 client_event_handler_.set_connecting_callback(base::Bind( |
219 &WebrtcTransportTest::CreateClientDataStream, base::Unretained(this))); | 219 &WebrtcTransportTest::CreateClientDataStream, base::Unretained(this))); |
220 host_event_handler_.set_connecting_callback(base::Bind( | 220 host_event_handler_.set_connecting_callback(base::Bind( |
221 &WebrtcTransportTest::CreateHostDataStream, base::Unretained(this))); | 221 &WebrtcTransportTest::CreateHostDataStream, base::Unretained(this))); |
222 | 222 |
223 InitializeConnection(); | 223 InitializeConnection(); |
224 StartConnection(); | 224 StartConnection(); |
225 | 225 |
226 run_loop_.reset(new base::RunLoop()); | 226 run_loop_.reset(new base::RunLoop()); |
227 run_loop_->Run(); | 227 run_loop_->Run(); |
228 | 228 |
229 EXPECT_TRUE(client_socket_); | 229 EXPECT_TRUE(client_message_pipe_); |
230 EXPECT_TRUE(host_socket_); | 230 EXPECT_TRUE(host_message_pipe_); |
231 | 231 |
232 const int kMessageSize = 1024; | 232 const int kMessageSize = 1024; |
233 const int kMessages = 100; | 233 const int kMessages = 100; |
234 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 234 MessagePipeConnectionTester tester(host_message_pipe_.get(), |
235 kMessageSize, kMessages); | 235 client_message_pipe_.get(), kMessageSize, |
236 tester.Start(); | 236 kMessages); |
237 message_loop_.Run(); | 237 tester.RunAndCheckResults(); |
238 tester.CheckResults(); | |
239 } | 238 } |
240 | 239 |
241 // Verify that data streams can be created after connection has been initiated. | 240 // Verify that data streams can be created after connection has been initiated. |
242 TEST_F(WebrtcTransportTest, DataStreamLate) { | 241 TEST_F(WebrtcTransportTest, DataStreamLate) { |
243 InitializeConnection(); | 242 InitializeConnection(); |
244 StartConnection(); | 243 StartConnection(); |
245 WaitUntilConnected(); | 244 WaitUntilConnected(); |
246 | 245 |
247 CreateClientDataStream(); | 246 CreateClientDataStream(); |
248 CreateHostDataStream(); | 247 CreateHostDataStream(); |
249 | 248 |
250 run_loop_.reset(new base::RunLoop()); | 249 run_loop_.reset(new base::RunLoop()); |
251 run_loop_->Run(); | 250 run_loop_->Run(); |
252 | 251 |
253 EXPECT_TRUE(client_socket_); | 252 EXPECT_TRUE(client_message_pipe_); |
254 EXPECT_TRUE(host_socket_); | 253 EXPECT_TRUE(host_message_pipe_); |
255 } | 254 } |
256 | 255 |
257 } // namespace protocol | 256 } // namespace protocol |
258 } // namespace remoting | 257 } // namespace remoting |
OLD | NEW |