summaryrefslogtreecommitdiff
path: root/tests/network/test-network-panel.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/network/test-network-panel.c')
-rw-r--r--tests/network/test-network-panel.c202
1 files changed, 144 insertions, 58 deletions
diff --git a/tests/network/test-network-panel.c b/tests/network/test-network-panel.c
index 4f33e41ab..b68c06fa4 100644
--- a/tests/network/test-network-panel.c
+++ b/tests/network/test-network-panel.c
@@ -1,4 +1,3 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (c) 2010-2014, 2018 Red Hat, Inc.
*
@@ -33,7 +32,6 @@
#include <sys/types.h>
#include <signal.h>
#include <gtk/gtk.h>
-#include <handy.h>
#include "cc-test-window.h"
#include "shell/cc-object-storage.h"
@@ -46,7 +44,7 @@ typedef struct {
NMDevice *main_ether;
- GtkWidget *shell;
+ GtkWindow *shell;
CcPanel *panel;
} NetworkPanelFixture;
@@ -70,7 +68,7 @@ fixture_set_up_empty (NetworkPanelFixture *fixture,
/* Insert into object storage so that we see the same events as the panel. */
cc_object_storage_add_object (CC_OBJECT_NMCLIENT, fixture->client);
- fixture->shell = GTK_WIDGET (cc_test_window_new ());
+ fixture->shell = GTK_WINDOW (cc_test_window_new ());
fixture->panel = g_object_new (cc_network_panel_get_type (),
"shell", CC_SHELL (fixture->shell),
@@ -79,7 +77,7 @@ fixture_set_up_empty (NetworkPanelFixture *fixture,
g_object_ref (fixture->panel);
cc_shell_set_active_panel (CC_SHELL (fixture->shell), fixture->panel);
- gtk_widget_show (GTK_WIDGET (fixture->shell));
+ gtk_window_present (fixture->shell);
}
static void
@@ -88,7 +86,7 @@ fixture_tear_down (NetworkPanelFixture *fixture,
{
g_clear_object (&fixture->panel);
g_clear_object (&fixture->client);
- g_clear_pointer (&fixture->shell, gtk_widget_destroy);
+ g_clear_pointer (&fixture->shell, gtk_window_destroy);
cc_object_storage_destroy ();
@@ -124,6 +122,7 @@ static GtkWidget *
find_label (GtkWidget *widget,
const gchar *label_pattern)
{
+ GtkWidget *child;
GtkWidget *label = NULL;
if (GTK_IS_LABEL (widget)) {
@@ -132,30 +131,119 @@ find_label (GtkWidget *widget,
return widget;
}
- if (HDY_IS_PREFERENCES_ROW (widget)) {
- const gchar *text = hdy_preferences_row_get_title (HDY_PREFERENCES_ROW (widget));
+ if (ADW_IS_PREFERENCES_ROW (widget)) {
+ const gchar *text = adw_preferences_row_get_title (ADW_PREFERENCES_ROW (widget));
if (g_pattern_match_simple (label_pattern, text))
return widget;
}
- if (HDY_IS_ACTION_ROW (widget)) {
- const gchar *text = hdy_action_row_get_subtitle (HDY_ACTION_ROW (widget));
+ if (ADW_IS_ACTION_ROW (widget)) {
+ const gchar *text = adw_action_row_get_subtitle (ADW_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 (child = gtk_widget_get_first_child (widget);
+ child;
+ child = gtk_widget_get_next_sibling (child)) {
+ label = find_label (child, label_pattern);
+ if (label)
+ break;
+ }
+
+ return label;
+}
+
+static int
+widget_geo_dist (GtkWidget *a,
+ GtkWidget *b,
+ GtkWidget *base)
+{
+ GtkAllocation allocation;
+ double ax0, ay0, ax1, ay1, bx0, by0, bx1, by1, xdist = 0, ydist = 0;
+
+ gtk_widget_get_allocation (a, &allocation);
+ if (!gtk_widget_translate_coordinates (a, base, 0, 0, &ax0, &ay0) ||
+ !gtk_widget_translate_coordinates (a, base, allocation.width, allocation.height, &ax1, &ay1))
+ return -G_MAXINT;
+
+ gtk_widget_get_allocation (b, &allocation);
+ if (!gtk_widget_translate_coordinates (b, base, 0, 0, &bx0, &by0) ||
+ !gtk_widget_translate_coordinates (b, base, allocation.width, allocation.height, &bx1, &by1))
+ return +G_MAXINT;
+
+ if (bx0 >= ax1)
+ xdist = bx0 - ax1;
+ else if (ax0 >= bx1)
+ xdist = ax0 - bx1;
+ if (by0 >= ay1)
+ ydist = by0 - ay1;
+ else if (ay0 >= by1)
+ ydist = ay0 - by1;
+
+ return xdist + ydist;
+}
- for (node = list; node; node = node->next) {
- label = find_label (node->data, label_pattern);
- if (label)
+static GList*
+test_list_descendants (GtkWidget *widget,
+ GType widget_type)
+{
+ GtkWidget *child;
+ GList *results = NULL;
+
+ for (child = gtk_widget_get_first_child (widget);
+ child;
+ child = gtk_widget_get_next_sibling (child)) {
+ if (!widget_type || g_type_is_a (G_OBJECT_TYPE (child), widget_type))
+ results = g_list_prepend (results, child);
+ else
+ results = g_list_concat (results, test_list_descendants (child, widget_type));
+ }
+
+ return results;
+}
+
+static int
+widget_geo_cmp (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data)
+{
+ gpointer *data = user_data;
+ GtkWidget *wa = (void*) a, *wb = (void*) b, *toplevel = data[0], *base_widget = data[1];
+ int adist = widget_geo_dist (wa, base_widget, toplevel);
+ int bdist = widget_geo_dist (wb, base_widget, toplevel);
+ return adist > bdist ? +1 : adist == bdist ? 0 : -1;
+}
+
+static GtkWidget *
+find_sibling (GtkWidget *widget,
+ GType parent_type,
+ GType sibling_type)
+{
+ g_autoptr(GList) siblings = NULL;
+ GtkWidget *tmpwidget = widget;
+ gpointer data[2];
+
+ /* find all sibling candidates */
+ while ((tmpwidget = gtk_widget_get_parent (tmpwidget)) != NULL)
+ {
+ siblings = g_list_concat (siblings, test_list_descendants (tmpwidget, sibling_type));
+
+ /* Stop searching further up if we reached the defined parent */
+ if (parent_type && g_type_is_a (G_OBJECT_TYPE (tmpwidget), parent_type))
break;
}
- }
- return label;
+ /* sort them by distance to base_widget */
+ data[0] = gtk_widget_get_native (widget);
+ data[1] = widget;
+ siblings = g_list_sort_with_data (siblings, widget_geo_cmp, data);
+
+ /* pick nearest != base_widget */
+ siblings = g_list_remove (siblings, widget);
+ tmpwidget = siblings ? siblings->data : NULL;
+
+ return tmpwidget;
}
/*****************************************************************************/
@@ -184,10 +272,10 @@ test_empty_ui (NetworkPanelFixture *fixture,
GtkWidget *wired_header;
/* There should be no Wired or Bluetooth sections */
- wired_header = find_label(fixture->shell, "Wired");
+ wired_header = find_label (GTK_WIDGET (fixture->shell), "Wired");
g_assert_false (wired_header && gtk_widget_is_visible(wired_header));
- bt_header = find_label(fixture->shell, "Bluetooth");
+ bt_header = find_label (GTK_WIDGET (fixture->shell), "Bluetooth");
g_assert_false (bt_header && gtk_widget_is_visible(bt_header));
}
@@ -210,7 +298,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 (find_label(fixture->shell, "Wired"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "Wired"));
}
static void
@@ -230,9 +318,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 (find_label (fixture->shell, "Wired"));
- g_assert_nonnull (find_label (fixture->shell, "Ethernet (eth1000)"));
- g_assert_nonnull (find_label (fixture->shell, "Ethernet (eth1001)"));
+ g_assert_null (find_label (GTK_WIDGET (fixture->shell), "Wired"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "Ethernet (eth1000)"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "Ethernet (eth1001)"));
}
static void
@@ -257,12 +345,12 @@ test_second_device_add_remove (NetworkPanelFixture *fixture,
g_debug("Second device removed again\n");
/* eth1000 should be labeled "Wired" again */
- 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)"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "Wired"));
+ g_assert_null (find_label (GTK_WIDGET (fixture->shell), "Ethernet (eth1000)"));
+ g_assert_null (find_label (GTK_WIDGET (fixture->shell), "Ethernet (eth1001)"));
/* Some more checks for unrelated UI not showing up randomly */
- bt_header = find_label(fixture->shell, "Bluetooth");
+ bt_header = find_label (GTK_WIDGET (fixture->shell), "Bluetooth");
g_assert_false (bt_header && gtk_widget_is_visible(bt_header));
}
@@ -324,7 +412,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 (find_label (fixture->shell, "Cable unplugged"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "Cable unplugged"));
}
/*****************************************************************************/
@@ -336,7 +424,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 (find_label (fixture->shell, "1234 Mb/s"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "1234 Mb/s"));
}
@@ -364,8 +452,8 @@ 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 = find_label (fixture->shell, "1234 Mb/s");
- sw = gtk_test_find_sibling (label, GTK_TYPE_SWITCH);
+ label = find_label (GTK_WIDGET (fixture->shell), "1234 Mb/s");
+ sw = find_sibling (label, GTK_TYPE_LIST_BOX_ROW, GTK_TYPE_SWITCH);
g_assert_nonnull (sw);
g_assert_false (gtk_switch_get_state (GTK_SWITCH (sw)));
@@ -377,7 +465,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 (find_label (fixture->shell, "Connected - 1234 Mb/s"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "Connected - 1234 Mb/s"));
}
static void
@@ -402,12 +490,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 (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"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "test-inactive"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "test-active"));
+ g_assert_null (find_label (GTK_WIDGET (fixture->shell), "52:54:00:ab:db:23"));
/* We have no switch if there are multiple connections */
- sw = gtk_test_find_sibling (find_label (fixture->shell, "test-active"), GTK_TYPE_SWITCH);
+ sw = find_sibling (find_label (GTK_WIDGET (fixture->shell), "test-active"), GTK_TYPE_LIST_BOX_ROW, GTK_TYPE_SWITCH);
if (sw)
g_assert_false (gtk_widget_is_visible (sw));
@@ -415,10 +503,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 (find_label (fixture->shell, "52:54:00:ab:db:23"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "52:54:00:ab:db:23"));
/* Some more checks for unrelated UI not showing up randomly */
- bt_header = find_label(fixture->shell, "Bluetooth");
+ bt_header = find_label (GTK_WIDGET (fixture->shell), "Bluetooth");
g_assert_false (bt_header && gtk_widget_is_visible(bt_header));
}
@@ -431,7 +519,7 @@ test_vpn_add (NetworkPanelFixture *fixture,
NMConnection *conn;
NMSettingConnection *connsetting;
NMSettingVpn *setting;
- g_autoptr(GError) error = NULL;
+
WAIT_DECL()
conn = nmtst_create_minimal_connection ("test_vpn_a", NULL, NM_SETTING_VPN_SETTING_NAME, &connsetting);
@@ -451,7 +539,7 @@ test_vpn_add (NetworkPanelFixture *fixture,
g_clear_object (&info.rc);
/* Make sure it shows up. */
- g_assert_nonnull (find_label (fixture->shell, "A VPN"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "A"));
}
/*****************************************************************************/
@@ -463,7 +551,6 @@ test_vpn_add_remove (NetworkPanelFixture *fixture,
NMConnection *conn;
NMSettingConnection *connsetting;
NMSettingVpn *setting;
- g_autoptr(GError) error = NULL;
WAIT_DECL()
conn = nmtst_create_minimal_connection ("test_vpn_a", NULL, NM_SETTING_VPN_SETTING_NAME, &connsetting);
@@ -479,7 +566,7 @@ test_vpn_add_remove (NetworkPanelFixture *fixture,
WAIT_FINISHED(5)
/* Make sure it shows up. */
- g_assert_nonnull (find_label (fixture->shell, "A VPN"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "A"));
/* And delete again */
nm_remote_connection_delete_async (info.rc, NULL, delete_cb, &info);
@@ -493,7 +580,7 @@ test_vpn_add_remove (NetworkPanelFixture *fixture,
g_object_unref (conn);
/* Make sure it does not show up. */
- g_assert_null (find_label (fixture->shell, "A VPN"));
+ g_assert_null (find_label (GTK_WIDGET (fixture->shell), "A"));
}
/*****************************************************************************/
@@ -505,7 +592,6 @@ test_vpn_updating (NetworkPanelFixture *fixture,
NMConnection *conn;
NMSettingConnection *connsetting;
NMSettingVpn *setting;
- g_autoptr(GError) error = NULL;
GVariantBuilder builder;
WAIT_DECL()
@@ -524,7 +610,7 @@ test_vpn_updating (NetworkPanelFixture *fixture,
g_object_unref (conn);
/* Make sure it shows up. */
- g_assert_nonnull (find_label (fixture->shell, "A VPN"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "A"));
/* Rename VPN from A to B */
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sa{sv}}"));
@@ -565,8 +651,8 @@ test_vpn_updating (NetworkPanelFixture *fixture,
g_clear_object (&info.rc);
/* Make sure it the label got renamed. */
- g_assert_null (find_label (fixture->shell, "A VPN"));
- g_assert_nonnull (find_label (fixture->shell, "B VPN"));
+ g_assert_null (find_label (GTK_WIDGET (fixture->shell), "A"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "B"));
}
/*****************************************************************************/
@@ -616,12 +702,12 @@ test_vpn_sorting (NetworkPanelFixture *fixture,
g_object_unref (conn);
/* Make sure both VPNs are there. */
- g_assert_nonnull (find_label (fixture->shell, "A VPN"));
- g_assert_nonnull (find_label (fixture->shell, "1 VPN"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "A"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "1"));
/* And test that A is after 1 */
- 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);
+ a = find_parent_of_type (find_label (GTK_WIDGET (fixture->shell), "A"), GTK_TYPE_STACK);
+ b = find_parent_of_type (find_label (GTK_WIDGET (fixture->shell), "1"), 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));
@@ -666,13 +752,13 @@ test_vpn_sorting (NetworkPanelFixture *fixture,
g_clear_object (&info.rc);
/* Make sure it the label got renamed. */
- 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"));
+ g_assert_null (find_label (GTK_WIDGET (fixture->shell), "1"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "A"));
+ g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "B"));
/* And test that A is before B */
- 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);
+ a = find_parent_of_type (find_label (GTK_WIDGET (fixture->shell), "A"), GTK_TYPE_STACK);
+ b = find_parent_of_type (find_label (GTK_WIDGET (fixture->shell), "B"), 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));
@@ -690,7 +776,7 @@ main (int argc, char **argv)
g_setenv ("LC_ALL", "C", TRUE);
gtk_test_init (&argc, &argv, NULL);
- hdy_init ();
+ adw_init ();
g_test_add ("/network-panel-wired/empty-ui",
NetworkPanelFixture,