File: window-mapped-inhibit-tests.c

package info (click to toggle)
mutter 50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 50,868 kB
  • sloc: ansic: 385,772; xml: 3,430; python: 3,272; sh: 325; ruby: 167; makefile: 60; javascript: 26
file content (283 lines) | stat: -rw-r--r-- 8,959 bytes parent folder | download | duplicates (2)
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
 * Copyright (C) 2025 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 "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 "wayland/meta-wayland.h"

static MetaContext *test_context;
static MetaWaylandTestDriver *test_driver;
static MetaVirtualMonitor *virtual_monitor;

#define TEST_CLIENT_TITLE "window-mapped-inhibit-test-window"

static void
wait_for_condition (gboolean (*condition_func) (gpointer),
                    gpointer   user_data)
{
  while (!condition_func (user_data))
    g_main_context_iteration (NULL, TRUE);
}

static gboolean
window_is_not_hidden (gpointer user_data)
{
  MetaWindow *window = (MetaWindow *) user_data;
  return !meta_window_is_hidden (window);
}

static gboolean
window_is_hidden (gpointer user_data)
{
  MetaWindow *window = (MetaWindow *) user_data;
  return meta_window_is_hidden (window);
}

static void
test_window_mapped_inhibit (MetaWindowClientType client_type)
{
  g_autoptr (GError) error = NULL;
  MetaTestClient *test_client;
  MetaWindow *window;

  g_debug ("Starting window mapped inhibit test");

  test_client = meta_test_client_new (test_context,
                                      TEST_CLIENT_TITLE,
                                      client_type,
                                      &error);
  g_assert_no_error (error);

  meta_test_client_run (test_client,
                        "create " TEST_CLIENT_TITLE " csd\n"
                        "show " TEST_CLIENT_TITLE "\n");

  /* Wait for the window to be created */
  while (!(window = meta_test_client_find_window (test_client,
                                                  TEST_CLIENT_TITLE,
                                                  NULL)))
    g_main_context_iteration (NULL, TRUE);
  g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);

  /* Wait for the window to be properly shown */
  wait_for_condition (window_is_not_hidden, window);

  /* Initially, the window should not be mapped inhibited */
  g_assert_false (meta_window_is_mapped_inhibited (window));

  /* The window should be showing normally */
  g_assert_false (meta_window_is_hidden (window));

  /* Inhibit the window mapping */
  meta_window_inhibit_mapped (window);

  /* Now the window should be mapped inhibited */
  g_assert_true (meta_window_is_mapped_inhibited (window));

  /* Wait for the window to be processed and hidden */
  wait_for_condition (window_is_hidden, window);

  /* The window should now be hidden due to the inhibit */
  g_assert_true (meta_window_is_hidden (window));

  /* Uninhibit the window mapping */
  meta_window_uninhibit_mapped (window);

  /* The window should no longer be mapped inhibited */
  g_assert_false (meta_window_is_mapped_inhibited (window));

  /* Wait for the window to be processed and shown again */
  wait_for_condition (window_is_not_hidden, window);

  /* The window should be showing again */
  g_assert_false (meta_window_is_hidden (window));

  g_debug ("Window mapped inhibit test passed");

  meta_test_client_destroy (test_client);

  /* Wait for the window to be removed */
  while (window)
    g_main_context_iteration (NULL, TRUE);
}

