39
37
GCancellable * cancellable;
40
38
IndicatorSessionActions * actions;
41
GSettings * indicator_settings;
43
40
virtual void SetUp ()
48
indicator_settings = g_settings_new ("com.canonical.indicator.session");
49
45
cancellable = g_cancellable_new ();
51
47
backend_get (cancellable, &actions, NULL, NULL);
192
187
TEST_F (Actions, Reboot)
194
189
ASSERT_TRUE (login1_manager->last_action().empty());
195
ASSERT_FALSE (g_settings_get_boolean (indicator_settings, SUPPRESS_KEY));
197
191
// confirm that user is prompted
198
192
// and that no action is taken when the user cancels the dialog
213
207
ASSERT_EQ (login1_manager->last_action(), "reboot");
215
209
// confirm that we try to reboot w/o prompting
216
// if prompting is disabled
210
// if the EndSessionDialog isn't available
211
delete end_session_dialog;
212
end_session_dialog = 0;
217
213
login1_manager->clear_last_action ();
218
ASSERT_EQ ("", login1_manager->last_action());
219
g_settings_set_boolean (indicator_settings, SUPPRESS_KEY, TRUE);
221
214
ASSERT_TRUE (login1_manager->last_action().empty());
223
216
indicator_session_actions_reboot (actions);
225
ASSERT_EQ ("reboot", login1_manager->last_action());
227
g_settings_reset (indicator_settings, SUPPRESS_KEY);
218
ASSERT_EQ (login1_manager->last_action(), "reboot");
230
221
TEST_F (Actions, PowerOff)
252
243
// confirm that we try to shutdown w/o prompting
253
244
// if the EndSessionDialog isn't available
254
// if prompting is disabled
245
delete end_session_dialog;
246
end_session_dialog = 0;
255
247
login1_manager->clear_last_action ();
256
ASSERT_EQ ("", login1_manager->last_action());
257
g_settings_set_boolean (indicator_settings, SUPPRESS_KEY, TRUE);
259
249
indicator_session_actions_power_off (actions);
261
251
ASSERT_EQ (login1_manager->last_action(), "power-off");
263
g_settings_reset (indicator_settings, SUPPRESS_KEY);
266
254
TEST_F (Actions, Logout)
286
274
ASSERT_EQ (MockSessionManager::LogoutQuiet, session_manager->last_action ());
288
// confirm that we try to call SessionManager::LogoutQuet
289
// when prompts are disabled
290
login1_manager->clear_last_action ();
291
ASSERT_EQ ("", login1_manager->last_action());
292
g_settings_set_boolean (indicator_settings, SUPPRESS_KEY, TRUE);
276
// confirm that we try to call SessionManager::LogoutNormal
277
// if the EndSessionDialog isn't available
278
delete end_session_dialog;
279
end_session_dialog = 0;
294
281
indicator_session_actions_logout (actions);
296
ASSERT_EQ (MockSessionManager::LogoutQuiet, session_manager->last_action ());
298
g_settings_reset (indicator_settings, SUPPRESS_KEY);
283
ASSERT_EQ (MockSessionManager::LogoutNormal, session_manager->last_action ());
301
286
TEST_F (Actions, Suspend)
404
389
ASSERT_EQ (b, gb);
409
static gboolean toggle_suppress (gpointer settings)
411
const char * key = SUPPRESS_KEY;
412
gboolean b = g_settings_get_boolean (G_SETTINGS(settings), key);
413
g_settings_set_boolean (G_SETTINGS(settings), key, !b);
414
return G_SOURCE_REMOVE;
418
TEST_F (Actions, SuppressPrompts)
420
for (int i=0; i<3; ++i)
425
b = indicator_session_actions_can_prompt (actions);
426
b2 = !g_settings_get_boolean (indicator_settings, SUPPRESS_KEY);
429
g_idle_add (toggle_suppress, indicator_settings);
430
wait_for_signal (actions, "notify::" INDICATOR_SESSION_ACTIONS_PROP_CAN_PROMPT);
433
g_settings_reset (indicator_settings, SUPPRESS_KEY);
392
TEST_F (Actions, CanPrompt)
396
ASSERT_TRUE (indicator_session_actions_can_prompt (actions));
398
delete end_session_dialog;
399
end_session_dialog = 0;
401
ASSERT_FALSE (indicator_session_actions_can_prompt (actions));
402
g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_CAN_PROMPT, &b, NULL);
405
end_session_dialog = new MockEndSessionDialog (loop, conn);
407
ASSERT_TRUE (indicator_session_actions_can_prompt (actions));
408
g_object_get (actions, INDICATOR_SESSION_ACTIONS_PROP_CAN_PROMPT, &b, NULL);