Merge branch 'matthiasc/for-main' into 'main'

testsuite: Add some more a11y tests

See merge request GNOME/gtk!6109
This commit is contained in:
Matthias Clasen 2023-06-18 03:03:33 +00:00
commit 48d719e58e
7 changed files with 148 additions and 6 deletions

View File

@ -24,6 +24,9 @@
<property name="spacing">12</property>
<child>
<object class="GtkDropDown" id="source_chooser">
<accessibility>
<property name="label">Source Type</property>
</accessibility>
<property name="valign">center</property>
<property name="model">
<object class="GtkStringList">
@ -54,6 +57,9 @@
<property name="name">Text</property>
<property name="child">
<object class="GtkEntry" id="source_text">
<accessibility>
<property name="label">Text Drag Source</property>
</accessibility>
<property name="valign">center</property>
<signal name="notify::text" handler="text_changed_cb" object="copy_button"/>
<property name="text">Copy this!</property>
@ -66,6 +72,9 @@
<property name="name">Color</property>
<property name="child">
<object class="GtkColorDialogButton" id="source_color">
<accessibility>
<property name="label">Color Drag Source</property>
</accessibility>
<property name="dialog">
<object class="GtkColorDialog">
</object>
@ -87,14 +96,17 @@
</style>
<child>
<object class="GtkToggleButton" id="image_rose">
<accessibility>
<property name="label">Photo Drag Source</property>
</accessibility>
<property name="active">1</property>
<child>
<object class="GtkDragSource">
<signal name="prepare" handler="drag_prepare"/>
</object>
</child>
<child>
<object class="GtkImage">
<accessibility>
<property name="label">Portland Rose Photo</property>
</accessibility>
<style>
<class name="large-icons"/>
</style>
@ -105,6 +117,9 @@
</child>
<child>
<object class="GtkToggleButton" id="image_floppy">
<accessibility>
<property name="label">Icon Drag Source</property>
</accessibility>
<property name="group">image_rose</property>
<child>
<object class="GtkDragSource">
@ -113,6 +128,9 @@
</child>
<child>
<object class="GtkImage">
<accessibility>
<property name="label">Floppy Buddy Icon</property>
</accessibility>
<style>
<class name="large-icons"/>
</style>
@ -123,6 +141,9 @@
</child>
<child>
<object class="GtkToggleButton" id="image_logo">
<accessibility>
<property name="label">SVG Drag Source</property>
</accessibility>
<property name="group">image_floppy</property>
<child>
<object class="GtkDragSource">
@ -131,6 +152,9 @@
</child>
<child>
<object class="GtkImage">
<accessibility>
<property name="label">gtk-demo logo</property>
</accessibility>
<style>
<class name="large-icons"/>
</style>
@ -148,6 +172,9 @@
<property name="name">File</property>
<property name="child">
<object class="GtkButton" id="source_file">
<accessibility>
<property name="label">File Drag Source</property>
</accessibility>
<child>
<object class="GtkDragSource">
<property name="propagation-phase">capture</property>
@ -172,6 +199,9 @@
<property name="name">Folder</property>
<property name="child">
<object class="GtkButton" id="source_folder">
<accessibility>
<property name="label">Folder Drag Source</property>
</accessibility>
<child>
<object class="GtkDragSource">
<property name="propagation-phase">capture</property>
@ -225,7 +255,7 @@
</object>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="paste_label">
<property name="xalign">0</property>
<binding name="label">
<lookup name="visible-child-name" type="GtkStack">
@ -252,6 +282,9 @@
<property name="name">Text</property>
<property name="child">
<object class="GtkLabel">
<accessibility>
<relation name="labelled-by">paste_label</relation>
</accessibility>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="xalign">0</property>
@ -265,6 +298,9 @@
<property name="name">Image</property>
<property name="child">
<object class="GtkImage">
<accessibility>
<relation name="labelled-by">paste_label</relation>
</accessibility>
<property name="halign">end</property>
<property name="valign">center</property>
<style>
@ -283,6 +319,9 @@
<property name="valign">center</property>
<child>
<object class="GtkColorSwatch">
<accessibility>
<relation name="labelled-by">paste_label</relation>
</accessibility>
<property name="accessible-role">img</property>
<property name="can-focus">0</property>
<property name="selectable">0</property>
@ -298,6 +337,9 @@
<property name="name">File</property>
<property name="child">
<object class="GtkLabel">
<accessibility>
<relation name="labelled-by">paste_label</relation>
</accessibility>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="xalign">0</property>

View File

