1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright (C) 2013 Canonical Ltd
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 3 as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
20
#include <gmock/gmock.h>
21
#include <UnityCore/GLibDBusProxy.h>
22
#include <UnityCore/GLibDBusServer.h>
23
#include <UnityCore/GnomeSessionManager.h>
24
#include <UnityCore/Variant.h>
25
#include "test_utils.h"
27
using namespace unity;
28
using namespace unity::glib;
34
const std::string TEST_SERVER_NAME = "com.canonical.Unity.Test.GnomeManager";
36
const std::string SHELL_INTERFACE = "org.gnome.SessionManager.EndSessionDialog";
37
const std::string SHELL_OBJECT_PATH = "/org/gnome/SessionManager/EndSessionDialog";
39
const std::string UPOWER_PATH = "/org/freedesktop/UPower";
40
const std::string LOGIND_PATH = "/org/freedesktop/login1";
41
const std::string CONSOLE_KIT_PATH = "/org/freedesktop/ConsoleKit/Manager";
42
const std::string SCREEN_SAVER_PATH = "/org/gnome/ScreenSaver";
43
const std::string SESSION_MANAGER_PATH = "/org/gnome/SessionManager";
45
const std::string SESSION_OPTIONS = "com.canonical.indicator.session";
46
const std::string SUPPRESS_DIALOGS_KEY = "suppress-logout-restart-shutdown";
49
namespace introspection
51
const std::string UPOWER =
53
<interface name="org.freedesktop.UPower">
54
<method name="Suspend"/>
55
<method name="Hibernate"/>
56
<method name="HibernateAllowed">
57
<arg type="b" name="hibernate_allowed" direction="out"/>
59
<method name="SuspendAllowed">
60
<arg type="b" name="suspend_allowed" direction="out"/>
65
const std::string LOGIND =
67
<interface name="org.freedesktop.login1.Manager">
68
<method name="CanSuspend">
69
<arg type="s" name="result" direction="out"/>
71
<method name="CanHibernate">
72
<arg type="s" name="result" direction="out"/>
74
<method name="PowerOff">
75
<arg type="b" name="interactive" direction="in"/>
77
<method name="Reboot">
78
<arg type="b" name="interactive" direction="in"/>
80
<method name="Suspend">
81
<arg type="b" name="interactive" direction="in"/>
83
<method name="Hibernate">
84
<arg type="b" name="interactive" direction="in"/>
86
<method name="TerminateSession">
87
<arg type="s" name="id" direction="in"/>
92
const std::string CONSOLE_KIT =
94
<interface name="org.freedesktop.ConsoleKit.Manager">
96
<method name="Restart"/>
97
<method name="CloseSession">
98
<arg type="s" name="cookie" direction="in"/>
103
const std::string SCREEN_SAVER =
105
<interface name="org.gnome.ScreenSaver">
106
<method name="Lock"/>
107
<method name="SimulateUserActivity"/>
111
const std::string SESSION_MANAGER =
113
<interface name="org.gnome.SessionManager">
114
<method name="Logout">
115
<arg type="u" name="type" direction="in"/>
117
<method name="Reboot"/>
118
<method name="Shutdown"/>
119
<method name="CanShutdown">
120
<arg type="b" name="can_shutdown" direction="out"/>
127
struct MockGnomeSessionManager : session::GnomeManager {
128
MockGnomeSessionManager()
129
: GnomeManager(GnomeManager::TestMode())
133
struct TestGnomeSessionManager : testing::Test
135
static void SetUpTestCase()
137
g_setenv("GSETTINGS_BACKEND", "memory", TRUE);
139
can_shutdown_ = (g_random_int() % 2) ? true : false;
140
can_suspend_ = (g_random_int() % 2) ? true : false;
141
can_hibernate_ = (g_random_int() % 2) ? true : false;
143
bool shutdown_called = false;
144
bool hibernate_called = false;
145
bool suspend_called = false;
147
upower_ = std::make_shared<DBusServer>();
148
upower_->AddObjects(introspection::UPOWER, UPOWER_PATH);
149
upower_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
150
if (method == "SuspendAllowed")
152
suspend_called = true;
153
return g_variant_new("(b)", can_suspend_ ? TRUE : FALSE);
155
else if (method == "HibernateAllowed")
157
hibernate_called = true;
158
return g_variant_new("(b)", can_hibernate_ ? TRUE : FALSE);
164
logind_ = std::make_shared<DBusServer>();
165
logind_->AddObjects(introspection::LOGIND, LOGIND_PATH);
166
logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
167
if (method == "CanSuspend")
169
suspend_called = true;
170
return g_variant_new("(s)", can_suspend_ ? "yes" : "no");
172
else if (method == "CanHibernate")
174
hibernate_called = true;
175
return g_variant_new("(s)", can_hibernate_ ? "yes" : "no");
181
console_kit_ = std::make_shared<DBusServer>();
182
console_kit_->AddObjects(introspection::CONSOLE_KIT, CONSOLE_KIT_PATH);
184
screen_saver_ = std::make_shared<DBusServer>();
185
screen_saver_->AddObjects(introspection::SCREEN_SAVER, SCREEN_SAVER_PATH);
187
session_manager_ = std::make_shared<DBusServer>();
188
session_manager_->AddObjects(introspection::SESSION_MANAGER, SESSION_MANAGER_PATH);
189
session_manager_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
190
if (method == "CanShutdown")
192
shutdown_called = true;
193
return g_variant_new("(b)", can_shutdown_ ? TRUE : FALSE);
199
manager = std::make_shared<MockGnomeSessionManager>();
200
shell_proxy_ = std::make_shared<DBusProxy>(TEST_SERVER_NAME, SHELL_OBJECT_PATH, SHELL_INTERFACE);
202
// We need to wait until the session manager has setup its internal values.
203
Utils::WaitUntilMSec(hibernate_called);
204
Utils::WaitUntilMSec(suspend_called);
205
Utils::WaitUntilMSec(shutdown_called);
206
EXPECT_TRUE(hibernate_called);
207
EXPECT_TRUE(suspend_called);
208
EXPECT_TRUE(shutdown_called);
209
Utils::WaitForTimeoutMSec(100);
214
ASSERT_NE(manager, nullptr);
215
Utils::WaitUntilMSec([] { return upower_->IsConnected(); });
216
Utils::WaitUntilMSec([] { return logind_->IsConnected(); });
217
Utils::WaitUntilMSec([] { return console_kit_->IsConnected(); });
218
Utils::WaitUntilMSec([] { return screen_saver_->IsConnected(); });
219
Utils::WaitUntilMSec([] { return session_manager_->IsConnected(); });
220
Utils::WaitUntilMSec([] { return shell_proxy_->IsConnected();});
221
ASSERT_TRUE(shell_proxy_->IsConnected());
222
EnableInteractiveShutdown(true);
224
// reset default logind methods, to avoid tests clobbering each other
225
logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
226
if (method == "CanSuspend")
227
return g_variant_new("(s)", can_suspend_ ? "yes" : "no");
228
else if (method == "CanHibernate")
229
return g_variant_new("(s)", can_hibernate_ ? "yes" : "no");
236
manager->logout_requested.clear();
237
manager->reboot_requested.clear();
238
manager->shutdown_requested.clear();
239
manager->cancel_requested.clear();
240
shell_proxy_->DisconnectSignal();
242
// By calling this we reset the internal pending action status
243
bool cancelled = false;
244
shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; });
245
manager->CancelAction();
246
Utils::WaitUntilMSec(cancelled);
247
shell_proxy_->DisconnectSignal("Canceled");
250
static void TearDownTestCase()
252
g_setenv("GSETTINGS_BACKEND", "", TRUE);
254
bool cancelled = false;
256
shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; });
257
shell_proxy_->Connect("Closed", [&closed] (GVariant*) { closed = true; });
261
Utils::WaitUntilMSec(cancelled);
262
Utils::WaitUntilMSec(closed);
263
EXPECT_TRUE(cancelled);
266
shell_proxy_.reset();
269
console_kit_.reset();
270
screen_saver_.reset();
271
session_manager_.reset();
274
bool SettingsAvailable()
276
const gchar* const* schemas = g_settings_list_schemas();
278
for (unsigned i = 0; schemas[i]; ++i)
280
if (g_strcmp0(schemas[i], SESSION_OPTIONS.c_str()) == 0)
287
void EnableInteractiveShutdown(bool enable)
289
ASSERT_TRUE(SettingsAvailable());
290
glib::Object<GSettings> setting(g_settings_new(SESSION_OPTIONS.c_str()));
291
g_settings_set_boolean(setting, SUPPRESS_DIALOGS_KEY.c_str(), enable ? FALSE : TRUE);
294
enum class Action : unsigned
301
void ShellOpenAction(Action action)
303
shell_proxy_->Call("Open", g_variant_new("(uuuao)", action, 0, 0, nullptr));
306
void ShellOpenActionWithInhibitor(Action action)
308
GVariantBuilder builder;
309
g_variant_builder_init(&builder, G_VARIANT_TYPE ("ao"));
310
g_variant_builder_add(&builder, "o", "/any/inhibitor/object");
311
shell_proxy_->Call("Open", g_variant_new("(uuuao)", action, 0, 0, &builder));
314
static bool can_shutdown_;
315
static bool can_suspend_;
316
static bool can_hibernate_;
318
static session::Manager::Ptr manager;
319
static DBusServer::Ptr upower_;
320
static DBusServer::Ptr console_kit_;
321
static DBusServer::Ptr logind_;
322
static DBusServer::Ptr screen_saver_;
323
static DBusServer::Ptr session_manager_;
324
static DBusProxy::Ptr shell_proxy_;
327
session::Manager::Ptr TestGnomeSessionManager::manager;
328
DBusServer::Ptr TestGnomeSessionManager::upower_;
329
DBusServer::Ptr TestGnomeSessionManager::console_kit_;
330
DBusServer::Ptr TestGnomeSessionManager::logind_;
331
DBusServer::Ptr TestGnomeSessionManager::screen_saver_;
332
DBusServer::Ptr TestGnomeSessionManager::session_manager_;
333
DBusProxy::Ptr TestGnomeSessionManager::shell_proxy_;
334
bool TestGnomeSessionManager::can_shutdown_;
335
bool TestGnomeSessionManager::can_suspend_;
336
bool TestGnomeSessionManager::can_hibernate_;
338
TEST_F(TestGnomeSessionManager, CanShutdown)
340
EXPECT_EQ(manager->CanShutdown(), can_shutdown_);
343
TEST_F(TestGnomeSessionManager, CanHibernate)
345
EXPECT_EQ(manager->CanHibernate(), can_hibernate_);
348
TEST_F(TestGnomeSessionManager, CanSuspend)
350
EXPECT_EQ(manager->CanSuspend(), can_suspend_);
353
TEST_F(TestGnomeSessionManager, RealName)
355
const char* name = g_get_real_name();
357
if (!name || g_strcmp0(name, "Unknown") == 0)
358
EXPECT_TRUE(manager->RealName().empty());
360
EXPECT_EQ(manager->RealName(), name);
363
TEST_F(TestGnomeSessionManager, UserName)
365
EXPECT_EQ(manager->UserName(), g_get_user_name());
368
TEST_F(TestGnomeSessionManager, LockScreen)
370
bool lock_called = false;
371
bool simulate_activity_called = false;
373
screen_saver_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
374
if (method == "Lock")
377
EXPECT_FALSE(simulate_activity_called);
379
else if (method == "SimulateUserActivity")
381
simulate_activity_called = true;
382
EXPECT_TRUE(lock_called);
388
manager->LockScreen();
390
Utils::WaitUntilMSec(lock_called);
391
EXPECT_TRUE(lock_called);
393
Utils::WaitUntilMSec(simulate_activity_called);
394
EXPECT_TRUE(simulate_activity_called);
397
TEST_F(TestGnomeSessionManager, Logout)
399
bool logout_called = false;
401
session_manager_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant* par) -> GVariant* {
402
if (method == "Logout")
404
logout_called = true;
405
EXPECT_EQ(Variant(par).GetUInt(), 1);
413
Utils::WaitUntilMSec(logout_called);
414
EXPECT_TRUE(logout_called);
417
TEST_F(TestGnomeSessionManager, LogoutFallbackLogind)
419
// This makes the standard call to return an error.
420
session_manager_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
421
g_setenv("XDG_SESSION_ID", "logind-id0", TRUE);
422
g_unsetenv("XDG_SESSION_COOKIE");
424
bool logout_called = false;
426
logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant* par) -> GVariant* {
427
if (method == "TerminateSession")
429
logout_called = true;
430
EXPECT_EQ(Variant(par).GetString(), "logind-id0");
438
Utils::WaitUntilMSec(logout_called);
439
EXPECT_TRUE(logout_called);
442
TEST_F(TestGnomeSessionManager, LogoutFallbackConsolekit)
444
// This makes the standard call to return an error.
445
session_manager_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
447
logind_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
449
g_setenv("XDG_SESSION_COOKIE", "ck-session-cookie", TRUE);
450
g_setenv("XDG_SESSION_ID", "logind-id0", TRUE);
452
bool logout_called = false;
454
console_kit_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant* par) -> GVariant* {
455
if (method == "CloseSession")
457
logout_called = true;
458
EXPECT_EQ(Variant(par).GetString(), "ck-session-cookie");
466
Utils::WaitUntilMSec(logout_called);
467
EXPECT_TRUE(logout_called);
470
TEST_F(TestGnomeSessionManager, LogoutFallbackConsolekitOnNoID)
472
// This makes the standard call to return an error.
473
session_manager_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
474
g_setenv("XDG_SESSION_COOKIE", "ck-session-cookie", TRUE);
475
g_unsetenv("XDG_SESSION_ID");
477
bool logout_called = false;
479
console_kit_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant* par) -> GVariant* {
480
if (method == "CloseSession")
482
logout_called = true;
483
EXPECT_EQ(Variant(par).GetString(), "ck-session-cookie");
491
Utils::WaitUntilMSec(logout_called);
492
EXPECT_TRUE(logout_called);
495
TEST_F(TestGnomeSessionManager, Reboot)
497
bool reboot_called = false;
499
session_manager_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
500
if (method == "Reboot")
501
reboot_called = true;
508
Utils::WaitUntilMSec(reboot_called);
509
EXPECT_TRUE(reboot_called);
512
TEST_F(TestGnomeSessionManager, RebootFallbackLogind)
514
// This makes the standard call to return an error.
515
session_manager_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
517
bool reboot_called = false;
519
logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
520
if (method == "Reboot")
521
reboot_called = true;
528
Utils::WaitUntilMSec(reboot_called);
529
EXPECT_TRUE(reboot_called);
532
TEST_F(TestGnomeSessionManager, RebootFallbackConsoleKit)
534
// This makes the standard call to return an error.
535
session_manager_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
537
logind_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
539
bool reboot_called = false;
541
console_kit_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
542
if (method == "Restart")
543
reboot_called = true;
550
Utils::WaitUntilMSec(reboot_called);
551
EXPECT_TRUE(reboot_called);
554
TEST_F(TestGnomeSessionManager, Shutdown)
556
bool shutdown_called = false;
558
session_manager_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
559
if (method == "Shutdown")
560
shutdown_called = true;
567
Utils::WaitUntilMSec(shutdown_called);
568
EXPECT_TRUE(shutdown_called);
571
TEST_F(TestGnomeSessionManager, ShutdownFallbackLogind)
573
// This makes the standard call to return an error.
574
session_manager_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
576
bool shutdown_called = false;
578
logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
579
if (method == "PowerOff")
580
shutdown_called = true;
587
Utils::WaitUntilMSec(shutdown_called);
588
EXPECT_TRUE(shutdown_called);
591
TEST_F(TestGnomeSessionManager, ShutdownFallbackConsoleKit)
593
// This makes the standard call to return an error.
594
session_manager_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
596
logind_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
598
bool shutdown_called = false;
600
console_kit_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
601
if (method == "Stop")
602
shutdown_called = true;
609
Utils::WaitUntilMSec(shutdown_called);
610
EXPECT_TRUE(shutdown_called);
613
TEST_F(TestGnomeSessionManager, SuspendUPower)
615
bool suspend_called = false;
618
logind_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
620
upower_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
621
if (method == "Suspend")
622
suspend_called = true;
629
Utils::WaitUntilMSec(suspend_called);
630
EXPECT_TRUE(suspend_called);
633
TEST_F(TestGnomeSessionManager, SuspendLogind)
635
bool suspend_called = false;
637
logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
638
if (method == "Suspend")
639
suspend_called = true;
646
Utils::WaitUntilMSec(suspend_called);
647
EXPECT_TRUE(suspend_called);
650
TEST_F(TestGnomeSessionManager, HibernateUPower)
652
bool hibernate_called = false;
655
logind_->GetObjects().front()->SetMethodsCallsHandler(nullptr);
657
upower_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
658
if (method == "Hibernate")
659
hibernate_called = true;
664
manager->Hibernate();
666
Utils::WaitUntilMSec(hibernate_called);
667
EXPECT_TRUE(hibernate_called);
670
TEST_F(TestGnomeSessionManager, HibernateLogind)
672
bool hibernate_called = false;
674
logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
675
if (method == "Hibernate")
676
hibernate_called = true;
681
manager->Hibernate();
683
Utils::WaitUntilMSec(hibernate_called);
684
EXPECT_TRUE(hibernate_called);
687
TEST_F(TestGnomeSessionManager, CancelAction)
689
bool cancelled = false;
691
shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; });
692
manager->CancelAction();
694
Utils::WaitUntilMSec(cancelled);
695
EXPECT_TRUE(cancelled);
698
TEST_F(TestGnomeSessionManager, LogoutRequested)
700
bool logout_requested = false;
701
bool cancelled = false;
703
manager->logout_requested.connect([&logout_requested] (bool inhibitors) {
704
logout_requested = true;
705
EXPECT_FALSE(inhibitors);
708
shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; });
710
ShellOpenAction(Action::LOGOUT);
712
Utils::WaitUntilMSec(logout_requested);
713
EXPECT_TRUE(logout_requested);
715
Utils::WaitUntilMSec(cancelled);
716
EXPECT_TRUE(cancelled);
719
struct InteractiveMode : TestGnomeSessionManager, testing::WithParamInterface<bool> {};
720
INSTANTIATE_TEST_CASE_P(TestGnomeSessionManager, InteractiveMode, testing::Bool());
722
TEST_P(/*TestGnomeSessionManager*/InteractiveMode, LogoutRequestedInhibitors)
724
EnableInteractiveShutdown(GetParam());
726
bool logout_requested = false;
727
bool cancelled = false;
729
manager->logout_requested.connect([&logout_requested] (bool inhibitors) {
730
logout_requested = true;
731
EXPECT_TRUE(inhibitors);
734
shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; });
736
ShellOpenActionWithInhibitor(Action::LOGOUT);
738
Utils::WaitUntilMSec(logout_requested);
739
EXPECT_TRUE(logout_requested);
741
Utils::WaitForTimeoutMSec(10);
742
EXPECT_FALSE(cancelled);
745
TEST_F(TestGnomeSessionManager, ImmediateLogout)
747
EnableInteractiveShutdown(false);
748
bool logout_requested = false;
749
bool confirmed = false;
752
manager->logout_requested.connect([&logout_requested] (bool inhibitors) {
753
logout_requested = true;
754
EXPECT_FALSE(inhibitors);
757
shell_proxy_->Connect("ConfirmedLogout", [&confirmed] (GVariant*) { confirmed = true; });
758
shell_proxy_->Connect("Closed", [&closed] (GVariant*) { closed = true; });
760
ShellOpenAction(Action::LOGOUT);
762
Utils::WaitForTimeoutMSec(100);
763
EXPECT_FALSE(logout_requested);
765
Utils::WaitUntilMSec(confirmed);
766
EXPECT_TRUE(confirmed);
768
Utils::WaitUntilMSec(closed);
772
TEST_F(TestGnomeSessionManager, SimulateRealLogout)
774
bool confirmed = false;
777
session_manager_->GetObjects().front()->SetMethodsCallsHandler([this] (std::string const& method, GVariant*) -> GVariant* {
778
if (method == "Logout")
779
ShellOpenAction(Action::LOGOUT);
786
shell_proxy_->Connect("ConfirmedLogout", [&confirmed] (GVariant*) { confirmed = true; });
787
shell_proxy_->Connect("Closed", [&closed] (GVariant*) { closed = true; });
789
Utils::WaitUntilMSec(confirmed);
790
EXPECT_TRUE(confirmed);
792
Utils::WaitUntilMSec(closed);
796
TEST_F(TestGnomeSessionManager, ShutdownRequested)
798
bool shutdown_requested = false;
799
bool cancelled = false;
801
manager->shutdown_requested.connect([&shutdown_requested] (bool inhibitors) {
802
shutdown_requested = true;
803
EXPECT_FALSE(inhibitors);
806
shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; });
808
ShellOpenAction(Action::SHUTDOWN);
810
Utils::WaitUntilMSec(shutdown_requested);
811
EXPECT_TRUE(shutdown_requested);
813
Utils::WaitUntilMSec(cancelled);
814
EXPECT_TRUE(cancelled);
817
TEST_P(/*TestGnomeSessionManager*/InteractiveMode, ShutdownRequestedInhibitors)
819
bool shutdown_requested = false;
820
bool cancelled = false;
822
manager->shutdown_requested.connect([&shutdown_requested] (bool inhibitors) {
823
shutdown_requested = true;
824
EXPECT_TRUE(inhibitors);
827
shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; });
829
ShellOpenActionWithInhibitor(Action::SHUTDOWN);
831
Utils::WaitUntilMSec(shutdown_requested);
832
EXPECT_TRUE(shutdown_requested);
834
Utils::WaitForTimeoutMSec(10);
835
EXPECT_FALSE(cancelled);
838
TEST_F(TestGnomeSessionManager, ImmediateShutdown)
840
EnableInteractiveShutdown(false);
841
bool shutdown_requested = false;
842
bool confirmed = false;
845
manager->shutdown_requested.connect([&shutdown_requested] (bool inhibitors) {
846
shutdown_requested = true;
847
EXPECT_FALSE(inhibitors);
850
shell_proxy_->Connect("ConfirmedShutdown", [&confirmed] (GVariant*) { confirmed = true; });
851
shell_proxy_->Connect("Closed", [&closed] (GVariant*) { closed = true; });
853
ShellOpenAction(Action::SHUTDOWN);
855
Utils::WaitForTimeoutMSec(100);
856
EXPECT_FALSE(shutdown_requested);
858
Utils::WaitUntilMSec(confirmed);
859
EXPECT_TRUE(confirmed);
861
Utils::WaitUntilMSec(closed);
865
TEST_F(TestGnomeSessionManager, SimulateRealShutdown)
867
bool confirmed = false;
870
session_manager_->GetObjects().front()->SetMethodsCallsHandler([this] (std::string const& method, GVariant*) -> GVariant* {
871
if (method == "Shutdown")
872
ShellOpenAction(Action::SHUTDOWN);
879
shell_proxy_->Connect("ConfirmedShutdown", [&confirmed] (GVariant*) { confirmed = true; });
880
shell_proxy_->Connect("Closed", [&closed] (GVariant*) { closed = true; });
882
Utils::WaitUntilMSec(confirmed);
883
EXPECT_TRUE(confirmed);
885
Utils::WaitUntilMSec(closed);
889
TEST_F(TestGnomeSessionManager, RebootRequested)
891
bool reboot_requested = false;
892
bool cancelled = false;
894
manager->reboot_requested.connect([&reboot_requested] (bool inhibitors) {
895
reboot_requested = true;
896
EXPECT_FALSE(inhibitors);
899
shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; });
901
ShellOpenAction(Action::REBOOT);
903
Utils::WaitUntilMSec(reboot_requested);
904
EXPECT_TRUE(reboot_requested);
906
Utils::WaitUntilMSec(cancelled);
907
EXPECT_TRUE(cancelled);
910
TEST_P(/*TestGnomeSessionManager*/InteractiveMode, RebootRequestedInhibitors)
912
bool reboot_requested = false;
913
bool cancelled = false;
915
manager->reboot_requested.connect([&reboot_requested] (bool inhibitors) {
916
reboot_requested = true;
917
EXPECT_TRUE(inhibitors);
920
shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; });
922
ShellOpenActionWithInhibitor(Action::REBOOT);
924
Utils::WaitUntilMSec(reboot_requested);
925
EXPECT_TRUE(reboot_requested);
927
Utils::WaitForTimeoutMSec(10);
928
EXPECT_FALSE(cancelled);
931
TEST_F(TestGnomeSessionManager, ImmediateReboot)
933
EnableInteractiveShutdown(false);
934
bool reboot_requested = false;
935
bool confirmed = false;
938
manager->reboot_requested.connect([&reboot_requested] (bool inhibitors) {
939
reboot_requested = true;
940
EXPECT_FALSE(inhibitors);
943
shell_proxy_->Connect("ConfirmedReboot", [&confirmed] (GVariant*) { confirmed = true; });
944
shell_proxy_->Connect("Closed", [&closed] (GVariant*) { closed = true; });
946
ShellOpenAction(Action::REBOOT);
948
Utils::WaitForTimeoutMSec(100);
949
EXPECT_FALSE(reboot_requested);
951
Utils::WaitUntilMSec(confirmed);
952
EXPECT_TRUE(confirmed);
954
Utils::WaitUntilMSec(closed);
958
TEST_F(TestGnomeSessionManager, SimulateRealReboot)
960
bool confirmed = false;
963
session_manager_->GetObjects().front()->SetMethodsCallsHandler([this] (std::string const& method, GVariant*) -> GVariant* {
964
if (method == "Reboot")
965
ShellOpenAction(Action::REBOOT);
972
shell_proxy_->Connect("ConfirmedReboot", [&confirmed] (GVariant*) { confirmed = true; });
973
shell_proxy_->Connect("Closed", [&closed] (GVariant*) { closed = true; });
975
Utils::WaitUntilMSec(confirmed);
976
EXPECT_TRUE(confirmed);
978
Utils::WaitUntilMSec(closed);
982
TEST_F(TestGnomeSessionManager, CancelRequested)
984
bool cancel_requested = false;
987
manager->cancel_requested.connect([&cancel_requested] { cancel_requested = true; });
988
shell_proxy_->Connect("Closed", [&closed] (GVariant*) { closed = true; });
990
shell_proxy_->Call("Close");
992
Utils::WaitUntilMSec(cancel_requested);
993
EXPECT_TRUE(cancel_requested);
995
Utils::WaitUntilMSec(closed);