@@ -14,6 +14,8 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17+#include "Greeter.h"
18+#include "MockController.h"
1719#include "UsersModel.h"
1820
1921#include <QLightDM/UsersModel>
@@ -40,17 +42,25 @@ private:
4042 return model->data(model->index(i, 0), role).toString();
4143 }
4244
45+ void recreateModel()
46+ {
47+ if (model) {
48+ delete model;
49+ }
50+ model = new UsersModel();
51+ QVERIFY(model);
52+ }
53+
4354private Q_SLOTS:
4455
4556 void init()
4657 {
47− model = new UsersModel();
48− QVERIFY(model);
58+ recreateModel();
4959 }
5060
5161 void cleanup()
5262 {
53− delete model;
63+ QLightDM::MockController::instance()->reset();
5464 }
5565
5666 void testMangleColor()
@@ -65,8 +75,30 @@ private Q_SLOTS:
6575 QVERIFY(name == "empty-name");
6676 }
6777
78+ void testHasGuest()
79+ {
80+ // sanity check that it doesn't start already present
81+ QCOMPARE(findName(model, QStringLiteral("*guest")), -1);
82+
83+ QLightDM::MockController::instance()->setHasGuestAccountHint(true);
84+ recreateModel();
85+
86+ int i = findName(model, QStringLiteral("*guest"));
87+ QVERIFY(i >= 0);
88+ QCOMPARE(i, model->count() - 1);
89+
90+ auto realName = model->data(i, QLightDM::UsersModel::RealNameRole).toString();
91+ QCOMPARE(realName, QStringLiteral("Guest Session"));
92+
93+ auto loggedIn = model->data(i, QLightDM::UsersModel::LoggedInRole).toBool();
94+ QVERIFY(!loggedIn);
95+
96+ auto session = model->data(i, QLightDM::UsersModel::SessionRole).toString();
97+ QCOMPARE(session, Greeter::instance()->defaultSessionHint());
98+ }
99+
68100private:
69− UsersModel *model;
101+ UsersModel *model = nullptr;
70102};
71103
72104QTEST_MAIN(GreeterUsersModelTest)