testsuite: Add some checks for focus states

This is some opportunistic checking in a test that
is really about focus chains, but better than nothing.
This commit is contained in:
Matthias Clasen 2020-04-16 12:09:54 -04:00
parent 54b99d281b
commit 5095e87bb7

View File

@ -86,6 +86,34 @@ done:
return diff;
}
static void
check_focus_states (GtkWidget *focus_widget)
{
GtkStateFlags state;
GtkWidget *parent;
if (focus_widget == NULL)
return;
/* Check that we set :focus and :focus-within on the focus_widget,
* and :focus-within on its ancestors
*/
state = gtk_widget_get_state_flags (focus_widget);
g_assert_true ((state & (GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_WITHIN)) ==
(GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_WITHIN));
parent = gtk_widget_get_parent (focus_widget);
while (parent)
{
state = gtk_widget_get_state_flags (parent);
g_assert_true ((state & GTK_STATE_FLAG_FOCUS_WITHIN) == GTK_STATE_FLAG_FOCUS_WITHIN);
g_assert_true ((state & GTK_STATE_FLAG_FOCUSED) == 0);
parent = gtk_widget_get_parent (parent);
}
}
static char *
generate_focus_chain (GtkWidget *window,
GtkDirectionType dir)
@ -109,6 +137,8 @@ generate_focus_chain (GtkWidget *window,
focus = gtk_window_get_focus (GTK_WINDOW (window));
check_focus_states (focus);
if (focus)
{
/* ui files can't put a name on the embedded text,