| 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 #include <utility> |
| 12 | 13 |
| 13 #include "webrtc/modules/desktop_capture/screen_capturer.h" | 14 #include "webrtc/modules/desktop_capture/screen_capturer.h" |
| 14 | 15 |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
| 18 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 19 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
| 19 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 20 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 20 #include "webrtc/modules/desktop_capture/desktop_region.h" | 21 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 21 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" | 22 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); | 69 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 ACTION_P(SaveUniquePtrArg, dest) { | 72 ACTION_P(SaveUniquePtrArg, dest) { |
| 72 *dest = std::move(*arg1); | 73 *dest = std::move(*arg1); |
| 73 } | 74 } |
| 74 | 75 |
| 75 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { | 76 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { |
| 76 webrtc::ScreenCapturer::ScreenList screens; | 77 webrtc::ScreenCapturer::ScreenList screens; |
| 77 EXPECT_TRUE(capturer_->GetScreenList(&screens)); | 78 EXPECT_TRUE(capturer_->GetScreenList(&screens)); |
| 78 for(webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); | 79 for (webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); |
| 79 it != screens.end(); ++it) { | 80 it != screens.end(); ++it) { |
| 80 EXPECT_TRUE(capturer_->SelectScreen(it->id)); | 81 EXPECT_TRUE(capturer_->SelectScreen(it->id)); |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 | 84 |
| 84 TEST_F(ScreenCapturerTest, StartCapturer) { | 85 TEST_F(ScreenCapturerTest, StartCapturer) { |
| 85 capturer_->Start(&callback_); | 86 capturer_->Start(&callback_); |
| 86 } | 87 } |
| 87 | 88 |
| 88 TEST_F(ScreenCapturerTest, Capture) { | 89 TEST_F(ScreenCapturerTest, Capture) { |
| 89 // Assume that Start() treats the screen as invalid initially. | 90 // Assume that Start() treats the screen as invalid initially. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 std::unique_ptr<DesktopFrame> frame; | 138 std::unique_ptr<DesktopFrame> frame; |
| 138 EXPECT_CALL(callback_, | 139 EXPECT_CALL(callback_, |
| 139 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | 140 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 140 .WillOnce(SaveUniquePtrArg(&frame)); | 141 .WillOnce(SaveUniquePtrArg(&frame)); |
| 141 | 142 |
| 142 capturer_->Start(&callback_); | 143 capturer_->Start(&callback_); |
| 143 capturer_->Capture(DesktopRegion()); | 144 capturer_->Capture(DesktopRegion()); |
| 144 ASSERT_TRUE(frame); | 145 ASSERT_TRUE(frame); |
| 145 } | 146 } |
| 146 | 147 |
| 148 TEST_F(ScreenCapturerTest, UseDirectxCapturer) { |
| 149 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
| 150 options.set_allow_directx_capturer(true); |
| 151 capturer_.reset(ScreenCapturer::Create(options)); |
| 152 |
| 153 std::unique_ptr<DesktopFrame> frame; |
| 154 EXPECT_CALL(callback_, |
| 155 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 156 .WillOnce(SaveUniquePtrArg(&frame)); |
| 157 |
| 158 capturer_->Start(&callback_); |
| 159 capturer_->Capture(DesktopRegion()); |
| 160 ASSERT_TRUE(frame); |
| 161 } |
| 162 |
| 163 TEST_F(ScreenCapturerTest, UseDirectxCapturerWithSharedBuffers) { |
| 164 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
| 165 options.set_allow_directx_capturer(true); |
| 166 capturer_.reset(ScreenCapturer::Create(options)); |
| 167 |
| 168 std::unique_ptr<DesktopFrame> frame; |
| 169 EXPECT_CALL(callback_, |
| 170 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
| 171 .WillOnce(SaveUniquePtrArg(&frame)); |
| 172 |
| 173 capturer_->Start(&callback_); |
| 174 capturer_->SetSharedMemoryFactory( |
| 175 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); |
| 176 capturer_->Capture(DesktopRegion()); |
| 177 ASSERT_TRUE(frame); |
| 178 ASSERT_TRUE(frame->shared_memory()); |
| 179 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
| 180 } |
| 181 |
| 147 #endif // defined(WEBRTC_WIN) | 182 #endif // defined(WEBRTC_WIN) |
| 148 | 183 |
| 149 } // namespace webrtc | 184 } // namespace webrtc |
| OLD | NEW |