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/capturer/video_frame_capturer.h" | 5 #include "media/video/capture/screen/screen_capturer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #if defined(OS_MACOSX) | 8 #if defined(OS_MACOSX) |
9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #endif // defined(OS_MACOSX) | 10 #endif // defined(OS_MACOSX) |
11 #include "remoting/capturer/capture_data.h" | 11 #include "media/video/capture/screen/screen_capture_data.h" |
12 #include "remoting/capturer/shared_buffer_factory.h" | 12 #include "media/video/capture/screen/screen_capturer_mock_objects.h" |
13 #include "remoting/capturer/video_capturer_mock_objects.h" | 13 #include "media/video/capture/screen/shared_buffer_factory.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 ::testing::_; | 17 using ::testing::_; |
18 using ::testing::AnyNumber; | 18 using ::testing::AnyNumber; |
19 | 19 |
20 namespace remoting { | 20 namespace media { |
21 | 21 |
22 class MockSharedBufferFactory : public SharedBufferFactory { | 22 class MockSharedBufferFactory : public SharedBufferFactory { |
23 public: | 23 public: |
24 MockSharedBufferFactory() {} | 24 MockSharedBufferFactory() {} |
25 virtual ~MockSharedBufferFactory() {} | 25 virtual ~MockSharedBufferFactory() {} |
26 | 26 |
27 MOCK_METHOD1(CreateSharedBuffer, scoped_refptr<SharedBuffer>(uint32)); | 27 MOCK_METHOD1(CreateSharedBuffer, scoped_refptr<SharedBuffer>(uint32)); |
28 MOCK_METHOD1(ReleaseSharedBuffer, void(scoped_refptr<SharedBuffer>)); | 28 MOCK_METHOD1(ReleaseSharedBuffer, void(scoped_refptr<SharedBuffer>)); |
29 | 29 |
30 private: | 30 private: |
31 DISALLOW_COPY_AND_ASSIGN(MockSharedBufferFactory); | 31 DISALLOW_COPY_AND_ASSIGN(MockSharedBufferFactory); |
32 }; | 32 }; |
33 | 33 |
34 MATCHER(DirtyRegionIsNonEmptyRect, "") { | 34 MATCHER(DirtyRegionIsNonEmptyRect, "") { |
35 const SkRegion& dirty_region = arg->dirty_region(); | 35 const SkRegion& dirty_region = arg->dirty_region(); |
36 const SkIRect& dirty_region_bounds = dirty_region.getBounds(); | 36 const SkIRect& dirty_region_bounds = dirty_region.getBounds(); |
37 if (dirty_region_bounds.isEmpty()) { | 37 if (dirty_region_bounds.isEmpty()) { |
38 return false; | 38 return false; |
39 } | 39 } |
40 return dirty_region == SkRegion(dirty_region_bounds); | 40 return dirty_region == SkRegion(dirty_region_bounds); |
41 } | 41 } |
42 | 42 |
43 class VideoFrameCapturerTest : public testing::Test { | 43 class ScreenCapturerTest : public testing::Test { |
44 public: | 44 public: |
45 scoped_refptr<SharedBuffer> CreateSharedBuffer(uint32 size); | 45 scoped_refptr<SharedBuffer> CreateSharedBuffer(uint32 size); |
46 | 46 |
47 protected: | 47 protected: |
48 scoped_ptr<VideoFrameCapturer> capturer_; | 48 scoped_ptr<ScreenCapturer> capturer_; |
49 MockSharedBufferFactory shared_buffer_factory_; | 49 MockSharedBufferFactory shared_buffer_factory_; |
50 MockVideoFrameCapturerDelegate delegate_; | 50 MockScreenCapturerDelegate delegate_; |
51 }; | 51 }; |
52 | 52 |
53 scoped_refptr<SharedBuffer> VideoFrameCapturerTest::CreateSharedBuffer( | 53 scoped_refptr<SharedBuffer> ScreenCapturerTest::CreateSharedBuffer( |
54 uint32 size) { | 54 uint32 size) { |
55 return scoped_refptr<SharedBuffer>(new SharedBuffer(size)); | 55 return scoped_refptr<SharedBuffer>(new SharedBuffer(size)); |
56 } | 56 } |
57 | 57 |
58 TEST_F(VideoFrameCapturerTest, StartCapturer) { | 58 TEST_F(ScreenCapturerTest, StartCapturer) { |
59 capturer_ = VideoFrameCapturer::Create(); | 59 capturer_ = ScreenCapturer::Create(); |
60 capturer_->Start(&delegate_); | 60 capturer_->Start(&delegate_); |
61 capturer_->Stop(); | 61 capturer_->Stop(); |
62 } | 62 } |
63 | 63 |
64 TEST_F(VideoFrameCapturerTest, Capture) { | 64 TEST_F(ScreenCapturerTest, Capture) { |
65 // Assume that Start() treats the screen as invalid initially. | 65 // Assume that Start() treats the screen as invalid initially. |
66 EXPECT_CALL(delegate_, | 66 EXPECT_CALL(delegate_, |
67 OnCaptureCompleted(DirtyRegionIsNonEmptyRect())); | 67 OnCaptureCompleted(DirtyRegionIsNonEmptyRect())); |
68 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) | 68 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) |
69 .Times(AnyNumber()); | 69 .Times(AnyNumber()); |
70 | 70 |
71 capturer_ = VideoFrameCapturer::Create(); | 71 capturer_ = ScreenCapturer::Create(); |
72 capturer_->Start(&delegate_); | 72 capturer_->Start(&delegate_); |
73 capturer_->CaptureFrame(); | 73 capturer_->CaptureFrame(); |
74 capturer_->Stop(); | 74 capturer_->Stop(); |
75 } | 75 } |
76 | 76 |
77 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
78 | 78 |
79 TEST_F(VideoFrameCapturerTest, UseSharedBuffers) { | 79 TEST_F(ScreenCapturerTest, UseSharedBuffers) { |
80 EXPECT_CALL(delegate_, | 80 EXPECT_CALL(delegate_, |
81 OnCaptureCompleted(DirtyRegionIsNonEmptyRect())); | 81 OnCaptureCompleted(DirtyRegionIsNonEmptyRect())); |
82 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) | 82 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) |
83 .Times(AnyNumber()); | 83 .Times(AnyNumber()); |
84 | 84 |
85 EXPECT_CALL(shared_buffer_factory_, CreateSharedBuffer(_)) | 85 EXPECT_CALL(shared_buffer_factory_, CreateSharedBuffer(_)) |
86 .Times(1) | 86 .Times(1) |
87 .WillOnce(Invoke(this, &VideoFrameCapturerTest::CreateSharedBuffer)); | 87 .WillOnce(Invoke(this, &ScreenCapturerTest::CreateSharedBuffer)); |
88 EXPECT_CALL(shared_buffer_factory_, ReleaseSharedBuffer(_)) | 88 EXPECT_CALL(shared_buffer_factory_, ReleaseSharedBuffer(_)) |
89 .Times(1); | 89 .Times(1); |
90 | 90 |
91 capturer_ = VideoFrameCapturer::CreateWithFactory(&shared_buffer_factory_); | 91 capturer_ = ScreenCapturer::CreateWithFactory(&shared_buffer_factory_); |
92 capturer_->Start(&delegate_); | 92 capturer_->Start(&delegate_); |
93 capturer_->CaptureFrame(); | 93 capturer_->CaptureFrame(); |
94 capturer_->Stop(); | 94 capturer_->Stop(); |
95 capturer_.reset(); | 95 capturer_.reset(); |
96 } | 96 } |
97 | 97 |
98 #endif // defined(OS_WIN) | 98 #endif // defined(OS_WIN) |
99 | 99 |
100 } // namespace remoting | 100 } // namespace media |
OLD | NEW |