| 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/video_scheduler.h" | 5 #include "remoting/host/video_scheduler.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/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "remoting/capturer/capture_data.h" | 10 #include "remoting/capturer/capture_data.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 private: | 66 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); | 67 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 MockVideoEncoder::MockVideoEncoder() {} | 70 MockVideoEncoder::MockVideoEncoder() {} |
| 71 | 71 |
| 72 MockVideoEncoder::~MockVideoEncoder() {} | 72 MockVideoEncoder::~MockVideoEncoder() {} |
| 73 | 73 |
| 74 class VideoSchedulerTest : public testing::Test { | 74 class VideoSchedulerTest : public testing::Test { |
| 75 public: | 75 public: |
| 76 VideoSchedulerTest() : size_(SkISize::Make(0, 0)) { | 76 VideoSchedulerTest() { |
| 77 } | 77 } |
| 78 | 78 |
| 79 virtual void SetUp() OVERRIDE { | 79 virtual void SetUp() OVERRIDE { |
| 80 encoder_ = new MockVideoEncoder(); | 80 encoder_ = new MockVideoEncoder(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void StartVideoScheduler() { | 83 void StartVideoScheduler() { |
| 84 scheduler_ = VideoScheduler::Create( | 84 scheduler_ = VideoScheduler::Create( |
| 85 message_loop_.message_loop_proxy(), | 85 message_loop_.message_loop_proxy(), |
| 86 message_loop_.message_loop_proxy(), | 86 message_loop_.message_loop_proxy(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 97 MessageLoop message_loop_; | 97 MessageLoop message_loop_; |
| 98 scoped_refptr<VideoScheduler> scheduler_; | 98 scoped_refptr<VideoScheduler> scheduler_; |
| 99 | 99 |
| 100 MockClientStub client_stub_; | 100 MockClientStub client_stub_; |
| 101 MockVideoStub video_stub_; | 101 MockVideoStub video_stub_; |
| 102 MockVideoFrameCapturer capturer_; | 102 MockVideoFrameCapturer capturer_; |
| 103 | 103 |
| 104 // The following mock objects are owned by VideoScheduler. | 104 // The following mock objects are owned by VideoScheduler. |
| 105 MockVideoEncoder* encoder_; | 105 MockVideoEncoder* encoder_; |
| 106 | 106 |
| 107 SkISize size_; | |
| 108 scoped_refptr<CaptureData> data_; | 107 scoped_refptr<CaptureData> data_; |
| 109 | 108 |
| 110 private: | 109 private: |
| 111 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); | 110 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); |
| 112 }; | 111 }; |
| 113 | 112 |
| 114 void VideoSchedulerTest::GenerateOnCaptureCompleted() { | 113 void VideoSchedulerTest::GenerateOnCaptureCompleted() { |
| 115 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); | 114 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); |
| 116 data_->mutable_dirty_region().op(update_region, SkRegion::kUnion_Op); | 115 data_->mutable_dirty_region().op(update_region, SkRegion::kUnion_Op); |
| 117 | 116 |
| 118 scheduler_->OnCaptureCompleted(data_); | 117 scheduler_->OnCaptureCompleted(data_); |
| 119 } | 118 } |
| 120 | 119 |
| 121 // This test mocks capturer, encoder and network layer to simulate one capture | 120 // This test mocks capturer, encoder and network layer to simulate one capture |
| 122 // cycle. When the first encoded packet is submitted to the network | 121 // cycle. When the first encoded packet is submitted to the network |
| 123 // VideoScheduler is instructed to come to a complete stop. We expect the stop | 122 // VideoScheduler is instructed to come to a complete stop. We expect the stop |
| 124 // sequence to be executed successfully. | 123 // sequence to be executed successfully. |
| 125 TEST_F(VideoSchedulerTest, StartAndStop) { | 124 TEST_F(VideoSchedulerTest, StartAndStop) { |
| 126 Expectation capturer_start = EXPECT_CALL(capturer_, Start(_)); | 125 Expectation capturer_start = EXPECT_CALL(capturer_, Start(_)); |
| 127 | 126 |
| 128 size_.set(kWidth, kHeight); | 127 data_ = new CaptureData(NULL, kWidth * CaptureData::kBytesPerPixel, |
| 129 data_ = new CaptureData(NULL, kWidth * CaptureData::kBytesPerPixel, size_); | 128 SkISize::Make(kWidth, kHeight)); |
| 130 | 129 |
| 131 // Create a RunLoop through which to drive |message_loop_|. | 130 // Create a RunLoop through which to drive |message_loop_|. |
| 132 base::RunLoop run_loop; | 131 base::RunLoop run_loop; |
| 133 | 132 |
| 134 EXPECT_CALL(capturer_, size_most_recent()) | |
| 135 .WillRepeatedly(ReturnRef(size_)); | |
| 136 | |
| 137 // First the capturer is called. | 133 // First the capturer is called. |
| 138 Expectation capturer_capture = EXPECT_CALL(capturer_, CaptureFrame()) | 134 Expectation capturer_capture = EXPECT_CALL(capturer_, CaptureFrame()) |
| 139 .After(capturer_start) | 135 .After(capturer_start) |
| 140 .WillRepeatedly(InvokeWithoutArgs( | 136 .WillRepeatedly(InvokeWithoutArgs( |
| 141 this, &VideoSchedulerTest::GenerateOnCaptureCompleted)); | 137 this, &VideoSchedulerTest::GenerateOnCaptureCompleted)); |
| 142 | 138 |
| 143 // Expect the encoder be called. | 139 // Expect the encoder be called. |
| 144 EXPECT_CALL(*encoder_, Encode(data_, false, _)) | 140 EXPECT_CALL(*encoder_, Encode(data_, false, _)) |
| 145 .WillRepeatedly(FinishEncode()); | 141 .WillRepeatedly(FinishEncode()); |
| 146 | 142 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 158 | 154 |
| 159 EXPECT_CALL(capturer_, Stop()) | 155 EXPECT_CALL(capturer_, Stop()) |
| 160 .After(capturer_capture); | 156 .After(capturer_capture); |
| 161 | 157 |
| 162 // Start video frame capture. | 158 // Start video frame capture. |
| 163 StartVideoScheduler(); | 159 StartVideoScheduler(); |
| 164 run_loop.Run(); | 160 run_loop.Run(); |
| 165 } | 161 } |
| 166 | 162 |
| 167 } // namespace remoting | 163 } // namespace remoting |
| OLD | NEW |