on xenial help sign in
Handle a user in the greeter having never selected a session better
ca2a20eJosh Arenson
plugins/LightDM/UsersModel.cpp+5
@@ -109,6 +109,11 @@ QVariant MangleModel::data(const QModelIndex &index, int role) const
109 variantData = stringData;
109 variantData = stringData;
110 }
110 }
111
111
112+ // Workaround for liblightdm returning "" when a user has no default session
113+ if (Q_UNLIKELY(role == QLightDM::UsersModel::SessionRole && variantData.toString().isEmpty())) {
114+ variantData = Greeter::instance()->defaultSessionHint();
115+ }
116+
112 return variantData;
117 return variantData;
113}
118}
114
119
tests/mocks/liblightdm/MockUsersModel.cpp+1
@@ -186,6 +186,7 @@ void UsersModel::resetEntries()
186 { "no-background", "No Background", "", 0, false, false, "ubuntu", 0 },
186 { "no-background", "No Background", "", 0, false, false, "ubuntu", 0 },
187 { "no-password", "No Password", 0, 0, false, false, "ubuntu", 0 },
187 { "no-password", "No Password", 0, 0, false, false, "ubuntu", 0 },
188 { "no-response", "No Response", 0, 0, false, false, "ubuntu", 0 },
188 { "no-response", "No Response", 0, 0, false, false, "ubuntu", 0 },
189+ { "no-session", "No Session", 0, 0, false, false, "", 0 },
189 { "question-prompt", "Question Prompt", 0, 0, false, false, "ubuntu", 0 },
190 { "question-prompt", "Question Prompt", 0, 0, false, false, "ubuntu", 0 },
190 { "two-factor", "Two Factor", 0, 0, false, false, "ubuntu", 0 },
191 { "two-factor", "Two Factor", 0, 0, false, false, "ubuntu", 0 },
191 { "two-prompts", "Two Prompts", 0, 0, false, false, "ubuntu", 0 },
192 { "two-prompts", "Two Prompts", 0, 0, false, false, "ubuntu", 0 },
tests/plugins/LightDM/IntegratedLightDM/usersmodel.cpp+13
@@ -113,6 +113,19 @@ private Q_SLOTS:
113 QCOMPARE(session, Greeter::instance()->defaultSessionHint());
113 QCOMPARE(session, Greeter::instance()->defaultSessionHint());
114 }
114 }
115
115
116+
117+ void testEmptySession()
118+ {
119+ int i = findName(model, QStringLiteral("no-session"));
120+ QVERIFY(i >= 0);
121+
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);
127+ }
128+
116 void testHideUsers()
129 void testHideUsers()
117 {
130 {
118 QLightDM::MockController::instance()->setHideUsersHint(true);
131 QLightDM::MockController::instance()->setHideUsersHint(true);
tests/qmltests/Greeter/tst_WideView.qml+14
@@ -395,6 +395,20 @@ StyledItem {
395 waitForRendering(view);
395 waitForRendering(view);
396 }
396 }
397
397
398+ function test_sessionless_user_is_still_valid() {
399+ var loginList = findChild(view, "loginList")
400+
401+ /*
402+ * If a user has never logged in before, or, for some reason
403+ * has no sessionHint, ensure that the model returns the default
404+ * session and that the view respects this
405+ */
406+ selectUser("no-session");
407+ compare(LightDM.Users.data(loginList.currentIndex, LightDM.UserRoles.SessionRole), LightDM.Greeter.defaultSession);
408+
409+ tryCompare(loginList, "currentSession", LightDM.Greeter.defaultSession);
410+ }
411+
398 function test_changingSessionSticksToUser() {
412 function test_changingSessionSticksToUser() {
399 var loginList = findChild(view, "loginList");
413 var loginList = findChild(view, "loginList");
400
414