74
74
ASSERT_EQ (user_state=="active", isu->is_current_user);
77
void compare_user (const MockUser * mu, const std::string& key, const std::string& user_state)
77
void compare_user (const MockUser * mu, guint uid, const std::string& user_state)
79
79
IndicatorSessionUser * isu;
80
isu = indicator_session_users_get_user (users, key.c_str());
80
isu = indicator_session_users_get_user (users, uid);
81
compare_user (mu, isu, user_state);
82
indicator_session_user_free (isu);
85
void compare_user (guint uid, const std::string& user_state)
87
IndicatorSessionUser * isu = indicator_session_users_get_user (users, uid);
88
MockUser * mu = accounts->find_by_uid (uid);
81
89
compare_user (mu, isu, user_state);
82
90
indicator_session_user_free (isu);
151
159
TEST_F (Users, InitialUsers)
153
GStrv keys = indicator_session_users_get_keys (users);
155
ASSERT_EQ (12, g_strv_length (keys));
157
for (int i=0; keys && keys[i]; ++i)
162
GList * uids = indicator_session_users_get_uids (users);
164
ASSERT_EQ (12, g_list_length (uids));
166
for (l=uids; l!=NULL; l=l->next)
159
IndicatorSessionUser * isu = indicator_session_users_get_user (users, keys[i]);
160
MockUser * mu = accounts->find_by_uid (isu->uid);
161
compare_user (mu, isu, login1_seat->user_state (isu->uid));
162
indicator_session_user_free (isu);
168
const guint uid = GPOINTER_TO_UINT (l->data);
169
compare_user (uid, login1_seat->user_state (uid));
188
195
MockUser * mu = accounts->find_by_username ("pdavison");
190
197
/* confirm that users knows about pdavison */
192
GStrv keys = indicator_session_users_get_keys (users);
193
ASSERT_EQ (12, g_strv_length (keys));
194
for (int i=0; !found && keys && keys[i]; i++)
196
IndicatorSessionUser * isu = indicator_session_users_get_user (users, keys[i]);
197
found = isu->uid == mu->uid();
198
indicator_session_user_free (isu);
198
IndicatorSessionUser * isu = indicator_session_users_get_user (users, mu->uid());
199
ASSERT_TRUE (isu != NULL);
200
compare_user (mu, isu, "offline");
201
g_clear_pointer (&isu, indicator_session_user_free);
203
203
/* on the bus, remove pdavison. */
204
204
accounts->remove_user (mu);
208
208
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_REMOVED, 1);
209
209
ASSERT_EQ (1, event_keys.size());
211
/* confirm that users doesn't know about pdavison */
212
keys = indicator_session_users_get_keys (users);
213
ASSERT_EQ (11, g_strv_length (keys));
214
for (int i=0; keys && keys[i]; i++)
216
IndicatorSessionUser * isu = indicator_session_users_get_user (users, keys[i]);
217
ASSERT_NE (event_keys[0], keys[i]);
218
ASSERT_NE (mu->uid(), isu->uid);
219
indicator_session_user_free (isu);
211
/* confirm that users won't give us pdavison's info */
212
isu = indicator_session_users_get_user (users, mu->uid());
213
ASSERT_TRUE (isu == NULL);
215
/* confirm that users won't give us pdavison's uid */
216
GList * uids = indicator_session_users_get_uids (users);
217
ASSERT_TRUE (g_list_find (uids, GUINT_TO_POINTER(mu->uid())) == NULL);
296
293
compare_user (msmith, event_keys[1], "active");
301
297
* Confirm that we can change the active session via users' API.
302
298
* This is nearly the same as ActivateSession but uses users' API
304
300
TEST_F (Users, ActivateUser)
306
// The fist doctor logs in.
307
// Confirm that 'users' notices.
308
MockUser * mu = accounts->find_by_username ("whartnell");
309
compare_user (mu->path(), mu, false, false);
310
MockConsoleKitSession * session = ck_seat->add_session_by_user (mu);
302
// confirm preconditions: msmith is active, msmith is offline
303
MockUser * const whartnell = accounts->find_by_username ("whartnell");
304
ASSERT_EQ (login1_seat->user_state (whartnell->uid()), "offline");
305
MockUser * const msmith = accounts->find_by_username ("msmith");
306
ASSERT_EQ (login1_seat->user_state (msmith->uid()), "active");
308
// whartnell logs in... confirm that 'users' notices
309
login1_manager->add_session (login1_seat, whartnell);
311
310
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 1);
312
ASSERT_STREQ (mu->path(), event_keys[0].c_str());
313
compare_user (mu->path(), mu, true, false);
315
// activate the first doctor's session.
316
// confirm that 'users' sees he's active and that ck_session isn't.
317
// this should come in the form of two 'user-changed' events
318
indicator_session_users_activate_user (users, mu->path());
319
ck_seat->activate_session (session);
320
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
321
ASSERT_EQ (2, event_keys.size());
322
compare_user (event_keys[0], ck_session->user(), true, false);
323
compare_user (event_keys[1], mu, true, true);
325
// switch back to the previous
326
// confirm that 'users' sees it's active and the first doctor's session isn't
327
// this should come in the form of two 'user-changed' events
328
indicator_session_users_activate_user (users, ck_session->user()->path());
329
ck_seat->activate_session (ck_session);
330
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
331
ASSERT_EQ (2, event_keys.size());
332
compare_user (event_keys[0], mu, true, false);
333
compare_user (event_keys[1], ck_session->user(), true, true);
311
ASSERT_EQ (1, event_keys.size());
312
compare_user (whartnell, event_keys[0], "online");
314
// activate whartnell's session... confirm that 'users' sees:
315
// 1. msmith changes from 'active' to 'online'
316
// 2. whartnell changes from 'online' to 'active'
317
indicator_session_users_activate_user (users, whartnell->uid());
318
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
319
ASSERT_EQ (2, event_keys.size());
320
compare_user (msmith, event_keys[0], "online");
321
compare_user (whartnell, event_keys[1], "active");
324
indicator_session_users_activate_user (users, msmith->uid());
325
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
326
ASSERT_EQ (2, event_keys.size());
327
compare_user (whartnell, event_keys[0], "online");
328
compare_user (msmith, event_keys[1], "active");
337
333
* Confirm that adding a Guest doesn't show up in the users list