aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2015-02-13 12:47:47 -0600
committerTed Gould <ted@gould.cx>2015-02-13 12:47:47 -0600
commitd1000c6d613b4cd26bd9ab3d890c3dee295f86a8 (patch)
tree0b5c4e53abb0dcdd0c7f7525e89a7af78bf9c378
parentd97e4bc15eb9edd7a25d4cf9e7ce773fcce94f73 (diff)
downloadayatana-indicator-sound-d1000c6d613b4cd26bd9ab3d890c3dee295f86a8.tar.gz
ayatana-indicator-sound-d1000c6d613b4cd26bd9ab3d890c3dee295f86a8.tar.bz2
ayatana-indicator-sound-d1000c6d613b4cd26bd9ab3d890c3dee295f86a8.zip
Adding a test for notification servers coming on and off the bus, and fixing the code for it
-rw-r--r--src/service.vala9
-rw-r--r--tests/notifications-test.cc48
2 files changed, 53 insertions, 4 deletions
diff --git a/src/service.vala b/src/service.vala
index 7ab0c9c..0b03b6e 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -33,11 +33,11 @@ public class IndicatorSound.Service: Object {
this.notification_proxy = new DBusProxy.for_bus_sync(GLib.BusType.SESSION,
DBusProxyFlags.DO_NOT_LOAD_PROPERTIES | DBusProxyFlags.DO_NOT_CONNECT_SIGNALS | DBusProxyFlags.DO_NOT_AUTO_START,
null, /* interface info */
- "org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
+ "org.freedesktop.Notifications",
+ "/org/freedesktop/Notifications",
+ "org.freedesktop.Notifications",
null);
- this.notification_proxy.notify["g-name-owner"].connect ( () => { check_sync_notification = false; } );
+ this.notification_proxy.notify["g-name-owner"].connect ( () => { debug("Notifications name owner changed"); check_sync_notification = false; } );
} catch (GLib.Error e) {
error("Unable to build notification proxy: %s", e.message);
}
@@ -288,6 +288,7 @@ public class IndicatorSound.Service: Object {
void update_sync_notification () {
if (!check_sync_notification) {
+ support_sync_notification = false;
List<string> caps = Notify.get_server_caps ();
if (caps.find_custom ("x-canonical-private-synchronous", strcmp) != null) {
support_sync_notification = true;
diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc
index c5e3748..0a4fd4a 100644
--- a/tests/notifications-test.cc
+++ b/tests/notifications-test.cc
@@ -258,3 +258,51 @@ TEST_F(NotificationsTest, IconTesting) {
EXPECT_EQ("audio-volume-high", notev[9].app_icon);
EXPECT_EQ("audio-volume-high", notev[10].app_icon);
}
+
+TEST_F(NotificationsTest, ServerRestart) {
+ auto volumeControl = volumeControlMock();
+ auto soundService = standardService(volumeControl, playerListMock());
+
+ /* Set a volume */
+ notifications->clearNotifications();
+ volume_control_set_volume(volumeControl.get(), 0.50);
+ loop(50);
+ auto notev = notifications->getNotifications();
+ ASSERT_EQ(1, notev.size());
+
+ /* Restart server without sync notifications */
+ notifications->clearNotifications();
+ dbus_test_service_remove_task(service, (DbusTestTask*)*notifications);
+ notifications.reset();
+
+ loop(50);
+
+ notifications = std::make_shared<NotificationsMock>(std::vector<std::string>({"body", "body-markup", "icon-static"}));
+ dbus_test_service_add_task(service, (DbusTestTask*)*notifications);
+ dbus_test_task_run((DbusTestTask*)*notifications);
+
+ /* Change the volume */
+ notifications->clearNotifications();
+ volume_control_set_volume(volumeControl.get(), 0.60);
+ loop(50);
+ notev = notifications->getNotifications();
+ ASSERT_EQ(0, notev.size());
+
+ /* Put a good server back */
+ dbus_test_service_remove_task(service, (DbusTestTask*)*notifications);
+ notifications.reset();
+
+ loop(50);
+
+ notifications = std::make_shared<NotificationsMock>();
+ dbus_test_service_add_task(service, (DbusTestTask*)*notifications);
+ dbus_test_task_run((DbusTestTask*)*notifications);
+
+ /* Change the volume again */
+ notifications->clearNotifications();
+ volume_control_set_volume(volumeControl.get(), 0.70);
+ loop(50);
+ notev = notifications->getNotifications();
+ ASSERT_EQ(1, notev.size());
+}
+