| 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" |
| 11 #include "remoting/host/host_mock_objects.h" | 11 #include "remoting/host/host_mock_objects.h" |
| 12 #include "remoting/proto/video.pb.h" | 12 #include "remoting/proto/video.pb.h" |
| 13 #include "remoting/protocol/protocol_mock_objects.h" | 13 #include "remoting/protocol/protocol_mock_objects.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using ::remoting::protocol::MockConnectionToClient; | 17 using ::remoting::protocol::MockConnectionToClient; |
| 18 using ::remoting::protocol::MockConnectionToClientEventHandler; | 18 using ::remoting::protocol::MockConnectionToClientEventHandler; |
| 19 using ::remoting::protocol::MockHostStub; | 19 using ::remoting::protocol::MockHostStub; |
| 20 using ::remoting::protocol::MockVideoStub; | 20 using ::remoting::protocol::MockVideoStub; |
| 21 | 21 |
| 22 using ::testing::_; | 22 using ::testing::_; |
| 23 using ::testing::AtLeast; | 23 using ::testing::AtLeast; |
| 24 using ::testing::DeleteArg; | 24 using ::testing::DeleteArg; |
| 25 using ::testing::DoAll; | 25 using ::testing::DoAll; |
| 26 using ::testing::InSequence; | 26 using ::testing::InSequence; |
| 27 using ::testing::InvokeWithoutArgs; | 27 using ::testing::InvokeWithoutArgs; |
| 28 using ::testing::NotNull; | |
| 29 using ::testing::Return; | 28 using ::testing::Return; |
| 30 using ::testing::SaveArg; | 29 using ::testing::SaveArg; |
| 31 | 30 |
| 32 namespace remoting { | 31 namespace remoting { |
| 33 | 32 |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 ACTION_P2(RunCallback, region, data) { | 35 ACTION_P2(RunCallback, region, data) { |
| 37 SkRegion& dirty_region = data->mutable_dirty_region(); | 36 SkRegion& dirty_region = data->mutable_dirty_region(); |
| 38 dirty_region.op(region, SkRegion::kUnion_Op); | 37 dirty_region.op(region, SkRegion::kUnion_Op); |
| 39 arg0->Run(data); | 38 arg0.Run(data); |
| 40 delete arg0; | |
| 41 } | 39 } |
| 42 | 40 |
| 43 ACTION(FinishEncode) { | 41 ACTION(FinishEncode) { |
| 44 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 42 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
| 45 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION); | 43 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION); |
| 46 arg2->Run(packet.release()); | 44 arg2.Run(packet.release()); |
| 47 delete arg2; | |
| 48 } | 45 } |
| 49 | 46 |
| 50 ACTION(FinishSend) { | 47 ACTION(FinishSend) { |
| 51 arg1.Run(); | 48 arg1.Run(); |
| 52 } | 49 } |
| 53 | 50 |
| 54 // Helper method to quit the main message loop. | 51 // Helper method to quit the main message loop. |
| 55 void QuitMessageLoop(MessageLoop* message_loop) { | 52 void QuitMessageLoop(MessageLoop* message_loop) { |
| 56 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 53 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 57 } | 54 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | 109 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
| 113 planes.data[i] = reinterpret_cast<uint8*>(i); | 110 planes.data[i] = reinterpret_cast<uint8*>(i); |
| 114 planes.strides[i] = kWidth * 4; | 111 planes.strides[i] = kWidth * 4; |
| 115 } | 112 } |
| 116 | 113 |
| 117 SkISize size(SkISize::Make(kWidth, kHeight)); | 114 SkISize size(SkISize::Make(kWidth, kHeight)); |
| 118 scoped_refptr<CaptureData> data(new CaptureData(planes, size, kFormat)); | 115 scoped_refptr<CaptureData> data(new CaptureData(planes, size, kFormat)); |
| 119 EXPECT_CALL(capturer_, InvalidateFullScreen()); | 116 EXPECT_CALL(capturer_, InvalidateFullScreen()); |
| 120 | 117 |
| 121 // First the capturer is called. | 118 // First the capturer is called. |
| 122 EXPECT_CALL(capturer_, CaptureInvalidRegion(NotNull())) | 119 EXPECT_CALL(capturer_, CaptureInvalidRegion(_)) |
| 123 .WillRepeatedly(RunCallback(update_region, data)); | 120 .WillRepeatedly(RunCallback(update_region, data)); |
| 124 | 121 |
| 125 // Expect the encoder be called. | 122 // Expect the encoder be called. |
| 126 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) | 123 EXPECT_CALL(*encoder_, Encode(data, false, _)) |
| 127 .WillRepeatedly(FinishEncode()); | 124 .WillRepeatedly(FinishEncode()); |
| 128 | 125 |
| 129 MockVideoStub video_stub; | 126 MockVideoStub video_stub; |
| 130 EXPECT_CALL(*connection_, video_stub()) | 127 EXPECT_CALL(*connection_, video_stub()) |
| 131 .WillRepeatedly(Return(&video_stub)); | 128 .WillRepeatedly(Return(&video_stub)); |
| 132 | 129 |
| 133 // By default delete the arguments when ProcessVideoPacket is received. | 130 // By default delete the arguments when ProcessVideoPacket is received. |
| 134 EXPECT_CALL(video_stub, ProcessVideoPacket(_, _)) | 131 EXPECT_CALL(video_stub, ProcessVideoPacket(_, _)) |
| 135 .WillRepeatedly(FinishSend()); | 132 .WillRepeatedly(FinishSend()); |
| 136 | 133 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 150 record_->Start(); | 147 record_->Start(); |
| 151 message_loop_.Run(); | 148 message_loop_.Run(); |
| 152 } | 149 } |
| 153 | 150 |
| 154 TEST_F(ScreenRecorderTest, StopWithoutStart) { | 151 TEST_F(ScreenRecorderTest, StopWithoutStart) { |
| 155 record_->Stop(base::Bind(&QuitMessageLoop, &message_loop_)); | 152 record_->Stop(base::Bind(&QuitMessageLoop, &message_loop_)); |
| 156 message_loop_.Run(); | 153 message_loop_.Run(); |
| 157 } | 154 } |
| 158 | 155 |
| 159 } // namespace remoting | 156 } // namespace remoting |
| OLD | NEW |