Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: webrtc/modules/desktop_capture/screen_capturer_integration_test.cc

Issue 2444583002: Move ScreenCapturer 'real' tests out of screen_capturer_unittest.cc. (Closed)
Patch Set: Resolve review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 <string.h> 11 #include <string.h>
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <initializer_list> 14 #include <initializer_list>
15 #include <memory> 15 #include <memory>
16 #include <utility> 16 #include <utility>
17 17
18 #include "webrtc/modules/desktop_capture/screen_capturer.h" 18 #include "webrtc/modules/desktop_capture/screen_capturer.h"
19 19
20 #include "webrtc/test/gmock.h" 20 #include "webrtc/test/gmock.h"
21 #include "webrtc/test/gtest.h" 21 #include "webrtc/test/gtest.h"
22 #include "webrtc/base/checks.h" 22 #include "webrtc/base/checks.h"
23 #include "webrtc/base/constructormagic.h" 23 #include "webrtc/base/constructormagic.h"
24 #include "webrtc/base/logging.h" 24 #include "webrtc/base/logging.h"
25 #include "webrtc/modules/desktop_capture/rgba_color.h" 25 #include "webrtc/modules/desktop_capture/rgba_color.h"
26 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" 26 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
27 #include "webrtc/modules/desktop_capture/desktop_frame.h" 27 #include "webrtc/modules/desktop_capture/desktop_frame.h"
28 #include "webrtc/modules/desktop_capture/desktop_region.h" 28 #include "webrtc/modules/desktop_capture/desktop_region.h"
29 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" 29 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h"
30 #include "webrtc/modules/desktop_capture/screen_drawer.h" 30 #include "webrtc/modules/desktop_capture/screen_drawer.h"
31 #include "webrtc/system_wrappers/include/sleep.h"
32 31
33 #if defined(WEBRTC_WIN) 32 #if defined(WEBRTC_WIN)
34 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h" 33 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h"
35 #endif // defined(WEBRTC_WIN) 34 #endif // defined(WEBRTC_WIN)
36 35
37 using ::testing::_; 36 using ::testing::_;
38 using ::testing::AnyNumber;
39 using ::testing::Return;
40
41 const int kTestSharedMemoryId = 123;
42 37
43 namespace webrtc { 38 namespace webrtc {
44 39
45 namespace { 40 namespace {
46 41
47 ACTION_P(SaveUniquePtrArg, dest) { 42 ACTION_P(SaveUniquePtrArg, dest) {
48 *dest = std::move(*arg1); 43 *dest = std::move(*arg1);
49 } 44 }
50 45
51 // Returns true if color in |rect| of |frame| is |color|. 46 // Returns true if color in |rect| of |frame| is |color|.
(...skipping 20 matching lines...) Expand all
72 } 67 }
73 column += DesktopFrame::kBytesPerPixel; 68 column += DesktopFrame::kBytesPerPixel;
74 } 69 }
75 row += frame.stride(); 70 row += frame.stride();
76 } 71 }
77 return true; 72 return true;
78 } 73 }
79 74
80 } // namespace 75 } // namespace
81 76
82 class ScreenCapturerTest : public testing::Test { 77 class ScreenCapturerIntegrationTest : public testing::Test {
83 public: 78 public:
84 void SetUp() override { 79 void SetUp() override {
85 capturer_.reset( 80 capturer_.reset(
86 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); 81 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault()));
87 } 82 }
88 83
89 protected: 84 protected:
90 void TestCaptureUpdatedRegion( 85 void TestCaptureUpdatedRegion(
91 std::initializer_list<ScreenCapturer*> capturers) { 86 std::initializer_list<ScreenCapturer*> capturers) {
92 RTC_DCHECK(capturers.size() > 0); 87 RTC_DCHECK(capturers.size() > 0);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 std::unique_ptr<DesktopFrame> frame; 214 std::unique_ptr<DesktopFrame> frame;
220 EXPECT_CALL(callback_, 215 EXPECT_CALL(callback_,
221 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) 216 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _))
222 .WillOnce(SaveUniquePtrArg(&frame)); 217 .WillOnce(SaveUniquePtrArg(&frame));
223 capturer->CaptureFrame(); 218 capturer->CaptureFrame();
224 EXPECT_TRUE(frame); 219 EXPECT_TRUE(frame);
225 return frame; 220 return frame;
226 } 221 }
227 }; 222 };
228 223
229 class FakeSharedMemory : public SharedMemory { 224 TEST_F(ScreenCapturerIntegrationTest, CaptureUpdatedRegion) {
230 public:
231 FakeSharedMemory(char* buffer, size_t size)
232 : SharedMemory(buffer, size, 0, kTestSharedMemoryId),
233 buffer_(buffer) {
234 }
235 virtual ~FakeSharedMemory() {
236 delete[] buffer_;
237 }
238 private:
239 char* buffer_;
240 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemory);
241 };
242
243 class FakeSharedMemoryFactory : public SharedMemoryFactory {
244 public:
245 FakeSharedMemoryFactory() {}
246 ~FakeSharedMemoryFactory() override {}
247
248 std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) override {
249 return std::unique_ptr<SharedMemory>(
250 new FakeSharedMemory(new char[size], size));
251 }
252
253 private:
254 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory);
255 };
256
257 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) {
258 webrtc::ScreenCapturer::ScreenList screens;
259 EXPECT_TRUE(capturer_->GetScreenList(&screens));
260 for (webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin();
261 it != screens.end(); ++it) {
262 EXPECT_TRUE(capturer_->SelectScreen(it->id));
263 }
264 }
265
266 TEST_F(ScreenCapturerTest, StartCapturer) {
267 capturer_->Start(&callback_);
268 }
269
270 TEST_F(ScreenCapturerTest, Capture) {
271 // Assume that Start() treats the screen as invalid initially.
272 std::unique_ptr<DesktopFrame> frame;
273 EXPECT_CALL(callback_,
274 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _))
275 .WillOnce(SaveUniquePtrArg(&frame));
276
277 capturer_->Start(&callback_);
278 capturer_->CaptureFrame();
279
280 ASSERT_TRUE(frame);
281 EXPECT_GT(frame->size().width(), 0);
282 EXPECT_GT(frame->size().height(), 0);
283 EXPECT_GE(frame->stride(),
284 frame->size().width() * DesktopFrame::kBytesPerPixel);
285 EXPECT_TRUE(frame->shared_memory() == NULL);
286
287 // Verify that the region contains whole screen.
288 EXPECT_FALSE(frame->updated_region().is_empty());
289 DesktopRegion::Iterator it(frame->updated_region());
290 ASSERT_TRUE(!it.IsAtEnd());
291 EXPECT_TRUE(it.rect().equals(DesktopRect::MakeSize(frame->size())));
292 it.Advance();
293 EXPECT_TRUE(it.IsAtEnd());
294 }
295
296 // Disabled due to being flaky due to the fact that it uses rendering / UI, see
297 // webrtc/6366.
298 TEST_F(ScreenCapturerTest, DISABLED_CaptureUpdatedRegion) {
299 TestCaptureUpdatedRegion(); 225 TestCaptureUpdatedRegion();
300 } 226 }
301 227
302 // Disabled due to being flaky due to the fact that it uses rendering / UI, see 228 TEST_F(ScreenCapturerIntegrationTest, TwoCapturers) {
303 // webrtc/6366.
304 TEST_F(ScreenCapturerTest, DISABLED_TwoCapturers) {
305 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); 229 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_);
306 SetUp(); 230 SetUp();
307 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); 231 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()});
308 } 232 }
309 233
310 #if defined(WEBRTC_WIN) 234 #if defined(WEBRTC_WIN)
311 235
312 TEST_F(ScreenCapturerTest, UseSharedBuffers) { 236 TEST_F(ScreenCapturerIntegrationTest, CaptureUpdatedRegionWithDirectxCapturer) {
313 std::unique_ptr<DesktopFrame> frame;
314 EXPECT_CALL(callback_,
315 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _))
316 .WillOnce(SaveUniquePtrArg(&frame));
317
318 capturer_->Start(&callback_);
319 capturer_->SetSharedMemoryFactory(
320 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory()));
321 capturer_->CaptureFrame();
322
323 ASSERT_TRUE(frame);
324 ASSERT_TRUE(frame->shared_memory());
325 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId);
326 }
327
328 TEST_F(ScreenCapturerTest, UseMagnifier) {
329 CreateMagnifierCapturer();
330
331 std::unique_ptr<DesktopFrame> frame;
332 EXPECT_CALL(callback_,
333 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _))
334 .WillOnce(SaveUniquePtrArg(&frame));
335
336 capturer_->Start(&callback_);
337 capturer_->CaptureFrame();
338 ASSERT_TRUE(frame);
339 }
340
341 TEST_F(ScreenCapturerTest, UseDirectxCapturer) {
342 if (!CreateDirectxCapturer()) { 237 if (!CreateDirectxCapturer()) {
343 return; 238 return;
344 } 239 }
345
346 std::unique_ptr<DesktopFrame> frame;
347 EXPECT_CALL(callback_,
348 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _))
349 .WillOnce(SaveUniquePtrArg(&frame));
350
351 capturer_->Start(&callback_);
352 capturer_->CaptureFrame();
353 ASSERT_TRUE(frame);
354 }
355
356 TEST_F(ScreenCapturerTest, UseDirectxCapturerWithSharedBuffers) {
357 if (!CreateDirectxCapturer()) {
358 return;
359 }
360
361 std::unique_ptr<DesktopFrame> frame;
362 EXPECT_CALL(callback_,
363 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _))
364 .WillOnce(SaveUniquePtrArg(&frame));
365
366 capturer_->Start(&callback_);
367 capturer_->SetSharedMemoryFactory(
368 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory()));
369 capturer_->CaptureFrame();
370 ASSERT_TRUE(frame);
371 ASSERT_TRUE(frame->shared_memory());
372 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId);
373 }
374
375 // Disabled due to being flaky due to the fact that it uses rendering / UI, see
376 // webrtc/6366.
377 TEST_F(ScreenCapturerTest, DISABLED_CaptureUpdatedRegionWithDirectxCapturer) {
378 if (!CreateDirectxCapturer()) {
379 return;
380 }
381 240
382 TestCaptureUpdatedRegion(); 241 TestCaptureUpdatedRegion();
383 } 242 }
384 243
385 // Disabled due to being flaky due to the fact that it uses rendering / UI, see 244 TEST_F(ScreenCapturerIntegrationTest, TwoDirectxCapturers) {
386 // webrtc/6366.
387 TEST_F(ScreenCapturerTest, DISABLED_TwoDirectxCapturers) {
388 if (!CreateDirectxCapturer()) { 245 if (!CreateDirectxCapturer()) {
389 return; 246 return;
390 } 247 }
391 248
392 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); 249 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_);
393 RTC_CHECK(CreateDirectxCapturer()); 250 RTC_CHECK(CreateDirectxCapturer());
394 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); 251 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()});
395 } 252 }
396 253
397 // Disabled due to being flaky due to the fact that it uses rendering / UI, see 254 TEST_F(ScreenCapturerIntegrationTest,
398 // webrtc/6366. 255 CaptureUpdatedRegionWithMagnifierCapturer) {
399 TEST_F(ScreenCapturerTest, DISABLED_CaptureUpdatedRegionWithMagnifierCapturer) {
400 CreateMagnifierCapturer(); 256 CreateMagnifierCapturer();
401 TestCaptureUpdatedRegion(); 257 TestCaptureUpdatedRegion();
402 } 258 }
403 259
404 // Disabled due to being flaky due to the fact that it uses rendering / UI, see 260 TEST_F(ScreenCapturerIntegrationTest, TwoMagnifierCapturers) {
405 // webrtc/6366.
406 TEST_F(ScreenCapturerTest, DISABLED_TwoMagnifierCapturers) {
407 CreateMagnifierCapturer(); 261 CreateMagnifierCapturer();
408 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_); 262 std::unique_ptr<ScreenCapturer> capturer2 = std::move(capturer_);
409 CreateMagnifierCapturer(); 263 CreateMagnifierCapturer();
410 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()}); 264 TestCaptureUpdatedRegion({capturer_.get(), capturer2.get()});
411 } 265 }
412 266
413 // Disabled due to being flaky due to the fact that it uses rendering / UI, see 267 TEST_F(ScreenCapturerIntegrationTest,
414 // webrtc/6366. 268 MaybeCaptureUpdatedRegionWithDirectxCapturer) {
415 TEST_F(ScreenCapturerTest,
416 DISABLED_MaybeCaptureUpdatedRegionWithDirectxCapturer) {
417 // Even DirectX capturer is not supported in current system, we should be able 269 // Even DirectX capturer is not supported in current system, we should be able
418 // to select a usable capturer. 270 // to select a usable capturer.
419 MaybeCreateDirectxCapturer(); 271 MaybeCreateDirectxCapturer();
420 TestCaptureUpdatedRegion(); 272 TestCaptureUpdatedRegion();
421 } 273 }
422 274
423 #endif // defined(WEBRTC_WIN) 275 #endif // defined(WEBRTC_WIN)
424 276
425 } // namespace webrtc 277 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/BUILD.gn ('k') | webrtc/modules/desktop_capture/screen_capturer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698