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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
12 #include "remoting/protocol/fake_session.h" | 13 #include "remoting/protocol/fake_session.h" |
13 #include "remoting/protocol/fake_video_renderer.h" | 14 #include "remoting/protocol/fake_video_renderer.h" |
14 #include "remoting/protocol/ice_connection_to_client.h" | 15 #include "remoting/protocol/ice_connection_to_client.h" |
15 #include "remoting/protocol/ice_connection_to_host.h" | 16 #include "remoting/protocol/ice_connection_to_host.h" |
16 #include "remoting/protocol/protocol_mock_objects.h" | 17 #include "remoting/protocol/protocol_mock_objects.h" |
17 #include "remoting/protocol/transport_context.h" | 18 #include "remoting/protocol/transport_context.h" |
18 #include "remoting/protocol/video_stream.h" | 19 #include "remoting/protocol/video_stream.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 public: | 65 public: |
65 TestScreenCapturer() {} | 66 TestScreenCapturer() {} |
66 ~TestScreenCapturer() override {} | 67 ~TestScreenCapturer() override {} |
67 | 68 |
68 // webrtc::DesktopCapturer interface. | 69 // webrtc::DesktopCapturer interface. |
69 void Start(Callback* callback) override { | 70 void Start(Callback* callback) override { |
70 callback_ = callback; | 71 callback_ = callback; |
71 } | 72 } |
72 void Capture(const webrtc::DesktopRegion& region) override { | 73 void Capture(const webrtc::DesktopRegion& region) override { |
73 // Return black 10x10 frame. | 74 // Return black 10x10 frame. |
74 scoped_ptr<webrtc::DesktopFrame> frame( | 75 std::unique_ptr<webrtc::DesktopFrame> frame( |
75 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(100, 100))); | 76 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(100, 100))); |
76 memset(frame->data(), 0, frame->stride() * frame->size().height()); | 77 memset(frame->data(), 0, frame->stride() * frame->size().height()); |
77 frame->mutable_updated_region()->SetRect( | 78 frame->mutable_updated_region()->SetRect( |
78 webrtc::DesktopRect::MakeSize(frame->size())); | 79 webrtc::DesktopRect::MakeSize(frame->size())); |
79 callback_->OnCaptureCompleted(frame.release()); | 80 callback_->OnCaptureCompleted(frame.release()); |
80 } | 81 } |
81 | 82 |
82 private: | 83 private: |
83 Callback* callback_ = nullptr; | 84 Callback* callback_ = nullptr; |
84 }; | 85 }; |
(...skipping 10 matching lines...) Expand all Loading... |
95 | 96 |
96 void SetUp() override { | 97 void SetUp() override { |
97 // Create fake sessions. | 98 // Create fake sessions. |
98 host_session_ = new FakeSession(); | 99 host_session_ = new FakeSession(); |
99 owned_client_session_.reset(new FakeSession()); | 100 owned_client_session_.reset(new FakeSession()); |
100 client_session_ = owned_client_session_.get(); | 101 client_session_ = owned_client_session_.get(); |
101 | 102 |
102 // Create Connection objects. | 103 // Create Connection objects. |
103 if (is_using_webrtc()) { | 104 if (is_using_webrtc()) { |
104 host_connection_.reset(new WebrtcConnectionToClient( | 105 host_connection_.reset(new WebrtcConnectionToClient( |
105 make_scoped_ptr(host_session_), | 106 base::WrapUnique(host_session_), |
106 TransportContext::ForTests(protocol::TransportRole::SERVER))); | 107 TransportContext::ForTests(protocol::TransportRole::SERVER))); |
107 client_connection_.reset(new WebrtcConnectionToHost()); | 108 client_connection_.reset(new WebrtcConnectionToHost()); |
108 | 109 |
109 } else { | 110 } else { |
110 host_connection_.reset(new IceConnectionToClient( | 111 host_connection_.reset(new IceConnectionToClient( |
111 make_scoped_ptr(host_session_), | 112 base::WrapUnique(host_session_), |
112 TransportContext::ForTests(protocol::TransportRole::SERVER), | 113 TransportContext::ForTests(protocol::TransportRole::SERVER), |
113 message_loop_.task_runner())); | 114 message_loop_.task_runner())); |
114 client_connection_.reset(new IceConnectionToHost()); | 115 client_connection_.reset(new IceConnectionToHost()); |
115 } | 116 } |
116 | 117 |
117 // Setup host side. | 118 // Setup host side. |
118 host_connection_->SetEventHandler(&host_event_handler_); | 119 host_connection_->SetEventHandler(&host_event_handler_); |
119 host_connection_->set_clipboard_stub(&host_clipboard_stub_); | 120 host_connection_->set_clipboard_stub(&host_clipboard_stub_); |
120 host_connection_->set_host_stub(&host_stub_); | 121 host_connection_->set_host_stub(&host_stub_); |
121 host_connection_->set_input_stub(&host_input_stub_); | 122 host_connection_->set_input_stub(&host_input_stub_); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 run_loop_->Quit(); | 181 run_loop_->Quit(); |
181 } | 182 } |
182 | 183 |
183 void OnClientConnected() { | 184 void OnClientConnected() { |
184 client_connected_ = true; | 185 client_connected_ = true; |
185 if (host_connected_ && run_loop_) | 186 if (host_connected_ && run_loop_) |
186 run_loop_->Quit(); | 187 run_loop_->Quit(); |
187 } | 188 } |
188 | 189 |
189 base::MessageLoopForIO message_loop_; | 190 base::MessageLoopForIO message_loop_; |
190 scoped_ptr<base::RunLoop> run_loop_; | 191 std::unique_ptr<base::RunLoop> run_loop_; |
191 | 192 |
192 MockConnectionToClientEventHandler host_event_handler_; | 193 MockConnectionToClientEventHandler host_event_handler_; |
193 MockClipboardStub host_clipboard_stub_; | 194 MockClipboardStub host_clipboard_stub_; |
194 MockHostStub host_stub_; | 195 MockHostStub host_stub_; |
195 MockInputStub host_input_stub_; | 196 MockInputStub host_input_stub_; |
196 scoped_ptr<ConnectionToClient> host_connection_; | 197 std::unique_ptr<ConnectionToClient> host_connection_; |
197 FakeSession* host_session_; // Owned by |host_connection_|. | 198 FakeSession* host_session_; // Owned by |host_connection_|. |
198 bool host_connected_ = false; | 199 bool host_connected_ = false; |
199 | 200 |
200 MockConnectionToHostEventCallback client_event_handler_; | 201 MockConnectionToHostEventCallback client_event_handler_; |
201 MockClientStub client_stub_; | 202 MockClientStub client_stub_; |
202 MockClipboardStub client_clipboard_stub_; | 203 MockClipboardStub client_clipboard_stub_; |
203 FakeVideoRenderer client_video_renderer_; | 204 FakeVideoRenderer client_video_renderer_; |
204 scoped_ptr<ConnectionToHost> client_connection_; | 205 std::unique_ptr<ConnectionToHost> client_connection_; |
205 FakeSession* client_session_; // Owned by |client_connection_|. | 206 FakeSession* client_session_; // Owned by |client_connection_|. |
206 scoped_ptr<FakeSession> owned_client_session_; | 207 std::unique_ptr<FakeSession> owned_client_session_; |
207 bool client_connected_ = false; | 208 bool client_connected_ = false; |
208 | 209 |
209 private: | 210 private: |
210 DISALLOW_COPY_AND_ASSIGN(ConnectionTest); | 211 DISALLOW_COPY_AND_ASSIGN(ConnectionTest); |
211 }; | 212 }; |
212 | 213 |
213 INSTANTIATE_TEST_CASE_P(Ice, ConnectionTest, ::testing::Values(false)); | 214 INSTANTIATE_TEST_CASE_P(Ice, ConnectionTest, ::testing::Values(false)); |
214 INSTANTIATE_TEST_CASE_P(Webrtc, ConnectionTest, ::testing::Values(true)); | 215 INSTANTIATE_TEST_CASE_P(Webrtc, ConnectionTest, ::testing::Values(true)); |
215 | 216 |
216 TEST_P(ConnectionTest, RejectConnection) { | 217 TEST_P(ConnectionTest, RejectConnection) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 273 |
273 // Send capabilities from the client. | 274 // Send capabilities from the client. |
274 client_connection_->input_stub()->InjectKeyEvent(event); | 275 client_connection_->input_stub()->InjectKeyEvent(event); |
275 | 276 |
276 run_loop.Run(); | 277 run_loop.Run(); |
277 } | 278 } |
278 | 279 |
279 TEST_P(ConnectionTest, Video) { | 280 TEST_P(ConnectionTest, Video) { |
280 Connect(); | 281 Connect(); |
281 | 282 |
282 scoped_ptr<VideoStream> video_stream = host_connection_->StartVideoStream( | 283 std::unique_ptr<VideoStream> video_stream = |
283 make_scoped_ptr(new TestScreenCapturer())); | 284 host_connection_->StartVideoStream( |
| 285 base::WrapUnique(new TestScreenCapturer())); |
284 | 286 |
285 base::RunLoop run_loop; | 287 base::RunLoop run_loop; |
286 | 288 |
287 // Expect frames to be passed to FrameConsumer when WebRTC is used, or to | 289 // Expect frames to be passed to FrameConsumer when WebRTC is used, or to |
288 // VideoStub otherwise. | 290 // VideoStub otherwise. |
289 if (is_using_webrtc()) { | 291 if (is_using_webrtc()) { |
290 client_video_renderer_.GetFrameConsumer()->set_on_frame_callback( | 292 client_video_renderer_.GetFrameConsumer()->set_on_frame_callback( |
291 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop))); | 293 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop))); |
292 } else { | 294 } else { |
293 client_video_renderer_.GetVideoStub()->set_on_frame_callback( | 295 client_video_renderer_.GetVideoStub()->set_on_frame_callback( |
(...skipping 13 matching lines...) Expand all Loading... |
307 client_video_renderer_.GetFrameConsumer()->received_frames().size(), | 309 client_video_renderer_.GetFrameConsumer()->received_frames().size(), |
308 0U); | 310 0U); |
309 EXPECT_EQ(client_video_renderer_.GetVideoStub()->received_packets().size(), | 311 EXPECT_EQ(client_video_renderer_.GetVideoStub()->received_packets().size(), |
310 1U); | 312 1U); |
311 } | 313 } |
312 | 314 |
313 } | 315 } |
314 | 316 |
315 } // namespace protocol | 317 } // namespace protocol |
316 } // namespace remoting | 318 } // namespace remoting |
OLD | NEW |