From 750eaf53d668c99bab227eb77db3c0d0b4367841 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 18 Feb 2014 13:48:13 +0100 Subject: [PATCH] testsuite: Add a test for a Firefox issue When creating a style context, the CSS for the theme might not be loaded. If it is, this test will succeed. https://bugzilla.redhat.com/show_bug.cgi?id=1064922 https://bugzilla.mozilla.org/show_bug.cgi?id=972382 --- testsuite/gtk/Makefile.am | 1 + testsuite/gtk/firefox-stylecontext.c | 66 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 testsuite/gtk/firefox-stylecontext.c diff --git a/testsuite/gtk/Makefile.am b/testsuite/gtk/Makefile.am index 077b4f3b10..d5a1bcb479 100644 --- a/testsuite/gtk/Makefile.am +++ b/testsuite/gtk/Makefile.am @@ -36,6 +36,7 @@ TEST_PROGS += \ defaultvalue \ entry \ expander \ + firefox-stylecontext \ floating \ grid \ gtkmenu \ diff --git a/testsuite/gtk/firefox-stylecontext.c b/testsuite/gtk/firefox-stylecontext.c new file mode 100644 index 0000000000..0e5ce78f88 --- /dev/null +++ b/testsuite/gtk/firefox-stylecontext.c @@ -0,0 +1,66 @@ +#include + +static void +test_init_of_theme (void) +{ + GtkStyleContext *context; + GtkCssProvider *provider; + GtkWidgetPath *path; + GdkRGBA before, after; + char *css; + + /* Test that a style context actually uses the theme loaded for the + * screen it is using. If no screen is set, it's the default one. + */ + context = gtk_style_context_new (); + path = gtk_widget_path_new (); + + /* Set a path that will have a color set. + * (This could actually fail if style classes change, so if this test + * fails, make sure to have this path represent something sane.) + */ + gtk_widget_path_append_type (path, GTK_TYPE_WINDOW); + gtk_widget_path_iter_add_class (path, -1, GTK_STYLE_CLASS_BACKGROUND); + gtk_style_context_set_path (context, path); + gtk_widget_path_free (path); + + /* Get the color. This should be initialized by the theme and not be + * the default. */ + gtk_style_context_get_color (context, 0, &before); + + /* Add a style that sets a different color for this widget. + * This style has a higher priority than fallback, but a lower + * priority than the theme. */ + css = g_strdup_printf (".background { color: %s; }", + before.alpha < 0.5 ? "black" : "transparent"); + provider = gtk_css_provider_new (); + gtk_css_provider_load_from_data (provider, css, -1, NULL); + gtk_style_context_add_provider (context, + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_FALLBACK + 1); + g_object_unref (provider); + + /* Get the color again. */ + gtk_style_context_get_color (context, 0, &after); + + /* Because the style we added does not influence the color, + * the before and after colors should be identical. */ + g_assert (gdk_rgba_equal (&before, &after)); + + g_object_unref (context); +} + +int +main (int argc, char *argv[]) +{ + /* If gdk_init() is called before gtk_init() the GTK code takes + * a different path (why?) + */ + gdk_init (NULL, NULL); + gtk_init (NULL, NULL); + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/style/init_of_theme", test_init_of_theme); + + return g_test_run (); +}