65
void compare_user (const IndicatorSessionUser * isu,
65
void compare_user (const MockUser * mu, const IndicatorSessionUser * isu, const std::string& user_state)
70
ASSERT_TRUE (isu != 0);
71
ASSERT_TRUE (mu != 0);
67
ASSERT_EQ (user_state, login1_seat->user_state (mu->uid()));
73
68
ASSERT_EQ (mu->uid(), isu->uid);
74
69
ASSERT_EQ (mu->login_frequency(), isu->login_frequency);
75
70
ASSERT_STREQ (mu->username(), isu->user_name);
76
71
ASSERT_STREQ (mu->realname(), isu->real_name);
77
ASSERT_EQ (is_logged_in, isu->is_logged_in);
78
ASSERT_EQ (is_current_user, isu->is_current_user);
79
// FIXME: test icon file?
72
ASSERT_EQ (mu->uid(), isu->uid);
73
ASSERT_EQ (user_state!="offline", isu->is_logged_in);
74
ASSERT_EQ (user_state=="active", isu->is_current_user);
82
void compare_user (const std::string & key,
77
void compare_user (const MockUser * mu, const std::string& key, const std::string& user_state)
87
79
IndicatorSessionUser * isu;
88
80
isu = indicator_session_users_get_user (users, key.c_str());
89
compare_user (isu, mu, is_logged_in, is_current_user);
81
compare_user (mu, isu, user_state);
90
82
indicator_session_user_free (isu);
189
177
ASSERT_EQ (0, event_keys.size());
190
178
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_ADDED, 1);
191
179
ASSERT_EQ (1, event_keys.size());
192
IndicatorSessionUser * isu = indicator_session_users_get_user (users, event_keys[0].c_str());
193
ASSERT_EQ (mu->uid(), isu->uid);
194
indicator_session_user_free (isu);
196
compare_user (event_keys[0], mu, false, false);
180
compare_user (mu, event_keys[0], "offline");
266
248
// The fist doctor logs in.
267
249
// Confirm that 'users' notices.
268
250
MockUser * mu = accounts->find_by_username ("whartnell");
269
compare_user (mu->path(), mu, false, false);
270
MockConsoleKitSession * session = ck_seat->add_session_by_user (mu);
251
ASSERT_EQ (login1_seat->user_state (mu->uid()), "offline");
252
const int session_tag = login1_manager->add_session (login1_seat, mu);
271
253
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 1);
272
ASSERT_STREQ (mu->path(), event_keys[0].c_str());
273
compare_user (mu->path(), mu, true, false);
254
ASSERT_EQ (1, event_keys.size());
255
compare_user (mu, event_keys[0], "online");
275
// The fist doctor logs out.
257
// The first doctor logs out.
276
258
// Confirm that 'users' notices.
277
ck_seat->remove_session (session);
259
login1_manager->remove_session (login1_seat, session_tag);
278
260
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 1);
279
261
ASSERT_EQ (1, event_keys.size());
280
ASSERT_STREQ (mu->path(), event_keys[0].c_str());
281
compare_user (event_keys[0], mu, false, false);
262
compare_user (mu, event_keys[0], "offline");
289
268
TEST_F (Users, ActivateSession)
291
// The fist doctor logs in.
292
// Confirm that 'users' notices.
293
MockUser * mu = accounts->find_by_username ("whartnell");
294
compare_user (mu->path(), mu, false, false);
295
MockConsoleKitSession * session = ck_seat->add_session_by_user (mu);
270
// confirm preconditions: msmith is active, msmith is offline
271
MockUser * const whartnell = accounts->find_by_username ("whartnell");
272
ASSERT_EQ (login1_seat->user_state (whartnell->uid()), "offline");
273
MockUser * const msmith = accounts->find_by_username ("msmith");
274
ASSERT_EQ (login1_seat->user_state (msmith->uid()), "active");
276
// whartnell logs in... confirm that 'users' notices
277
login1_manager->add_session (login1_seat, whartnell);
296
278
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 1);
297
ASSERT_STREQ (mu->path(), event_keys[0].c_str());
298
compare_user (mu->path(), mu, true, false);
300
// activate the first doctor's session.
301
// confirm that 'users' sees he's active and that ck_session isn't.
302
// this should come in the form of two 'user-changed' events
303
ck_seat->activate_session (session);
304
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
305
ASSERT_EQ (2, event_keys.size());
306
compare_user (event_keys[0], ck_session->user(), true, false);
307
compare_user (event_keys[1], mu, true, true);
309
// switch back to the previous
310
// confirm that 'users' sees it's active and the first doctor's session isn't
311
// this should come in the form of two 'user-changed' events
312
ck_seat->activate_session (ck_session);
313
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
314
ASSERT_EQ (2, event_keys.size());
315
compare_user (event_keys[0], mu, true, false);
316
compare_user (event_keys[1], ck_session->user(), true, true);
279
ASSERT_EQ (1, event_keys.size());
280
compare_user (whartnell, event_keys[0], "online");
282
// activate whartnell's session... confirm that 'users' sees:
283
// 1. msmith changes from 'active' to 'online'
284
// 2. whartnell changes from 'online' to 'active'
285
login1_seat->switch_to_user (whartnell->username());
286
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
287
ASSERT_EQ (2, event_keys.size());
288
compare_user (msmith, event_keys[0], "online");
289
compare_user (whartnell, event_keys[1], "active");
292
login1_seat->switch_to_user (msmith->username());
293
wait_for_signals (users, INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, 2);
294
ASSERT_EQ (2, event_keys.size());
295
compare_user (whartnell, event_keys[0], "online");
296
compare_user (msmith, event_keys[1], "active");
320
301
* Confirm that we can change the active session via users' API.
321
302
* This is nearly the same as ActivateSession but uses users' API