Compare commits

...

10 Commits

Author SHA1 Message Date
Benjamin Berg
42926f208a more messages 2022-01-20 18:13:54 +01:00
Benjamin Berg
e717b953bf Disable buffering properly 2022-01-20 17:56:48 +01:00
Benjamin Berg
7d2702cfc9 more debug printing 2022-01-20 17:47:59 +01:00
Benjamin Berg
6bb6fc1366 tests: Force NM server stdout/stderr to be unbuffered 2022-01-20 17:47:15 +01:00
Benjamin Berg
a1d5f44c9e add some more debug output 2022-01-20 17:31:08 +01:00
Benjamin Berg
f41c8695b6 tests: Leave dummy NM server running for longer
It would quit after 20s, but we can get close to that if all tests are
running together (rather than split into individual ones).
2022-01-20 17:20:41 +01:00
Benjamin Berg
b969ca8b97 tests: Add some NM test server debug printing 2022-01-20 16:23:04 +01:00
Benjamin Berg
76ea6bd51b tests: Disable all service start dirs 2022-01-20 15:58:53 +01:00
Benjamin Berg
1a79f45f6b tests: Show X server output 2022-01-20 14:19:30 +01:00
Georges Basile Stavracas Neto
68f816d325 tests: Port tests to GTK4
Port the tests, especially the interactive ones, to GTK4, and
libadwaita.
2022-01-20 09:49:01 -03:00
12 changed files with 255 additions and 281 deletions

View File

@@ -275,7 +275,7 @@ subdir('shell')
subdir('search-provider')
if get_option('tests')
# subdir('tests')
subdir('tests')
endif
if get_option('documentation')

View File

@@ -8,4 +8,4 @@ Type=Application
NoDisplay=true
StartupNotify=true
Categories=GNOME;GTK;Settings;X-GNOME-Settings-Panel;X-GNOME-DetailsSettings;
OnlyShowIn=GNOME;Unity;
OnlyShowIn=GNOME;Unity;

View File

@@ -2,75 +2,26 @@
<interface>
<requires lib="gtk+" version="3.22"/>
<template class="GtpDynamicPanel" parent="CcPanel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child type="content">
<object class="AdwStatusPage">
<property name="icon-name">weather-clear-night-symbolic</property>
<property name="title">Dynamic Panel</property>
<property name="description">Dynamic panels may hide if you don't have some hardware. Use the button below to toggle the panel visibility:</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">96</property>
<property name="icon_name">weather-clear-night-symbolic</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="max-width-chars">50</property>
<property name="wrap">True</property>
<property name="label">Dynamic panels may hide if you don't have some hardware. Use the switch below to toggle the panel visibility:</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="label">Hide</property>
<signal name="clicked" handler="on_button_clicked_cb" object="GtpDynamicPanel" swapped="no" />
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
<object class="GtkButton">
<property name="halign">center</property>
<property name="label">Hide</property>
<signal name="clicked" handler="on_button_clicked_cb" object="GtpDynamicPanel" swapped="no" />
<style>
<class name="pill" />
</style>
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@@ -23,35 +23,16 @@
struct _GtpHeaderWidget
{
CcPanel parent;
GtkWidget *header_widget;
};
G_DEFINE_TYPE (GtpHeaderWidget, gtp_header_widget, CC_TYPE_PANEL)
static void
gtp_header_widget_constructed (GObject *object)
{
GtpHeaderWidget *self = (GtpHeaderWidget *)object;
CcShell *shell;
G_OBJECT_CLASS (gtp_header_widget_parent_class)->constructed (object);
shell = cc_panel_get_shell (CC_PANEL (self));
cc_shell_embed_widget_in_header (shell, self->header_widget, GTK_POS_LEFT);
}
static void
gtp_header_widget_class_init (GtpHeaderWidgetClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = gtp_header_widget_constructed;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/tests/panels/gtp-header-widget.ui");
gtk_widget_class_bind_template_child (widget_class, GtpHeaderWidget, header_widget);
}
static void

View File

