2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
11 #include "webrtc/modules/desktop_capture/screen_capturer.h"
13 #include <ApplicationServices/ApplicationServices.h>
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/modules/desktop_capture/desktop_frame.h"
19 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
20 #include "webrtc/modules/desktop_capture/desktop_region.h"
21 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h"
22 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h"
23 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
26 using ::testing::AnyNumber;
27 using ::testing::Return;
31 class ScreenCapturerMacTest : public testing::Test {
33 // Verifies that the whole screen is initially dirty.
34 void CaptureDoneCallback1(DesktopFrame* frame);
36 // Verifies that a rectangle explicitly marked as dirty is propagated
38 void CaptureDoneCallback2(DesktopFrame* frame);
41 virtual void SetUp() OVERRIDE {
42 capturer_.reset(ScreenCapturer::Create());
45 scoped_ptr<ScreenCapturer> capturer_;
46 MockScreenCapturerCallback callback_;
49 void ScreenCapturerMacTest::CaptureDoneCallback1(
50 DesktopFrame* frame) {
51 scoped_ptr<DesktopFrame> owned_frame(frame);
53 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent(
54 MacDesktopConfiguration::BottomLeftOrigin);
56 // Verify that the region contains full frame.
57 DesktopRegion::Iterator it(frame->updated_region());
58 EXPECT_TRUE(!it.IsAtEnd() && it.rect().equals(config.pixel_bounds));
61 void ScreenCapturerMacTest::CaptureDoneCallback2(
62 DesktopFrame* frame) {
63 scoped_ptr<DesktopFrame> owned_frame(frame);
65 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent(
66 MacDesktopConfiguration::BottomLeftOrigin);
67 int width = config.pixel_bounds.width();
68 int height = config.pixel_bounds.height();
70 EXPECT_EQ(width, frame->size().width());
71 EXPECT_EQ(height, frame->size().height());
72 EXPECT_TRUE(frame->data() != NULL);
73 // Depending on the capture method, the screen may be flipped or not, so
74 // the stride may be positive or negative.
75 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width),
76 abs(frame->stride()));
79 TEST_F(ScreenCapturerMacTest, Capture) {
80 EXPECT_CALL(callback_, OnCaptureCompleted(_))
82 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1))
83 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2));
85 EXPECT_CALL(callback_, CreateSharedMemory(_))
87 .WillRepeatedly(Return(static_cast<SharedMemory*>(NULL)));
90 capturer_->Start(&callback_);
92 // Check that we get an initial full-screen updated.
93 capturer_->Capture(DesktopRegion());
95 // Check that subsequent dirty rects are propagated correctly.
96 capturer_->Capture(DesktopRegion());