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; |
26 | 27 |
27 const int kTestSharedMemoryId = 123; | 28 const int kTestSharedMemoryId = 123; |
28 | 29 |
29 namespace webrtc { | 30 namespace webrtc { |
30 | 31 |
31 class ScreenCapturerTest : public testing::Test { | 32 class ScreenCapturerTest : public testing::Test { |
32 public: | 33 public: |
33 void SetUp() override { | 34 void SetUp() override { |
34 capturer_.reset( | 35 capturer_.reset( |
35 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); | 36 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); |
(...skipping 25 matching lines...) Expand all Loading... |
61 | 62 |
62 std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) override { | 63 std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) override { |
63 return std::unique_ptr<SharedMemory>( | 64 return std::unique_ptr<SharedMemory>( |
64 new FakeSharedMemory(new char[size], size)); | 65 new FakeSharedMemory(new char[size], size)); |
65 } | 66 } |
66 | 67 |
67 private: | 68 private: |
68 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); | 69 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); |
69 }; | 70 }; |
70 | 71 |
71 ACTION_P(SaveUniquePtrArg, dest) { | |
72 *dest = std::move(*arg1); | |
73 } | |
74 | |
75 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { | 72 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { |
76 webrtc::ScreenCapturer::ScreenList screens; | 73 webrtc::ScreenCapturer::ScreenList screens; |
77 EXPECT_TRUE(capturer_->GetScreenList(&screens)); | 74 EXPECT_TRUE(capturer_->GetScreenList(&screens)); |
78 for(webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); | 75 for(webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); |
79 it != screens.end(); ++it) { | 76 it != screens.end(); ++it) { |
80 EXPECT_TRUE(capturer_->SelectScreen(it->id)); | 77 EXPECT_TRUE(capturer_->SelectScreen(it->id)); |
81 } | 78 } |
82 } | 79 } |
83 | 80 |
84 TEST_F(ScreenCapturerTest, StartCapturer) { | 81 TEST_F(ScreenCapturerTest, StartCapturer) { |
85 capturer_->Start(&callback_); | 82 capturer_->Start(&callback_); |
86 } | 83 } |
87 | 84 |
88 TEST_F(ScreenCapturerTest, Capture) { | 85 TEST_F(ScreenCapturerTest, Capture) { |
89 // Assume that Start() treats the screen as invalid initially. | 86 // Assume that Start() treats the screen as invalid initially. |
90 std::unique_ptr<DesktopFrame> frame; | 87 DesktopFrame* frame = NULL; |
91 EXPECT_CALL(callback_, | 88 EXPECT_CALL(callback_, OnCaptureCompleted(_)) |
92 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | 89 .WillOnce(SaveArg<0>(&frame)); |
93 .WillOnce(SaveUniquePtrArg(&frame)); | |
94 | 90 |
95 capturer_->Start(&callback_); | 91 capturer_->Start(&callback_); |
96 capturer_->Capture(DesktopRegion()); | 92 capturer_->Capture(DesktopRegion()); |
97 | 93 |
98 ASSERT_TRUE(frame); | 94 ASSERT_TRUE(frame); |
99 EXPECT_GT(frame->size().width(), 0); | 95 EXPECT_GT(frame->size().width(), 0); |
100 EXPECT_GT(frame->size().height(), 0); | 96 EXPECT_GT(frame->size().height(), 0); |
101 EXPECT_GE(frame->stride(), | 97 EXPECT_GE(frame->stride(), |
102 frame->size().width() * DesktopFrame::kBytesPerPixel); | 98 frame->size().width() * DesktopFrame::kBytesPerPixel); |
103 EXPECT_TRUE(frame->shared_memory() == NULL); | 99 EXPECT_TRUE(frame->shared_memory() == NULL); |
104 | 100 |
105 // Verify that the region contains whole screen. | 101 // Verify that the region contains whole screen. |
106 EXPECT_FALSE(frame->updated_region().is_empty()); | 102 EXPECT_FALSE(frame->updated_region().is_empty()); |
107 DesktopRegion::Iterator it(frame->updated_region()); | 103 DesktopRegion::Iterator it(frame->updated_region()); |
108 ASSERT_TRUE(!it.IsAtEnd()); | 104 ASSERT_TRUE(!it.IsAtEnd()); |
109 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); | 105 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); |
110 it.Advance(); | 106 it.Advance(); |
111 EXPECT_TRUE(it.IsAtEnd()); | 107 EXPECT_TRUE(it.IsAtEnd()); |
| 108 |
| 109 delete frame; |
112 } | 110 } |
113 | 111 |
114 #if defined(WEBRTC_WIN) | 112 #if defined(WEBRTC_WIN) |
115 | 113 |
116 TEST_F(ScreenCapturerTest, UseSharedBuffers) { | 114 TEST_F(ScreenCapturerTest, UseSharedBuffers) { |
117 std::unique_ptr<DesktopFrame> frame; | 115 DesktopFrame* frame = NULL; |
118 EXPECT_CALL(callback_, | 116 EXPECT_CALL(callback_, OnCaptureCompleted(_)) |
119 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | 117 .WillOnce(SaveArg<0>(&frame)); |
120 .WillOnce(SaveUniquePtrArg(&frame)); | |
121 | 118 |
122 capturer_->Start(&callback_); | 119 capturer_->Start(&callback_); |
123 capturer_->SetSharedMemoryFactory( | 120 capturer_->SetSharedMemoryFactory( |
124 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); | 121 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); |
125 capturer_->Capture(DesktopRegion()); | 122 capturer_->Capture(DesktopRegion()); |
126 | 123 |
127 ASSERT_TRUE(frame); | 124 ASSERT_TRUE(frame); |
128 ASSERT_TRUE(frame->shared_memory()); | 125 ASSERT_TRUE(frame->shared_memory()); |
129 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); | 126 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
| 127 |
| 128 delete frame; |
130 } | 129 } |
131 | 130 |
132 TEST_F(ScreenCapturerTest, UseMagnifier) { | 131 TEST_F(ScreenCapturerTest, UseMagnifier) { |
133 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 132 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
134 options.set_allow_use_magnification_api(true); | 133 options.set_allow_use_magnification_api(true); |
135 capturer_.reset(ScreenCapturer::Create(options)); | 134 capturer_.reset(ScreenCapturer::Create(options)); |
136 | 135 |
137 std::unique_ptr<DesktopFrame> frame; | 136 DesktopFrame* frame = NULL; |
138 EXPECT_CALL(callback_, | 137 EXPECT_CALL(callback_, OnCaptureCompleted(_)).WillOnce(SaveArg<0>(&frame)); |
139 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | |
140 .WillOnce(SaveUniquePtrArg(&frame)); | |
141 | 138 |
142 capturer_->Start(&callback_); | 139 capturer_->Start(&callback_); |
143 capturer_->Capture(DesktopRegion()); | 140 capturer_->Capture(DesktopRegion()); |
144 ASSERT_TRUE(frame); | 141 ASSERT_TRUE(frame); |
| 142 delete frame; |
145 } | 143 } |
146 | 144 |
147 #endif // defined(WEBRTC_WIN) | 145 #endif // defined(WEBRTC_WIN) |
148 | 146 |
149 } // namespace webrtc | 147 } // namespace webrtc |
OLD | NEW |