| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/task.h" | 6 #include "base/task.h" |
| 7 #include "remoting/base/mock_objects.h" | 7 #include "remoting/base/mock_objects.h" |
| 8 #include "remoting/host/mock_objects.h" | 8 #include "remoting/host/mock_objects.h" |
| 9 #include "remoting/host/screen_recorder.h" | 9 #include "remoting/host/screen_recorder.h" |
| 10 #include "remoting/proto/video.pb.h" | 10 #include "remoting/proto/video.pb.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 static const VideoPacketFormat::Encoding kEncoding = | 69 static const VideoPacketFormat::Encoding kEncoding = |
| 70 VideoPacketFormat::ENCODING_VERBATIM; | 70 VideoPacketFormat::ENCODING_VERBATIM; |
| 71 | 71 |
| 72 class ScreenRecorderTest : public testing::Test { | 72 class ScreenRecorderTest : public testing::Test { |
| 73 public: | 73 public: |
| 74 ScreenRecorderTest() { | 74 ScreenRecorderTest() { |
| 75 } | 75 } |
| 76 | 76 |
| 77 virtual void SetUp() { | 77 virtual void SetUp() { |
| 78 // Capturer and Encoder are owned by ScreenRecorder. | 78 // Capturer and Encoder are owned by ScreenRecorder. |
| 79 capturer_ = new MockCapturer(); |
| 79 encoder_ = new MockEncoder(); | 80 encoder_ = new MockEncoder(); |
| 80 connection_ = new MockConnectionToClient(); | 81 connection_ = new MockConnectionToClient(); |
| 81 record_ = new ScreenRecorder( | 82 record_ = new ScreenRecorder( |
| 82 &message_loop_, &message_loop_, &message_loop_, | 83 &message_loop_, &message_loop_, &message_loop_, |
| 83 &capturer_, encoder_); | 84 capturer_, encoder_); |
| 84 } | 85 } |
| 85 | 86 |
| 86 protected: | 87 protected: |
| 87 scoped_refptr<ScreenRecorder> record_; | 88 scoped_refptr<ScreenRecorder> record_; |
| 88 scoped_refptr<MockConnectionToClient> connection_; | 89 scoped_refptr<MockConnectionToClient> connection_; |
| 89 | 90 |
| 90 // The following mock objects are owned by ScreenRecorder. | 91 // The following mock objects are owned by ScreenRecorder. |
| 91 MockCapturer capturer_; | 92 MockCapturer* capturer_; |
| 92 MockEncoder* encoder_; | 93 MockEncoder* encoder_; |
| 93 MessageLoop message_loop_; | 94 MessageLoop message_loop_; |
| 94 private: | 95 private: |
| 95 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); | 96 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 // This test mocks capturer, encoder and network layer to operate one recording | 99 // This test mocks capturer, encoder and network layer to operate one recording |
| 99 // cycle. | 100 // cycle. |
| 100 TEST_F(ScreenRecorderTest, OneRecordCycle) { | 101 TEST_F(ScreenRecorderTest, OneRecordCycle) { |
| 101 InvalidRects update_rects; | 102 InvalidRects update_rects; |
| 102 update_rects.insert(gfx::Rect(0, 0, 10, 10)); | 103 update_rects.insert(gfx::Rect(0, 0, 10, 10)); |
| 103 DataPlanes planes; | 104 DataPlanes planes; |
| 104 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | 105 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
| 105 planes.data[i] = reinterpret_cast<uint8*>(i); | 106 planes.data[i] = reinterpret_cast<uint8*>(i); |
| 106 planes.strides[i] = kWidth * 4; | 107 planes.strides[i] = kWidth * 4; |
| 107 } | 108 } |
| 108 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, | 109 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, |
| 109 kHeight, kFormat)); | 110 kHeight, kFormat)); |
| 110 EXPECT_CALL(capturer_, width()).WillRepeatedly(Return(kWidth)); | 111 EXPECT_CALL(*capturer_, width()).WillRepeatedly(Return(kWidth)); |
| 111 EXPECT_CALL(capturer_, height()).WillRepeatedly(Return(kHeight)); | 112 EXPECT_CALL(*capturer_, height()).WillRepeatedly(Return(kHeight)); |
| 112 | 113 |
| 113 // First the capturer is called. | 114 // First the capturer is called. |
| 114 EXPECT_CALL(capturer_, CaptureInvalidRects(NotNull())) | 115 EXPECT_CALL(*capturer_, CaptureInvalidRects(NotNull())) |
| 115 .WillOnce(RunCallback(update_rects, data)); | 116 .WillOnce(RunCallback(update_rects, data)); |
| 116 | 117 |
| 117 // Expect the encoder be called. | 118 // Expect the encoder be called. |
| 118 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) | 119 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) |
| 119 .WillOnce(FinishEncode()); | 120 .WillOnce(FinishEncode()); |
| 120 | 121 |
| 121 MockVideoStub video_stub; | 122 MockVideoStub video_stub; |
| 122 EXPECT_CALL(*connection_, video_stub()) | 123 EXPECT_CALL(*connection_, video_stub()) |
| 123 .WillRepeatedly(Return(&video_stub)); | 124 .WillRepeatedly(Return(&video_stub)); |
| 124 | 125 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 150 TEST_F(ScreenRecorderTest, StartAndStop) { | 151 TEST_F(ScreenRecorderTest, StartAndStop) { |
| 151 InvalidRects update_rects; | 152 InvalidRects update_rects; |
| 152 update_rects.insert(gfx::Rect(0, 0, 10, 10)); | 153 update_rects.insert(gfx::Rect(0, 0, 10, 10)); |
| 153 DataPlanes planes; | 154 DataPlanes planes; |
| 154 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | 155 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
| 155 planes.data[i] = reinterpret_cast<uint8*>(i); | 156 planes.data[i] = reinterpret_cast<uint8*>(i); |
| 156 planes.strides[i] = kWidth * 4; | 157 planes.strides[i] = kWidth * 4; |
| 157 } | 158 } |
| 158 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, | 159 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, |
| 159 kHeight, kFormat)); | 160 kHeight, kFormat)); |
| 160 EXPECT_CALL(capturer_, width()).WillRepeatedly(Return(kWidth)); | 161 EXPECT_CALL(*capturer_, width()).WillRepeatedly(Return(kWidth)); |
| 161 EXPECT_CALL(capturer_, height()).WillRepeatedly(Return(kHeight)); | 162 EXPECT_CALL(*capturer_, height()).WillRepeatedly(Return(kHeight)); |
| 162 | 163 |
| 163 // First the capturer is called. | 164 // First the capturer is called. |
| 164 EXPECT_CALL(capturer_, CaptureInvalidRects(NotNull())) | 165 EXPECT_CALL(*capturer_, CaptureInvalidRects(NotNull())) |
| 165 .WillRepeatedly(RunCallback(update_rects, data)); | 166 .WillRepeatedly(RunCallback(update_rects, data)); |
| 166 | 167 |
| 167 // Expect the encoder be called. | 168 // Expect the encoder be called. |
| 168 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) | 169 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) |
| 169 .WillRepeatedly(FinishEncode()); | 170 .WillRepeatedly(FinishEncode()); |
| 170 | 171 |
| 171 MockVideoStub video_stub; | 172 MockVideoStub video_stub; |
| 172 EXPECT_CALL(*connection_, video_stub()) | 173 EXPECT_CALL(*connection_, video_stub()) |
| 173 .WillRepeatedly(Return(&video_stub)); | 174 .WillRepeatedly(Return(&video_stub)); |
| 174 | 175 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 191 | 192 |
| 192 // Start the recording. | 193 // Start the recording. |
| 193 record_->Start(); | 194 record_->Start(); |
| 194 message_loop_.Run(); | 195 message_loop_.Run(); |
| 195 } | 196 } |
| 196 | 197 |
| 197 // TODO(hclam): Add test for double buffering. | 198 // TODO(hclam): Add test for double buffering. |
| 198 // TODO(hclam): Add test for multiple captures. | 199 // TODO(hclam): Add test for multiple captures. |
| 199 | 200 |
| 200 } // namespace remoting | 201 } // namespace remoting |
| OLD | NEW |