diff options
-rw-r--r-- | src/backend-dbus/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/backend-dbus/actions.c | 75 | ||||
-rw-r--r-- | src/backend-dbus/com.canonical.Unity.Session.xml | 12 | ||||
-rw-r--r-- | tests/backend-dbus/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/backend-dbus/gtest-mock-dbus-fixture.h | 4 | ||||
-rw-r--r-- | tests/backend-dbus/mock-unity-session.cc | 71 | ||||
-rw-r--r-- | tests/backend-dbus/mock-unity-session.h | 53 | ||||
-rw-r--r-- | tests/backend-dbus/test-actions.cc | 8 |
8 files changed, 223 insertions, 8 deletions
diff --git a/src/backend-dbus/CMakeLists.txt b/src/backend-dbus/CMakeLists.txt index fa41534..1fb9d7c 100644 --- a/src/backend-dbus/CMakeLists.txt +++ b/src/backend-dbus/CMakeLists.txt @@ -14,7 +14,7 @@ add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-webcredentials add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-accounts org.freedesktop ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.Accounts.xml) - + add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-user org.freedesktop ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.Accounts.User.xml) @@ -43,6 +43,10 @@ add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-end-session-dialog org.gnome.SessionManager ${CMAKE_CURRENT_SOURCE_DIR}/org.gnome.SessionManager.EndSessionDialog.xml) +add_gdbus_codegen (BACKEND_GENERATED_SOURCES unity-session + com.canonical + ${CMAKE_CURRENT_SOURCE_DIR}/com.canonical.Unity.Session.xml) + set (SOURCES actions.c guest.c users.c backend-dbus.c utils.c) # add warnings/coverage info on handwritten files diff --git a/src/backend-dbus/actions.c b/src/backend-dbus/actions.c index b1fa8ac..cac7c40 100644 --- a/src/backend-dbus/actions.c +++ b/src/backend-dbus/actions.c @@ -25,6 +25,7 @@ #include "dbus-webcredentials.h" #include "gnome-screen-saver.h" #include "gnome-session-manager.h" +#include "unity-session.h" #include "actions.h" @@ -43,6 +44,7 @@ struct _IndicatorSessionActionsDbusPriv GSettings * indicator_settings; GnomeScreenSaver * screen_saver; GnomeSessionManager * session_manager; + UnitySession * unity_session; Login1Manager * login1_manager; GCancellable * login1_manager_cancellable; Login1Seat * login1_seat; @@ -197,6 +199,22 @@ on_screensaver_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpoin } static void +on_unity_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself) +{ + GError * err; + UnitySession * us; + + err = NULL; + us = unity_session_proxy_new_for_bus_finish (res, &err); + if (err == NULL) + { + INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv->unity_session = us; + } + + log_and_clear_error (&err, G_STRLOC, G_STRFUNC); +} + +static void on_can_suspend_ready (GObject * o, GAsyncResult * res, gpointer gself) { char * str; @@ -758,20 +776,54 @@ my_about (IndicatorSessionActions * self G_GNUC_UNUSED) **** ***/ +static gboolean +have_unity_session (IndicatorSessionActions * self) +{ + priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv; + gchar * name_owner; + + if (G_IS_DBUS_PROXY (p->unity_session)) + { + name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (p->unity_session)); + + if (name_owner) + { + g_free (name_owner); + return TRUE; + } + } + + return FALSE; +} + static void -lock_current_session (IndicatorSessionActions * self) +lock_current_session (IndicatorSessionActions * self, gboolean immediate) { priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv; - g_return_if_fail (p->screen_saver != NULL); + if (have_unity_session (self)) + { + if (immediate) + { + unity_session_call_prompt_lock (p->unity_session, p->cancellable, NULL, NULL); + } + else + { + unity_session_call_lock (p->unity_session, p->cancellable, NULL, NULL); + } + } + else + { + g_return_if_fail (p->screen_saver != NULL); - gnome_screen_saver_call_lock (p->screen_saver, p->cancellable, NULL, NULL); + gnome_screen_saver_call_lock (p->screen_saver, p->cancellable, NULL, NULL); + } } static void my_switch_to_screensaver (IndicatorSessionActions * self) { - lock_current_session (self); + lock_current_session (self, FALSE); } static void @@ -781,6 +833,8 @@ my_switch_to_greeter (IndicatorSessionActions * self) g_return_if_fail (p->dm_seat != NULL); + lock_current_session (self, TRUE); + display_manager_seat_call_switch_to_greeter (p->dm_seat, p->dm_seat_cancellable, NULL, NULL); @@ -793,7 +847,7 @@ my_switch_to_guest (IndicatorSessionActions * self) g_return_if_fail (p->dm_seat != NULL); - lock_current_session (self); + lock_current_session (self, TRUE); display_manager_seat_call_switch_to_guest (p->dm_seat, "", p->dm_seat_cancellable, @@ -807,6 +861,8 @@ my_switch_to_username (IndicatorSessionActions * self, const char * username) g_return_if_fail (p->dm_seat != NULL); + lock_current_session (self, TRUE); + display_manager_seat_call_switch_to_user (p->dm_seat, username, "", p->dm_seat_cancellable, NULL, NULL); @@ -850,6 +906,7 @@ my_dispose (GObject * o) g_clear_object (&p->screen_saver); g_clear_object (&p->session_manager); + g_clear_object (&p->unity_session); set_dm_seat (self, NULL); set_login1_manager (self, NULL); set_login1_seat (self, NULL); @@ -952,6 +1009,14 @@ indicator_session_actions_dbus_init (IndicatorSessionActionsDbus * self) on_screensaver_proxy_ready, self); + unity_session_proxy_new_for_bus (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + "com.canonical.Unity", + "/com/canonical/Unity/Session", + p->cancellable, + on_unity_proxy_ready, + self); + gnome_session_manager_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, "org.gnome.SessionManager", diff --git a/src/backend-dbus/com.canonical.Unity.Session.xml b/src/backend-dbus/com.canonical.Unity.Session.xml new file mode 100644 index 0000000..1dce43e --- /dev/null +++ b/src/backend-dbus/com.canonical.Unity.Session.xml @@ -0,0 +1,12 @@ +<!DOCTYPE node PUBLIC +"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> + <interface name="com.canonical.Unity.Session"> + <method name="Lock" /> + <method name="PromptLock" /> + <method name="RequestLogout" /> + <method name="RequestReboot" /> + <method name="RequestShutdown" /> + </interface> +</node> diff --git a/tests/backend-dbus/CMakeLists.txt b/tests/backend-dbus/CMakeLists.txt index e28d8e6..6ef68bd 100644 --- a/tests/backend-dbus/CMakeLists.txt +++ b/tests/backend-dbus/CMakeLists.txt @@ -23,6 +23,8 @@ add_library (desktopmock STATIC mock-object.h mock-screen-saver.cc mock-screen-saver.h + mock-unity-session.cc + mock-unity-session.h mock-session-manager.cc mock-session-manager.h mock-user.cc diff --git a/tests/backend-dbus/gtest-mock-dbus-fixture.h b/tests/backend-dbus/gtest-mock-dbus-fixture.h index bab82bf..d4f598c 100644 --- a/tests/backend-dbus/gtest-mock-dbus-fixture.h +++ b/tests/backend-dbus/gtest-mock-dbus-fixture.h @@ -25,6 +25,7 @@ #include "mock-display-manager-seat.h" #include "mock-end-session-dialog.h" #include "mock-screen-saver.h" +#include "mock-unity-session.h" #include "mock-session-manager.h" #include "mock-user.h" #include "mock-webcredentials.h" @@ -42,6 +43,7 @@ class GTestMockDBusFixture: public GTestDBusFixture protected: MockScreenSaver * screen_saver; + MockUnitySession * unity_session; MockSessionManager * session_manager; MockDisplayManagerSeat * dm_seat; MockAccounts * accounts; @@ -60,6 +62,7 @@ class GTestMockDBusFixture: public GTestDBusFixture end_session_dialog = new MockEndSessionDialog (loop, conn); session_manager = new MockSessionManager (loop, conn); screen_saver = new MockScreenSaver (loop, conn); + unity_session = new MockUnitySession (loop, conn); dm_seat = new MockDisplayManagerSeat (loop, conn); g_setenv ("XDG_SEAT_PATH", dm_seat->path(), TRUE); dm_seat->set_guest_allowed (false); @@ -83,6 +86,7 @@ class GTestMockDBusFixture: public GTestDBusFixture delete login1_manager; delete dm_seat; delete screen_saver; + delete unity_session; delete session_manager; delete end_session_dialog; delete webcredentials; diff --git a/tests/backend-dbus/mock-unity-session.cc b/tests/backend-dbus/mock-unity-session.cc new file mode 100644 index 0000000..c996310 --- /dev/null +++ b/tests/backend-dbus/mock-unity-session.cc @@ -0,0 +1,71 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * Authors: + * Marco Trevisan <marco.trevisan@canonical.com> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "mock-unity-session.h" + + +gboolean +MockUnitySession :: handle_lock (UnitySession * us, + GDBusMethodInvocation * inv, + gpointer gself) +{ + static_cast<MockUnitySession*>(gself)->my_last_action = Lock; + unity_session_complete_lock (us, inv); + return true; +} + +gboolean +MockUnitySession :: handle_prompt_lock (UnitySession * us, + GDBusMethodInvocation * inv, + gpointer gself) +{ + static_cast<MockUnitySession*>(gself)->my_last_action = PromptLock; + unity_session_complete_prompt_lock (us, inv); + return true; +} + +/*** +**** +***/ + +namespace +{ + const char * const UNITY_SESSION_NAME = "com.canonical.Unity"; + const char * const UNITY_SESSION_PATH = "/com/canonical/Unity/Session"; + +} + +MockUnitySession :: MockUnitySession (GMainLoop * loop, + GDBusConnection * bus_connection): + MockObject (loop, bus_connection, UNITY_SESSION_NAME, UNITY_SESSION_PATH), + my_skeleton (unity_session_skeleton_new ()), + my_last_action (None) +{ + g_signal_connect (my_skeleton, "handle-lock", + G_CALLBACK(handle_lock), this); + g_signal_connect (my_skeleton, "handle-prompt-lock", + G_CALLBACK(handle_prompt_lock), this); + + set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton)); +} + +MockUnitySession :: ~MockUnitySession () +{ + g_clear_object (&my_skeleton); +} diff --git a/tests/backend-dbus/mock-unity-session.h b/tests/backend-dbus/mock-unity-session.h new file mode 100644 index 0000000..ded246a --- /dev/null +++ b/tests/backend-dbus/mock-unity-session.h @@ -0,0 +1,53 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * Authors: + * Marco Trevisan <marco.trevisan@canonical.com> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MOCK_UNITY_SESSION_H +#define MOCK_UNITY_SESSION_H + +#include "mock-object.h" // parent class +#include "backend-dbus/unity-session.h" // Unity Session + +class MockUnitySession: public MockObject +{ + public: + + MockUnitySession (GMainLoop * loop, + GDBusConnection * bus_connection); + virtual ~MockUnitySession (); + + public: + + enum Action { None, Lock, PromptLock, RequestLogout, RequestShutdown, RequestReboot }; + Action last_action () { return my_last_action; } + + private: + + UnitySession * my_skeleton; + Action my_last_action; + + static gboolean handle_lock (UnitySession *, + GDBusMethodInvocation *, + gpointer); + static gboolean handle_prompt_lock (UnitySession *, + GDBusMethodInvocation *, + gpointer); + +}; + +#endif diff --git a/tests/backend-dbus/test-actions.cc b/tests/backend-dbus/test-actions.cc index c0f8517..717509d 100644 --- a/tests/backend-dbus/test-actions.cc +++ b/tests/backend-dbus/test-actions.cc @@ -316,17 +316,19 @@ TEST_F (Actions, Hibernate) TEST_F (Actions, SwitchToScreensaver) { - ASSERT_EQ (MockScreenSaver::None, screen_saver->last_action()); + ASSERT_EQ (MockUnitySession::None, unity_session->last_action()); indicator_session_actions_switch_to_screensaver (actions); wait_msec (50); - ASSERT_EQ (MockScreenSaver::Lock, screen_saver->last_action()); + ASSERT_EQ (MockUnitySession::Lock, unity_session->last_action()); } TEST_F (Actions, SwitchToGreeter) { ASSERT_NE (MockDisplayManagerSeat::GREETER, dm_seat->last_action()); + ASSERT_EQ (MockUnitySession::None, unity_session->last_action()); indicator_session_actions_switch_to_greeter (actions); wait_msec (50); + ASSERT_EQ (MockUnitySession::PromptLock, unity_session->last_action()); ASSERT_EQ (MockDisplayManagerSeat::GREETER, dm_seat->last_action()); } @@ -346,6 +348,7 @@ TEST_F (Actions, SwitchToGuest) wait_for_signal (login1_seat->skeleton(), "notify::active-session"); ASSERT_EQ (guest_session_tag, login1_seat->active_session()); wait_msec (50); + ASSERT_EQ (MockUnitySession::PromptLock, unity_session->last_action()); } TEST_F (Actions, SwitchToUsername) @@ -367,6 +370,7 @@ TEST_F (Actions, SwitchToUsername) wait_for_signal (login1_seat->skeleton(), "notify::active-session"); ASSERT_EQ (dr1_session, login1_seat->active_session()); wait_msec (50); + ASSERT_EQ (MockUnitySession::PromptLock, unity_session->last_action()); indicator_session_actions_switch_to_username (actions, dr2_username); wait_for_signal (login1_seat->skeleton(), "notify::active-session"); |