[mutter] tests: Add Wayland fullscreen test client



commit bb19fe2bd48b5f7040ab3a5a5496da8dc5ce417a
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Fri Mar 4 15:04:59 2022 +0100

    tests: Add Wayland fullscreen test client
    
    Fullscreen Wayland toplevel surfaces don't need to respect the
    configured size in which case the window content get centered on a black
    background which covers the whole monitor.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>

 src/tests/meson.build                       |   8 ++
 src/tests/wayland-fullscreen-test.c         | 125 ++++++++++++++++++++++++++++
 src/tests/wayland-test-clients/fullscreen.c | 107 ++++++++++++++++++++++++
 src/tests/wayland-test-clients/meson.build  |   3 +
 4 files changed, 243 insertions(+)
---
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 0ffd9a20ef..f28436a401 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -386,6 +386,14 @@ if have_native_tests
         'xwayland-tests.c',
       ],
     },
+    {
+      'name': 'wayland-fullscreen',
+      'suite': 'wayland',
+      'sources': [
+        'wayland-fullscreen-test.c',
+        wayland_test_utils,
+      ],
+    },
   ]
 
   foreach test_case: test_cases
diff --git a/src/tests/wayland-fullscreen-test.c b/src/tests/wayland-fullscreen-test.c
new file mode 100644
index 0000000000..87fa56201a
--- /dev/null
+++ b/src/tests/wayland-fullscreen-test.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2022 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "backends/meta-virtual-monitor.h"
+#include "compositor/meta-window-actor-private.h"
+#include "meta-test/meta-context-test.h"
+#include "tests/meta-test-utils.h"
+#include "tests/meta-wayland-test-driver.h"
+#include "tests/meta-wayland-test-utils.h"
+
+static MetaContext *test_context;
+static MetaWaylandTestDriver *test_driver;
+
+static void
+on_first_frame (MetaWindowActor *window_actor,
+                gboolean        *done)
+{
+  *done = TRUE;
+}
+
+static void
+wait_for_first_frame (MetaWindow *window)
+{
+  MetaWindowActor *window_actor;
+  gboolean done = FALSE;
+  glong handler_id;
+
+  window_actor = meta_window_actor_from_window (window);
+  handler_id = g_signal_connect (window_actor, "first-frame",
+                                 G_CALLBACK (on_first_frame), &done);
+
+  while (!done)
+    g_main_context_iteration (NULL, TRUE);
+
+  g_signal_handler_disconnect (window_actor, handler_id);
+}
+
+static void
+toplevel_fullscreen (void)
+{
+  g_autoptr (MetaVirtualMonitor) virtual_monitor = NULL;
+  MetaWaylandTestClient *wayland_test_client;
+  MetaWindow *window = NULL;
+  MetaRectangle rect;
+
+  virtual_monitor = meta_create_test_monitor (test_context, 100, 100, 10.0);
+
+  wayland_test_client = meta_wayland_test_client_new ("fullscreen");
+
+  while (!(window = meta_find_window_from_title (test_context, "fullscreen")))
+    g_main_context_iteration (NULL, TRUE);
+
+  wait_for_first_frame (window);
+
+  meta_window_get_frame_rect (window, &rect);
+  g_assert_cmpint (rect.width, ==, 100);
+  g_assert_cmpint (rect.height, ==, 100);
+  g_assert_cmpint (rect.x, ==, 0);
+  g_assert_cmpint (rect.y, ==, 0);
+
+  meta_wayland_test_driver_emit_sync_event (test_driver, 0);
+
+  meta_wayland_test_client_finish (wayland_test_client);
+}
+
+static void
+on_before_tests (void)
+{
+  MetaWaylandCompositor *compositor =
+    meta_context_get_wayland_compositor (test_context);
+
+  test_driver = meta_wayland_test_driver_new (compositor);
+}
+
+static void
+on_after_tests (void)
+{
+  g_clear_object (&test_driver);
+}
+
+static void
+init_tests (void)
+{
+  g_test_add_func ("/wayland/toplevel/fullscreen",
+                   toplevel_fullscreen);
+}
+
+int
+main (int   argc,
+      char *argv[])
+{
+  g_autoptr (MetaContext) context = NULL;
+
+  context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
+                                      META_CONTEXT_TEST_FLAG_NO_X11);
+  g_assert (meta_context_configure (context, &argc, &argv, NULL));
+
+  test_context = context;
+
+  init_tests ();
+
+  g_signal_connect (context, "before-tests",
+                    G_CALLBACK (on_before_tests), NULL);
+  g_signal_connect (context, "after-tests",
+                    G_CALLBACK (on_after_tests), NULL);
+
+  return meta_context_test_run_tests (META_CONTEXT_TEST (context),
+                                      META_TEST_RUN_FLAG_NONE);
+}
diff --git a/src/tests/wayland-test-clients/fullscreen.c b/src/tests/wayland-test-clients/fullscreen.c
new file mode 100644
index 0000000000..9690f6e853
--- /dev/null
+++ b/src/tests/wayland-test-clients/fullscreen.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2022 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <wayland-client.h>
+
+#include "wayland-test-client-utils.h"
+
+static WaylandDisplay *display;
+
+static struct wl_surface *surface;
+static struct xdg_surface *xdg_surface;
+static struct xdg_toplevel *xdg_toplevel;
+
+static gboolean running;
+
+static void
+handle_xdg_toplevel_configure (void                *data,
+                               struct xdg_toplevel *xdg_toplevel,
+                               int32_t              width,
+                               int32_t              height,
+                               struct wl_array     *state)
+{
+}
+
+static void
+handle_xdg_toplevel_close (void                *data,
+                           struct xdg_toplevel *xdg_toplevel)
+{
+  g_assert_not_reached ();
+}
+
+static const struct xdg_toplevel_listener xdg_toplevel_listener = {
+  handle_xdg_toplevel_configure,
+  handle_xdg_toplevel_close,
+};
+
+static void
+handle_xdg_surface_configure (void               *data,
+                              struct xdg_surface *xdg_surface,
+                              uint32_t            serial)
+{
+  draw_surface (display, surface, 10, 10, 0x1f109f20);
+  xdg_surface_ack_configure (xdg_surface, serial);
+  wl_surface_commit (surface);
+
+  g_assert_cmpint (wl_display_roundtrip (display->display), !=, -1);
+}
+
+static const struct xdg_surface_listener xdg_surface_listener = {
+  handle_xdg_surface_configure,
+};
+
+static void
+on_sync_event (WaylandDisplay *display,
+               uint32_t        serial)
+{
+  g_assert (serial == 0);
+  running = FALSE;
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  display = wayland_display_new (WAYLAND_DISPLAY_CAPABILITY_TEST_DRIVER);
+  g_signal_connect (display, "sync-event", G_CALLBACK (on_sync_event), NULL);
+
+  surface = wl_compositor_create_surface (display->compositor);
+  xdg_surface = xdg_wm_base_get_xdg_surface (display->xdg_wm_base, surface);
+  xdg_surface_add_listener (xdg_surface, &xdg_surface_listener, NULL);
+  xdg_toplevel = xdg_surface_get_toplevel (xdg_surface);
+  xdg_toplevel_add_listener (xdg_toplevel, &xdg_toplevel_listener, NULL);
+  xdg_toplevel_set_title (xdg_toplevel, "fullscreen");
+  xdg_toplevel_set_fullscreen (xdg_toplevel, NULL);
+  wl_surface_commit (surface);
+
+  running = TRUE;
+  while (running)
+    {
+      if (wl_display_dispatch (display->display) == -1)
+        return EXIT_FAILURE;
+    }
+
+  wl_display_roundtrip (display->display);
+
+  g_clear_pointer (&xdg_toplevel, xdg_toplevel_destroy);
+  g_clear_pointer (&xdg_surface, xdg_surface_destroy);
+}
diff --git a/src/tests/wayland-test-clients/meson.build b/src/tests/wayland-test-clients/meson.build
index 0610f3cc5a..ac838231ce 100644
--- a/src/tests/wayland-test-clients/meson.build
+++ b/src/tests/wayland-test-clients/meson.build
@@ -76,6 +76,9 @@ wayland_test_clients = [
   {
     'name': 'xdg-toplevel-bounds',
   },
+  {
+    'name': 'fullscreen',
+  },
   {
     'name': 'dma-buf-scanout',
     'extra_deps': [


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]