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