2
* Copyright 2013 Canonical Ltd.
5
* Charles Kerr <charles.kerr@canonical.com>
7
* This program is free software: you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License version 3, as published
9
* by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranties of
13
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
* PURPOSE. See the GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "gtest-mock-dbus-fixture.h"
23
#include "backend-dbus/backend-dbus.h"
29
class Guest: public GTestMockDBusFixture
33
typedef GTestMockDBusFixture super;
37
GCancellable * cancellable;
38
IndicatorSessionGuest * guest;
45
cancellable = g_cancellable_new ();
47
backend_get (cancellable, NULL, NULL, &guest);
50
// test the default state
51
ASSERT_TRUE (guest != 0);
52
ASSERT_FALSE (indicator_session_guest_is_allowed (guest));
53
ASSERT_FALSE (indicator_session_guest_is_logged_in (guest));
54
ASSERT_FALSE (indicator_session_guest_is_active (guest));
57
virtual void TearDown ()
59
g_cancellable_cancel (cancellable);
60
g_clear_object (&cancellable);
61
g_clear_object (&guest);
68
void add_mock_guest (MockUser *& guest_user,
69
int & guest_session_tag)
71
guest_user = new MockUser (loop, conn, "guest-jjbEVV", "Guest", 10, 100);
72
accounts->add_user (guest_user);
73
guest_user->set_system_account (true);
74
guest_session_tag = login1_manager->add_session (login1_seat, guest_user);
79
* Confirms that the Fixture's SetUp() and TearDown() work
81
TEST_F (Guest, HelloWorld)
87
* Toggle in the DM whether or not guests are allowed.
88
* Confirm that "guest" reflects the changes.
90
TEST_F (Guest, Allowed)
92
dm_seat->set_guest_allowed (true);
93
wait_for_signal (guest, "notify::guest-is-allowed");
94
ASSERT_TRUE (indicator_session_guest_is_allowed (guest));
95
ASSERT_FALSE (indicator_session_guest_is_logged_in (guest));
96
ASSERT_FALSE (indicator_session_guest_is_active (guest));
98
dm_seat->set_guest_allowed (false);
99
wait_for_signal (guest, "notify::guest-is-allowed");
100
ASSERT_FALSE (indicator_session_guest_is_allowed (guest));
101
ASSERT_FALSE (indicator_session_guest_is_logged_in (guest));
102
ASSERT_FALSE (indicator_session_guest_is_active (guest));
106
* Have a guest user log in & out.
107
* Confirm that "guest" reflects the changes.
109
TEST_F (Guest, Login)
113
dm_seat->set_guest_allowed (true);
116
// And confirm that guest's is_login changes to true
117
MockUser * guest_user;
119
add_mock_guest (guest_user, session_tag);
120
wait_for_signal (guest, "notify::guest-is-logged-in");
121
ASSERT_TRUE (indicator_session_guest_is_allowed (guest));
122
ASSERT_TRUE (indicator_session_guest_is_logged_in (guest));
123
g_object_get (guest, INDICATOR_SESSION_GUEST_PROPERTY_LOGGED_IN, &b,NULL);
125
ASSERT_FALSE (indicator_session_guest_is_active (guest));
127
// Log the Guest User out
128
// and confirm that guest's is_login changes to false
129
login1_manager->remove_session (login1_seat, session_tag);
130
accounts->remove_user (guest_user);
132
wait_for_signal (guest, "notify::guest-is-logged-in");
133
ASSERT_TRUE (indicator_session_guest_is_allowed (guest));
134
ASSERT_FALSE (indicator_session_guest_is_logged_in (guest));
135
g_object_get (guest, INDICATOR_SESSION_GUEST_PROPERTY_LOGGED_IN, &b,NULL);
137
ASSERT_FALSE (indicator_session_guest_is_active (guest));
141
* Activate a Guest session, then activate a different session.
142
* Confirm that "guest" reflects the changes.
144
TEST_F (Guest, Active)
147
const int user_session_tag = login1_seat->active_session();
149
dm_seat->set_guest_allowed (true);
150
MockUser * guest_user;
151
int guest_session_tag;
152
add_mock_guest (guest_user, guest_session_tag);
154
// Activate the guest session
155
// and confirm that guest's is_active changes to true
156
login1_seat->activate_session (guest_session_tag);
157
wait_for_signal (guest, "notify::guest-is-active-session");
158
ASSERT_TRUE (indicator_session_guest_is_allowed (guest));
159
ASSERT_TRUE (indicator_session_guest_is_logged_in (guest));
160
ASSERT_TRUE (indicator_session_guest_is_active (guest));
161
g_object_get (guest, INDICATOR_SESSION_GUEST_PROPERTY_ACTIVE, &b,NULL);
164
// Activate a non-guest session
165
// and confirm that guest's is_active changes to false
166
login1_seat->activate_session (user_session_tag);
167
wait_for_signal (guest, "notify::guest-is-active-session");
168
ASSERT_TRUE (indicator_session_guest_is_allowed (guest));
169
ASSERT_TRUE (indicator_session_guest_is_logged_in (guest));
170
ASSERT_FALSE (indicator_session_guest_is_active (guest));
171
g_object_get (guest, INDICATOR_SESSION_GUEST_PROPERTY_ACTIVE, &b,NULL);
176
* Activate a guest session using the "guest" API.
177
* Confirm that the guest session gets activated on the bus.
179
TEST_F (Guest, Activate)
181
dm_seat->set_guest_allowed (true);
182
wait_for_signal (guest, "notify::guest-is-allowed");
184
MockUser * guest_user;
185
int guest_session_tag;
186
add_mock_guest (guest_user, guest_session_tag);
188
indicator_session_guest_switch_to_guest (guest);
190
wait_for_signal (login1_seat->skeleton(), "notify::active-session");
191
ASSERT_EQ (guest_session_tag, login1_seat->active_session());