on xenial help sign in
Let tests pass again
commite5a20912d645791707e81c5c5cecc7e64ae85545 authorMichael Terry <mike@mterry.name> dateThu 12 Jan 2017, 11:49 (10 years ago) parent123d061
3 files changed+55−22
plugins/LightDM/UsersModel.cpp+51−20 tests/mocks/liblightdm/MockUsersModel.cpp+2 tests/qmltests/Greeter/tst_Greeter.qml+2−2
plugins/LightDM/UsersModel.cpp+51−20
@@ -44,41 +44,50 @@ private:
4444 QString realName;
4545 };
4646
47− void addCustomRow(const CustomRow &newRow);
48− void removeCustomRow(const QString &rowName);
47+ int sourceRowCount() const;
48+
4949 void updateGuestRow();
5050 void updateManualRow();
51+ void updateCustomRows();
52+
53+ void addCustomRow(const CustomRow &newRow);
54+ void removeCustomRow(const QString &rowName);
5155
5256 QList<CustomRow> m_customRows;
57+ bool m_updatingCustomRows;
5358};
5459
5560MangleModel::MangleModel(QObject* parent)
5661 : QIdentityProxyModel(parent)
62+ , m_updatingCustomRows(false)
5763{
58− if (!Greeter::instance()->hideUsersHint()) {
59− setSourceModel(new QLightDM::UsersModel(this));
60− }
64+ setSourceModel(new QLightDM::UsersModel(this));
6165
62− updateGuestRow();
63− updateManualRow();
66+ updateCustomRows();
6467
65− // Would be nice if there were a rowCountChanged signal in the base class
68+ // Would be nice if there were a rowCountChanged signal in the base class.
69+ // We redo all custom rows on any row count change, because (A) some of
70+ // custom rows (manual login) use row count information and (B) when
71+ // testing, we use a modelReset signal as a way to indicate that a custom
72+ // row has been toggled off or on.
6673 connect(this, &QIdentityProxyModel::modelReset,
67− this, &MangleModel::updateManualRow);
74+ this, &MangleModel::updateCustomRows);
6875 connect(this, &QIdentityProxyModel::rowsInserted,
69− this, &MangleModel::updateManualRow);
76+ this, &MangleModel::updateCustomRows);
7077 connect(this, &QIdentityProxyModel::rowsRemoved,
71− this, &MangleModel::updateManualRow);
78+ this, &MangleModel::updateCustomRows);
7279}
7380
7481QVariant MangleModel::data(const QModelIndex &index, int role) const
7582{
7683 QVariant variantData;
7784
78− bool isCustomRow = index.row() >= sourceModel()->rowCount() &&
79− index.row() < rowCount();
85+ if (index.row() >= rowCount())
86+ return QVariant();
87+
88+ bool isCustomRow = index.row() >= sourceRowCount();
8089 if (isCustomRow && index.column() == 0) {
81− int customIndex = index.row() - sourceModel()->rowCount();
90+ int customIndex = index.row() - sourceRowCount();
8291 if (role == QLightDM::UsersModel::NameRole) {
8392 variantData = m_customRows[customIndex].name;
8493 } else if (role == QLightDM::UsersModel::RealNameRole) {
@@ -120,7 +129,7 @@ void MangleModel::removeCustomRow(const QString &rowName)
120129{
121130 for (int i = 0; i < m_customRows.size(); i++) {
122131 if (m_customRows[i].name == rowName) {
123− int rowNum = sourceModel()->rowCount() + i;
132+ int rowNum = sourceRowCount() + i;
124133 beginRemoveRows(QModelIndex(), rowNum, rowNum);
125134 m_customRows.removeAt(i);
126135 endRemoveRows();
@@ -131,7 +140,7 @@ void MangleModel::removeCustomRow(const QString &rowName)
131140
132141void MangleModel::updateManualRow()
133142{
134− bool hasAnotherEntry = sourceModel()->rowCount() > 0;
143+ bool hasAnotherEntry = sourceRowCount() > 0;
135144 for (int i = 0; !hasAnotherEntry && i < m_customRows.size(); i++) {
136145 if (m_customRows[i].name != QStringLiteral("*other")) {
137146 hasAnotherEntry = true;
@@ -153,16 +162,38 @@ void MangleModel::updateGuestRow()
153162 removeCustomRow(QStringLiteral("*guest"));
154163}
155164
165+void MangleModel::updateCustomRows()
166+{
167+ // We update when rowCount changes, but we also insert/remove rows here.
168+ // So guard this function to avoid recursion.
169+ if (m_updatingCustomRows)
170+ return;
171+
172+ m_updatingCustomRows = true;
173+ updateGuestRow();
174+ updateManualRow();
175+ m_updatingCustomRows = false;
176+}
177+
156178int MangleModel::rowCount(const QModelIndex &parent) const
157179{
158− return QIdentityProxyModel::rowCount(parent) +
159− (parent.isValid() ? 0 : m_customRows.size());
180+ if (parent.isValid())
181+ return 0;
182+ else
183+ return sourceRowCount() + m_customRows.size();
184+}
185+
186+int MangleModel::sourceRowCount() const
187+{
188+ return Greeter::instance()->hideUsersHint() ? 0 : sourceModel()->rowCount();
160189}
161190
162191QModelIndex MangleModel::index(int row, int column, const QModelIndex &parent) const
163192{
164− bool isCustomRow = row >= sourceModel()->rowCount() &&
165− row < rowCount();
193+ if (row >= rowCount())
194+ return QModelIndex();
195+
196+ bool isCustomRow = row >= sourceRowCount();
166197 if (isCustomRow && !parent.isValid()) {
167198 return createIndex(row, column);
168199 } else {
tests/mocks/liblightdm/MockUsersModel.cpp+2
@@ -69,6 +69,8 @@ UsersModel::UsersModel(QObject *parent)
6969 this, &UsersModel::resetEntries);
7070 connect(MockController::instance(), &MockController::showManualLoginHintChanged,
7171 this, &UsersModel::resetEntries);
72+ connect(MockController::instance(), &MockController::hideUsersHintChanged,
73+ this, &UsersModel::resetEntries);
7274 connect(MockController::instance(), &MockController::userModeChanged,
7375 this, &UsersModel::resetEntries);
7476 resetEntries();
tests/qmltests/Greeter/tst_Greeter.qml+2−2
@@ -201,7 +201,7 @@ Item {
201201 var i = getIndexOf(name);
202202 compare(view.currentIndex, i);
203203 compare(AccountsService.user, name);
204− if (name === "*guest") // guest has no authenticationUser set
204+ if (name[0] === "*") // custom rows have no authenticationUser set
205205 compare(LightDM.Greeter.authenticationUser, "");
206206 else
207207 compare(LightDM.Greeter.authenticationUser, name);
@@ -612,7 +612,7 @@ Item {
612612 verify(!view.locked);
613613 }
614614
615− function test_hasManualLoginHint() {
615+ function test_showManualLoginHint() {
616616 LightDMController.showManualLoginHint = true;
617617 resetLoader();
618618 var i = selectUser("*other");