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/host/screen_recorder.h" | 5 #include "remoting/host/screen_recorder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "remoting/base/capture_data.h" | 9 #include "remoting/base/capture_data.h" |
10 #include "remoting/codec/video_encoder.h" | 10 #include "remoting/codec/video_encoder.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 | 65 |
66 static const int kWidth = 640; | 66 static const int kWidth = 640; |
67 static const int kHeight = 480; | 67 static const int kHeight = 480; |
68 static const media::VideoFrame::Format kFormat = media::VideoFrame::RGB32; | 68 static const media::VideoFrame::Format kFormat = media::VideoFrame::RGB32; |
69 static const VideoPacketFormat::Encoding kEncoding = | 69 static const VideoPacketFormat::Encoding kEncoding = |
70 VideoPacketFormat::ENCODING_VERBATIM; | 70 VideoPacketFormat::ENCODING_VERBATIM; |
71 | 71 |
72 class MockEncoder : public Encoder { | 72 class MockVideoEncoder : public VideoEncoder { |
73 public: | 73 public: |
74 MockEncoder(); | 74 MockVideoEncoder(); |
75 virtual ~MockEncoder(); | 75 virtual ~MockVideoEncoder(); |
76 | 76 |
77 MOCK_METHOD3(Encode, void( | 77 MOCK_METHOD3(Encode, void( |
78 scoped_refptr<CaptureData> capture_data, | 78 scoped_refptr<CaptureData> capture_data, |
79 bool key_frame, | 79 bool key_frame, |
80 const DataAvailableCallback& data_available_callback)); | 80 const DataAvailableCallback& data_available_callback)); |
81 | 81 |
82 private: | 82 private: |
83 DISALLOW_COPY_AND_ASSIGN(MockEncoder); | 83 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); |
84 }; | 84 }; |
85 | 85 |
86 MockEncoder::MockEncoder() {} | 86 MockVideoEncoder::MockVideoEncoder() {} |
87 | 87 |
88 MockEncoder::~MockEncoder() {} | 88 MockVideoEncoder::~MockVideoEncoder() {} |
89 | 89 |
90 class ScreenRecorderTest : public testing::Test { | 90 class ScreenRecorderTest : public testing::Test { |
91 public: | 91 public: |
92 ScreenRecorderTest() { | 92 ScreenRecorderTest() { |
93 } | 93 } |
94 | 94 |
95 virtual void SetUp() OVERRIDE { | 95 virtual void SetUp() OVERRIDE { |
96 // VideoFrameCapturer and Encoder are owned by ScreenRecorder. | 96 // VideoFrameCapturer and VideoEncoder are owned by ScreenRecorder. |
97 encoder_ = new MockEncoder(); | 97 encoder_ = new MockVideoEncoder(); |
98 | 98 |
99 session_ = new MockSession(); | 99 session_ = new MockSession(); |
100 EXPECT_CALL(*session_, SetEventHandler(_)); | 100 EXPECT_CALL(*session_, SetEventHandler(_)); |
101 EXPECT_CALL(*session_, Close()) | 101 EXPECT_CALL(*session_, Close()) |
102 .Times(AnyNumber()); | 102 .Times(AnyNumber()); |
103 connection_.reset(new MockConnectionToClient( | 103 connection_.reset(new MockConnectionToClient( |
104 session_, &host_stub_, &event_executor_)); | 104 session_, &host_stub_, &event_executor_)); |
105 connection_->SetEventHandler(&handler_); | 105 connection_->SetEventHandler(&handler_); |
106 | 106 |
107 record_ = new ScreenRecorder( | 107 record_ = new ScreenRecorder( |
(...skipping 13 matching lines...) Expand all Loading... |
121 scoped_refptr<ScreenRecorder> record_; | 121 scoped_refptr<ScreenRecorder> record_; |
122 | 122 |
123 MockConnectionToClientEventHandler handler_; | 123 MockConnectionToClientEventHandler handler_; |
124 MockHostStub host_stub_; | 124 MockHostStub host_stub_; |
125 MockEventExecutor event_executor_; | 125 MockEventExecutor event_executor_; |
126 MockSession* session_; // Owned by |connection_|. | 126 MockSession* session_; // Owned by |connection_|. |
127 scoped_ptr<MockConnectionToClient> connection_; | 127 scoped_ptr<MockConnectionToClient> connection_; |
128 | 128 |
129 // The following mock objects are owned by ScreenRecorder. | 129 // The following mock objects are owned by ScreenRecorder. |
130 MockVideoFrameCapturer capturer_; | 130 MockVideoFrameCapturer capturer_; |
131 MockEncoder* encoder_; | 131 MockVideoEncoder* encoder_; |
132 | 132 |
133 private: | 133 private: |
134 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); | 134 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); |
135 }; | 135 }; |
136 | 136 |
137 // This test mocks capturer, encoder and network layer to simulate one recording | 137 // This test mocks capturer, encoder and network layer to simulate one recording |
138 // cycle. When the first encoded packet is submitted to the network | 138 // cycle. When the first encoded packet is submitted to the network |
139 // ScreenRecorder is instructed to come to a complete stop. We expect the stop | 139 // ScreenRecorder is instructed to come to a complete stop. We expect the stop |
140 // sequence to be executed successfully. | 140 // sequence to be executed successfully. |
141 TEST_F(ScreenRecorderTest, StartAndStop) { | 141 TEST_F(ScreenRecorderTest, StartAndStop) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 message_loop_.Run(); | 193 message_loop_.Run(); |
194 } | 194 } |
195 | 195 |
196 TEST_F(ScreenRecorderTest, StopWithoutStart) { | 196 TEST_F(ScreenRecorderTest, StopWithoutStart) { |
197 EXPECT_CALL(capturer_, Stop()); | 197 EXPECT_CALL(capturer_, Stop()); |
198 record_->Stop(base::Bind(&QuitMessageLoop, &message_loop_)); | 198 record_->Stop(base::Bind(&QuitMessageLoop, &message_loop_)); |
199 message_loop_.Run(); | 199 message_loop_.Run(); |
200 } | 200 } |
201 | 201 |
202 } // namespace remoting | 202 } // namespace remoting |
OLD | NEW |