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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "remoting/base/constants.h" | 11 #include "remoting/base/constants.h" |
12 #include "remoting/protocol/fake_session.h" | 12 #include "remoting/protocol/fake_session.h" |
13 #include "remoting/protocol/fake_video_renderer.h" | 13 #include "remoting/protocol/fake_video_renderer.h" |
14 #include "remoting/protocol/ice_connection_to_client.h" | 14 #include "remoting/protocol/ice_connection_to_client.h" |
15 #include "remoting/protocol/ice_connection_to_host.h" | 15 #include "remoting/protocol/ice_connection_to_host.h" |
16 #include "remoting/protocol/protocol_mock_objects.h" | 16 #include "remoting/protocol/protocol_mock_objects.h" |
17 #include "remoting/protocol/transport_context.h" | 17 #include "remoting/protocol/transport_context.h" |
| 18 #include "remoting/protocol/video_stream.h" |
18 #include "remoting/protocol/webrtc_connection_to_client.h" | 19 #include "remoting/protocol/webrtc_connection_to_client.h" |
19 #include "remoting/protocol/webrtc_connection_to_host.h" | 20 #include "remoting/protocol/webrtc_connection_to_host.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
| 24 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
22 | 25 |
23 using ::testing::_; | 26 using ::testing::_; |
24 using ::testing::InvokeWithoutArgs; | 27 using ::testing::InvokeWithoutArgs; |
25 using ::testing::NotNull; | 28 using ::testing::NotNull; |
26 using ::testing::StrictMock; | 29 using ::testing::StrictMock; |
27 | 30 |
28 namespace remoting { | 31 namespace remoting { |
29 namespace protocol { | 32 namespace protocol { |
30 | 33 |
31 namespace { | 34 namespace { |
(...skipping 18 matching lines...) Expand all Loading... |
50 ~MockConnectionToHostEventCallback() override {} | 53 ~MockConnectionToHostEventCallback() override {} |
51 | 54 |
52 MOCK_METHOD2(OnConnectionState, | 55 MOCK_METHOD2(OnConnectionState, |
53 void(ConnectionToHost::State state, ErrorCode error)); | 56 void(ConnectionToHost::State state, ErrorCode error)); |
54 MOCK_METHOD1(OnConnectionReady, void(bool ready)); | 57 MOCK_METHOD1(OnConnectionReady, void(bool ready)); |
55 MOCK_METHOD2(OnRouteChanged, | 58 MOCK_METHOD2(OnRouteChanged, |
56 void(const std::string& channel_name, | 59 void(const std::string& channel_name, |
57 const TransportRoute& route)); | 60 const TransportRoute& route)); |
58 }; | 61 }; |
59 | 62 |
| 63 class TestScreenCapturer : public webrtc::DesktopCapturer { |
| 64 public: |
| 65 TestScreenCapturer() {} |
| 66 ~TestScreenCapturer() override {} |
| 67 |
| 68 // webrtc::DesktopCapturer interface. |
| 69 void Start(Callback* callback) override { |
| 70 callback_ = callback; |
| 71 } |
| 72 void Capture(const webrtc::DesktopRegion& region) override { |
| 73 // Return black 10x10 frame. |
| 74 scoped_ptr<webrtc::DesktopFrame> frame( |
| 75 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(100, 100))); |
| 76 memset(frame->data(), 0, frame->stride() * frame->size().height()); |
| 77 frame->mutable_updated_region()->SetRect( |
| 78 webrtc::DesktopRect::MakeSize(frame->size())); |
| 79 callback_->OnCaptureCompleted(frame.release()); |
| 80 } |
| 81 |
| 82 private: |
| 83 Callback* callback_ = nullptr; |
| 84 }; |
| 85 |
60 } // namespace | 86 } // namespace |
61 | 87 |
62 class ConnectionTest : public testing::Test, | 88 class ConnectionTest : public testing::Test, |
63 public testing::WithParamInterface<bool> { | 89 public testing::WithParamInterface<bool> { |
64 public: | 90 public: |
65 ConnectionTest() {} | 91 ConnectionTest() {} |
66 | 92 |
67 protected: | 93 protected: |
| 94 bool is_using_webrtc() { return GetParam(); } |
| 95 |
68 void SetUp() override { | 96 void SetUp() override { |
69 // Create fake sessions. | 97 // Create fake sessions. |
70 host_session_ = new FakeSession(); | 98 host_session_ = new FakeSession(); |
71 owned_client_session_.reset(new FakeSession()); | 99 owned_client_session_.reset(new FakeSession()); |
72 client_session_ = owned_client_session_.get(); | 100 client_session_ = owned_client_session_.get(); |
73 | 101 |
74 // Create Connection objects | 102 // Create Connection objects. |
75 if (GetParam()) { | 103 if (is_using_webrtc()) { |
76 host_connection_.reset(new WebrtcConnectionToClient( | 104 host_connection_.reset(new WebrtcConnectionToClient( |
77 make_scoped_ptr(host_session_), | 105 make_scoped_ptr(host_session_), |
78 TransportContext::ForTests(protocol::TransportRole::SERVER))); | 106 TransportContext::ForTests(protocol::TransportRole::SERVER))); |
79 client_connection_.reset(new WebrtcConnectionToHost()); | 107 client_connection_.reset(new WebrtcConnectionToHost()); |
80 | 108 |
81 } else { | 109 } else { |
82 host_connection_.reset(new IceConnectionToClient( | 110 host_connection_.reset(new IceConnectionToClient( |
83 make_scoped_ptr(host_session_), | 111 make_scoped_ptr(host_session_), |
84 TransportContext::ForTests(protocol::TransportRole::SERVER), | 112 TransportContext::ForTests(protocol::TransportRole::SERVER), |
85 message_loop_.task_runner())); | 113 message_loop_.task_runner())); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 OnInputEventReceived(host_connection_.get(), _)); | 269 OnInputEventReceived(host_connection_.get(), _)); |
242 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(event))) | 270 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(event))) |
243 .WillOnce(QuitRunLoop(&run_loop)); | 271 .WillOnce(QuitRunLoop(&run_loop)); |
244 | 272 |
245 // Send capabilities from the client. | 273 // Send capabilities from the client. |
246 client_connection_->input_stub()->InjectKeyEvent(event); | 274 client_connection_->input_stub()->InjectKeyEvent(event); |
247 | 275 |
248 run_loop.Run(); | 276 run_loop.Run(); |
249 } | 277 } |
250 | 278 |
| 279 TEST_P(ConnectionTest, Video) { |
| 280 Connect(); |
| 281 |
| 282 scoped_ptr<VideoStream> video_stream = host_connection_->StartVideoStream( |
| 283 make_scoped_ptr(new TestScreenCapturer())); |
| 284 |
| 285 base::RunLoop run_loop; |
| 286 |
| 287 // Expect frames to be passed to FrameConsumer when WebRTC is used, or to |
| 288 // VideoStub otherwise. |
| 289 if (is_using_webrtc()) { |
| 290 client_video_renderer_.GetFrameConsumer()->set_on_frame_callback( |
| 291 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop))); |
| 292 } else { |
| 293 client_video_renderer_.GetVideoStub()->set_on_frame_callback( |
| 294 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop))); |
| 295 } |
| 296 |
| 297 run_loop.Run(); |
| 298 |
| 299 if (is_using_webrtc()) { |
| 300 EXPECT_EQ( |
| 301 client_video_renderer_.GetFrameConsumer()->received_frames().size(), |
| 302 1U); |
| 303 EXPECT_EQ(client_video_renderer_.GetVideoStub()->received_packets().size(), |
| 304 0U); |
| 305 } else { |
| 306 EXPECT_EQ( |
| 307 client_video_renderer_.GetFrameConsumer()->received_frames().size(), |
| 308 0U); |
| 309 EXPECT_EQ(client_video_renderer_.GetVideoStub()->received_packets().size(), |
| 310 1U); |
| 311 } |
| 312 |
| 313 } |
| 314 |
251 } // namespace protocol | 315 } // namespace protocol |
252 } // namespace remoting | 316 } // namespace remoting |
OLD | NEW |