1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
/*
* 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 "backends/native/meta-backend-native.h"
#include "backends/native/meta-kms.h"
#include "backends/native/meta-kms-device.h"
#include "compositor/meta-window-actor-private.h"
#include "core/window-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"
#include "backends/native/meta-renderer-native.h"
#include "tests/meta-ref-test.h"
#include "wayland/meta-window-wayland.h"
#include "wayland/meta-wayland-surface-private.h"
static MetaContext *test_context;
static MetaWaylandTestDriver *test_driver;
static MetaVirtualMonitor *virtual_monitor;
static MetaWaylandTestClient *wayland_test_client;
static MetaWindow *test_window = NULL;
#define assert_wayland_surface_size(window, width, height) \
{ \
g_assert_cmpint (meta_wayland_surface_get_width (meta_window_get_wayland_surface (window)), \
==, \
width); \
g_assert_cmpint (meta_wayland_surface_get_height (meta_window_get_wayland_surface (window)), \
==, \
height); \
}
static ClutterStageView *
get_view (void)
{
MetaBackend *backend = meta_context_get_backend (test_context);
MetaRenderer *renderer = meta_backend_get_renderer (backend);
return CLUTTER_STAGE_VIEW (meta_renderer_get_views (renderer)->data);
}
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
on_effects_completed (MetaWindowActor *window_actor,
gboolean *done)
{
*done = TRUE;
}
static void
wait_for_window_added (MetaWindow *window)
{
MetaWindowActor *window_actor;
gboolean done = FALSE;
gulong handler_id;
window_actor = meta_window_actor_from_window (window);
handler_id = g_signal_connect (window_actor, "effects-completed",
G_CALLBACK (on_effects_completed), &done);
while (!done)
g_main_context_iteration (NULL, TRUE);
g_signal_handler_disconnect (window_actor, handler_id);
}
static void
toplevel_fullscreen (void)
{
MtkRectangle rect;
wait_for_first_frame (test_window);
meta_window_get_frame_rect (test_window, &rect);
g_assert_cmpint (rect.width, ==, 640);
g_assert_cmpint (rect.height, ==, 480);
g_assert_cmpint (rect.x, ==, 0);
g_assert_cmpint (rect.y, ==, 0);
assert_wayland_surface_size (test_window, 10, 10);
}
static void
toplevel_fullscreen_ref_test (void)
{
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (test_window);
MtkRectangle rect;
wait_for_window_added (test_window);
assert_wayland_surface_size (test_window, 10, 10);
g_assert_true (meta_window_wayland_is_acked_fullscreen (wl_window));
meta_ref_test_verify_view (get_view (),
g_test_get_path (), 1,
meta_ref_test_determine_ref_test_flag ());
meta_window_unmake_fullscreen (test_window);
while (meta_window_wayland_is_acked_fullscreen (wl_window))
g_main_context_iteration (NULL, FALSE);
meta_window_move_frame (test_window, FALSE, 12, 13);
meta_window_get_frame_rect (test_window, &rect);
g_assert_cmpint (rect.width, ==, 10);
g_assert_cmpint (rect.height, ==, 10);
g_assert_cmpint (rect.x, ==, 12);
g_assert_cmpint (rect.y, ==, 13);
assert_wayland_surface_size (test_window, 10, 10);
meta_ref_test_verify_view (get_view (),
g_test_get_path (), 2,
meta_ref_test_determine_ref_test_flag ());
meta_window_make_fullscreen (test_window);
while (!meta_window_wayland_is_acked_fullscreen (wl_window))
g_main_context_iteration (NULL, FALSE);
meta_window_get_frame_rect (test_window, &rect);
g_assert_cmpint (rect.width, ==, 640);
g_assert_cmpint (rect.height, ==, 480);
g_assert_cmpint (rect.x, ==, 0);
g_assert_cmpint (rect.y, ==, 0);
assert_wayland_surface_size (test_window, 10, 10);
meta_ref_test_verify_view (get_view (),
g_test_get_path (), 3,
meta_ref_test_determine_ref_test_flag ());
}
static void
on_before_tests (void)
{
MetaWaylandCompositor *compositor =
meta_context_get_wayland_compositor (test_context);
MetaBackend *backend = meta_context_get_backend (test_context);
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
#ifdef MUTTER_PRIVILEGED_TEST
MetaKms *kms = meta_backend_native_get_kms (META_BACKEND_NATIVE (backend));
MetaKmsDevice *kms_device = meta_kms_get_devices (kms)->data;
#endif
test_driver = meta_wayland_test_driver_new (compositor);
#ifdef MUTTER_PRIVILEGED_TEST
meta_wayland_test_driver_set_property (test_driver,
"gpu-path",
meta_kms_device_get_path (kms_device));
meta_set_custom_monitor_config_full (backend,
"vkms-640x480.xml",
META_MONITORS_CONFIG_FLAG_NONE);
#else
virtual_monitor = meta_create_test_monitor (test_context,
640, 480, 60.0);
#endif
meta_monitor_manager_reload (monitor_manager);
wayland_test_client = meta_wayland_test_client_new (test_context,
"fullscreen");
while (!(test_window =
meta_find_window_from_title (test_context, "fullscreen")))
g_main_context_iteration (NULL, TRUE);
}
static void
on_after_tests (void)
{
meta_wayland_test_driver_emit_sync_event (test_driver, 0);
meta_wayland_test_client_finish (wayland_test_client);
g_clear_object (&virtual_monitor);
g_clear_object (&test_driver);
}
static void
init_tests (void)
{
g_test_add_func ("/wayland/toplevel/fullscreen",
toplevel_fullscreen);
g_test_add_func ("/wayland/toplevel/fullscreen-ref-test",
toplevel_fullscreen_ref_test);
}
int
main (int argc,
char *argv[])
{
g_autoptr (MetaContext) context = NULL;
MetaTestRunFlags test_run_flags;
#ifdef MUTTER_PRIVILEGED_TEST
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_VKMS,
META_CONTEXT_TEST_FLAG_NO_X11);
#else
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
META_CONTEXT_TEST_FLAG_NO_X11);
#endif
g_assert_true (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);
#ifdef MUTTER_PRIVILEGED_TEST
test_run_flags = META_TEST_RUN_FLAG_CAN_SKIP;
#else
test_run_flags = META_TEST_RUN_FLAG_NONE;
#endif
return meta_context_test_run_tests (META_CONTEXT_TEST (context),
test_run_flags);
}
|