@ -110,7 +110,9 @@ gtk_color_dialog_button_init (GtkColorDialogButton *self)
self->color = GDK_RGBA ("00000000");
self->button = gtk_button_new ();
self->button = g_object_new (GTK_TYPE_BUTTON,
"accessible-role", GTK_ACCESSIBLE_ROLE_GENERIC,
NULL);
g_signal_connect_swapped (self->button, "clicked", G_CALLBACK (button_clicked), self);
gtk_widget_set_parent (self->button, GTK_WIDGET (self));
@ -280,6 +282,7 @@ gtk_color_dialog_button_class_init (GtkColorDialogButtonClass *class)
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_css_name (widget_class, "colorbutton");
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_BUTTON);
}
/* }}} */

View File

@ -695,7 +695,10 @@ setup_item (GtkSignalListItemFactory *factory,
label = gtk_label_new (NULL);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_box_append (GTK_BOX (box), label);
icon = gtk_image_new_from_icon_name ("object-select-symbolic");
icon = g_object_new (GTK_TYPE_IMAGE,
"icon-name", "object-select-symbolic",
"accessible-role", GTK_ACCESSIBLE_ROLE_NONE,
NULL);
gtk_box_append (GTK_BOX (box), icon);
gtk_list_item_set_child (list_item, box);
}

View File

@ -3,6 +3,7 @@
<template class="GtkDropDown" parent="GtkWidget">
<child>
<object class="GtkToggleButton" id="button">
<property name="accessible-role">generic</property>
<signal name="toggled" handler="button_toggled"/>
<child>
<object class="GtkBox">

View File

@ -25,6 +25,7 @@ entry_properties (void)
gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_PLACEHOLDER, "Hello");
gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_READ_ONLY, TRUE);
gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, TRUE);
g_object_unref (widget);
}

View File

@ -28,6 +28,7 @@ tests = [
{ 'name': 'stack' },
{ 'name': 'switch' },
{ 'name': 'textview' },
{ 'name': 'togglebutton' },
{ 'name': 'window' },
]

View File

@ -0,0 +1,91 @@
#include <gtk/gtk.h>
static void
toggle_button_role (void)
{
GtkWidget *button = gtk_toggle_button_new ();
g_object_ref_sink (button);
gtk_test_accessible_assert_role (button, GTK_ACCESSIBLE_ROLE_TOGGLE_BUTTON);
/* Simple command buttons have a "pressed" state set to "undefined" */
gtk_test_accessible_assert_state (button, GTK_ACCESSIBLE_STATE_PRESSED, GTK_ACCESSIBLE_VALUE_UNDEFINED);
g_object_unref (button);
}
static void
toggle_button_label (void)
{
GtkWidget *button = gtk_toggle_button_new_with_label ("Hello");
g_object_ref_sink (button);
gtk_test_accessible_assert_relation (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, gtk_widget_get_first_child (button), NULL);
g_object_unref (button);
}
/* Check that we set up a labelled_by relationship between a button
* and its label.
*/
static void
toggle_button_relation (void)
{
GtkWidget *button = gtk_toggle_button_new_with_mnemonic ("_Hello");
g_object_ref_sink (button);
gtk_test_accessible_assert_relation (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, gtk_widget_get_first_child (button), NULL);
g_object_unref (button);
}
static void
toggle_button_generic (void)
{
GtkBuilder *builder;
GtkWidget *button;
GError *error = NULL;
button = g_object_new (GTK_TYPE_TOGGLE_BUTTON,
"accessible-role", GTK_ACCESSIBLE_ROLE_GENERIC,
NULL);
g_object_ref_sink (button);
gtk_test_accessible_assert_role (button, GTK_ACCESSIBLE_ROLE_GENERIC);
g_object_unref (button);
builder = gtk_builder_new ();
gtk_builder_add_from_string (builder,
"<interface>"
" <object class='GtkToggleButton' id='togglebutton'>"
" <property name='accessible-role'>generic</property>"
" </object>"
"</interface>",
-1, &error);
g_assert_no_error (error);
button = GTK_WIDGET (gtk_builder_get_object (builder, "togglebutton"));
gtk_test_accessible_assert_role (button, GTK_ACCESSIBLE_ROLE_GENERIC);
g_object_unref (builder);
}
int
main (int argc, char *argv[])
{
gtk_test_init (&argc, &argv, NULL);
g_test_add_func ("/a11y/togglebutton/role", toggle_button_role);
g_test_add_func ("/a11y/togglebutton/label", toggle_button_label);
g_test_add_func ("/a11y/togglebutton/relation", toggle_button_relation);
g_test_add_func ("/a11y/togglebutton/generic", toggle_button_generic);
return g_test_run ();
}