Flutter Linux Embedder
fl_wayland_display_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 <gdk/gdkwayland.h>
6 #include <wayland-client.h>
7 
8 #include "gtest/gtest.h"
9 
11 #include "flutter/shell/platform/linux/testing/wayland_test.h"
12 
13 using flutter::testing::fl_mock_wayland_free_surface;
14 using flutter::testing::fl_mock_wayland_get_display;
15 using flutter::testing::fl_mock_wayland_get_surface;
16 
17 class FlWaylandDisplayTest : public flutter::testing::WaylandTest {};
18 
20  // The registry is created to bind the globals, then released once they have
21  // been received.
22  EXPECT_CALL(wayland, CreateObject(::testing::StrEq("wl_registry")));
23  EXPECT_CALL(wayland, DestroyObject(::testing::StrEq("wl_registry")));
24 
25  g_autoptr(FlWaylandDisplay) display =
26  fl_wayland_display_open(fl_mock_wayland_get_display());
27  EXPECT_NE(display, nullptr);
28  EXPECT_FALSE(HasReceivedLogLevel(G_LOG_LEVEL_WARNING));
29 }
30 
31 // The display can't be used if the compositor doesn't support subsurfaces.
32 TEST_F(FlWaylandDisplayTest, OpenMissingSubcompositor) {
33  wayland.has_subcompositor = false;
34 
35  FlWaylandDisplay* display =
36  fl_wayland_display_open(fl_mock_wayland_get_display());
37  EXPECT_EQ(display, nullptr);
38  EXPECT_TRUE(HasReceivedLogLevel(G_LOG_LEVEL_WARNING));
39 }
40 
41 TEST_F(FlWaylandDisplayTest, OpenMissingCompositor) {
42  wayland.has_compositor = false;
43 
44  FlWaylandDisplay* display =
45  fl_wayland_display_open(fl_mock_wayland_get_display());
46  EXPECT_EQ(display, nullptr);
47  EXPECT_TRUE(HasReceivedLogLevel(G_LOG_LEVEL_WARNING));
48 }
49 
50 // Asking for the Wayland display of a display that isn't Wayland is a
51 // programmer error.
52 TEST_F(FlWaylandDisplayTest, GetForNonWaylandDisplay) {
53  // Tests are run on X11 (gdk_display_get_default() is mocked, so the display
54  // manager is used to get the display actually in use).
55  GdkDisplay* gdk_display =
56  gdk_display_manager_get_default_display(gdk_display_manager_get());
57  ASSERT_FALSE(GDK_IS_WAYLAND_DISPLAY(gdk_display));
58 
59  EXPECT_CALL(wayland, CreateObject(::testing::_)).Times(0);
60 
61  EXPECT_EQ(fl_wayland_display_get_for_display(gdk_display), nullptr);
62  EXPECT_TRUE(HasReceivedLogLevel(G_LOG_LEVEL_CRITICAL));
63 }
64 
65 // Subsurfaces are made from the globals bound when the display was opened, so
66 // the registry is only used once however many subsurfaces are created.
67 TEST_F(FlWaylandDisplayTest, CreateSubsurface) {
68  g_autoptr(FlWaylandDisplay) display =
69  fl_wayland_display_open(fl_mock_wayland_get_display());
70  ASSERT_NE(display, nullptr);
71  struct wl_surface* parent_surface = fl_mock_wayland_get_surface();
72 
73  EXPECT_CALL(wayland, CreateObject(::testing::StrEq("wl_registry"))).Times(0);
74 
75  g_autoptr(FlSubsurface) subsurface1 =
76  fl_wayland_display_create_subsurface(display, parent_surface);
77  g_autoptr(FlSubsurface) subsurface2 =
78  fl_wayland_display_create_subsurface(display, parent_surface);
79  ASSERT_NE(subsurface1, nullptr);
80  ASSERT_NE(subsurface2, nullptr);
81  EXPECT_NE(fl_subsurface_get_surface(subsurface1),
82  fl_subsurface_get_surface(subsurface2));
83 
84  fl_mock_wayland_free_surface(parent_surface);
85 }
g_autoptr(FlEngine) engine
struct wl_surface * fl_subsurface_get_surface(FlSubsurface *self)
FlSubsurface * fl_wayland_display_create_subsurface(FlWaylandDisplay *self, struct wl_surface *parent_surface)
FlWaylandDisplay * fl_wayland_display_get_for_display(GdkDisplay *gdk_display)
FlWaylandDisplay * fl_wayland_display_open(struct wl_display *wl_display)
TEST_F(FlWaylandDisplayTest, Open)