Chromium Code Reviews| 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/session_manager.h" | 9 #include "remoting/host/screen_recorder.h" |
| 10 #include "remoting/proto/video.pb.h" | 10 #include "remoting/proto/video.pb.h" |
| 11 #include "remoting/protocol/mock_objects.h" | 11 #include "remoting/protocol/mock_objects.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 using ::remoting::protocol::MockConnectionToClient; | 15 using ::remoting::protocol::MockConnectionToClient; |
| 16 | 16 |
| 17 using ::testing::_; | 17 using ::testing::_; |
| 18 using ::testing::AtLeast; | 18 using ::testing::AtLeast; |
| 19 using ::testing::NotNull; | 19 using ::testing::NotNull; |
| 20 using ::testing::Return; | 20 using ::testing::Return; |
| 21 | 21 |
| 22 namespace remoting { | 22 namespace remoting { |
| 23 | 23 |
| 24 static const int kWidth = 640; | 24 static const int kWidth = 640; |
| 25 static const int kHeight = 480; | 25 static const int kHeight = 480; |
| 26 static const media::VideoFrame::Format kFormat = media::VideoFrame::RGB32; | 26 static const media::VideoFrame::Format kFormat = media::VideoFrame::RGB32; |
| 27 static const VideoPacketFormat::Encoding kEncoding = | 27 static const VideoPacketFormat::Encoding kEncoding = |
| 28 VideoPacketFormat::ENCODING_VERBATIM; | 28 VideoPacketFormat::ENCODING_VERBATIM; |
| 29 | 29 |
| 30 class SessionManagerTest : public testing::Test { | 30 class ScreenRecorderTest : public testing::Test { |
| 31 public: | 31 public: |
| 32 SessionManagerTest() { | 32 ScreenRecorderTest() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 protected: | 35 virtual void SetUp() { |
| 36 void Init() { | |
| 37 capturer_ = new MockCapturer(); | 36 capturer_ = new MockCapturer(); |
|
dmac
2010/11/19 23:24:24
Could you add the comment about ownership here ins
| |
| 38 encoder_ = new MockEncoder(); | 37 encoder_ = new MockEncoder(); |
| 39 connection_ = new MockConnectionToClient(); | 38 connection_ = new MockConnectionToClient(); |
| 40 record_ = new SessionManager( | 39 record_ = new ScreenRecorder( |
| 41 &message_loop_, &message_loop_, &message_loop_, | 40 &message_loop_, &message_loop_, &message_loop_, |
| 42 capturer_, encoder_); | 41 capturer_, encoder_); |
| 43 } | 42 } |
| 44 | 43 |
| 45 scoped_refptr<SessionManager> record_; | 44 protected: |
| 45 scoped_refptr<ScreenRecorder> record_; | |
| 46 scoped_refptr<MockConnectionToClient> connection_; | 46 scoped_refptr<MockConnectionToClient> connection_; |
| 47 | |
| 48 // The following mock objects are owned by ScreenRecorder. | |
| 47 MockCapturer* capturer_; | 49 MockCapturer* capturer_; |
| 48 MockEncoder* encoder_; | 50 MockEncoder* encoder_; |
| 49 MessageLoop message_loop_; | 51 MessageLoop message_loop_; |
| 50 private: | 52 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(SessionManagerTest); | 53 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 TEST_F(SessionManagerTest, Init) { | |
| 55 Init(); | |
| 56 } | |
| 57 | |
| 58 ACTION_P2(RunCallback, rects, data) { | 56 ACTION_P2(RunCallback, rects, data) { |
| 59 InvalidRects& dirty_rects = data->mutable_dirty_rects(); | 57 InvalidRects& dirty_rects = data->mutable_dirty_rects(); |
| 60 InvalidRects temp_rects; | 58 InvalidRects temp_rects; |
| 61 std::set_union(dirty_rects.begin(), dirty_rects.end(), | 59 std::set_union(dirty_rects.begin(), dirty_rects.end(), |
| 62 rects.begin(), rects.end(), | 60 rects.begin(), rects.end(), |
| 63 std::inserter(temp_rects, temp_rects.begin())); | 61 std::inserter(temp_rects, temp_rects.begin())); |
| 64 dirty_rects.swap(temp_rects); | 62 dirty_rects.swap(temp_rects); |
| 65 arg0->Run(data); | 63 arg0->Run(data); |
| 66 delete arg0; | 64 delete arg0; |
| 67 } | 65 } |
| 68 | 66 |
| 69 ACTION_P(FinishEncode, msg) { | 67 ACTION_P(FinishEncode, msg) { |
| 70 arg2->Run(msg); | 68 arg2->Run(msg); |
| 71 delete arg2; | 69 delete arg2; |
| 72 } | 70 } |
| 73 | 71 |
| 74 // BUG 57351 | 72 TEST_F(ScreenRecorderTest, OneRecordCycle) { |
| 75 TEST_F(SessionManagerTest, DISABLED_OneRecordCycle) { | |
| 76 Init(); | |
| 77 | |
| 78 InvalidRects update_rects; | 73 InvalidRects update_rects; |
| 79 update_rects.insert(gfx::Rect(0, 0, 10, 10)); | 74 update_rects.insert(gfx::Rect(0, 0, 10, 10)); |
| 80 DataPlanes planes; | 75 DataPlanes planes; |
| 81 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | 76 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
| 82 planes.data[i] = reinterpret_cast<uint8*>(i); | 77 planes.data[i] = reinterpret_cast<uint8*>(i); |
| 83 planes.strides[i] = kWidth * 4; | 78 planes.strides[i] = kWidth * 4; |
| 84 } | 79 } |
| 85 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, | 80 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, |
| 86 kHeight, kFormat)); | 81 kHeight, kFormat)); |
| 87 // Set the recording rate to very low to avoid capture twice. | 82 // Set the recording rate to very low to avoid capture twice. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 112 | 107 |
| 113 // Make sure all tasks are completed. | 108 // Make sure all tasks are completed. |
| 114 message_loop_.RunAllPending(); | 109 message_loop_.RunAllPending(); |
| 115 } | 110 } |
| 116 | 111 |
| 117 // TODO(hclam): Add test for double buffering. | 112 // TODO(hclam): Add test for double buffering. |
| 118 // TODO(hclam): Add test for multiple captures. | 113 // TODO(hclam): Add test for multiple captures. |
| 119 // TODO(hclam): Add test for interruption. | 114 // TODO(hclam): Add test for interruption. |
| 120 | 115 |
| 121 } // namespace remoting | 116 } // namespace remoting |
| OLD | NEW |