static void
test_window_mapped_inhibit_multiple (MetaWindowClientType client_type)
{
  g_autoptr (GError) error = NULL;
  MetaTestClient *test_client;
  MetaWindow *window;

  g_debug ("Starting multiple window mapped inhibit test");

  test_client = meta_test_client_new (test_context,
                                      TEST_CLIENT_TITLE,
                                      client_type,
                                      &error);
  g_assert_no_error (error);

  meta_test_client_run (test_client,
                        "create " TEST_CLIENT_TITLE " csd\n"
                        "show " TEST_CLIENT_TITLE "\n");

  /* Wait for the window to be created */
  while (!(window = meta_test_client_find_window (test_client,
                                                  TEST_CLIENT_TITLE,
                                                  NULL)))
    g_main_context_iteration (NULL, TRUE);
  g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);

  /* Wait for the window to be properly shown */
  wait_for_condition (window_is_not_hidden, window);

  /* Initially, the window should not be mapped inhibited */
  g_assert_false (meta_window_is_mapped_inhibited (window));

  /* Inhibit the window mapping multiple times */
  meta_window_inhibit_mapped (window);
  g_assert_true (meta_window_is_mapped_inhibited (window));
  wait_for_condition (window_is_hidden, window);

  meta_window_inhibit_mapped (window);
  g_assert_true (meta_window_is_mapped_inhibited (window));
  g_assert_true (meta_window_is_hidden (window));

  meta_window_inhibit_mapped (window);
  g_assert_true (meta_window_is_mapped_inhibited (window));
  g_assert_true (meta_window_is_hidden (window));

  /* Uninhibit once - should still be inhibited */
  meta_window_uninhibit_mapped (window);
  g_assert_true (meta_window_is_mapped_inhibited (window));
  g_assert_true (meta_window_is_hidden (window));

  /* Uninhibit again - should still be inhibited */
  meta_window_uninhibit_mapped (window);
  g_assert_true (meta_window_is_mapped_inhibited (window));
  g_assert_true (meta_window_is_hidden (window));

  /* Uninhibit the final time - should no longer be inhibited */
  meta_window_uninhibit_mapped (window);
  g_assert_false (meta_window_is_mapped_inhibited (window));
  wait_for_condition (window_is_not_hidden, window);
  g_assert_false (meta_window_is_hidden (window));

  g_debug ("Multiple window mapped inhibit test passed");

  meta_test_client_destroy (test_client);

  /* Wait for the window to be removed */
  while (window)
    g_main_context_iteration (NULL, TRUE);
}

static void
test_window_mapped_inhibit_wayland (void)
{
  test_window_mapped_inhibit (META_WINDOW_CLIENT_TYPE_WAYLAND);
}

static void
test_window_mapped_inhibit_x11 (void)
{
#ifdef MUTTER_PRIVILEGED_TEST
  g_test_skip ("Running Xwayland in CI KVM doesn't work currently");
#else
  test_window_mapped_inhibit (META_WINDOW_CLIENT_TYPE_X11);
#endif
}

static void
test_window_mapped_inhibit_multiple_wayland (void)
{
  test_window_mapped_inhibit_multiple (META_WINDOW_CLIENT_TYPE_WAYLAND);
}

static void
test_window_mapped_inhibit_multiple_x11 (void)
{
#ifdef MUTTER_PRIVILEGED_TEST
  g_test_skip ("Running Xwayland in CI KVM doesn't work currently");
#else
  test_window_mapped_inhibit_multiple (META_WINDOW_CLIENT_TYPE_X11);
#endif
}

static void
on_before_tests (void)
{
  MetaWaylandCompositor *compositor =
    meta_context_get_wayland_compositor (test_context);

  test_driver = meta_wayland_test_driver_new (compositor);
  virtual_monitor = meta_create_test_monitor (test_context,
                                              400, 400, 60.0);
}

static void
on_after_tests (void)
{
  g_clear_object (&test_driver);
  g_clear_object (&virtual_monitor);
}

static void
init_tests (void)
{
  g_test_add_func ("/window/mapped-inhibit",
                   test_window_mapped_inhibit_wayland);
  g_test_add_func ("/window/mapped-inhibit/x11",
                   test_window_mapped_inhibit_x11);
  g_test_add_func ("/window/mapped-inhibit/multiple",
                   test_window_mapped_inhibit_multiple_wayland);
  g_test_add_func ("/window/mapped-inhibit/multiple/x11",
                   test_window_mapped_inhibit_multiple_x11);
}

int
main (int    argc,
      char **argv)
{
  g_autoptr (MetaContext) context = NULL;

  context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
#ifdef MUTTER_PRIVILEGED_TEST
                                      META_CONTEXT_TEST_FLAG_NO_X11 |
#endif
                                      META_CONTEXT_TEST_FLAG_TEST_CLIENT);
  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);

  return meta_context_test_run_tests (META_CONTEXT_TEST (context),
                                      META_TEST_RUN_FLAG_CAN_SKIP);
}