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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 using ::testing::AnyNumber; | 21 using ::testing::AnyNumber; |
22 using ::testing::Return; | 22 using ::testing::Return; |
23 using ::testing::SaveArg; | 23 using ::testing::SaveArg; |
24 | 24 |
25 const int kTestSharedMemoryId = 123; | 25 const int kTestSharedMemoryId = 123; |
26 | 26 |
27 namespace webrtc { | 27 namespace webrtc { |
28 | 28 |
29 class ScreenCapturerTest : public testing::Test { | 29 class ScreenCapturerTest : public testing::Test { |
30 public: | 30 public: |
31 SharedMemory* CreateSharedMemory(size_t size); | |
32 | |
33 void SetUp() override { | 31 void SetUp() override { |
34 capturer_.reset( | 32 capturer_.reset( |
35 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); | 33 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); |
36 } | 34 } |
37 | 35 |
38 protected: | 36 protected: |
39 rtc::scoped_ptr<ScreenCapturer> capturer_; | 37 rtc::scoped_ptr<ScreenCapturer> capturer_; |
40 MockScreenCapturerCallback callback_; | 38 MockScreenCapturerCallback callback_; |
41 }; | 39 }; |
42 | 40 |
43 class FakeSharedMemory : public SharedMemory { | 41 class FakeSharedMemory : public SharedMemory { |
44 public: | 42 public: |
45 FakeSharedMemory(char* buffer, size_t size) | 43 FakeSharedMemory(char* buffer, size_t size) |
46 : SharedMemory(buffer, size, 0, kTestSharedMemoryId), | 44 : SharedMemory(buffer, size, 0, kTestSharedMemoryId), |
47 buffer_(buffer) { | 45 buffer_(buffer) { |
48 } | 46 } |
49 virtual ~FakeSharedMemory() { | 47 virtual ~FakeSharedMemory() { |
50 delete[] buffer_; | 48 delete[] buffer_; |
51 } | 49 } |
52 private: | 50 private: |
53 char* buffer_; | 51 char* buffer_; |
54 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemory); | 52 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemory); |
55 }; | 53 }; |
56 | 54 |
57 SharedMemory* ScreenCapturerTest::CreateSharedMemory(size_t size) { | 55 class FakeSharedMemoryFactory : public SharedMemoryFactory { |
58 return new FakeSharedMemory(new char[size], size); | 56 public: |
59 } | 57 FakeSharedMemoryFactory() {} |
| 58 ~FakeSharedMemoryFactory() override {} |
| 59 |
| 60 rtc::scoped_ptr<SharedMemory> CreateSharedMemory(size_t size) override { |
| 61 return rtc_make_scoped_ptr(new FakeSharedMemory(new char[size], size)) |
| 62 } |
| 63 |
| 64 private: |
| 65 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); |
| 66 }; |
60 | 67 |
61 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { | 68 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { |
62 webrtc::ScreenCapturer::ScreenList screens; | 69 webrtc::ScreenCapturer::ScreenList screens; |
63 EXPECT_TRUE(capturer_->GetScreenList(&screens)); | 70 EXPECT_TRUE(capturer_->GetScreenList(&screens)); |
64 for(webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); | 71 for(webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); |
65 it != screens.end(); ++it) { | 72 it != screens.end(); ++it) { |
66 EXPECT_TRUE(capturer_->SelectScreen(it->id)); | 73 EXPECT_TRUE(capturer_->SelectScreen(it->id)); |
67 } | 74 } |
68 } | 75 } |
69 | 76 |
70 TEST_F(ScreenCapturerTest, StartCapturer) { | 77 TEST_F(ScreenCapturerTest, StartCapturer) { |
71 capturer_->Start(&callback_); | 78 capturer_->Start(&callback_); |
72 } | 79 } |
73 | 80 |
74 TEST_F(ScreenCapturerTest, Capture) { | 81 TEST_F(ScreenCapturerTest, Capture) { |
75 // Assume that Start() treats the screen as invalid initially. | 82 // Assume that Start() treats the screen as invalid initially. |
76 DesktopFrame* frame = NULL; | 83 DesktopFrame* frame = NULL; |
77 EXPECT_CALL(callback_, OnCaptureCompleted(_)) | 84 EXPECT_CALL(callback_, OnCaptureCompleted(_)) |
78 .WillOnce(SaveArg<0>(&frame)); | 85 .WillOnce(SaveArg<0>(&frame)); |
79 | 86 |
80 EXPECT_CALL(callback_, CreateSharedMemory(_)) | |
81 .Times(AnyNumber()) | |
82 .WillRepeatedly(Return(static_cast<SharedMemory*>(NULL))); | |
83 | |
84 capturer_->Start(&callback_); | 87 capturer_->Start(&callback_); |
85 capturer_->Capture(DesktopRegion()); | 88 capturer_->Capture(DesktopRegion()); |
86 | 89 |
87 ASSERT_TRUE(frame); | 90 ASSERT_TRUE(frame); |
88 EXPECT_GT(frame->size().width(), 0); | 91 EXPECT_GT(frame->size().width(), 0); |
89 EXPECT_GT(frame->size().height(), 0); | 92 EXPECT_GT(frame->size().height(), 0); |
90 EXPECT_GE(frame->stride(), | 93 EXPECT_GE(frame->stride(), |
91 frame->size().width() * DesktopFrame::kBytesPerPixel); | 94 frame->size().width() * DesktopFrame::kBytesPerPixel); |
92 EXPECT_TRUE(frame->shared_memory() == NULL); | 95 EXPECT_TRUE(frame->shared_memory() == NULL); |
93 | 96 |
94 // Verify that the region contains whole screen. | 97 // Verify that the region contains whole screen. |
95 EXPECT_FALSE(frame->updated_region().is_empty()); | 98 EXPECT_FALSE(frame->updated_region().is_empty()); |
96 DesktopRegion::Iterator it(frame->updated_region()); | 99 DesktopRegion::Iterator it(frame->updated_region()); |
97 ASSERT_TRUE(!it.IsAtEnd()); | 100 ASSERT_TRUE(!it.IsAtEnd()); |
98 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); | 101 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size()))); |
99 it.Advance(); | 102 it.Advance(); |
100 EXPECT_TRUE(it.IsAtEnd()); | 103 EXPECT_TRUE(it.IsAtEnd()); |
101 | 104 |
102 delete frame; | 105 delete frame; |
103 } | 106 } |
104 | 107 |
105 #if defined(WEBRTC_WIN) | 108 #if defined(WEBRTC_WIN) |
106 | 109 |
107 TEST_F(ScreenCapturerTest, UseSharedBuffers) { | 110 TEST_F(ScreenCapturerTest, UseSharedBuffers) { |
108 DesktopFrame* frame = NULL; | 111 DesktopFrame* frame = NULL; |
109 EXPECT_CALL(callback_, OnCaptureCompleted(_)) | 112 EXPECT_CALL(callback_, OnCaptureCompleted(_)) |
110 .WillOnce(SaveArg<0>(&frame)); | 113 .WillOnce(SaveArg<0>(&frame)); |
111 | 114 |
112 EXPECT_CALL(callback_, CreateSharedMemory(_)) | |
113 .Times(AnyNumber()) | |
114 .WillRepeatedly(Invoke(this, &ScreenCapturerTest::CreateSharedMemory)); | |
115 | |
116 capturer_->Start(&callback_); | 115 capturer_->Start(&callback_); |
| 116 capturer_->SetSharedMemoryFactory( |
| 117 rtc_make_scoped_ptr(new FakeSharedMemoryFactory())); |
117 capturer_->Capture(DesktopRegion()); | 118 capturer_->Capture(DesktopRegion()); |
118 | 119 |
119 ASSERT_TRUE(frame); | 120 ASSERT_TRUE(frame); |
120 ASSERT_TRUE(frame->shared_memory()); | 121 ASSERT_TRUE(frame->shared_memory()); |
121 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); | 122 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
122 | 123 |
123 delete frame; | 124 delete frame; |
124 } | 125 } |
125 | 126 |
126 TEST_F(ScreenCapturerTest, UseMagnifier) { | 127 TEST_F(ScreenCapturerTest, UseMagnifier) { |
127 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 128 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
128 options.set_allow_use_magnification_api(true); | 129 options.set_allow_use_magnification_api(true); |
129 capturer_.reset(ScreenCapturer::Create(options)); | 130 capturer_.reset(ScreenCapturer::Create(options)); |
130 | 131 |
131 DesktopFrame* frame = NULL; | 132 DesktopFrame* frame = NULL; |
132 EXPECT_CALL(callback_, OnCaptureCompleted(_)).WillOnce(SaveArg<0>(&frame)); | 133 EXPECT_CALL(callback_, OnCaptureCompleted(_)).WillOnce(SaveArg<0>(&frame)); |
133 | 134 |
134 capturer_->Start(&callback_); | 135 capturer_->Start(&callback_); |
135 capturer_->Capture(DesktopRegion()); | 136 capturer_->Capture(DesktopRegion()); |
136 ASSERT_TRUE(frame); | 137 ASSERT_TRUE(frame); |
137 delete frame; | 138 delete frame; |
138 } | 139 } |
139 | 140 |
140 #endif // defined(WEBRTC_WIN) | 141 #endif // defined(WEBRTC_WIN) |
141 | 142 |
142 } // namespace webrtc | 143 } // namespace webrtc |
OLD | NEW |