tests: Also search text in HdyActionRow's title and subtitle

This is needed as the labels of HdyActionRow are private.
This commit is contained in:
Adrien Plazas 2020-07-04 09:13:59 +02:00
parent a0dfbb7aac
commit 097ecd4468

View file

@ -121,6 +121,44 @@ fixture_set_up_wired (NetworkPanelFixture *fixture,
/*****************************************************************************/
static GtkWidget *
find_label (GtkWidget *widget,
const gchar *label_pattern)
{
GtkWidget *label = NULL;
if (GTK_IS_LABEL (widget)) {
const gchar *text = gtk_label_get_text (GTK_LABEL (widget));
if (g_pattern_match_simple (label_pattern, text))
return widget;
}
if (HDY_IS_ACTION_ROW (widget)) {
const gchar *text = hdy_action_row_get_title (HDY_ACTION_ROW (widget));
if (g_pattern_match_simple (label_pattern, text))
return widget;
text = hdy_action_row_get_subtitle (HDY_ACTION_ROW (widget));
if (g_pattern_match_simple (label_pattern, text))
return widget;
}
if (GTK_IS_CONTAINER (widget)) {
g_autoptr(GList) list = gtk_container_get_children (GTK_CONTAINER (widget));
GList *node;
for (node = list; node; node = node->next) {
label = find_label (node->data, label_pattern);
if (label)
break;
}
}
return label;
}
/*****************************************************************************/
#if 0 /* See /network-panel-wired/vpn-sorting note */
static GtkWidget*
find_parent_of_type(GtkWidget *widget, GType parent)
@ -145,10 +183,10 @@ test_empty_ui (NetworkPanelFixture *fixture,
GtkWidget *wired_header;
/* There should be no Wired or Bluetooth sections */
wired_header = gtk_test_find_label(fixture->shell, "Wired");
wired_header = find_label(fixture->shell, "Wired");
g_assert_false (wired_header && gtk_widget_is_visible(wired_header));
bt_header = gtk_test_find_label(fixture->shell, "Bluetooth");
bt_header = find_label(fixture->shell, "Bluetooth");
g_assert_false (bt_header && gtk_widget_is_visible(bt_header));
}
@ -171,7 +209,7 @@ test_device_add (NetworkPanelFixture *fixture,
device_path = nm_object_get_path (NM_OBJECT (fixture->main_ether));
g_debug("Device added: %s\n", device_path);
g_assert_nonnull (gtk_test_find_label(fixture->shell, "Wired"));
g_assert_nonnull (find_label(fixture->shell, "Wired"));
}
static void
@ -191,9 +229,9 @@ test_second_device_add (NetworkPanelFixture *fixture,
device_path = nm_object_get_path (NM_OBJECT (device));
g_debug("Second device added: %s\n", device_path);
g_assert_null (gtk_test_find_label (fixture->shell, "Wired"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "Ethernet (eth1000)"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "Ethernet (eth1001)"));
g_assert_null (find_label (fixture->shell, "Wired"));
g_assert_nonnull (find_label (fixture->shell, "Ethernet (eth1000)"));
g_assert_nonnull (find_label (fixture->shell, "Ethernet (eth1001)"));
}
static void
@ -218,12 +256,12 @@ test_second_device_add_remove (NetworkPanelFixture *fixture,
g_debug("Second device removed again\n");
/* eth1000 should be labeled "Wired" again */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "Wired"));
g_assert_null (gtk_test_find_label (fixture->shell, "Ethernet (eth1000)"));
g_assert_null (gtk_test_find_label (fixture->shell, "Ethernet (eth1001)"));
g_assert_nonnull (find_label (fixture->shell, "Wired"));
g_assert_null (find_label (fixture->shell, "Ethernet (eth1000)"));
g_assert_null (find_label (fixture->shell, "Ethernet (eth1001)"));
/* Some more checks for unrelated UI not showing up randomly */
bt_header = gtk_test_find_label(fixture->shell, "Bluetooth");
bt_header = find_label(fixture->shell, "Bluetooth");
g_assert_false (bt_header && gtk_widget_is_visible(bt_header));
}
@ -285,7 +323,7 @@ test_connection_add (NetworkPanelFixture *fixture,
g_object_unref (conn);
/* We have one (non-active) connection only, so we get a special case */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "Cable unplugged"));
g_assert_nonnull (find_label (fixture->shell, "Cable unplugged"));
}
/*****************************************************************************/
@ -297,7 +335,7 @@ test_unconnected_carrier_plug (NetworkPanelFixture *fixture,
nmtst_set_wired_speed (fixture->sinfo, fixture->main_ether, 1234);
nmtst_set_device_state (fixture->sinfo, fixture->main_ether, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_CARRIER);
g_assert_nonnull (gtk_test_find_label (fixture->shell, "1234 Mb/s"));
g_assert_nonnull (find_label (fixture->shell, "1234 Mb/s"));
}
@ -325,7 +363,7 @@ test_connection_add_activate (NetworkPanelFixture *fixture,
active_conn = nmtst_add_and_activate_connection (fixture->sinfo, fixture->client, fixture->main_ether, conn);
g_object_unref (active_conn);
label = gtk_test_find_label (fixture->shell, "1234 Mb/s");
label = find_label (fixture->shell, "1234 Mb/s");
sw = gtk_test_find_sibling (label, GTK_TYPE_SWITCH);
g_assert_nonnull (sw);
g_assert_false (gtk_switch_get_state (GTK_SWITCH (sw)));
@ -338,7 +376,7 @@ test_connection_add_activate (NetworkPanelFixture *fixture,
gtk_switch_set_active (GTK_SWITCH (sw), FALSE);
/* Only one connection, so a generic label. */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "Connected - 1234 Mb/s"));
g_assert_nonnull (find_label (fixture->shell, "Connected - 1234 Mb/s"));
}
static void
@ -363,12 +401,12 @@ test_connection_multi_add_activate (NetworkPanelFixture *fixture,
g_object_unref (nmtst_add_and_activate_connection (fixture->sinfo, fixture->client, fixture->main_ether, conn));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "test-inactive"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "test-active"));
g_assert_null (gtk_test_find_label (fixture->shell, "52:54:00:ab:db:23"));
g_assert_nonnull (find_label (fixture->shell, "test-inactive"));
g_assert_nonnull (find_label (fixture->shell, "test-active"));
g_assert_null (find_label (fixture->shell, "52:54:00:ab:db:23"));
/* We have no switch if there are multiple connections */
sw = gtk_test_find_sibling (gtk_test_find_label (fixture->shell, "test-active"), GTK_TYPE_SWITCH);
sw = gtk_test_find_sibling (find_label (fixture->shell, "test-active"), GTK_TYPE_SWITCH);
if (sw)
g_assert_false (gtk_widget_is_visible (sw));
@ -376,10 +414,10 @@ test_connection_multi_add_activate (NetworkPanelFixture *fixture,
nmtst_set_device_state (fixture->sinfo, fixture->main_ether, NM_DEVICE_STATE_ACTIVATED, NM_DEVICE_STATE_REASON_NONE);
/* Hardware address is shown at this point */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "52:54:00:ab:db:23"));
g_assert_nonnull (find_label (fixture->shell, "52:54:00:ab:db:23"));
/* Some more checks for unrelated UI not showing up randomly */
bt_header = gtk_test_find_label(fixture->shell, "Bluetooth");
bt_header = find_label(fixture->shell, "Bluetooth");
g_assert_false (bt_header && gtk_widget_is_visible(bt_header));
}
@ -412,7 +450,7 @@ test_vpn_add (NetworkPanelFixture *fixture,
g_clear_object (&info.rc);
/* Make sure it shows up. */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_nonnull (find_label (fixture->shell, "A VPN"));
}
/*****************************************************************************/
@ -440,7 +478,7 @@ test_vpn_add_remove (NetworkPanelFixture *fixture,
WAIT_FINISHED(5)
/* Make sure it shows up. */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_nonnull (find_label (fixture->shell, "A VPN"));
/* And delete again */
nm_remote_connection_delete_async (info.rc, NULL, delete_cb, &info);
@ -454,7 +492,7 @@ test_vpn_add_remove (NetworkPanelFixture *fixture,
g_object_unref (conn);
/* Make sure it does not show up. */
g_assert_null (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_null (find_label (fixture->shell, "A VPN"));
}
/*****************************************************************************/
@ -485,7 +523,7 @@ test_vpn_updating (NetworkPanelFixture *fixture,
g_object_unref (conn);
/* Make sure it shows up. */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_nonnull (find_label (fixture->shell, "A VPN"));
/* Rename VPN from A to B */
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sa{sv}}"));
@ -526,8 +564,8 @@ test_vpn_updating (NetworkPanelFixture *fixture,
g_clear_object (&info.rc);
/* Make sure it the label got renamed. */
g_assert_null (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "B VPN"));
g_assert_null (find_label (fixture->shell, "A VPN"));
g_assert_nonnull (find_label (fixture->shell, "B VPN"));
}
/*****************************************************************************/
@ -577,12 +615,12 @@ test_vpn_sorting (NetworkPanelFixture *fixture,
g_object_unref (conn);
/* Make sure both VPNs are there. */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "1 VPN"));
g_assert_nonnull (find_label (fixture->shell, "A VPN"));
g_assert_nonnull (find_label (fixture->shell, "1 VPN"));
/* And test that A is after 1 */
a = find_parent_of_type (gtk_test_find_label (fixture->shell, "A VPN"), GTK_TYPE_STACK);
b = find_parent_of_type (gtk_test_find_label (fixture->shell, "1 VPN"), GTK_TYPE_STACK);
a = find_parent_of_type (find_label (fixture->shell, "A VPN"), GTK_TYPE_STACK);
b = find_parent_of_type (find_label (fixture->shell, "1 VPN"), GTK_TYPE_STACK);
container = gtk_widget_get_parent (a);
list = gtk_container_get_children (GTK_CONTAINER (container));
g_assert_cmpint (g_list_index (list, a), >, g_list_index (list, b));
@ -627,13 +665,13 @@ test_vpn_sorting (NetworkPanelFixture *fixture,
g_clear_object (&info.rc);
/* Make sure it the label got renamed. */
g_assert_null (gtk_test_find_label (fixture->shell, "1 VPN"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "B VPN"));
g_assert_null (find_label (fixture->shell, "1 VPN"));
g_assert_nonnull (find_label (fixture->shell, "A VPN"));
g_assert_nonnull (find_label (fixture->shell, "B VPN"));
/* And test that A is before B */
a = find_parent_of_type (gtk_test_find_label (fixture->shell, "A VPN"), GTK_TYPE_STACK);
b = find_parent_of_type (gtk_test_find_label (fixture->shell, "B VPN"), GTK_TYPE_STACK);
a = find_parent_of_type (find_label (fixture->shell, "A VPN"), GTK_TYPE_STACK);
b = find_parent_of_type (find_label (fixture->shell, "B VPN"), GTK_TYPE_STACK);
container = gtk_widget_get_parent (a);
list = gtk_container_get_children (GTK_CONTAINER (container));
g_assert_cmpint (g_list_index (list, a), <, g_list_index (list, b));