@@ -1,47 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.22"/>
<template class="GtpHeaderWidget" parent="CcPanel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">96</property>
<property name="icon_name">go-top-symbolic</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Embedding widgets in the header bar</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child type="titlebar-end">
<object class="GtkLabel" id="header_widget">
<property name="label">I'm a header widget</property>
</object>
</child>
<child type="content">
<object class="AdwStatusPage">
<property name="icon-name">go-top-symbolic</property>
<property name="title">Header Widgets</property>
<property name="description">Embed widgets in the header bar</property>
</object>
</child>
</template>
<object class="GtkLabel" id="header_widget">
<property name="visible">True</property>
<property name="label">I'm a header widget</property>
</object>
</interface>

View File

@@ -1,46 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.22"/>
<template class="GtpSidebarWidget" parent="CcPanel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">96</property>
<property name="icon_name">go-first-symbolic</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Embedding widgets in the sidebar</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child type="content">
<object class="AdwStatusPage">
<property name="icon_name">go-first-symbolic</property>
<property name="title">Sidebar</property>
<property name="description">Add a custom sidebar to the panel</property>
</object>
</child>
</template>
<object class="GtkLabel" id="sidebar_widget">
<property name="visible">True</property>
<property name="label">I'm a sidebar widget</property>
</object>
</interface>

View File

@@ -1,42 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.22"/>
<template class="GtpStaticInit" parent="CcPanel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">96</property>
<property name="icon_name">view-continuous-symbolic</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Static initializers</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child type="content">
<object class="AdwStatusPage">
<property name="icon_name">view-continuous-symbolic</property>
<property name="title">Static Initializer</property>
<property name="description">A panel with a static initializer</property>
</object>
</child>
</template>
</interface>

View File

@@ -29,7 +29,6 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkx.h>
#include <string.h>
#include "shell/cc-panel.h"
@@ -73,12 +72,7 @@ set_active_panel (CcTestWindow *shell,
if (panel)
{
shell->active_panel = g_object_ref (panel);
gtk_container_add_with_properties (GTK_CONTAINER (shell->main_box), GTK_WIDGET (panel),
"pack-type", GTK_PACK_END,
"expand", TRUE,
"fill", TRUE,
NULL);
gtk_widget_show (GTK_WIDGET (shell->active_panel));
gtk_box_append (GTK_BOX (shell->main_box), GTK_WIDGET (panel));
}
}
@@ -93,22 +87,6 @@ cc_test_window_set_active_panel_from_id (CcShell *shell,
g_assert_not_reached ();
}
static void
cc_test_window_embed_widget_in_header (CcShell *shell,
GtkWidget *widget,
GtkPositionType position)
{
CcTestWindow *self = CC_TEST_WINDOW (shell);
/* add to main box */
gtk_container_add_with_properties (GTK_CONTAINER (self->main_box), GTK_WIDGET (widget),
"pack-type", GTK_PACK_START,
"expand", FALSE,
"fill", TRUE,
NULL);
gtk_widget_show (widget);
}
static GtkWidget *
cc_test_window_get_toplevel (CcShell *shell)
{
@@ -119,7 +97,6 @@ static void
cc_shell_iface_init (CcShellInterface *iface)
{
iface->set_active_panel_from_id = cc_test_window_set_active_panel_from_id;
iface->embed_widget_in_header = cc_test_window_embed_widget_in_header;
iface->get_toplevel = cc_test_window_get_toplevel;
}
@@ -191,8 +168,7 @@ cc_test_window_init (CcTestWindow *self)
self->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add (GTK_CONTAINER (self), self->main_box);
gtk_widget_show (self->main_box);
gtk_window_set_child (GTK_WINDOW (self), self->main_box);
}
CcTestWindow *
@@ -201,6 +177,5 @@ cc_test_window_new (void)
return g_object_new (CC_TYPE_TEST_WINDOW,
"resizable", TRUE,
"title", "Test Settings",
"window-position", GTK_WIN_POS_CENTER,
NULL);
}

View File

