Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/task.h" | 9 #include "base/task.h" |
| 10 #include "remoting/base/base_mock_objects.h" | 10 #include "remoting/base/base_mock_objects.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 scoped_refptr<MockConnectionToClient> connection_; | 95 scoped_refptr<MockConnectionToClient> connection_; |
| 96 | 96 |
| 97 // The following mock objects are owned by ScreenRecorder. | 97 // The following mock objects are owned by ScreenRecorder. |
| 98 MockCapturer capturer_; | 98 MockCapturer capturer_; |
| 99 MockEncoder* encoder_; | 99 MockEncoder* encoder_; |
| 100 MessageLoop message_loop_; | 100 MessageLoop message_loop_; |
| 101 private: | 101 private: |
| 102 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); | 102 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 // This test mocks capturer, encoder and network layer to operate one recording | |
| 106 // cycle. | |
| 107 TEST_F(ScreenRecorderTest, OneRecordCycle) { | |
| 108 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); | |
| 109 DataPlanes planes; | |
| 110 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | |
| 111 planes.data[i] = reinterpret_cast<uint8*>(i); | |
| 112 planes.strides[i] = kWidth * 4; | |
| 113 } | |
| 114 SkISize size(SkISize::Make(kWidth, kHeight)); | |
| 115 scoped_refptr<CaptureData> data(new CaptureData(planes, size, kFormat)); | |
| 116 EXPECT_CALL(capturer_, InvalidateFullScreen()); | |
| 117 | |
| 118 // First the capturer is called. | |
| 119 EXPECT_CALL(capturer_, CaptureInvalidRegion(NotNull())) | |
| 120 .WillOnce(RunCallback(update_region, data)); | |
| 121 | |
| 122 // Expect the encoder be called. | |
| 123 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) | |
| 124 .WillOnce(FinishEncode()); | |
| 125 | |
| 126 MockVideoStub video_stub; | |
| 127 EXPECT_CALL(*connection_, video_stub()) | |
| 128 .WillRepeatedly(Return(&video_stub)); | |
| 129 | |
| 130 // Expect the client be notified. | |
| 131 EXPECT_CALL(video_stub, ProcessVideoPacket(_, _)) | |
| 132 .Times(1) | |
| 133 .WillOnce(DeleteArg<0>()); | |
| 134 EXPECT_CALL(video_stub, GetPendingPackets()) | |
| 135 .Times(AtLeast(0)) | |
| 136 .WillRepeatedly(Return(0)); | |
| 137 | |
| 138 // Set the recording rate to very low to avoid capture twice. | |
| 139 record_->SetMaxRate(0.01); | |
| 140 | |
| 141 // Add the mock client connection to the session. | |
| 142 record_->AddConnection(connection_); | |
| 143 | |
| 144 // Start the recording. | |
| 145 record_->Start(); | |
| 146 | |
| 147 // Make sure all tasks are completed. | |
| 148 message_loop_.RunAllPending(); | |
| 149 } | |
|
Wez
2011/10/20 00:52:15
No replacement test?
| |
| 150 | |
| 151 // This test mocks capturer, encoder and network layer to simulate one recording | 105 // This test mocks capturer, encoder and network layer to simulate one recording |
| 152 // cycle. When the first encoded packet is submitted to the network | 106 // cycle. When the first encoded packet is submitted to the network |
| 153 // ScreenRecorder is instructed to come to a complete stop. We expect the stop | 107 // ScreenRecorder is instructed to come to a complete stop. We expect the stop |
| 154 // sequence to be executed successfully. | 108 // sequence to be executed successfully. |
| 155 TEST_F(ScreenRecorderTest, StartAndStop) { | 109 TEST_F(ScreenRecorderTest, StartAndStop) { |
| 156 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); | 110 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); |
| 157 DataPlanes planes; | 111 DataPlanes planes; |
| 158 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | 112 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
| 159 planes.data[i] = reinterpret_cast<uint8*>(i); | 113 planes.data[i] = reinterpret_cast<uint8*>(i); |
| 160 planes.strides[i] = kWidth * 4; | 114 planes.strides[i] = kWidth * 4; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 record_->Start(); | 150 record_->Start(); |
| 197 message_loop_.Run(); | 151 message_loop_.Run(); |
| 198 } | 152 } |
| 199 | 153 |
| 200 TEST_F(ScreenRecorderTest, StopWithoutStart) { | 154 TEST_F(ScreenRecorderTest, StopWithoutStart) { |
| 201 record_->Stop(base::Bind(&QuitMessageLoop, &message_loop_)); | 155 record_->Stop(base::Bind(&QuitMessageLoop, &message_loop_)); |
| 202 message_loop_.Run(); | 156 message_loop_.Run(); |
| 203 } | 157 } |
| 204 | 158 |
| 205 } // namespace remoting | 159 } // namespace remoting |
| OLD | NEW |