1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "remoting/host/shaped_screen_capturer.h"
7 #include "remoting/host/desktop_shape_tracker.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
10 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
11 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
15 const int kScreenSize
= 10;
17 class FakeScreenCapturer
: public webrtc::ScreenCapturer
{
19 FakeScreenCapturer() {}
20 virtual ~FakeScreenCapturer() {}
22 virtual void Start(Callback
* callback
) OVERRIDE
{
26 virtual void Capture(const webrtc::DesktopRegion
& region
) OVERRIDE
{
27 webrtc::DesktopFrame
* frame
= new webrtc::BasicDesktopFrame(
28 webrtc::DesktopSize(kScreenSize
, kScreenSize
));
29 memset(frame
->data(), 0, frame
->stride() * kScreenSize
);
30 callback_
->OnCaptureCompleted(frame
);
33 virtual void SetMouseShapeObserver(
34 MouseShapeObserver
* mouse_shape_observer
) OVERRIDE
{
36 virtual bool GetScreenList(ScreenList
* screens
) OVERRIDE
{
39 virtual bool SelectScreen(webrtc::ScreenId id
) OVERRIDE
{
47 class FakeDesktopShapeTracker
: public DesktopShapeTracker
{
49 FakeDesktopShapeTracker() {}
50 virtual ~FakeDesktopShapeTracker() {}
52 static webrtc::DesktopRegion
CreateShape() {
53 webrtc::DesktopRegion result
;
54 result
.AddRect(webrtc::DesktopRect::MakeXYWH(0, 0, 5, 5));
55 result
.AddRect(webrtc::DesktopRect::MakeXYWH(5, 5, 5, 5));
59 virtual void RefreshDesktopShape() OVERRIDE
{
60 shape_
= CreateShape();
63 virtual const webrtc::DesktopRegion
& desktop_shape() OVERRIDE
{
64 // desktop_shape() can't be called before RefreshDesktopShape().
65 EXPECT_FALSE(shape_
.is_empty());
70 webrtc::DesktopRegion shape_
;
73 class ShapedScreenCapturerTest
: public testing::Test
,
74 public webrtc::DesktopCapturer::Callback
{
76 // webrtc::DesktopCapturer::Callback interface
77 virtual webrtc::SharedMemory
* CreateSharedMemory(size_t size
) OVERRIDE
{
81 virtual void OnCaptureCompleted(webrtc::DesktopFrame
* frame
) OVERRIDE
{
82 last_frame_
.reset(frame
);
85 scoped_ptr
<webrtc::DesktopFrame
> last_frame_
;
88 // Verify that captured frame have shape.
89 TEST_F(ShapedScreenCapturerTest
, Basic
) {
90 ShapedScreenCapturer
capturer(
91 scoped_ptr
<webrtc::ScreenCapturer
>(new FakeScreenCapturer()),
92 scoped_ptr
<DesktopShapeTracker
>(new FakeDesktopShapeTracker()));
94 capturer
.Capture(webrtc::DesktopRegion());
95 ASSERT_TRUE(last_frame_
.get());
96 ASSERT_TRUE(last_frame_
->shape());
98 FakeDesktopShapeTracker::CreateShape().Equals(*last_frame_
->shape()));
101 } // namespace remoting