Flutter Linux Embedder
fl_subsurface_test.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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.
4 
5 #include <wayland-client.h>
6 
7 #include "gtest/gtest.h"
8 
10 #include "flutter/shell/platform/linux/testing/wayland_test.h"
11 
12 using flutter::testing::fl_mock_wayland_free_surface;
13 using flutter::testing::fl_mock_wayland_get_display;
14 using flutter::testing::fl_mock_wayland_get_surface;
15 
16 class FlSubsurfaceTest : public flutter::testing::WaylandTest {
17  protected:
18  void SetUp() override {
19  display_ = fl_wayland_display_open(fl_mock_wayland_get_display());
20  ASSERT_NE(display_, nullptr);
21  parent_surface_ = fl_mock_wayland_get_surface();
22  }
23 
24  void TearDown() override {
25  g_clear_object(&display_);
26  fl_mock_wayland_free_surface(parent_surface_);
27  }
28 
29  FlSubsurface* CreateSubsurface() {
30  return fl_wayland_display_create_subsurface(display_, parent_surface_);
31  }
32 
33  private:
34  FlWaylandDisplay* display_ = nullptr;
35  struct wl_surface* parent_surface_ = nullptr;
36 };
37 
39  // A surface and a subsurface attached to the parent surface are created.
40  EXPECT_CALL(wayland, CreateObject(::testing::StrEq("wl_surface")));
41  EXPECT_CALL(wayland, CreateObject(::testing::StrEq("wl_subsurface")));
42 
43  g_autoptr(FlSubsurface) subsurface = CreateSubsurface();
44  ASSERT_NE(subsurface, nullptr);
45  EXPECT_NE(fl_subsurface_get_surface(subsurface), nullptr);
46 }
47 
48 // Input is handled by the parent (GTK) surface, so the subsurface is given an
49 // empty input region to let events pass through to it.
50 TEST_F(FlSubsurfaceTest, EmptyInputRegion) {
51  ::testing::InSequence sequence;
52  EXPECT_CALL(wayland, CreateObject(::testing::StrEq("wl_region")));
53  EXPECT_CALL(wayland, Request(::testing::StrEq("wl_surface"),
54  WL_SURFACE_SET_INPUT_REGION));
55  EXPECT_CALL(wayland, DestroyObject(::testing::StrEq("wl_region")));
56 
57  g_autoptr(FlSubsurface) subsurface = CreateSubsurface();
58  ASSERT_NE(subsurface, nullptr);
59 }
60 
61 // The subsurface is synchronized with the parent surface, so its contents stay
62 // in step with the GTK window.
63 TEST_F(FlSubsurfaceTest, Synchronized) {
64  EXPECT_CALL(wayland, Request(::testing::StrEq("wl_subsurface"),
65  WL_SUBSURFACE_SET_SYNC));
66 
67  g_autoptr(FlSubsurface) subsurface = CreateSubsurface();
68  ASSERT_NE(subsurface, nullptr);
69 }
70 
71 TEST_F(FlSubsurfaceTest, SetPosition) {
72  g_autoptr(FlSubsurface) subsurface = CreateSubsurface();
73  ASSERT_NE(subsurface, nullptr);
74 
75  EXPECT_CALL(wayland, Request(::testing::StrEq("wl_subsurface"),
76  WL_SUBSURFACE_SET_POSITION))
77  .Times(2);
78 
81 }
82 
83 // The Wayland objects are released when the subsurface is destroyed.
85  FlSubsurface* subsurface = CreateSubsurface();
86  ASSERT_NE(subsurface, nullptr);
87 
88  EXPECT_CALL(wayland, DestroyObject(::testing::StrEq("wl_subsurface")));
89  EXPECT_CALL(wayland, DestroyObject(::testing::StrEq("wl_surface")));
90 
91  g_object_unref(subsurface);
92 }
FlSubsurface * CreateSubsurface()
void SetUp() override
void TearDown() override
g_autoptr(FlEngine) engine
void fl_subsurface_set_position(FlSubsurface *self, gint x, gint y)
struct wl_surface * fl_subsurface_get_surface(FlSubsurface *self)
G_BEGIN_DECLS FlSubsurface * subsurface
TEST_F(FlSubsurfaceTest, Create)
FlSubsurface * fl_wayland_display_create_subsurface(FlWaylandDisplay *self, struct wl_surface *parent_surface)
FlWaylandDisplay * fl_wayland_display_open(struct wl_display *wl_display)