@@ -35,6 +35,7 @@ name_exists (GDBusConnection *c, const char *name)
GVariant *reply;
gboolean exists = FALSE;
g_message("testing if %s exists, %ld", name, g_get_real_time ());
reply = g_dbus_connection_call_sync (c,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
@@ -47,6 +48,7 @@ name_exists (GDBusConnection *c, const char *name)
NULL,
NULL);
if (reply != NULL) {
g_message("received non-null reply, %ld", g_get_real_time ());
exists = TRUE;
g_variant_unref (reply);
}
@@ -76,7 +78,7 @@ NMTstcServiceInfo *
nmtstc_service_init (void)
{
NMTstcServiceInfo *info;
const char *args[] = { TEST_NM_PYTHON, TEST_NM_SERVICE, NULL };
const char *args[] = { TEST_NM_PYTHON, "-u", TEST_NM_SERVICE, NULL };
GError *error = NULL;
int i;
@@ -89,20 +91,25 @@ nmtstc_service_init (void)
* stdin; if it closes, the service will exit immediately. We use this to
* make sure the service exits if the test program crashes.
*/
g_message("Starting test service, %ld", g_get_real_time ());
g_spawn_async_with_pipes (NULL, (char **) args, NULL,
G_SPAWN_SEARCH_PATH,
NULL, NULL,
&info->pid, &info->keepalive_fd, NULL, NULL, &error);
g_assert_no_error (error);
g_message("launched NM test service, %ld", g_get_real_time ());
/* Wait until the service is registered on the bus */
for (i = 1000; i > 0; i--) {
if (name_exists (info->bus, "org.freedesktop.NetworkManager"))
break;
g_message("sleeping before rechecking, %ld", g_get_real_time ());
g_usleep (G_USEC_PER_SEC / 50);
}
g_assert (i > 0);
g_message("Test service is now on bus (i: %d)", i);
/* Grab a proxy to our fake NM service to trigger tests */
info->proxy = g_dbus_proxy_new_sync (info->bus,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |

View File

@@ -1404,12 +1404,16 @@ class DnsManager(ExportedObj):
###################################################################
def stdin_cb(io, condition):
print("quitting because stdin got condition: %d", condition)
mainloop.quit()
def quit_cb(user_data):
print("quitting after 60s")
mainloop.quit()
def main():
import time
print("test-networkmanager-service.py", time.time())
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
random.seed()
@@ -1423,7 +1427,9 @@ def main():
agent_manager = AgentManager(bus, "/org/freedesktop/NetworkManager/AgentManager")
dns_manager = DnsManager(bus, "/org/freedesktop/NetworkManager/DnsManager")
if not bus.request_name("org.freedesktop.NetworkManager"):
r = bus.request_name("org.freedesktop.NetworkManager")
print(r)
if not r:
sys.exit(1)
# Watch stdin; if it closes, assume our parent has crashed, and exit
@@ -1431,13 +1437,15 @@ def main():
GLib.io_add_watch(io, GLib.PRIORITY_LOW, GLib.IOCondition.HUP, stdin_cb)
# also quit after inactivity to ensure we don't stick around if the above fails somehow
GLib.timeout_add_seconds(20, quit_cb, None)
GLib.timeout_add_seconds(60, quit_cb, None)
try:
print("test-networkmanager-service.py entered mainloop", time.time())
mainloop.run()
except Exception as e:
pass
print("test-networkmanager-service.py exiting", time.time())
sys.exit(0)
if __name__ == '__main__':

View File

@@ -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,32 +131,114 @@ 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 (node = list; node; node = node->next) {
label = find_label (node->data, label_pattern);
if (label)
break;
}
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;
}
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 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));
/* 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;
}
/*****************************************************************************/
#if 0 /* See /network-panel-wired/vpn-sorting note */
@@ -184,10 +265,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 +291,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 +311,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 +338,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 +405,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 +417,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 +445,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_SWITCH);
g_assert_nonnull (sw);
g_assert_false (gtk_switch_get_state (GTK_SWITCH (sw)));
@@ -377,7 +458,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 +483,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_SWITCH);
if (sw)
g_assert_false (gtk_widget_is_visible (sw));
@@ -415,10 +496,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 +512,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 +532,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 VPN"));
}
/*****************************************************************************/
@@ -463,7 +544,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 +559,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 VPN"));
/* And delete again */
nm_remote_connection_delete_async (info.rc, NULL, delete_cb, &info);
@@ -493,7 +573,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 VPN"));
}
/*****************************************************************************/
@@ -505,7 +585,6 @@ test_vpn_updating (NetworkPanelFixture *fixture,
NMConnection *conn;
NMSettingConnection *connsetting;
NMSettingVpn *setting;
g_autoptr(GError) error = NULL;
GVariantBuilder builder;
WAIT_DECL()
@@ -524,7 +603,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 VPN"));
/* Rename VPN from A to B */
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sa{sv}}"));
@@ -565,8 +644,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 VPN"));
g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "B VPN"));
}
/*****************************************************************************/
@@ -616,12 +695,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 VPN"));
g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "1 VPN"));
/* 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 VPN"), GTK_TYPE_STACK);
b = find_parent_of_type (find_label (GTK_WIDGET (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));
@@ -666,13 +745,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 VPN"));
g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "A VPN"));
g_assert_nonnull (find_label (GTK_WIDGET (fixture->shell), "B VPN"));
/* 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 VPN"), GTK_TYPE_STACK);
b = find_parent_of_type (find_label (GTK_WIDGET (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));
@@ -690,7 +769,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,

View File

@@ -18,6 +18,7 @@
import os
import sys
import subprocess
import tempfile
from dbusmock import DBusTestCase
# Intended to be shared across projects, submitted for inclusion into
@@ -34,7 +35,7 @@ class X11SessionTestCase(DBusTestCase):
Xserver_args = ['-screen', '0', '1280x1024x24', '+extension', 'GLX']
#: Where to redirect the X stdout and stderr to. Set to None for debugging
#: purposes if the X server is failing for some reason.
Xserver_output = subprocess.DEVNULL
Xserver_output = None
@classmethod
def setUpClass(klass):
@@ -42,6 +43,60 @@ class X11SessionTestCase(DBusTestCase):
klass.start_system_bus()
klass.start_session_bus()
@classmethod
def start_session_bus(cls) -> None:
'''Set up a private local session bus
This gets stopped automatically in tearDownClass().
'''
with tempfile.NamedTemporaryFile(prefix='dbusmock_session_cfg') as c:
c.write(b'''<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<type>session</type>
<keep_umask/>
<listen>unix:tmpdir=/tmp</listen>
<!-- We do not add standard_system_servicedirs (i.e. we have *no* service directory). -->
<policy context="default">
<allow send_destination="*" eavesdrop="true"/>
<allow eavesdrop="true"/>
<allow own="*"/>
</policy>
</busconfig>
''')
c.flush()
(DBusTestCase.system_bus_pid, addr) = cls.start_dbus(conf=c.name)
os.environ['DBUS_SESSION_BUS_ADDRESS'] = addr
@classmethod
def start_system_bus(cls) -> None:
'''Set up a private local system bus
This gets stopped automatically in tearDownClass().
'''
# create a temporary configuration which makes the fake bus actually
# appear a type "system"
with tempfile.NamedTemporaryFile(prefix='dbusmock_cfg') as c:
c.write(b'''<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<type>system</type>
<keep_umask/>
<listen>unix:tmpdir=/tmp</listen>
<!-- We do not add standard_system_servicedirs (i.e. we have *no* service directory). -->
<policy context="default">
<allow send_destination="*" eavesdrop="true"/>
<allow eavesdrop="true"/>
<allow own="*"/>
</policy>
</busconfig>
''')
c.flush()
(DBusTestCase.system_bus_pid, addr) = cls.start_dbus(conf=c.name)
os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = addr
@classmethod
def start_xorg(klass):
r, w = os.pipe()