~codygarver/+junk/ind-sess

« back to all changes in this revision

Viewing changes to tests/backend-dbus/test-guest.cc

  • Committer: Cody Garver
  • Date: 2014-04-03 17:08:08 UTC
  • Revision ID: cody@elementaryos.org-20140403170808-z56s93rorb1dzvmk
Initial import, version 12.10.5+14.04.20140324-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *   Charles Kerr <charles.kerr@canonical.com>
 
6
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
#include "gtest-mock-dbus-fixture.h"
 
21
 
 
22
#include "backend.h"
 
23
#include "backend-dbus/backend-dbus.h"
 
24
 
 
25
/***
 
26
****
 
27
***/
 
28
 
 
29
class Guest: public GTestMockDBusFixture
 
30
{
 
31
  private:
 
32
 
 
33
    typedef GTestMockDBusFixture super;
 
34
 
 
35
  protected:
 
36
 
 
37
    GCancellable * cancellable;
 
38
    IndicatorSessionGuest * guest;
 
39
 
 
40
    virtual void SetUp ()
 
41
    {
 
42
      super :: SetUp ();
 
43
 
 
44
      // get the guest-dbus
 
45
      cancellable = g_cancellable_new ();
 
46
      guest = 0;
 
47
      backend_get (cancellable, NULL, NULL, &guest);
 
48
      wait_msec (100);
 
49
 
 
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));
 
55
    }
 
56
 
 
57
    virtual void TearDown ()
 
58
    {
 
59
      g_cancellable_cancel (cancellable);
 
60
      g_clear_object (&cancellable);
 
61
      g_clear_object (&guest); 
 
62
 
 
63
      super :: TearDown ();
 
64
    }
 
65
 
 
66
  protected:
 
67
 
 
68
    void add_mock_guest (MockUser               *& guest_user,
 
69
                         int                     & guest_session_tag)
 
70
    {
 
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);
 
75
    }
 
76
};
 
77
 
 
78
/**
 
79
 * Confirms that the Fixture's SetUp() and TearDown() work
 
80
 */
 
81
TEST_F (Guest, HelloWorld)
 
82
{
 
83
  ASSERT_TRUE (true);
 
84
}
 
85
 
 
86
/**
 
87
 * Toggle in the DM whether or not guests are allowed.
 
88
 * Confirm that "guest" reflects the changes.
 
89
 */
 
90
TEST_F (Guest, Allowed)
 
91
{
 
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));
 
97
 
 
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));
 
103
}
 
104
 
 
105
/**
 
106
 * Have a guest user log in & out.
 
107
 * Confirm that "guest" reflects the changes.
 
108
 */
 
109
TEST_F (Guest, Login)
 
110
{
 
111
  gboolean b;
 
112
 
 
113
  dm_seat->set_guest_allowed (true);
 
114
 
 
115
  // Log a Guest in
 
116
  // And confirm that guest's is_login changes to true
 
117
  MockUser * guest_user;
 
118
  int session_tag;
 
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);
 
124
  ASSERT_TRUE (b);
 
125
  ASSERT_FALSE (indicator_session_guest_is_active (guest));
 
126
 
 
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);
 
131
  delete 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);
 
136
  ASSERT_FALSE (b);
 
137
  ASSERT_FALSE (indicator_session_guest_is_active (guest));
 
138
}
 
139
 
 
140
/**
 
141
 * Activate a Guest session, then activate a different session.
 
142
 * Confirm that "guest" reflects the changes.
 
143
 */
 
144
TEST_F (Guest, Active)
 
145
{
 
146
  gboolean b;
 
147
  const int user_session_tag = login1_seat->active_session();
 
148
 
 
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);
 
153
 
 
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);
 
162
  ASSERT_TRUE (b);
 
163
 
 
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);
 
172
  ASSERT_FALSE (b);
 
173
}
 
174
 
 
175
/**
 
176
 * Activate a guest session using the "guest" API.
 
177
 * Confirm that the guest session gets activated on the bus.
 
178
 */
 
179
TEST_F (Guest, Activate)
 
180
{
 
181
  dm_seat->set_guest_allowed (true);
 
182
  wait_for_signal (guest, "notify::guest-is-allowed");
 
183
 
 
184
  MockUser * guest_user;
 
185
  int guest_session_tag;
 
186
  add_mock_guest (guest_user, guest_session_tag);
 
187
 
 
188
  indicator_session_guest_switch_to_guest (guest);
 
189
 
 
190
  wait_for_signal (login1_seat->skeleton(), "notify::active-session");
 
191
  ASSERT_EQ (guest_session_tag, login1_seat->active_session());
 
192
  wait_msec (50);
 
193
}