Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1250)

Side by Side Diff: remoting/host/video_frame_capturer_unittest.cc

Issue 11470028: Move screen capturers to remoting/capturer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/host/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/base/capture_data.h"
12 #include "remoting/base/shared_buffer_factory.h"
13 #include "remoting/host/host_mock_objects.h"
14 #include "remoting/protocol/protocol_mock_objects.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 using ::testing::_;
19 using ::testing::AnyNumber;
20
21 namespace remoting {
22
23 class MockSharedBufferFactory : public SharedBufferFactory {
24 public:
25 MockSharedBufferFactory() {}
26 virtual ~MockSharedBufferFactory() {}
27
28 MOCK_METHOD1(CreateSharedBuffer, scoped_refptr<SharedBuffer>(uint32));
29 MOCK_METHOD1(ReleaseSharedBuffer, void(scoped_refptr<SharedBuffer>));
30
31 private:
32 DISALLOW_COPY_AND_ASSIGN(MockSharedBufferFactory);
33 };
34
35 MATCHER(DirtyRegionIsNonEmptyRect, "") {
36 const SkRegion& dirty_region = arg->dirty_region();
37 const SkIRect& dirty_region_bounds = dirty_region.getBounds();
38 if (dirty_region_bounds.isEmpty()) {
39 return false;
40 }
41 return dirty_region == SkRegion(dirty_region_bounds);
42 }
43
44 class VideoFrameCapturerTest : public testing::Test {
45 public:
46 scoped_refptr<SharedBuffer> CreateSharedBuffer(uint32 size);
47
48 protected:
49 scoped_ptr<VideoFrameCapturer> capturer_;
50 MockSharedBufferFactory shared_buffer_factory_;
51 MockVideoFrameCapturerDelegate delegate_;
52 };
53
54 scoped_refptr<SharedBuffer> VideoFrameCapturerTest::CreateSharedBuffer(
55 uint32 size) {
56 return scoped_refptr<SharedBuffer>(new SharedBuffer(size));
57 }
58
59 TEST_F(VideoFrameCapturerTest, StartCapturer) {
60 capturer_ = VideoFrameCapturer::Create();
61 capturer_->Start(&delegate_);
62 capturer_->Stop();
63 }
64
65 TEST_F(VideoFrameCapturerTest, Capture) {
66 // Assume that Start() treats the screen as invalid initially.
67 EXPECT_CALL(delegate_,
68 OnCaptureCompleted(DirtyRegionIsNonEmptyRect()));
69 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_))
70 .Times(AnyNumber());
71
72 capturer_ = VideoFrameCapturer::Create();
73 capturer_->Start(&delegate_);
74 capturer_->CaptureFrame();
75 capturer_->Stop();
76 }
77
78 #if defined(OS_WIN)
79
80 TEST_F(VideoFrameCapturerTest, UseSharedBuffers) {
81 EXPECT_CALL(delegate_,
82 OnCaptureCompleted(DirtyRegionIsNonEmptyRect()));
83 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_))
84 .Times(AnyNumber());
85
86 EXPECT_CALL(shared_buffer_factory_, CreateSharedBuffer(_))
87 .Times(1)
88 .WillOnce(Invoke(this, &VideoFrameCapturerTest::CreateSharedBuffer));
89 EXPECT_CALL(shared_buffer_factory_, ReleaseSharedBuffer(_))
90 .Times(1);
91
92 capturer_ = VideoFrameCapturer::CreateWithFactory(&shared_buffer_factory_);
93 capturer_->Start(&delegate_);
94 capturer_->CaptureFrame();
95 capturer_->Stop();
96 capturer_.reset();
97 }
98
99 #endif // defined(OS_WIN)
100
101 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698