319
318
void check_header (const char * expected_label, const char * expected_icon, const char * expected_a11y)
321
GVariant * state = g_action_group_get_action_state (G_ACTION_GROUP(action_group), "_header");
322
ASSERT_TRUE (state != NULL);
323
ASSERT_TRUE (g_variant_is_of_type (state, G_VARIANT_TYPE ("a{sv}")));
321
const gchar * label = NULL;
322
const gchar * icon = NULL;
323
const gchar * a11y = NULL;
326
variant = g_action_group_get_action_state (G_ACTION_GROUP(action_group), "_header");
327
g_variant_get (variant, "(&s&s&sb)", &label, &icon, &a11y, &visible);
325
329
if (expected_label != NULL)
327
GVariant * v = g_variant_lookup_value (state, "label", G_VARIANT_TYPE_STRING);
328
if (!v) // if no label in the state, expected_label must be an empty string
329
ASSERT_FALSE (*expected_label);
331
ASSERT_STREQ (expected_label, g_variant_get_string (v, NULL));
330
ASSERT_STREQ (expected_label, label);
332
if (expected_icon != NULL)
333
ASSERT_STREQ (expected_icon, icon);
334
335
if (expected_a11y != NULL)
336
GVariant * v = g_variant_lookup_value (state, "accessible-desc", G_VARIANT_TYPE_STRING);
337
ASSERT_TRUE (v != NULL);
338
ASSERT_STREQ (expected_a11y, g_variant_get_string (v, NULL));
342
if (expected_icon != NULL)
344
GVariant * v = g_variant_lookup_value (state, "icon", NULL);
345
GIcon * expected = g_themed_icon_new_with_default_fallbacks (expected_icon);
346
GIcon * actual = g_icon_deserialize (v);
347
ASSERT_TRUE (g_icon_equal (expected, actual));
348
g_object_unref (actual);
349
g_object_unref (expected);
336
ASSERT_STREQ (expected_a11y, a11y);
353
338
// the session menu is always visible...
354
gboolean visible = false;
355
g_variant_lookup (state, "visible", "b", &visible);
356
339
ASSERT_TRUE (visible);
358
g_variant_unref (state);
341
g_variant_unref (variant);
361
344
void check_label (const char * expected_label, GMenuModel * model, int pos)
504
487
bool confirm = confirm_supported && !confirm_disabled;
506
489
// confirm that the ellipsis are correct
507
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));
490
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-greeter"));
508
491
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));
509
492
if (action_menuitem_exists ("indicator.reboot"))
510
493
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.reboot"));
538
521
bool confirm = confirm_supported && !confirm_disabled;
540
523
// confirm that the ellipsis are correct
541
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));
524
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-greeter"));
542
525
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));
543
526
if (action_menuitem_exists ("indicator.reboot"))
544
527
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.reboot"));
570
553
ASSERT_TRUE (find_menu_item_for_action ("indicator.about", NULL, NULL));
571
554
ASSERT_TRUE (find_menu_item_for_action ("indicator.help", NULL, NULL));
572
555
ASSERT_TRUE (find_menu_item_for_action ("indicator.settings", NULL, NULL));
573
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", NULL, NULL));
556
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-greeter", NULL, NULL));
574
557
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-guest", NULL, NULL));
575
558
ASSERT_TRUE (find_menu_item_for_action ("indicator.logout", NULL, NULL));
576
559
ASSERT_TRUE (find_menu_item_for_action ("indicator.suspend", NULL, NULL));
606
589
ASSERT_TRUE (find_menu_item_for_action ("indicator.online-accounts", &model, &pos));
607
590
g_clear_object (&model);
609
// check that the service has a corresponding action
610
ASSERT_TRUE (g_action_group_has_action (G_ACTION_GROUP(action_group), "online-accounts"));
611
ASSERT_TRUE (g_action_group_get_action_enabled (G_ACTION_GROUP(action_group), "online-accounts"));
613
// confirm that activating the action is handled by the service
614
g_action_group_activate_action (G_ACTION_GROUP(action_group), "online-accounts", NULL);
615
wait_for_signal (mock_settings, "changed::last-command");
616
check_last_command_is ("online-accounts");
618
592
// check that the header's icon and a11y adjusted to the error state
619
593
check_header ("", "system-devices-panel-alert", "System (Attention Required)");
683
657
// Find the switcher menu model.
684
// In BackendMock's default setup, it will only have two menuitems: lockswitch & guest
658
// In BackendMock's default setup, it will only two menuitems: greeter & guest
686
660
GMenuModel * switch_menu = 0;
687
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos));
661
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-greeter", &switch_menu, &pos));
688
662
ASSERT_EQ (0, pos);
689
663
ASSERT_EQ (2, g_menu_model_get_n_items (switch_menu));
690
664
g_clear_object (&switch_menu);
709
683
wait_for_menu_resync ();
711
685
// now there should be 7 menuitems: greeter + guest + the five doctors
712
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos));
686
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-greeter", &switch_menu, &pos));
713
687
ASSERT_EQ (0, pos);
714
688
ASSERT_EQ (7, g_menu_model_get_n_items (switch_menu));
715
689
// confirm that the doctor names are sorted
727
701
wait_for_menu_resync ();
729
703
// now there should be 5 menuitems: greeter + guest + the three doctors
730
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos));
704
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-greeter", &switch_menu, &pos));
731
705
ASSERT_EQ (0, pos);
732
706
ASSERT_EQ (5, g_menu_model_get_n_items (switch_menu));
733
707
// confirm that the doctor names are sorted
744
718
wait_for_menu_resync ();
746
720
// now there should be 5 menuitems: greeter + guest + the three doctors
747
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos));
721
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-greeter", &switch_menu, &pos));
748
722
ASSERT_EQ (0, pos);
749
723
ASSERT_EQ (5, g_menu_model_get_n_items (switch_menu));
750
724
g_clear_object (&switch_menu);
770
744
g_object_get (service, "max-users", &max_users, NULL);
771
745
ASSERT_EQ (2, max_users);
772
746
wait_for_menu_resync ();
773
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos));
747
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-greeter", &switch_menu, &pos));
774
748
ASSERT_EQ (0, pos);
775
749
ASSERT_EQ (4, g_menu_model_get_n_items (switch_menu));
776
750
check_label ("First Doctor", switch_menu, 2);
800
774
users[10]->is_logged_in = true;
801
775
indicator_session_users_changed (mock_users, users[10]->uid);
802
776
wait_for_menu_resync ();
803
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos));
777
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-greeter", &switch_menu, &pos));
804
778
ASSERT_EQ (0, pos);
805
779
ASSERT_EQ (9, g_menu_model_get_n_items (switch_menu));
806
780
check_label ("Eleventh Doctor", switch_menu, 2);
819
793
wait_for_signal (mock_settings, "changed::last-command");
820
794
check_last_command_is ("switch-to-user::tbaker");
823
TEST_F (ServiceTest, UserLabels)
826
GMenuModel * switch_menu = 0;
828
// Check label uses username when real name is blank
829
IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
831
u->user_name = g_strdup ("blank");
832
u->real_name = g_strdup ("");
833
indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
834
wait_for_menu_resync ();
835
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos));
836
check_label ("blank", switch_menu, 2);
837
g_clear_object (&switch_menu);
838
indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), 100);
840
// Check label uses username when real name is all whitespace
841
u = g_new0 (IndicatorSessionUser, 1);
843
u->user_name = g_strdup ("whitespace");
844
u->real_name = g_strdup (" ");
845
indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
846
wait_for_menu_resync ();
847
ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos));
848
check_label ("whitespace", switch_menu, 2);
849
g_clear_object (&switch_menu);
850
indicator_session_users_mock_remove_user (INDICATOR_SESSION_USERS_MOCK(mock_users), 100);