Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / shaped_desktop_capturer_unittest.cc
blob371c473dbc7738117c23b1618721457fdc7f8afb
1 // Copyright 2014 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_desktop_capturer.h"
7 #include "remoting/host/desktop_shape_tracker.h"
8 #include "remoting/host/fake_desktop_capturer.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
11 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
14 namespace remoting {
16 class FakeDesktopShapeTracker : public DesktopShapeTracker {
17 public:
18 FakeDesktopShapeTracker() {}
19 ~FakeDesktopShapeTracker() override {}
21 static webrtc::DesktopRegion CreateShape() {
22 webrtc::DesktopRegion result;
23 result.AddRect(webrtc::DesktopRect::MakeXYWH(0, 0, 5, 5));
24 result.AddRect(webrtc::DesktopRect::MakeXYWH(5, 5, 5, 5));
25 return result;
28 void RefreshDesktopShape() override { shape_ = CreateShape(); }
30 const webrtc::DesktopRegion& desktop_shape() override {
31 // desktop_shape() can't be called before RefreshDesktopShape().
32 EXPECT_FALSE(shape_.is_empty());
33 return shape_;
36 private:
37 webrtc::DesktopRegion shape_;
40 class ShapedDesktopCapturerTest : public testing::Test,
41 public webrtc::DesktopCapturer::Callback {
42 public:
43 // webrtc::DesktopCapturer::Callback interface
44 webrtc::SharedMemory* CreateSharedMemory(size_t size) override {
45 return nullptr;
48 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override {
49 last_frame_.reset(frame);
52 scoped_ptr<webrtc::DesktopFrame> last_frame_;
55 // Verify that captured frame have shape.
56 TEST_F(ShapedDesktopCapturerTest, Basic) {
57 ShapedDesktopCapturer capturer(
58 make_scoped_ptr(new FakeDesktopCapturer()),
59 make_scoped_ptr(new FakeDesktopShapeTracker()));
60 capturer.Start(this);
61 capturer.Capture(webrtc::DesktopRegion());
62 ASSERT_TRUE(last_frame_.get());
63 ASSERT_TRUE(last_frame_->shape());
64 EXPECT_TRUE(
65 FakeDesktopShapeTracker::CreateShape().Equals(*last_frame_->shape()));
68 } // namespace remoting