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> |
| 12 |
11 #include "webrtc/modules/desktop_capture/screen_capturer.h" | 13 #include "webrtc/modules/desktop_capture/screen_capturer.h" |
12 | 14 |
13 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 17 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
16 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 18 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
17 #include "webrtc/modules/desktop_capture/desktop_region.h" | 19 #include "webrtc/modules/desktop_capture/desktop_region.h" |
18 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" | 20 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" |
19 | 21 |
20 using ::testing::_; | 22 using ::testing::_; |
21 using ::testing::AnyNumber; | 23 using ::testing::AnyNumber; |
22 using ::testing::Return; | 24 using ::testing::Return; |
23 using ::testing::SaveArg; | 25 using ::testing::SaveArg; |
24 | 26 |
25 const int kTestSharedMemoryId = 123; | 27 const int kTestSharedMemoryId = 123; |
26 | 28 |
27 namespace webrtc { | 29 namespace webrtc { |
28 | 30 |
29 class ScreenCapturerTest : public testing::Test { | 31 class ScreenCapturerTest : public testing::Test { |
30 public: | 32 public: |
31 void SetUp() override { | 33 void SetUp() override { |
32 capturer_.reset( | 34 capturer_.reset( |
33 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); | 35 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); |
34 } | 36 } |
35 | 37 |
36 protected: | 38 protected: |
37 rtc::scoped_ptr<ScreenCapturer> capturer_; | 39 std::unique_ptr<ScreenCapturer> capturer_; |
38 MockScreenCapturerCallback callback_; | 40 MockScreenCapturerCallback callback_; |
39 }; | 41 }; |
40 | 42 |
41 class FakeSharedMemory : public SharedMemory { | 43 class FakeSharedMemory : public SharedMemory { |
42 public: | 44 public: |
43 FakeSharedMemory(char* buffer, size_t size) | 45 FakeSharedMemory(char* buffer, size_t size) |
44 : SharedMemory(buffer, size, 0, kTestSharedMemoryId), | 46 : SharedMemory(buffer, size, 0, kTestSharedMemoryId), |
45 buffer_(buffer) { | 47 buffer_(buffer) { |
46 } | 48 } |
47 virtual ~FakeSharedMemory() { | 49 virtual ~FakeSharedMemory() { |
48 delete[] buffer_; | 50 delete[] buffer_; |
49 } | 51 } |
50 private: | 52 private: |
51 char* buffer_; | 53 char* buffer_; |
52 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemory); | 54 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemory); |
53 }; | 55 }; |
54 | 56 |
55 class FakeSharedMemoryFactory : public SharedMemoryFactory { | 57 class FakeSharedMemoryFactory : public SharedMemoryFactory { |
56 public: | 58 public: |
57 FakeSharedMemoryFactory() {} | 59 FakeSharedMemoryFactory() {} |
58 ~FakeSharedMemoryFactory() override {} | 60 ~FakeSharedMemoryFactory() override {} |
59 | 61 |
60 rtc::scoped_ptr<SharedMemory> CreateSharedMemory(size_t size) override { | 62 rtc::scoped_ptr<SharedMemory> CreateSharedMemory(size_t size) override { |
61 return rtc_make_scoped_ptr(new FakeSharedMemory(new char[size], size)); | 63 return rtc::scoped_ptr<SharedMemory>( |
| 64 new FakeSharedMemory(new char[size], size)); |
62 } | 65 } |
63 | 66 |
64 private: | 67 private: |
65 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); | 68 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); |
66 }; | 69 }; |
67 | 70 |
68 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { | 71 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { |
69 webrtc::ScreenCapturer::ScreenList screens; | 72 webrtc::ScreenCapturer::ScreenList screens; |
70 EXPECT_TRUE(capturer_->GetScreenList(&screens)); | 73 EXPECT_TRUE(capturer_->GetScreenList(&screens)); |
71 for(webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); | 74 for(webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 110 |
108 #if defined(WEBRTC_WIN) | 111 #if defined(WEBRTC_WIN) |
109 | 112 |
110 TEST_F(ScreenCapturerTest, UseSharedBuffers) { | 113 TEST_F(ScreenCapturerTest, UseSharedBuffers) { |
111 DesktopFrame* frame = NULL; | 114 DesktopFrame* frame = NULL; |
112 EXPECT_CALL(callback_, OnCaptureCompleted(_)) | 115 EXPECT_CALL(callback_, OnCaptureCompleted(_)) |
113 .WillOnce(SaveArg<0>(&frame)); | 116 .WillOnce(SaveArg<0>(&frame)); |
114 | 117 |
115 capturer_->Start(&callback_); | 118 capturer_->Start(&callback_); |
116 capturer_->SetSharedMemoryFactory( | 119 capturer_->SetSharedMemoryFactory( |
117 rtc_make_scoped_ptr(new FakeSharedMemoryFactory())); | 120 rtc::scoped_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); |
118 capturer_->Capture(DesktopRegion()); | 121 capturer_->Capture(DesktopRegion()); |
119 | 122 |
120 ASSERT_TRUE(frame); | 123 ASSERT_TRUE(frame); |
121 ASSERT_TRUE(frame->shared_memory()); | 124 ASSERT_TRUE(frame->shared_memory()); |
122 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); | 125 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
123 | 126 |
124 delete frame; | 127 delete frame; |
125 } | 128 } |
126 | 129 |
127 TEST_F(ScreenCapturerTest, UseMagnifier) { | 130 TEST_F(ScreenCapturerTest, UseMagnifier) { |
128 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 131 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
129 options.set_allow_use_magnification_api(true); | 132 options.set_allow_use_magnification_api(true); |
130 capturer_.reset(ScreenCapturer::Create(options)); | 133 capturer_.reset(ScreenCapturer::Create(options)); |
131 | 134 |
132 DesktopFrame* frame = NULL; | 135 DesktopFrame* frame = NULL; |
133 EXPECT_CALL(callback_, OnCaptureCompleted(_)).WillOnce(SaveArg<0>(&frame)); | 136 EXPECT_CALL(callback_, OnCaptureCompleted(_)).WillOnce(SaveArg<0>(&frame)); |
134 | 137 |
135 capturer_->Start(&callback_); | 138 capturer_->Start(&callback_); |
136 capturer_->Capture(DesktopRegion()); | 139 capturer_->Capture(DesktopRegion()); |
137 ASSERT_TRUE(frame); | 140 ASSERT_TRUE(frame); |
138 delete frame; | 141 delete frame; |
139 } | 142 } |
140 | 143 |
141 #endif // defined(WEBRTC_WIN) | 144 #endif // defined(WEBRTC_WIN) |
142 | 145 |
143 } // namespace webrtc | 146 } // namespace webrtc |
OLD | NEW |