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...) 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(*arg1); |
| 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_, |
89 .WillOnce(SaveArg<0>(&frame)); | 92 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 93 .WillOnce(SaveUniquePtrArg(&frame)); |
90 | 94 |
91 capturer_->Start(&callback_); | 95 capturer_->Start(&callback_); |
92 capturer_->Capture(DesktopRegion()); | 96 capturer_->Capture(DesktopRegion()); |
93 | 97 |
94 ASSERT_TRUE(frame); | 98 ASSERT_TRUE(frame); |
95 EXPECT_GT(frame->size().width(), 0); | 99 EXPECT_GT(frame->size().width(), 0); |
96 EXPECT_GT(frame->size().height(), 0); | 100 EXPECT_GT(frame->size().height(), 0); |
97 EXPECT_GE(frame->stride(), | 101 EXPECT_GE(frame->stride(), |
98 frame->size().width() * DesktopFrame::kBytesPerPixel); | 102 frame->size().width() * DesktopFrame::kBytesPerPixel); |
99 EXPECT_TRUE(frame->shared_memory() == NULL); | 103 EXPECT_TRUE(frame->shared_memory() == NULL); |
100 | 104 |
101 // Verify that the region contains whole screen. | 105 // Verify that the region contains whole screen. |
102 EXPECT_FALSE(frame->updated_region().is_empty()); | 106 EXPECT_FALSE(frame->updated_region().is_empty()); |
103 DesktopRegion::Iterator it(frame->updated_region()); | 107 DesktopRegion::Iterator it(frame->updated_region()); |
104 ASSERT_TRUE(!it.IsAtEnd()); | 108 ASSERT_TRUE(!it.IsAtEnd()); |
105 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); | 109 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); |
106 it.Advance(); | 110 it.Advance(); |
107 EXPECT_TRUE(it.IsAtEnd()); | 111 EXPECT_TRUE(it.IsAtEnd()); |
108 | |
109 delete frame; | |
110 } | 112 } |
111 | 113 |
112 #if defined(WEBRTC_WIN) | 114 #if defined(WEBRTC_WIN) |
113 | 115 |
114 TEST_F(ScreenCapturerTest, UseSharedBuffers) { | 116 TEST_F(ScreenCapturerTest, UseSharedBuffers) { |
115 DesktopFrame* frame = NULL; | 117 std::unique_ptr<DesktopFrame> frame; |
116 EXPECT_CALL(callback_, OnCaptureCompleted(_)) | 118 EXPECT_CALL(callback_, |
117 .WillOnce(SaveArg<0>(&frame)); | 119 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 120 .WillOnce(SaveUniquePtrArg(&frame)); |
118 | 121 |
119 capturer_->Start(&callback_); | 122 capturer_->Start(&callback_); |
120 capturer_->SetSharedMemoryFactory( | 123 capturer_->SetSharedMemoryFactory( |
121 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); | 124 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); |
122 capturer_->Capture(DesktopRegion()); | 125 capturer_->Capture(DesktopRegion()); |
123 | 126 |
124 ASSERT_TRUE(frame); | 127 ASSERT_TRUE(frame); |
125 ASSERT_TRUE(frame->shared_memory()); | 128 ASSERT_TRUE(frame->shared_memory()); |
126 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); | 129 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
127 | |
128 delete frame; | |
129 } | 130 } |
130 | 131 |
131 TEST_F(ScreenCapturerTest, UseMagnifier) { | 132 TEST_F(ScreenCapturerTest, UseMagnifier) { |
132 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 133 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
133 options.set_allow_use_magnification_api(true); | 134 options.set_allow_use_magnification_api(true); |
134 capturer_.reset(ScreenCapturer::Create(options)); | 135 capturer_.reset(ScreenCapturer::Create(options)); |
135 | 136 |
136 DesktopFrame* frame = NULL; | 137 std::unique_ptr<DesktopFrame> frame; |
137 EXPECT_CALL(callback_, OnCaptureCompleted(_)).WillOnce(SaveArg<0>(&frame)); | 138 EXPECT_CALL(callback_, |
| 139 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 140 .WillOnce(SaveUniquePtrArg(&frame)); |
138 | 141 |
139 capturer_->Start(&callback_); | 142 capturer_->Start(&callback_); |
140 capturer_->Capture(DesktopRegion()); | 143 capturer_->Capture(DesktopRegion()); |
141 ASSERT_TRUE(frame); | 144 ASSERT_TRUE(frame); |
142 delete frame; | |
143 } | 145 } |
144 | 146 |
145 #endif // defined(WEBRTC_WIN) | 147 #endif // defined(WEBRTC_WIN) |
146 | 148 |
147 } // namespace webrtc | 149 } // namespace webrtc |
OLD | NEW |