blob: 96e844066a0637f39b12a698b2d56d0c5ad148d2 [file] [log] [blame]
sergeyu@chromium.org3d34f662013-06-04 18:51:231/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
sergeyu@chromium.org3d34f662013-06-04 18:51:2311#include <ApplicationServices/ApplicationServices.h>
12
kwiberg2bb3afa2016-03-16 22:58:0813#include <memory>
sergeyu@chromium.org3d34f662013-06-04 18:51:2314#include <ostream>
15
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "modules/desktop_capture/desktop_capture_options.h"
Yves Gerey665174f2018-06-19 13:03:0517#include "modules/desktop_capture/desktop_capturer.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3118#include "modules/desktop_capture/desktop_frame.h"
19#include "modules/desktop_capture/desktop_geometry.h"
20#include "modules/desktop_capture/desktop_region.h"
21#include "modules/desktop_capture/mac/desktop_configuration.h"
22#include "modules/desktop_capture/mock_desktop_capturer_callback.h"
23#include "test/gtest.h"
sergeyu@chromium.org3d34f662013-06-04 18:51:2324
25using ::testing::_;
26using ::testing::AnyNumber;
27using ::testing::Return;
28
29namespace webrtc {
30
Mirko Bonadei6a489f22019-04-09 13:11:1231class ScreenCapturerMacTest : public ::testing::Test {
sergeyu@chromium.org3d34f662013-06-04 18:51:2332 public:
33 // Verifies that the whole screen is initially dirty.
sergeyu5d910282016-06-07 23:41:5834 void CaptureDoneCallback1(DesktopCapturer::Result result,
35 std::unique_ptr<DesktopFrame>* frame);
sergeyu@chromium.org3d34f662013-06-04 18:51:2336
37 // Verifies that a rectangle explicitly marked as dirty is propagated
38 // correctly.
sergeyu5d910282016-06-07 23:41:5839 void CaptureDoneCallback2(DesktopCapturer::Result result,
40 std::unique_ptr<DesktopFrame>* frame);
sergeyu@chromium.org3d34f662013-06-04 18:51:2341
42 protected:
sergeyu6acd9f42016-04-21 16:46:2243 void SetUp() override {
zijiehe30455892016-11-10 00:37:4844 capturer_ = DesktopCapturer::CreateScreenCapturer(
45 DesktopCaptureOptions::CreateDefault());
sergeyu6acd9f42016-04-21 16:46:2246 }
sergeyu@chromium.org3d34f662013-06-04 18:51:2347
zijiehe30455892016-11-10 00:37:4848 std::unique_ptr<DesktopCapturer> capturer_;
zijiehe372719b2016-11-12 01:18:3449 MockDesktopCapturerCallback callback_;
sergeyu@chromium.org3d34f662013-06-04 18:51:2350};
51
52void ScreenCapturerMacTest::CaptureDoneCallback1(
sergeyu5d910282016-06-07 23:41:5853 DesktopCapturer::Result result,
54 std::unique_ptr<DesktopFrame>* frame) {
55 EXPECT_EQ(result, DesktopCapturer::Result::SUCCESS);
sergeyu@chromium.org3d34f662013-06-04 18:51:2356
57 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent(
58 MacDesktopConfiguration::BottomLeftOrigin);
59
60 // Verify that the region contains full frame.
sergeyu5d910282016-06-07 23:41:5861 DesktopRegion::Iterator it((*frame)->updated_region());
sergeyu@chromium.org7d055a62014-04-18 23:45:3862 EXPECT_TRUE(!it.IsAtEnd() && it.rect().equals(config.pixel_bounds));
sergeyu@chromium.org3d34f662013-06-04 18:51:2363}
64
65void ScreenCapturerMacTest::CaptureDoneCallback2(
sergeyu5d910282016-06-07 23:41:5866 DesktopCapturer::Result result,
67 std::unique_ptr<DesktopFrame>* frame) {
68 EXPECT_EQ(result, DesktopCapturer::Result::SUCCESS);
sergeyu@chromium.org3d34f662013-06-04 18:51:2369
70 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent(
71 MacDesktopConfiguration::BottomLeftOrigin);
sergeyu@chromium.org7d055a62014-04-18 23:45:3872 int width = config.pixel_bounds.width();
73 int height = config.pixel_bounds.height();
sergeyu@chromium.org3d34f662013-06-04 18:51:2374
sergeyu5d910282016-06-07 23:41:5875 EXPECT_EQ(width, (*frame)->size().width());
76 EXPECT_EQ(height, (*frame)->size().height());
77 EXPECT_TRUE((*frame)->data() != NULL);
sergeyu@chromium.org3d34f662013-06-04 18:51:2378 // Depending on the capture method, the screen may be flipped or not, so
79 // the stride may be positive or negative.
80 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width),
sergeyu5d910282016-06-07 23:41:5881 abs((*frame)->stride()));
sergeyu@chromium.org3d34f662013-06-04 18:51:2382}
83
84TEST_F(ScreenCapturerMacTest, Capture) {
sergeyu5d910282016-06-07 23:41:5885 EXPECT_CALL(callback_,
86 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _))
sergeyu@chromium.org3d34f662013-06-04 18:51:2387 .Times(2)
88 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1))
89 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2));
90
sergeyu@chromium.org3d34f662013-06-04 18:51:2391 SCOPED_TRACE("");
92 capturer_->Start(&callback_);
93
94 // Check that we get an initial full-screen updated.
zijiehe249beee2016-10-19 06:13:2995 capturer_->CaptureFrame();
sergeyu@chromium.org3d34f662013-06-04 18:51:2396
97 // Check that subsequent dirty rects are propagated correctly.
zijiehe249beee2016-10-19 06:13:2998 capturer_->CaptureFrame();
sergeyu@chromium.org3d34f662013-06-04 18:51:2399}
100
101} // namespace webrtc