From c94d929332d9371646fde15668097c4ea136147c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 16 Dec 2020 23:27:19 +0100 Subject: [PATCH] tests/stacking: Add test hiding a modal with a not shown parent This adds a test case for https://gitlab.gnome.org/GNOME/mutter/-/issues/862 that checks that hiding a dialog where its parent is not yet shown doesn't trigger any asserts or crashes. Part-of: --- src/tests/meson.build | 1 + src/tests/stacking/modals.metatest | 32 ++++++++++++++++++++++++++++++ src/tests/test-client.c | 28 ++++++++++++++++++++++++++ src/tests/test-runner.c | 14 ++++++++++--- 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/tests/stacking/modals.metatest diff --git a/src/tests/meson.build b/src/tests/meson.build index 351d8c245..f63e28952 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -179,6 +179,7 @@ stacking_tests = [ 'fullscreen-maximize', 'restore-position', 'default-size', + 'modals', ] foreach stacking_test: stacking_tests diff --git a/src/tests/stacking/modals.metatest b/src/tests/stacking/modals.metatest new file mode 100644 index 000000000..6c76eadf8 --- /dev/null +++ b/src/tests/stacking/modals.metatest @@ -0,0 +1,32 @@ +new_client w wayland + +# Create two Wayland windows, and make the second a transient of the +# first. Then make the parent not actually ever show, but show the +# transient. + +# Then make sure that hiding the transient can hide without causing +# issues. + +# https://gitlab.gnome.org/GNOME/mutter/-/issues/862 + +create w/1 csd +create w/2 csd + +set_parent w/2 1 + +freeze w/1 + +show w/1 async +show w/2 + +wait + +assert_stacking w/1 w/2 + +hide w/2 +wait + +assert_stacking w/1 + +hide w/2 +wait diff --git a/src/tests/test-client.c b/src/tests/test-client.c index 81ce51ab6..9c2f17863 100644 --- a/src/tests/test-client.c +++ b/src/tests/test-client.c @@ -766,6 +766,34 @@ process_line (const char *line) gtk_window_unfullscreen (GTK_WINDOW (window)); } + else if (strcmp (argv[0], "freeze") == 0) + { + if (argc != 2) + { + g_print ("usage: freeze \n"); + goto out; + } + + GtkWidget *window = lookup_window (argv[1]); + if (!window) + goto out; + + gdk_window_freeze_updates (gtk_widget_get_window (window)); + } + else if (strcmp (argv[0], "thaw") == 0) + { + if (argc != 2) + { + g_print ("usage: thaw \n"); + goto out; + } + + GtkWidget *window = lookup_window (argv[1]); + if (!window) + goto out; + + gdk_window_thaw_updates (gtk_widget_get_window (window)); + } else if (strcmp (argv[0], "assert_size") == 0) { int expected_width; diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c index 1a5ccd944..65fa54682 100644 --- a/src/tests/test-runner.c +++ b/src/tests/test-runner.c @@ -561,8 +561,13 @@ test_case_do (TestCase *test, } else if (strcmp (argv[0], "show") == 0) { - if (argc != 2) - BAD_COMMAND("usage: %s /", argv[0]); + gboolean show_async = FALSE; + + if (argc != 2 && argc != 3) + BAD_COMMAND("usage: %s / [async]", argv[0]); + + if (argc == 3 && strcmp (argv[2], "async") == 0) + show_async = TRUE; TestClient *client; const char *window_id; @@ -579,7 +584,8 @@ test_case_do (TestCase *test, if (!window) return FALSE; - test_client_wait_for_window_shown (client, window); + if (!show_async) + test_client_wait_for_window_shown (client, window); } else if (strcmp (argv[0], "resize") == 0) { @@ -671,6 +677,8 @@ test_case_do (TestCase *test, strcmp (argv[0], "unmaximize") == 0 || strcmp (argv[0], "fullscreen") == 0 || strcmp (argv[0], "unfullscreen") == 0 || + strcmp (argv[0], "freeze") == 0 || + strcmp (argv[0], "thaw") == 0 || strcmp (argv[0], "destroy") == 0) { if (argc != 2)