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

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

Issue 11363128: Converted VideoFrameCapturer callbacks into a VideoFrameCapturer::Delegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
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_frame_capturer.h" 5 #include "remoting/host/video_frame_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/base/capture_data.h" 11 #include "remoting/base/capture_data.h"
12 #include "remoting/host/host_mock_objects.h" 12 #include "remoting/host/host_mock_objects.h"
13 #include "remoting/protocol/protocol_mock_objects.h" 13 #include "remoting/protocol/protocol_mock_objects.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::_;
18
17 namespace remoting { 19 namespace remoting {
18 20
19 namespace { 21 namespace {
20 22
21 void IgnoreCursorShapeChanged(scoped_ptr<protocol::CursorShapeInfo> info) { 23 class MockCapturerDelegate : public VideoFrameCapturer::Delegate {
24 public:
25 MockCapturerDelegate();
26 virtual ~MockCapturerDelegate();
27
28 virtual void OnCursorShapeChanged(
29 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) OVERRIDE;
30
31 MOCK_METHOD1(OnCaptureCompleted, void(scoped_refptr<CaptureData>));
32 MOCK_METHOD1(OnCursorShapeChangedPtr, void(protocol::CursorShapeInfo*));
33
34 private:
35 DISALLOW_COPY_AND_ASSIGN(MockCapturerDelegate);
36 };
37
38 MockCapturerDelegate::MockCapturerDelegate() {
39 }
40
41 MockCapturerDelegate::~MockCapturerDelegate() {
42 }
43
44 void MockCapturerDelegate::OnCursorShapeChanged(
45 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) {
46 // Notify the mock method.
47 OnCursorShapeChangedPtr(cursor_shape.get());
22 } 48 }
23 49
24 } // namespace 50 } // namespace
25 51
26 MATCHER(DirtyRegionIsNonEmptyRect, "") { 52 MATCHER(DirtyRegionIsNonEmptyRect, "") {
27 const SkRegion& dirty_region = arg->dirty_region(); 53 const SkRegion& dirty_region = arg->dirty_region();
28 const SkIRect& dirty_region_bounds = dirty_region.getBounds(); 54 const SkIRect& dirty_region_bounds = dirty_region.getBounds();
29 if (dirty_region_bounds.isEmpty()) { 55 if (dirty_region_bounds.isEmpty()) {
30 return false; 56 return false;
31 } 57 }
32 return dirty_region == SkRegion(dirty_region_bounds); 58 return dirty_region == SkRegion(dirty_region_bounds);
33 } 59 }
34 60
35 class VideoFrameCapturerTest : public testing::Test { 61 class VideoFrameCapturerTest : public testing::Test {
36 protected: 62 protected:
37 virtual void SetUp() OVERRIDE { 63 virtual void SetUp() OVERRIDE {
38 capturer_.reset(VideoFrameCapturer::Create()); 64 capturer_.reset(VideoFrameCapturer::Create());
39 } 65 }
40 66
41 scoped_ptr<VideoFrameCapturer> capturer_; 67 scoped_ptr<VideoFrameCapturer> capturer_;
42 MockCaptureCompletedCallback capture_completed_callback_; 68 MockCapturerDelegate delegate_;
43 }; 69 };
44 70
45 TEST_F(VideoFrameCapturerTest, StartCapturer) { 71 TEST_F(VideoFrameCapturerTest, StartCapturer) {
46 capturer_->Start(base::Bind(&IgnoreCursorShapeChanged)); 72 capturer_->Start(&delegate_);
47 capturer_->Stop(); 73 capturer_->Stop();
48 } 74 }
49 75
50 TEST_F(VideoFrameCapturerTest, Capture) { 76 TEST_F(VideoFrameCapturerTest, Capture) {
51 // Assume that Start() treats the screen as invalid initially. 77 // Assume that Start() treats the screen as invalid initially.
52 EXPECT_CALL(capture_completed_callback_, 78 EXPECT_CALL(delegate_,
53 CaptureCompletedPtr(DirtyRegionIsNonEmptyRect())); 79 OnCaptureCompleted(DirtyRegionIsNonEmptyRect()));
80 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_));
54 81
55 capturer_->Start(base::Bind(&IgnoreCursorShapeChanged)); 82 capturer_->Start(&delegate_);
56 capturer_->CaptureInvalidRegion(base::Bind( 83 capturer_->CaptureInvalidRegion();
57 &MockCaptureCompletedCallback::CaptureCompleted,
58 base::Unretained(&capture_completed_callback_)));
59 capturer_->Stop(); 84 capturer_->Stop();
60 } 85 }
61 86
62 } // namespace remoting 87 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698