2 * Copyright (C) 2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18#include "MockController.h"
19#include "UsersModel.h"
21#include <QLightDM/UsersModel>
24class GreeterUsersModelTest : public QObject
29 static int findName(QAbstractItemModel *model, const QString &name)
31 for (int i = 0; i < model->rowCount(QModelIndex()); i++) {
32 if (model->data(model->index(i, 0), QLightDM::UsersModel::NameRole).toString() == name) {
39 static QString getStringValue(QAbstractItemModel *model, const QString &name, int role)
41 int i = findName(model, name);
42 return model->data(model->index(i, 0), role).toString();
48 model = new UsersModel();
61 QLightDM::MockController::instance()->reset();
64 void testMangleColor()
66 auto background = getStringValue(model, "color-background", QLightDM::UsersModel::BackgroundPathRole);
67 QVERIFY(background == "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#E95420'/></svg>");
70 void testMangleEmptyName()
72 auto name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
73 QVERIFY(name == "empty-name");
78 // sanity check that it doesn't start already present
79 QCOMPARE(findName(model, QStringLiteral("*guest")), -1);
81 QLightDM::MockController::instance()->setHasGuestAccountHint(true);
83 int i = findName(model, QStringLiteral("*guest"));
86 auto realName = model->data(i, QLightDM::UsersModel::RealNameRole).toString();
87 QCOMPARE(realName, QStringLiteral("Guest Session"));
89 auto loggedIn = model->data(i, QLightDM::UsersModel::LoggedInRole).toBool();
92 auto session = model->data(i, QLightDM::UsersModel::SessionRole).toString();
93 QCOMPARE(session, Greeter::instance()->defaultSessionHint());
98 // sanity check that it doesn't start already present
99 QCOMPARE(findName(model, QStringLiteral("*other")), -1);
101 QLightDM::MockController::instance()->setShowManualLoginHint(true);
103 int i = findName(model, QStringLiteral("*other"));
106 auto realName = model->data(i, QLightDM::UsersModel::RealNameRole).toString();
107 QCOMPARE(realName, QStringLiteral("Login"));
109 auto loggedIn = model->data(i, QLightDM::UsersModel::LoggedInRole).toBool();
112 auto session = model->data(i, QLightDM::UsersModel::SessionRole).toString();
113 QCOMPARE(session, Greeter::instance()->defaultSessionHint());
117 void testEmptySession()
119 int i = findName(model, QStringLiteral("no-session"));
122 // A valid test as 'no-session' is instantiated with it's
123 // SessionRole as an empty string. This ensures something,
124 // hopefully sensical, is returned.
125 auto session = model->data(i, QLightDM::UsersModel::SessionRole);
126 QCOMPARE(session.toString().isEmpty(), false);
131 QLightDM::MockController::instance()->setHideUsersHint(true);
133 QCOMPARE(model->count(), 1);
134 auto name = model->data(0, QLightDM::UsersModel::NameRole).toString();
135 QCOMPARE(name, QStringLiteral("*other"));
138 void testHideUsersWithGuest()
140 QLightDM::MockController::instance()->setHideUsersHint(true);
141 QLightDM::MockController::instance()->setHasGuestAccountHint(true);
143 QCOMPARE(model->count(), 1);
144 auto name = model->data(0, QLightDM::UsersModel::NameRole).toString();
145 QCOMPARE(name, QStringLiteral("*guest"));
148 void testCustomEntriesAreLast()
150 QLightDM::MockController::instance()->setHasGuestAccountHint(true);
151 QLightDM::MockController::instance()->setShowManualLoginHint(true);
153 QVERIFY(model->count() > 2);
155 int manualIndex = findName(model, QStringLiteral("*other"));
156 QCOMPARE(manualIndex, model->count() - 2);
158 int guestIndex = findName(model, QStringLiteral("*guest"));
159 QCOMPARE(guestIndex, model->count() - 1);
163 UsersModel *model = nullptr;
166QTEST_MAIN(GreeterUsersModelTest)
168#include "usersmodel.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list