| 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(); | |
| 80 encoder_ = new MockEncoder(); | 79 encoder_ = new MockEncoder(); |
| 81 connection_ = new MockConnectionToClient(); | 80 connection_ = new MockConnectionToClient(); |
| 82 record_ = new ScreenRecorder( | 81 record_ = new ScreenRecorder( |
| 83 &message_loop_, &message_loop_, &message_loop_, | 82 &message_loop_, &message_loop_, &message_loop_, |
| 84 capturer_, encoder_); | 83 &capturer_, encoder_); |
| 85 } | 84 } |
| 86 | 85 |
| 87 protected: | 86 protected: |
| 88 scoped_refptr<ScreenRecorder> record_; | 87 scoped_refptr<ScreenRecorder> record_; |
| 89 scoped_refptr<MockConnectionToClient> connection_; | 88 scoped_refptr<MockConnectionToClient> connection_; |
| 90 | 89 |
| 91 // The following mock objects are owned by ScreenRecorder. | 90 // The following mock objects are owned by ScreenRecorder. |
| 92 MockCapturer* capturer_; | 91 MockCapturer capturer_; |
| 93 MockEncoder* encoder_; | 92 MockEncoder* encoder_; |
| 94 MessageLoop message_loop_; | 93 MessageLoop message_loop_; |
| 95 private: | 94 private: |
| 96 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); | 95 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); |
| 97 }; | 96 }; |
| 98 | 97 |
| 99 TEST_F(ScreenRecorderTest, OneRecordCycle) { | 98 TEST_F(ScreenRecorderTest, OneRecordCycle) { |
| 100 InvalidRects update_rects; | 99 InvalidRects update_rects; |
| 101 update_rects.insert(gfx::Rect(0, 0, 10, 10)); | 100 update_rects.insert(gfx::Rect(0, 0, 10, 10)); |
| 102 DataPlanes planes; | 101 DataPlanes planes; |
| 103 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | 102 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
| 104 planes.data[i] = reinterpret_cast<uint8*>(i); | 103 planes.data[i] = reinterpret_cast<uint8*>(i); |
| 105 planes.strides[i] = kWidth * 4; | 104 planes.strides[i] = kWidth * 4; |
| 106 } | 105 } |
| 107 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, | 106 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, |
| 108 kHeight, kFormat)); | 107 kHeight, kFormat)); |
| 109 EXPECT_CALL(*capturer_, width()).WillRepeatedly(Return(kWidth)); | 108 EXPECT_CALL(capturer_, width()).WillRepeatedly(Return(kWidth)); |
| 110 EXPECT_CALL(*capturer_, height()).WillRepeatedly(Return(kHeight)); | 109 EXPECT_CALL(capturer_, height()).WillRepeatedly(Return(kHeight)); |
| 111 | 110 |
| 112 // First the capturer is called. | 111 // First the capturer is called. |
| 113 EXPECT_CALL(*capturer_, CaptureInvalidRects(NotNull())) | 112 EXPECT_CALL(capturer_, CaptureInvalidRects(NotNull())) |
| 114 .WillOnce(RunCallback(update_rects, data)); | 113 .WillOnce(RunCallback(update_rects, data)); |
| 115 | 114 |
| 116 // Expect the encoder be called. | 115 // Expect the encoder be called. |
| 117 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) | 116 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) |
| 118 .WillOnce(FinishEncode()); | 117 .WillOnce(FinishEncode()); |
| 119 | 118 |
| 120 MockVideoStub video_stub; | 119 MockVideoStub video_stub; |
| 121 EXPECT_CALL(*connection_, video_stub()) | 120 EXPECT_CALL(*connection_, video_stub()) |
| 122 .WillRepeatedly(Return(&video_stub)); | 121 .WillRepeatedly(Return(&video_stub)); |
| 123 | 122 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 145 TEST_F(ScreenRecorderTest, StartAndStop) { | 144 TEST_F(ScreenRecorderTest, StartAndStop) { |
| 146 InvalidRects update_rects; | 145 InvalidRects update_rects; |
| 147 update_rects.insert(gfx::Rect(0, 0, 10, 10)); | 146 update_rects.insert(gfx::Rect(0, 0, 10, 10)); |
| 148 DataPlanes planes; | 147 DataPlanes planes; |
| 149 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | 148 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
| 150 planes.data[i] = reinterpret_cast<uint8*>(i); | 149 planes.data[i] = reinterpret_cast<uint8*>(i); |
| 151 planes.strides[i] = kWidth * 4; | 150 planes.strides[i] = kWidth * 4; |
| 152 } | 151 } |
| 153 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, | 152 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, |
| 154 kHeight, kFormat)); | 153 kHeight, kFormat)); |
| 155 EXPECT_CALL(*capturer_, width()).WillRepeatedly(Return(kWidth)); | 154 EXPECT_CALL(capturer_, width()).WillRepeatedly(Return(kWidth)); |
| 156 EXPECT_CALL(*capturer_, height()).WillRepeatedly(Return(kHeight)); | 155 EXPECT_CALL(capturer_, height()).WillRepeatedly(Return(kHeight)); |
| 157 | 156 |
| 158 // First the capturer is called. | 157 // First the capturer is called. |
| 159 EXPECT_CALL(*capturer_, CaptureInvalidRects(NotNull())) | 158 EXPECT_CALL(capturer_, CaptureInvalidRects(NotNull())) |
| 160 .WillRepeatedly(RunCallback(update_rects, data)); | 159 .WillRepeatedly(RunCallback(update_rects, data)); |
| 161 | 160 |
| 162 // Expect the encoder be called. | 161 // Expect the encoder be called. |
| 163 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) | 162 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) |
| 164 .WillRepeatedly(FinishEncode()); | 163 .WillRepeatedly(FinishEncode()); |
| 165 | 164 |
| 166 MockVideoStub video_stub; | 165 MockVideoStub video_stub; |
| 167 EXPECT_CALL(*connection_, video_stub()) | 166 EXPECT_CALL(*connection_, video_stub()) |
| 168 .WillRepeatedly(Return(&video_stub)); | 167 .WillRepeatedly(Return(&video_stub)); |
| 169 | 168 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 186 | 185 |
| 187 // Start the recording. | 186 // Start the recording. |
| 188 record_->Start(); | 187 record_->Start(); |
| 189 message_loop_.Run(); | 188 message_loop_.Run(); |
| 190 } | 189 } |
| 191 | 190 |
| 192 // TODO(hclam): Add test for double buffering. | 191 // TODO(hclam): Add test for double buffering. |
| 193 // TODO(hclam): Add test for multiple captures. | 192 // TODO(hclam): Add test for multiple captures. |
| 194 | 193 |
| 195 } // namespace remoting | 194 } // namespace remoting |
| OLD | NEW |