| 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 #if defined(THREAD_SANITIZER) | |
| 65 // ThreadSanitizer v2 reports a use-after-free, see http://crbug.com/163641. | |
| 66 #define MAYBE_Capture DISABLED_Capture | |
| 67 #else | |
| 68 #define MAYBE_Capture Capture | |
| 69 #endif | |
| 70 TEST_F(VideoFrameCapturerTest, MAYBE_Capture) { | |
| 71 // Assume that Start() treats the screen as invalid initially. | |
| 72 EXPECT_CALL(delegate_, | |
| 73 OnCaptureCompleted(DirtyRegionIsNonEmptyRect())); | |
| 74 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) | |
| 75 .Times(AnyNumber()); | |
| 76 | |
| 77 capturer_ = VideoFrameCapturer::Create(); | |
| 78 capturer_->Start(&delegate_); | |
| 79 capturer_->CaptureFrame(); | |
| 80 capturer_->Stop(); | |
| 81 } | |
| 82 | |
| 83 #if defined(OS_WIN) | |
| 84 | |
| 85 TEST_F(VideoFrameCapturerTest, UseSharedBuffers) { | |
| 86 EXPECT_CALL(delegate_, | |
| 87 OnCaptureCompleted(DirtyRegionIsNonEmptyRect())); | |
| 88 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_)) | |
| 89 .Times(AnyNumber()); | |
| 90 | |
| 91 EXPECT_CALL(shared_buffer_factory_, CreateSharedBuffer(_)) | |
| 92 .Times(1) | |
| 93 .WillOnce(Invoke(this, &VideoFrameCapturerTest::CreateSharedBuffer)); | |
| 94 EXPECT_CALL(shared_buffer_factory_, ReleaseSharedBuffer(_)) | |
| 95 .Times(1); | |
| 96 | |
| 97 capturer_ = VideoFrameCapturer::CreateWithFactory(&shared_buffer_factory_); | |
| 98 capturer_->Start(&delegate_); | |
| 99 capturer_->CaptureFrame(); | |
| 100 capturer_->Stop(); | |
| 101 capturer_.reset(); | |
| 102 } | |
| 103 | |
| 104 #endif // defined(OS_WIN) | |
| 105 | |
| 106 } // namespace remoting | |
| OLD | NEW |