| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "webrtc/modules/desktop_capture/screen_capturer.h" | 13 #include "webrtc/modules/desktop_capture/screen_capturer.h" |
| 14 | 14 |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webrtc/base/constructormagic.h" | 17 #include "webrtc/base/constructormagic.h" |
| 18 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 18 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
| 19 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 19 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 20 #include "webrtc/modules/desktop_capture/desktop_region.h" | 20 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 21 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" | 21 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" |
| 22 | 22 |
| 23 using ::testing::_; | 23 using ::testing::_; |
| 24 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
| 25 using ::testing::Return; | 25 using ::testing::Return; |
| 26 using ::testing::SaveArg; | |
| 27 | 26 |
| 28 const int kTestSharedMemoryId = 123; | 27 const int kTestSharedMemoryId = 123; |
| 29 | 28 |
| 30 namespace webrtc { | 29 namespace webrtc { |
| 31 | 30 |
| 32 class ScreenCapturerTest : public testing::Test { | 31 class ScreenCapturerTest : public testing::Test { |
| 33 public: | 32 public: |
| 34 void SetUp() override { | 33 void SetUp() override { |
| 35 capturer_.reset( | 34 capturer_.reset( |
| 36 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); | 35 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 62 | 61 |
| 63 std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) override { | 62 std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) override { |
| 64 return std::unique_ptr<SharedMemory>( | 63 return std::unique_ptr<SharedMemory>( |
| 65 new FakeSharedMemory(new char[size], size)); | 64 new FakeSharedMemory(new char[size], size)); |
| 66 } | 65 } |
| 67 | 66 |
| 68 private: | 67 private: |
| 69 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); | 68 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); |
| 70 }; | 69 }; |
| 71 | 70 |
| 71 ACTION_P(SaveUniquePtrArg, dest) { |
| 72 *dest = std::move(*arg0); |
| 73 } |
| 74 |
| 72 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { | 75 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { |
| 73 webrtc::ScreenCapturer::ScreenList screens; | 76 webrtc::ScreenCapturer::ScreenList screens; |
| 74 EXPECT_TRUE(capturer_->GetScreenList(&screens)); | 77 EXPECT_TRUE(capturer_->GetScreenList(&screens)); |
| 75 for(webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); | 78 for(webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); |
| 76 it != screens.end(); ++it) { | 79 it != screens.end(); ++it) { |
| 77 EXPECT_TRUE(capturer_->SelectScreen(it->id)); | 80 EXPECT_TRUE(capturer_->SelectScreen(it->id)); |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 | 83 |
| 81 TEST_F(ScreenCapturerTest, StartCapturer) { | 84 TEST_F(ScreenCapturerTest, StartCapturer) { |
| 82 capturer_->Start(&callback_); | 85 capturer_->Start(&callback_); |
| 83 } | 86 } |
| 84 | 87 |
| 85 TEST_F(ScreenCapturerTest, Capture) { | 88 TEST_F(ScreenCapturerTest, Capture) { |
| 86 // Assume that Start() treats the screen as invalid initially. | 89 // Assume that Start() treats the screen as invalid initially. |
| 87 DesktopFrame* frame = NULL; | 90 std::unique_ptr<DesktopFrame> frame; |
| 88 EXPECT_CALL(callback_, OnCaptureCompleted(_)) | 91 EXPECT_CALL(callback_, OnCaptureCompletedPtr(_)) |
| 89 .WillOnce(SaveArg<0>(&frame)); | 92 .WillOnce(SaveUniquePtrArg(&frame)); |
| 90 | 93 |
| 91 capturer_->Start(&callback_); | 94 capturer_->Start(&callback_); |
| 92 capturer_->Capture(DesktopRegion()); | 95 capturer_->Capture(DesktopRegion()); |
| 93 | 96 |
| 94 ASSERT_TRUE(frame); | 97 ASSERT_TRUE(frame); |
| 95 EXPECT_GT(frame->size().width(), 0); | 98 EXPECT_GT(frame->size().width(), 0); |
| 96 EXPECT_GT(frame->size().height(), 0); | 99 EXPECT_GT(frame->size().height(), 0); |
| 97 EXPECT_GE(frame->stride(), | 100 EXPECT_GE(frame->stride(), |
| 98 frame->size().width() * DesktopFrame::kBytesPerPixel); | 101 frame->size().width() * DesktopFrame::kBytesPerPixel); |
| 99 EXPECT_TRUE(frame->shared_memory() == NULL); | 102 EXPECT_TRUE(frame->shared_memory() == NULL); |
| 100 | 103 |
| 101 // Verify that the region contains whole screen. | 104 // Verify that the region contains whole screen. |
| 102 EXPECT_FALSE(frame->updated_region().is_empty()); | 105 EXPECT_FALSE(frame->updated_region().is_empty()); |
| 103 DesktopRegion::Iterator it(frame->updated_region()); | 106 DesktopRegion::Iterator it(frame->updated_region()); |
| 104 ASSERT_TRUE(!it.IsAtEnd()); | 107 ASSERT_TRUE(!it.IsAtEnd()); |
| 105 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); | 108 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); |
| 106 it.Advance(); | 109 it.Advance(); |
| 107 EXPECT_TRUE(it.IsAtEnd()); | 110 EXPECT_TRUE(it.IsAtEnd()); |
| 108 | |
| 109 delete frame; | |
| 110 } | 111 } |
| 111 | 112 |
| 112 #if defined(WEBRTC_WIN) | 113 #if defined(WEBRTC_WIN) |
| 113 | 114 |
| 114 TEST_F(ScreenCapturerTest, UseSharedBuffers) { | 115 TEST_F(ScreenCapturerTest, UseSharedBuffers) { |
| 115 DesktopFrame* frame = NULL; | 116 std::unique_ptr<DesktopFrame> frame; |
| 116 EXPECT_CALL(callback_, OnCaptureCompleted(_)) | 117 EXPECT_CALL(callback_, OnCaptureCompleted(_)) |
| 117 .WillOnce(SaveArg<0>(&frame)); | 118 .WillOnce(SaveUniquePtrArg(&frame)); |
| 118 | 119 |
| 119 capturer_->Start(&callback_); | 120 capturer_->Start(&callback_); |
| 120 capturer_->SetSharedMemoryFactory( | 121 capturer_->SetSharedMemoryFactory( |
| 121 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); | 122 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); |
| 122 capturer_->Capture(DesktopRegion()); | 123 capturer_->Capture(DesktopRegion()); |
| 123 | 124 |
| 124 ASSERT_TRUE(frame); | 125 ASSERT_TRUE(frame); |
| 125 ASSERT_TRUE(frame->shared_memory()); | 126 ASSERT_TRUE(frame->shared_memory()); |
| 126 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); | 127 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
| 127 | |
| 128 delete frame; | |
| 129 } | 128 } |
| 130 | 129 |
| 131 TEST_F(ScreenCapturerTest, UseMagnifier) { | 130 TEST_F(ScreenCapturerTest, UseMagnifier) { |
| 132 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 131 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
| 133 options.set_allow_use_magnification_api(true); | 132 options.set_allow_use_magnification_api(true); |
| 134 capturer_.reset(ScreenCapturer::Create(options)); | 133 capturer_.reset(ScreenCapturer::Create(options)); |
| 135 | 134 |
| 136 DesktopFrame* frame = NULL; | 135 std::unique_ptr<DesktopFrame> frame; |
| 137 EXPECT_CALL(callback_, OnCaptureCompleted(_)).WillOnce(SaveArg<0>(&frame)); | 136 EXPECT_CALL(callback_, OnCaptureCompleted(_)) |
| 137 .WillOnce(SaveUniquePtrArg(&frame)); |
| 138 | 138 |
| 139 capturer_->Start(&callback_); | 139 capturer_->Start(&callback_); |
| 140 capturer_->Capture(DesktopRegion()); | 140 capturer_->Capture(DesktopRegion()); |
| 141 ASSERT_TRUE(frame); | 141 ASSERT_TRUE(frame); |
| 142 delete frame; | |
| 143 } | 142 } |
| 144 | 143 |
| 145 #endif // defined(WEBRTC_WIN) | 144 #endif // defined(WEBRTC_WIN) |
| 146 | 145 |
| 147 } // namespace webrtc | 146 } // namespace webrtc |
| OLD | NEW |